From 2bdfc092d40daaf1af87a4cc2285caa63f35e9d3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 3 Oct 2017 11:45:56 +0200 Subject: core: don't track route metric in ip-config It's not needed. Whenever we add a route, we pass in the route metric (for example, based on the device's configuration). No need to merge and track it into the NMIP4Config/NMIP6Config. The metric was only used in nm_ip4_config_create_setting() and nm_ip6_config_create_setting(). In fact it's wrong to do that, because it means we first capture some settings, and guess the configured route metric. But we cannot do that. Our best guess what a configured setting might be is -1. --- src/nm-ip4-config.c | 33 --------------------------------- src/nm-ip4-config.h | 1 - src/nm-ip6-config.c | 33 --------------------------------- src/nm-ip6-config.h | 1 - 4 files changed, 68 deletions(-) diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 101b3b0fbc..b80ff8cc11 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -295,7 +295,6 @@ typedef struct { int ifindex; NMIPConfigSource mtu_source; gint dns_priority; - gint64 route_metric; GArray *nameservers; GPtrArray *domains; GPtrArray *searches; @@ -643,10 +642,6 @@ nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i _add_route (self, plobj, NULL, NULL); } - /* we detect the route metric based on the default route. All non-default - * routes have their route metrics explicitly set. */ - priv->route_metric = priv->has_gateway ? (gint64) lowest_metric : (gint64) -1; - /* If the interface has the default route, and has IPv4 addresses, capture * nameservers from /etc/resolv.conf. */ @@ -880,9 +875,6 @@ nm_ip4_config_merge_setting (NMIP4Config *self, nm_ip4_config_set_gateway (self, gateway); } - if (priv->route_metric == -1) - priv->route_metric = nm_setting_ip_config_get_route_metric (setting); - /* Addresses */ for (i = 0; i < naddresses; i++) { NMIPAddress *s_addr = nm_setting_ip_config_get_address (setting, i); @@ -974,7 +966,6 @@ nm_ip4_config_create_setting (const NMIP4Config *self) guint nnameservers, nsearches, noptions; const char *method = NULL; int i; - gint64 route_metric; NMDedupMultiIter ipconf_iter; const NMPlatformIP4Address *address; const NMPlatformIP4Route *route; @@ -992,7 +983,6 @@ nm_ip4_config_create_setting (const NMIP4Config *self) nnameservers = nm_ip4_config_get_num_nameservers (self); nsearches = nm_ip4_config_get_num_searches (self); noptions = nm_ip4_config_get_num_dns_options (self); - route_metric = nm_ip4_config_get_route_metric (self); /* Addresses */ nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, self, &address) { @@ -1030,7 +1020,6 @@ nm_ip4_config_create_setting (const NMIP4Config *self) g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, method, - NM_SETTING_IP_CONFIG_ROUTE_METRIC, (gint64) route_metric, NULL); /* Routes */ @@ -1117,11 +1106,6 @@ nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src, NMIPConfigMergeFl _add_route (dst, ipconf_iter.current->obj, NULL, NULL); } - if (dst_priv->route_metric == -1) - dst_priv->route_metric = src_priv->route_metric; - else if (src_priv->route_metric != -1) - dst_priv->route_metric = MIN (dst_priv->route_metric, src_priv->route_metric); - /* domains */ if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { for (i = 0; i < nm_ip4_config_get_num_domains (src); i++) @@ -1320,8 +1304,6 @@ nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src) if (!nm_ip4_config_get_num_addresses (dst)) nm_ip4_config_unset_gateway (dst); - /* ignore route_metric */ - /* routes */ changed = FALSE; changed_default_route = FALSE; @@ -1431,7 +1413,6 @@ nm_ip4_config_intersect (NMIP4Config *dst, const NMIP4Config *src) if (changed) _notify_addresses (dst); - /* ignore route_metric */ /* ignore nameservers */ /* default gateway */ @@ -1537,11 +1518,6 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev has_relevant_changes = TRUE; } - if (src_priv->route_metric != dst_priv->route_metric) { - dst_priv->route_metric = src_priv->route_metric; - has_minor_changes = TRUE; - } - /* addresses */ head_entry_src = nm_ip4_config_lookup_addresses (src); nm_dedup_multi_iter_init (&ipconf_iter_src, head_entry_src); @@ -1960,14 +1936,6 @@ nm_ip4_config_get_gateway (const NMIP4Config *self) return priv->gateway; } -gint64 -nm_ip4_config_get_route_metric (const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); - - return priv->route_metric; -} - /*****************************************************************************/ void @@ -3092,7 +3060,6 @@ nm_ip4_config_init (NMIP4Config *self) priv->dns_options = g_ptr_array_new_with_free_func (g_free); priv->nis = g_array_new (FALSE, TRUE, sizeof (guint32)); priv->wins = g_array_new (FALSE, TRUE, sizeof (guint32)); - priv->route_metric = -1; } NMIP4Config * diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index 429c0752fe..775869cd20 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -181,7 +181,6 @@ void nm_ip4_config_set_gateway (NMIP4Config *self, guint32 gateway); void nm_ip4_config_unset_gateway (NMIP4Config *self); gboolean nm_ip4_config_has_gateway (const NMIP4Config *self); guint32 nm_ip4_config_get_gateway (const NMIP4Config *self); -gint64 nm_ip4_config_get_route_metric (const NMIP4Config *self); const NMPObject *nm_ip4_config_best_default_route_get (const NMIP4Config *self); const NMPObject *_nm_ip4_config_best_default_route_find (const NMIP4Config *self); diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 6516b8b840..75c1515acb 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -62,7 +62,6 @@ typedef struct { int ifindex; int dns_priority; NMSettingIP6ConfigPrivacy privacy; - gint64 route_metric; struct in6_addr gateway; GArray *nameservers; GPtrArray *domains; @@ -439,10 +438,6 @@ nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i _add_route (self, plobj, NULL, NULL); } - /* we detect the route metric based on the default route. All non-default - * routes have their route metrics explicitly set. */ - priv->route_metric = has_gateway ? (gint64) lowest_metric : (gint64) -1; - /* If the interface has the default route, and has IPv6 addresses, capture * nameservers from /etc/resolv.conf. */ @@ -678,9 +673,6 @@ nm_ip6_config_merge_setting (NMIP6Config *self, nm_ip6_config_set_gateway (self, &gateway); } - if (priv->route_metric == -1) - priv->route_metric = nm_setting_ip_config_get_route_metric (setting); - /* Addresses */ for (i = 0; i < naddresses; i++) { NMIPAddress *s_addr = nm_setting_ip_config_get_address (setting, i); @@ -766,7 +758,6 @@ nm_ip6_config_create_setting (const NMIP6Config *self) guint nnameservers, nsearches, noptions; const char *method = NULL; int i; - gint64 route_metric; NMDedupMultiIter ipconf_iter; const NMPlatformIP6Address *address; const NMPlatformIP6Route *route; @@ -784,7 +775,6 @@ nm_ip6_config_create_setting (const NMIP6Config *self) nnameservers = nm_ip6_config_get_num_nameservers (self); nsearches = nm_ip6_config_get_num_searches (self); noptions = nm_ip6_config_get_num_dns_options (self); - route_metric = nm_ip6_config_get_route_metric (self); /* Addresses */ nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, self, &address) { @@ -826,7 +816,6 @@ nm_ip6_config_create_setting (const NMIP6Config *self) g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, method, - NM_SETTING_IP_CONFIG_ROUTE_METRIC, (gint64) route_metric, NULL); /* Routes */ @@ -916,11 +905,6 @@ nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src, NMIPConfigMergeFl _add_route (dst, ipconf_iter.current->obj, NULL, NULL); } - if (dst_priv->route_metric == -1) - dst_priv->route_metric = src_priv->route_metric; - else if (src_priv->route_metric != -1) - dst_priv->route_metric = MIN (dst_priv->route_metric, src_priv->route_metric); - /* domains */ if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { for (i = 0; i < nm_ip6_config_get_num_domains (src); i++) @@ -1084,8 +1068,6 @@ nm_ip6_config_subtract (NMIP6Config *dst, const NMIP6Config *src) if (!nm_ip6_config_get_num_addresses (dst)) nm_ip6_config_set_gateway (dst, NULL); - /* ignore route_metric */ - /* routes */ changed = FALSE; changed_default_route = FALSE; @@ -1174,7 +1156,6 @@ nm_ip6_config_intersect (NMIP6Config *dst, const NMIP6Config *src) if (changed) _notify_addresses (dst); - /* ignore route_metric */ /* ignore nameservers */ /* default gateway */ @@ -1278,11 +1259,6 @@ nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relev has_relevant_changes = TRUE; } - if (src_priv->route_metric != dst_priv->route_metric) { - dst_priv->route_metric = src_priv->route_metric; - has_minor_changes = TRUE; - } - /* addresses */ head_entry_src = nm_ip6_config_lookup_addresses (src); nm_dedup_multi_iter_init (&ipconf_iter_src, head_entry_src); @@ -1583,14 +1559,6 @@ nm_ip6_config_get_gateway (const NMIP6Config *self) return IN6_IS_ADDR_UNSPECIFIED (&priv->gateway) ? NULL : &priv->gateway; } -gint64 -nm_ip6_config_get_route_metric (const NMIP6Config *self) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self); - - return priv->route_metric; -} - /*****************************************************************************/ void @@ -2737,7 +2705,6 @@ nm_ip6_config_init (NMIP6Config *self) priv->domains = g_ptr_array_new_with_free_func (g_free); priv->searches = g_ptr_array_new_with_free_func (g_free); priv->dns_options = g_ptr_array_new_with_free_func (g_free); - priv->route_metric = -1; } NMIP6Config * diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h index 3555d53eb5..0440bc52d3 100644 --- a/src/nm-ip6-config.h +++ b/src/nm-ip6-config.h @@ -135,7 +135,6 @@ void nm_ip6_config_set_never_default (NMIP6Config *self, gboolean never_default) gboolean nm_ip6_config_get_never_default (const NMIP6Config *self); void nm_ip6_config_set_gateway (NMIP6Config *self, const struct in6_addr *); const struct in6_addr *nm_ip6_config_get_gateway (const NMIP6Config *self); -gint64 nm_ip6_config_get_route_metric (const NMIP6Config *self); const NMPObject *nm_ip6_config_best_default_route_get (const NMIP6Config *self); const NMPObject *_nm_ip6_config_best_default_route_find (const NMIP6Config *self); -- cgit v1.2.1