From fa09e7eb538a6fcb92ac8a86e9a8eb8ddb02d8d0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Mar 2018 13:39:40 +0100 Subject: [PATCH 01/28] device/ndisc: skip link-local addresses from NDisc --- src/devices/nm-device.c | 3 ++- src/ndisc/nm-lndp-ndisc.c | 4 ++++ src/ndisc/nm-ndisc.c | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 6c23a77286..f9e453bc5b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -11669,7 +11669,8 @@ queued_ip6_config_change (gpointer user_data) * ("Addressing Model"): "All interfaces are required to have at least * one link-local unicast address". */ - if (priv->ip6_config && nm_ip6_config_get_num_addresses (priv->ip6_config)) + if ( priv->ip6_config + && nm_ip6_config_get_num_addresses (priv->ip6_config)) need_ipv6ll = TRUE; if (need_ipv6ll) diff --git a/src/ndisc/nm-lndp-ndisc.c b/src/ndisc/nm-lndp-ndisc.c index 70200ed34c..9c7d3c4dfa 100644 --- a/src/ndisc/nm-lndp-ndisc.c +++ b/src/ndisc/nm-lndp-ndisc.c @@ -195,6 +195,10 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) continue; nm_utils_ip6_address_clear_host_address (&r_network, ndp_msg_opt_prefix (msg, offset), r_plen); + if ( IN6_IS_ADDR_UNSPECIFIED (&r_network) + || IN6_IS_ADDR_LINKLOCAL (&r_network)) + continue; + if (ndp_msg_opt_prefix_flag_on_link (msg, offset)) { NMNDiscRoute route = { .network = r_network, diff --git a/src/ndisc/nm-ndisc.c b/src/ndisc/nm-ndisc.c index ede655dd95..ba61cb1125 100644 --- a/src/ndisc/nm-ndisc.c +++ b/src/ndisc/nm-ndisc.c @@ -351,6 +351,8 @@ nm_ndisc_add_address (NMNDisc *ndisc, const NMNDiscAddress *new) nm_assert (new); nm_assert (new->timestamp > 0 && new->timestamp < G_MAXINT32); + nm_assert (!IN6_IS_ADDR_UNSPECIFIED (&new->address)); + nm_assert (!IN6_IS_ADDR_LINKLOCAL (&new->address)); for (i = 0; i < rdata->addresses->len; i++) { NMNDiscAddress *item = &g_array_index (rdata->addresses, NMNDiscAddress, i); From 781ba0ff050a0c0b1f9cd469162b259fa38bf02c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 17 Mar 2018 16:41:32 +0100 Subject: [PATCH 02/28] logging: add LOGD_IP_from_af() util --- src/nm-logging.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/nm-logging.h b/src/nm-logging.h index 8fcbc8cc41..29acb09f65 100644 --- a/src/nm-logging.h +++ b/src/nm-logging.h @@ -83,6 +83,16 @@ typedef enum { /*< skip >*/ LOGD_IP = LOGD_IP4 | LOGD_IP6, } NMLogDomain; +static inline NMLogDomain +LOGD_IP_from_af (int addr_family) +{ + switch (addr_family) { + case AF_INET: return LOGD_IP4; + case AF_INET6: return LOGD_IP6; + } + g_return_val_if_reached (LOGD_NONE); +} + /* Log levels */ typedef enum { /*< skip >*/ LOGL_TRACE, From f813164d552deef0f293759c85367f31aa9c1d90 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 6 Mar 2018 12:52:06 +0100 Subject: [PATCH 03/28] device: drop and inline trival function linklocal6_cleanup() It doesn't seem to make code clearer, rather, slightly more complex. --- src/devices/nm-device.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index f9e453bc5b..7a5d33b310 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -7401,17 +7401,11 @@ nm_device_copy_ip6_dns_config (NMDevice *self, NMDevice *from_device) /*****************************************************************************/ static void -linklocal6_cleanup (NMDevice *self) +linklocal6_failed (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); nm_clear_g_source (&priv->linklocal6_timeout_id); -} - -static void -linklocal6_failed (NMDevice *self) -{ - linklocal6_cleanup (self); nm_device_activate_schedule_ip6_config_timeout (self); } @@ -7432,11 +7426,11 @@ linklocal6_complete (NMDevice *self) NMConnection *connection; const char *method; - g_assert (priv->linklocal6_timeout_id); - g_assert (priv->ext_ip6_config_captured); - g_assert (nm_ip6_config_get_address_first_nontentative (priv->ext_ip6_config_captured, TRUE)); + nm_assert (priv->linklocal6_timeout_id); + nm_assert (priv->ext_ip6_config_captured); + nm_assert (nm_ip6_config_get_address_first_nontentative (priv->ext_ip6_config_captured, TRUE)); - linklocal6_cleanup (self); + nm_clear_g_source (&priv->linklocal6_timeout_id); connection = nm_device_get_applied_connection (self); g_assert (connection); @@ -7554,7 +7548,7 @@ linklocal6_start (NMDevice *self) NMConnection *connection; const char *method; - linklocal6_cleanup (self); + nm_clear_g_source (&priv->linklocal6_timeout_id); if ( priv->ext_ip6_config_captured && nm_ip6_config_get_address_first_nontentative (priv->ext_ip6_config_captured, TRUE)) @@ -9402,7 +9396,7 @@ _cleanup_ip6_pre (NMDevice *self, CleanupType cleanup_type) g_clear_object (&priv->dad6_ip6_config); dhcp6_cleanup (self, cleanup_type, FALSE); - linklocal6_cleanup (self); + nm_clear_g_source (&priv->linklocal6_timeout_id); addrconf6_cleanup (self); } From 0cc605e72b6af395daf2e9bb5cbe8b62243782fe Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 6 Mar 2018 13:02:16 +0100 Subject: [PATCH 04/28] device: simplify return values for addrconf6_start_with_link_ready() and linklocal6_start() addrconf6_start_with_link_ready() cannot fail. Hence, don' return a boolean success value. linklocal6_start() can only either POSTPONE or succeed right away. Don't return a NMActStageReturn value, TRUE/FALSE is enough. This simplifies the callers that don't have to check for values that never come. --- src/devices/nm-device.c | 51 +++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 7a5d33b310..1896a39771 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -530,8 +530,8 @@ static gboolean nm_device_master_add_slave (NMDevice *self, NMDevice *slave, gbo static void nm_device_slave_notify_enslave (NMDevice *self, gboolean success); static void nm_device_slave_notify_release (NMDevice *self, NMDeviceStateReason reason); -static gboolean addrconf6_start_with_link_ready (NMDevice *self); -static NMActStageReturn linklocal6_start (NMDevice *self); +static void addrconf6_start_with_link_ready (NMDevice *self); +static gboolean linklocal6_start (NMDevice *self); static void _carrier_wait_check_queued_act_request (NMDevice *self); static gint64 _get_carrier_wait_ms (NMDevice *self); @@ -7272,17 +7272,12 @@ dhcp6_start (NMDevice *self, gboolean wait_for_ll) nm_device_add_pending_action (self, NM_PENDING_ACTION_DHCP6, TRUE); if (wait_for_ll) { - NMActStageReturn ret; - /* ensure link local is ready... */ - ret = linklocal6_start (self); - if (ret == NM_ACT_STAGE_RETURN_POSTPONE) { - /* success; wait for the LL address to show up */ + if (!linklocal6_start (self)) { + /* wait for the LL address to show up */ return TRUE; } - - /* success; already have the LL address; kick off DHCP */ - g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS); + /* already have the LL address; kick off DHCP */ } if (!dhcp6_start_with_link_ready (self, connection)) @@ -7440,12 +7435,9 @@ linklocal6_complete (NMDevice *self) _LOGD (LOGD_DEVICE, "linklocal6: waiting for link-local addresses successful, continue with method %s", method); if ( strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0 - || strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0) { - if (!addrconf6_start_with_link_ready (self)) { - /* Time out IPv6 instead of failing the entire activation */ - nm_device_activate_schedule_ip6_config_timeout (self); - } - } else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) { + || strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0) + addrconf6_start_with_link_ready (self); + else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) { if (!dhcp6_start_with_link_ready (self, connection)) { /* Time out IPv6 instead of failing the entire activation */ nm_device_activate_schedule_ip6_config_timeout (self); @@ -7541,7 +7533,7 @@ check_and_add_ipv6ll_addr (NMDevice *self) } } -static NMActStageReturn +static gboolean linklocal6_start (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); @@ -7552,7 +7544,7 @@ linklocal6_start (NMDevice *self) if ( priv->ext_ip6_config_captured && nm_ip6_config_get_address_first_nontentative (priv->ext_ip6_config_captured, TRUE)) - return NM_ACT_STAGE_RETURN_SUCCESS; + return TRUE; connection = nm_device_get_applied_connection (self); g_assert (connection); @@ -7568,8 +7560,7 @@ linklocal6_start (NMDevice *self) * (rh #1101809) */ priv->linklocal6_timeout_id = g_timeout_add_seconds (15, linklocal6_timeout_cb, self); - - return NM_ACT_STAGE_RETURN_POSTPONE; + return FALSE; } /*****************************************************************************/ @@ -7958,7 +7949,7 @@ ndisc_ra_timeout (NMNDisc *ndisc, NMDevice *self) } } -static gboolean +static void addrconf6_start_with_link_ready (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); @@ -8012,7 +8003,7 @@ addrconf6_start_with_link_ready (NMDevice *self) ndisc_set_router_config (priv->ndisc, self); nm_ndisc_start (priv->ndisc); - return TRUE; + return; } static NMNDiscNodeType @@ -8035,7 +8026,6 @@ addrconf6_start (NMDevice *self, NMSettingIP6ConfigPrivacy use_tempaddr) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMConnection *connection; - NMActStageReturn ret; NMSettingIP6Config *s_ip6 = NULL; GError *error = NULL; NMUtilsStableType stable_type; @@ -8082,15 +8072,14 @@ addrconf6_start (NMDevice *self, NMSettingIP6ConfigPrivacy use_tempaddr) nm_device_add_pending_action (self, NM_PENDING_ACTION_AUTOCONF6, TRUE); /* ensure link local is ready... */ - ret = linklocal6_start (self); - if (ret == NM_ACT_STAGE_RETURN_POSTPONE) { - /* success; wait for the LL address to show up */ + if (!linklocal6_start (self)) { + /* wait for the LL address to show up */ return TRUE; } - /* success; already have the LL address; kick off neighbor discovery */ - g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS); - return addrconf6_start_with_link_ready (self); + /* already have the LL address; kick off neighbor discovery */ + addrconf6_start_with_link_ready (self); + return TRUE; } static void @@ -8383,7 +8372,9 @@ act_stage3_ip6_config_start (NMDevice *self, } else ret = NM_ACT_STAGE_RETURN_POSTPONE; } else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0) { - ret = linklocal6_start (self); + ret = linklocal6_start (self) + ? NM_ACT_STAGE_RETURN_SUCCESS + : NM_ACT_STAGE_RETURN_POSTPONE; } else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) { priv->dhcp6.mode = NM_NDISC_DHCP_LEVEL_MANAGED; if (!dhcp6_start (self, TRUE)) { From 041afd2c3a0c6f5c9daeba8c6000b964d9d9cabd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 8 Mar 2018 12:31:44 +0100 Subject: [PATCH 05/28] device/trivial: rename internal field "nm_ipv6ll" to "ipv6ll_handle" The "nm_" prefix should not be used for internal names. --- src/devices/nm-device.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 1896a39771..2183371494 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -437,7 +437,7 @@ typedef struct _NMDevicePrivate { NMIP6Config * ext_ip6_config; /* Stuff added outside NM */ NMIP6Config * ext_ip6_config_captured; /* Configuration captured from platform. */ GSList * vpn6_configs; /* VPNs which use this device */ - bool nm_ipv6ll; /* TRUE if NM handles the device's IPv6LL address */ + bool ipv6ll_handle; /* TRUE if NM handles the device's IPv6LL address */ NMIP6Config * dad6_ip6_config; GHashTable * rt6_temporary_not_available; @@ -3525,7 +3525,7 @@ realize_start_setup (NMDevice *self, if (nm_platform_check_kernel_support (nm_device_get_platform (self), NM_PLATFORM_KERNEL_SUPPORT_USER_IPV6LL)) - priv->nm_ipv6ll = nm_platform_link_get_user_ipv6ll_enabled (nm_device_get_platform (self), priv->ifindex); + priv->ipv6ll_handle = nm_platform_link_get_user_ipv6ll_enabled (nm_device_get_platform (self), priv->ifindex); if (nm_platform_link_supports_sriov (nm_device_get_platform (self), priv->ifindex)) capabilities |= NM_DEVICE_CAP_SRIOV; @@ -7458,7 +7458,7 @@ check_and_add_ipv6ll_addr (NMDevice *self) NMSettingIP6Config *s_ip6 = NULL; GError *error = NULL; - if (priv->nm_ipv6ll == FALSE) + if (priv->ipv6ll_handle == FALSE) return; if (priv->ext_ip6_config_captured) { @@ -8146,7 +8146,7 @@ restore_ip6_properties (NMDevice *self) g_hash_table_iter_init (&iter, priv->ip6_saved_properties); while (g_hash_table_iter_next (&iter, &key, &value)) { /* Don't touch "disable_ipv6" if we're doing userland IPv6LL */ - if (priv->nm_ipv6ll && strcmp (key, "disable_ipv6") == 0) + if (priv->ipv6ll_handle && strcmp (key, "disable_ipv6") == 0) continue; nm_device_ipv6_sysctl_set (self, key, value); } @@ -8156,7 +8156,7 @@ static inline void set_disable_ipv6 (NMDevice *self, const char *value) { /* We only touch disable_ipv6 when NM is not managing the IPv6LL address */ - if (NM_DEVICE_GET_PRIVATE (self)->nm_ipv6ll == FALSE) + if (NM_DEVICE_GET_PRIVATE (self)->ipv6ll_handle == FALSE) nm_device_ipv6_sysctl_set (self, "disable_ipv6", value); } @@ -8171,7 +8171,7 @@ set_nm_ipv6ll (NMDevice *self, gboolean enable) NM_PLATFORM_KERNEL_SUPPORT_USER_IPV6LL)) return; - priv->nm_ipv6ll = enable; + priv->ipv6ll_handle = enable; if (ifindex > 0) { NMPlatformError plerr; const char *detail = enable ? "enable" : "disable"; @@ -8320,14 +8320,14 @@ act_stage3_ip6_config_start (NMDevice *self, if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0) { if ( !priv->master && !nm_device_sys_iface_state_is_external (self)) { - gboolean old_nm_ipv6ll = priv->nm_ipv6ll; + gboolean ipv6ll_handle_old = priv->ipv6ll_handle; /* When activating an IPv6 'ignore' connection we need to revert back * to kernel IPv6LL, but the kernel won't actually assign an address * to the interface until disable_ipv6 is bounced. */ set_nm_ipv6ll (self, FALSE); - if (old_nm_ipv6ll == TRUE) + if (ipv6ll_handle_old == TRUE) nm_device_ipv6_sysctl_set (self, "disable_ipv6", "1"); restore_ip6_properties (self); } From fe02bb4f2a0903d3ecc48be303b8578805c41972 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 8 Mar 2018 12:33:26 +0100 Subject: [PATCH 06/28] device: minor cleanups for ipv6ll_handle boolean variable Don't do "if (var == FALSE)" for boolean variables. Also, make booleans in NMDevicePrivate structure bitfields and reorder the fields beside other bitfields. This allows a tighter packing of the structure. --- src/devices/nm-device.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 2183371494..0aad58f7b8 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -360,6 +360,11 @@ typedef struct _NMDevicePrivate { NMDeviceAutoconnectBlockedFlags autoconnect_blocked_flags:4; + bool is_enslaved:1; + bool master_ready_handled:1; + + bool ipv6ll_handle:1; /* TRUE if NM handles the device's IPv6LL address */ + /* Generic DHCP stuff */ char * dhcp_anycast_address; @@ -437,7 +442,6 @@ typedef struct _NMDevicePrivate { NMIP6Config * ext_ip6_config; /* Stuff added outside NM */ NMIP6Config * ext_ip6_config_captured; /* Configuration captured from platform. */ GSList * vpn6_configs; /* VPNs which use this device */ - bool ipv6ll_handle; /* TRUE if NM handles the device's IPv6LL address */ NMIP6Config * dad6_ip6_config; GHashTable * rt6_temporary_not_available; @@ -471,8 +475,6 @@ typedef struct _NMDevicePrivate { /* master interface for bridge/bond/team slave */ NMDevice * master; - bool is_enslaved; - bool master_ready_handled; gulong master_ready_id; /* slave management */ @@ -7458,7 +7460,7 @@ check_and_add_ipv6ll_addr (NMDevice *self) NMSettingIP6Config *s_ip6 = NULL; GError *error = NULL; - if (priv->ipv6ll_handle == FALSE) + if (!priv->ipv6ll_handle) return; if (priv->ext_ip6_config_captured) { @@ -8146,7 +8148,8 @@ restore_ip6_properties (NMDevice *self) g_hash_table_iter_init (&iter, priv->ip6_saved_properties); while (g_hash_table_iter_next (&iter, &key, &value)) { /* Don't touch "disable_ipv6" if we're doing userland IPv6LL */ - if (priv->ipv6ll_handle && strcmp (key, "disable_ipv6") == 0) + if ( priv->ipv6ll_handle + && nm_streq (key, "disable_ipv6")) continue; nm_device_ipv6_sysctl_set (self, key, value); } @@ -8156,7 +8159,7 @@ static inline void set_disable_ipv6 (NMDevice *self, const char *value) { /* We only touch disable_ipv6 when NM is not managing the IPv6LL address */ - if (NM_DEVICE_GET_PRIVATE (self)->ipv6ll_handle == FALSE) + if (!NM_DEVICE_GET_PRIVATE (self)->ipv6ll_handle) nm_device_ipv6_sysctl_set (self, "disable_ipv6", value); } @@ -8327,7 +8330,7 @@ act_stage3_ip6_config_start (NMDevice *self, * to the interface until disable_ipv6 is bounced. */ set_nm_ipv6ll (self, FALSE); - if (ipv6ll_handle_old == TRUE) + if (ipv6ll_handle_old) nm_device_ipv6_sysctl_set (self, "disable_ipv6", "1"); restore_ip6_properties (self); } From 945339cba53ab25fdd3eaded56eec35312f94867 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Mar 2018 16:08:52 +0100 Subject: [PATCH 07/28] core: add nm_ip6_config_find_first_address() function and refactor lookup of code Instead have one particular nm_ip6_config_get_address_first_nontentative() function, make it more extendable. Now, we pass a match-type argument, which can control which element to search. This patch has no change in behavior, but it already makes clear, that nm_ip6_config_get_address_first_nontentative() was buggy, because it would also return addresses that failed DAD. --- src/devices/nm-device.c | 47 +++++++++++++++++++++++++------------- src/nm-ip6-config.c | 34 +++++++++++++++++++++++---- src/nm-ip6-config.h | 3 ++- src/platform/nm-platform.h | 28 +++++++++++++++++++++++ 4 files changed, 90 insertions(+), 22 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 0aad58f7b8..8d79738302 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -7207,8 +7207,12 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection) s_ip6 = nm_connection_get_setting_ip6_config (connection); g_assert (s_ip6); - if (priv->ext_ip6_config_captured) - ll_addr = nm_ip6_config_get_address_first_nontentative (priv->ext_ip6_config_captured, TRUE); + if (priv->ext_ip6_config_captured) { + ll_addr = nm_ip6_config_find_first_address (priv->ext_ip6_config_captured, + NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED); + } if (!ll_addr) { _LOGW (LOGD_DHCP6, "can't start DHCPv6: no link-local address"); @@ -7425,7 +7429,10 @@ linklocal6_complete (NMDevice *self) nm_assert (priv->linklocal6_timeout_id); nm_assert (priv->ext_ip6_config_captured); - nm_assert (nm_ip6_config_get_address_first_nontentative (priv->ext_ip6_config_captured, TRUE)); + nm_assert (nm_ip6_config_find_first_address (priv->ext_ip6_config_captured, + NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED)); nm_clear_g_source (&priv->linklocal6_timeout_id); @@ -7545,7 +7552,10 @@ linklocal6_start (NMDevice *self) nm_clear_g_source (&priv->linklocal6_timeout_id); if ( priv->ext_ip6_config_captured - && nm_ip6_config_get_address_first_nontentative (priv->ext_ip6_config_captured, TRUE)) + && nm_ip6_config_find_first_address (priv->ext_ip6_config_captured, + NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED)) return TRUE; connection = nm_device_get_applied_connection (self); @@ -7944,7 +7954,10 @@ ndisc_ra_timeout (NMNDisc *ndisc, NMDevice *self) * config, consider that sufficient for IPv6 success. */ if ( priv->ip6_config - && nm_ip6_config_get_address_first_nontentative (priv->ip6_config, FALSE)) + && nm_ip6_config_find_first_address (priv->ip6_config, + NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED)) nm_device_activate_schedule_ip6_config_result (self); else nm_device_activate_schedule_ip6_config_timeout (self); @@ -11538,7 +11551,10 @@ update_ip_config (NMDevice *self, int addr_family, gboolean initial) if ( addr_family == AF_INET6 && priv->linklocal6_timeout_id && priv->ext_ip6_config_captured - && nm_ip6_config_get_address_first_nontentative (priv->ext_ip6_config_captured, TRUE)) { + && nm_ip6_config_find_first_address (priv->ext_ip6_config_captured, + NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED)) { /* linklocal6 is ready now, do the state transition... we are also * invoked as g_idle_add, so no problems with reentrance doing it now. */ @@ -11671,16 +11687,15 @@ queued_ip6_config_change (gpointer user_data) /* Check if DAD is still pending */ if ( priv->ip6_state == IP_CONF && priv->dad6_ip6_config - && priv->ext_ip6_config_captured) { - if (!nm_ip6_config_has_any_dad_pending (priv->ext_ip6_config_captured, - priv->dad6_ip6_config)) { - _LOGD (LOGD_DEVICE | LOGD_IP6, "IPv6 DAD terminated"); - g_clear_object (&priv->dad6_ip6_config); - _set_ip_state (self, AF_INET6, IP_DONE); - check_ip_state (self, FALSE, TRUE); - if (priv->rt6_temporary_not_available) - nm_device_activate_schedule_ip6_config_result (self); - } + && priv->ext_ip6_config_captured + && !nm_ip6_config_has_any_dad_pending (priv->ext_ip6_config_captured, + priv->dad6_ip6_config)) { + _LOGD (LOGD_DEVICE | LOGD_IP6, "IPv6 DAD terminated"); + g_clear_object (&priv->dad6_ip6_config); + _set_ip_state (self, AF_INET6, IP_DONE); + check_ip_state (self, FALSE, TRUE); + if (priv->rt6_temporary_not_available) + nm_device_activate_schedule_ip6_config_result (self); } set_unmanaged_external_down (self, TRUE); diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 883e8e00fa..5700f5e64e 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -1691,19 +1691,43 @@ nm_ip6_config_lookup_address (const NMIP6Config *self, } const NMPlatformIP6Address * -nm_ip6_config_get_address_first_nontentative (const NMIP6Config *self, gboolean linklocal) +nm_ip6_config_find_first_address (const NMIP6Config *self, + NMPlatformMatchFlags match_flag) { const NMPlatformIP6Address *addr; NMDedupMultiIter iter; g_return_val_if_fail (NM_IS_IP6_CONFIG (self), NULL); - linklocal = !!linklocal; + nm_assert (!NM_FLAGS_ANY (match_flag, ~( NM_PLATFORM_MATCH_WITH_ADDRTYPE__ANY + | NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY))); + + nm_assert (NM_FLAGS_ANY (match_flag, NM_PLATFORM_MATCH_WITH_ADDRTYPE__ANY)); + nm_assert (NM_FLAGS_ANY (match_flag, NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY)); nm_ip_config_iter_ip6_address_for_each (&iter, self, &addr) { - if ( ((!!IN6_IS_ADDR_LINKLOCAL (&addr->address)) == linklocal) - && !(addr->n_ifa_flags & IFA_F_TENTATIVE)) - return addr; + + if (IN6_IS_ADDR_LINKLOCAL (&addr->address)) { + if (!NM_FLAGS_HAS (match_flag, NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL)) + continue; + } else { + if (!NM_FLAGS_HAS (match_flag, NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL)) + continue; + } + + if (NM_FLAGS_HAS (addr->n_ifa_flags, IFA_F_DADFAILED)) { + if (!NM_FLAGS_HAS (match_flag, NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED)) + continue; + } else if ( NM_FLAGS_HAS (addr->n_ifa_flags, IFA_F_TENTATIVE) + && !NM_FLAGS_HAS (addr->n_ifa_flags, IFA_F_OPTIMISTIC)) { + if (!NM_FLAGS_HAS (match_flag, NM_PLATFORM_MATCH_WITH_ADDRSTATE_TENTATIVE)) + continue; + } else { + if (!NM_FLAGS_HAS (match_flag, NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL)) + continue; + } + + return addr; } return NULL; diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h index 882047d1c1..ef5e310520 100644 --- a/src/nm-ip6-config.h +++ b/src/nm-ip6-config.h @@ -149,7 +149,8 @@ void _nmtst_ip6_config_del_address (NMIP6Config *self, guint i); guint nm_ip6_config_get_num_addresses (const NMIP6Config *self); const NMPlatformIP6Address *nm_ip6_config_get_first_address (const NMIP6Config *self); const NMPlatformIP6Address *_nmtst_ip6_config_get_address (const NMIP6Config *self, guint i); -const NMPlatformIP6Address *nm_ip6_config_get_address_first_nontentative (const NMIP6Config *self, gboolean linklocal); +const NMPlatformIP6Address *nm_ip6_config_find_first_address (const NMIP6Config *self, + NMPlatformMatchFlags match_flag); gboolean nm_ip6_config_address_exists (const NMIP6Config *self, const NMPlatformIP6Address *address); const NMPlatformIP6Address *nm_ip6_config_lookup_address (const NMIP6Config *self, const struct in6_addr *addr); diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 0afdb3b060..824735083a 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -171,6 +171,34 @@ typedef enum { /*< skip >*/ NM_PLATFORM_ERROR_CANT_SET_MTU, } NMPlatformError; +typedef enum { + + /* match-flags are strictly inclusive. That means, + * by default nothing is matched, but if you enable a particular + * flag, a candidate that matches passes the check. + * + * In other words: adding more flags can only extend the result + * set of matching objects. + * + * Also, the flags form partitions. Like, an address can be either of + * ADDRTYPE_NORMAL or ADDRTYPE_LINKLOCAL, but never both. Same for + * the ADDRSTATE match types. + */ + NM_PLATFORM_MATCH_WITH_NONE = 0, + + NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL = (1LL << 0), + NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL = (1LL << 1), + NM_PLATFORM_MATCH_WITH_ADDRTYPE__ANY = NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL + | NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL, + + NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL = (1LL << 2), + NM_PLATFORM_MATCH_WITH_ADDRSTATE_TENTATIVE = (1LL << 3), + NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED = (1LL << 4), + NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY = NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_TENTATIVE + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED, +} NMPlatformMatchFlags; + #define NM_PLATFORM_LINK_OTHER_NETNS (-1) #define __NMPlatformObject_COMMON \ From a58d4f5d3f62b2bf0bec615370c3d98b35c06c27 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Mar 2018 16:17:31 +0100 Subject: [PATCH 08/28] device: use nm_ip6_config_find_first_address() in check_and_add_ipv6ll_addr() --- src/devices/nm-device.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 8d79738302..a82deb4fe3 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -7470,17 +7470,13 @@ check_and_add_ipv6ll_addr (NMDevice *self) if (!priv->ipv6ll_handle) return; - if (priv->ext_ip6_config_captured) { - NMDedupMultiIter ipconf_iter; - const NMPlatformIP6Address *addr; - - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, priv->ext_ip6_config_captured, &addr) { - if ( IN6_IS_ADDR_LINKLOCAL (&addr->address) - && !(addr->n_ifa_flags & IFA_F_DADFAILED)) { - /* Already have an LL address, nothing to do */ - return; - } - } + if ( priv->ext_ip6_config_captured + && nm_ip6_config_find_first_address (priv->ext_ip6_config_captured, + NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_TENTATIVE)) { + /* Already have an LL address, nothing to do */ + return; } memset (&lladdr, 0, sizeof (lladdr)); From 6cdf0b182077dd10fcb4dc6834a918595806f33f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Mar 2018 16:32:12 +0100 Subject: [PATCH 09/28] device: fix check for existing addresses to ignore DADFAILED Likewise, in ndisc_ra_timeout() we also want to include tentative addresses. Looking into priv->ip6_config to determine whether an other IP configuration is active, is anyway odd, and likely a bug. --- src/devices/nm-device.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index a82deb4fe3..f5b8ce8171 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -7210,8 +7210,7 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection) if (priv->ext_ip6_config_captured) { ll_addr = nm_ip6_config_find_first_address (priv->ext_ip6_config_captured, NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED); + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL); } if (!ll_addr) { @@ -7431,8 +7430,7 @@ linklocal6_complete (NMDevice *self) nm_assert (priv->ext_ip6_config_captured); nm_assert (nm_ip6_config_find_first_address (priv->ext_ip6_config_captured, NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED)); + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL)); nm_clear_g_source (&priv->linklocal6_timeout_id); @@ -7550,8 +7548,7 @@ linklocal6_start (NMDevice *self) if ( priv->ext_ip6_config_captured && nm_ip6_config_find_first_address (priv->ext_ip6_config_captured, NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED)) + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL)) return TRUE; connection = nm_device_get_applied_connection (self); @@ -7948,12 +7945,14 @@ ndisc_ra_timeout (NMNDisc *ndisc, NMDevice *self) * ever receive one, then time out IPv6. But if there is other * IPv6 configuration, like manual IPv6 addresses or external IPv6 * config, consider that sufficient for IPv6 success. + * + * FIXME: it doesn't seem correct to determine this based on which + * addresses we find inside priv->ip6_config. */ if ( priv->ip6_config && nm_ip6_config_find_first_address (priv->ip6_config, NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED)) + | NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY)) nm_device_activate_schedule_ip6_config_result (self); else nm_device_activate_schedule_ip6_config_timeout (self); @@ -11549,8 +11548,7 @@ update_ip_config (NMDevice *self, int addr_family, gboolean initial) && priv->ext_ip6_config_captured && nm_ip6_config_find_first_address (priv->ext_ip6_config_captured, NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED)) { + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL)) { /* linklocal6 is ready now, do the state transition... we are also * invoked as g_idle_add, so no problems with reentrance doing it now. */ From 5fd82a20358dccec7f03f00df22237d1b7d2eb96 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Mar 2018 17:01:18 +0100 Subject: [PATCH 10/28] device: cleanup completing wait for linklocal6 linklocal6_complete() had only one caller. The caller would check whether the conditions for linklocal6_complete() are satisfied, and then call it. Note that linklocal6_complete() would again assert that these conditions hold. Don't do this. Just move the check inside linklocal6_complete(), and rename to linklocal6_check_complete(). Also, linklocal6_complete() was called by update_ip_config(), which was called by nm_device_capture_initial_config() and queued_ip6_config_change(). It doesn't make sense to call linklocal6_complete() during nm_device_capture_initial_config(). Move the call to queued_ip6_config_change(). --- src/devices/nm-device.c | 43 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index f5b8ce8171..5a8f0bfd15 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -7420,17 +7420,24 @@ linklocal6_timeout_cb (gpointer user_data) } static void -linklocal6_complete (NMDevice *self) +linklocal6_check_complete (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMConnection *connection; const char *method; - nm_assert (priv->linklocal6_timeout_id); - nm_assert (priv->ext_ip6_config_captured); - nm_assert (nm_ip6_config_find_first_address (priv->ext_ip6_config_captured, - NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL)); + if (!priv->linklocal6_timeout_id) { + /* we are not waiting for linklocal to complete. Nothing to do. */ + return; + } + + if ( !priv->ext_ip6_config_captured + || !nm_ip6_config_find_first_address (priv->ext_ip6_config_captured, + NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL + | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL)) { + /* we don't have a non-tentative link local address yet. Wait longer. */ + return; + } nm_clear_g_source (&priv->linklocal6_timeout_id); @@ -11542,18 +11549,6 @@ update_ip_config (NMDevice *self, int addr_family, gboolean initial) ip6_config_merge_and_apply (self, FALSE); } } - - if ( addr_family == AF_INET6 - && priv->linklocal6_timeout_id - && priv->ext_ip6_config_captured - && nm_ip6_config_find_first_address (priv->ext_ip6_config_captured, - NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL)) { - /* linklocal6 is ready now, do the state transition... we are also - * invoked as g_idle_add, so no problems with reentrance doing it now. - */ - linklocal6_complete (self); - } } void @@ -11620,7 +11615,7 @@ queued_ip6_config_change (gpointer user_data) /* Wait for any queued state changes */ if (priv->queued_state.id) - return TRUE; + return G_SOURCE_CONTINUE; priv->queued_ip6_config_id = 0; @@ -11634,9 +11629,15 @@ queued_ip6_config_change (gpointer user_data) priv->queued_ip6_config_pending = FALSE; priv->queued_ip6_config_id = g_idle_add (queued_ip6_config_change, self); _LOGT (LOGD_DEVICE, "IP6 update was postponed"); - } else + } else { update_ip_config (self, AF_INET6, FALSE); + /* Check whether we need to complete waiting for link-local. + * We are also called from an idle handler, so no problem doing state transitions + * now. */ + linklocal6_check_complete (self); + } + if ( priv->state < NM_DEVICE_STATE_DEACTIVATING && (platform = nm_device_get_platform (self)) && nm_platform_link_get (platform, priv->ifindex)) { @@ -11694,7 +11695,7 @@ queued_ip6_config_change (gpointer user_data) set_unmanaged_external_down (self, TRUE); - return FALSE; + return G_SOURCE_REMOVE; } static void From 1d88f50443125170b2ed11287e3857126975e1ae Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 15 Mar 2018 19:24:51 +0100 Subject: [PATCH 11/28] device: also export NMIPxConfig on error in nm_device_set_ipx_config() A failure to configure an address family does not mean that the connection is going to fail. It depends, for example on ipvx.may-fail. Always export the NMIPxConfig instance in that case. --- src/devices/nm-device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 5a8f0bfd15..9772c26791 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -10550,7 +10550,7 @@ nm_device_set_ip4_config (NMDevice *self, has_changes = TRUE; priv->ip4_config = g_object_ref (new_config); - if (success && !nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) + if (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) nm_dbus_object_export (NM_DBUS_OBJECT (new_config)); _LOGD (LOGD_IP4, "ip4-config: set IP4Config instance (%s)", @@ -10723,7 +10723,7 @@ nm_device_set_ip6_config (NMDevice *self, has_changes = TRUE; priv->ip6_config = g_object_ref (new_config); - if (success && !nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) + if (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) nm_dbus_object_export (NM_DBUS_OBJECT (new_config)); _LOGD (LOGD_IP6, "ip6-config: set IP6Config instance (%s)", From 19e657474d6f7b82cb2df0f0c7b6fbaace77d088 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 17 Mar 2018 15:48:32 +0100 Subject: [PATCH 12/28] device: fix assertion in queued_ip6_config_change() Fixes: 31ca7962f8f7d1993f0a363b9677c7cee89e7ee3 --- src/devices/nm-device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 9772c26791..98085c9dca 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -11611,7 +11611,7 @@ queued_ip6_config_change (gpointer user_data) priv = NM_DEVICE_GET_PRIVATE (self); - nm_assert (!priv->queued_ip4_config_pending); + nm_assert (!priv->queued_ip6_config_pending); /* Wait for any queued state changes */ if (priv->queued_state.id) From 453f9e5140481819d851c97f179c3c36142cf295 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Mar 2018 18:16:15 +0100 Subject: [PATCH 13/28] device: drop capture_lease_config() during connection assumption Drop capture_lease_config(). It was added by commit 0321073b3cb9060817c7743e1c203c6b72659dfe. Note that it was only called by ... - manager:recheck_assume_connection() - manager:get_existing_connection() - nm_device_capture_initial_config() - update_ext_ip_config(addr_family=AF_INET, initial=TRUE) - capture_lease_config() It had only effect when the device had IPv4 permanent addresses. But then, capture_lease_config() would go on and iterate over all connections (sorted by last-connect timestamp). It would consider connection candidates that are compatible with the device, and try to read the lease information from disk It's really unclear what this means. For assuming (graceful take over), do we need the lease information in the device? I don't think so, because we will match an existing connection. The lease information shall be read while activating (if necessary). For external connections, we don't even have a matching connection and we always generate a new one. It doesn't seem right to consider leases from disk, for a different connection. Just drop this. It's really ugly. If this causes an issue, it must be fixed differently. We want to behave determinstically and well defined. I don't even comprehend all the implications of what this had. Also note that update_ext_ip_config() no longer clears priv->dev_ip4_config. --- src/devices/nm-device.c | 118 ---------------------------------------- 1 file changed, 118 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 98085c9dca..968d7a3cf6 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -11264,116 +11264,6 @@ nm_device_get_firmware_missing (NMDevice *self) return NM_DEVICE_GET_PRIVATE (self)->firmware_missing; } -static NMIP4Config * -find_ip4_lease_config (NMDevice *self, - NMConnection *connection, - NMIP4Config *ext_ip4_config) -{ - const char *ip_iface = nm_device_get_ip_iface (self); - int ip_ifindex = nm_device_get_ip_ifindex (self); - GSList *leases, *liter; - NMIP4Config *found = NULL; - - g_return_val_if_fail (NM_IS_IP4_CONFIG (ext_ip4_config), NULL); - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - leases = nm_dhcp_manager_get_lease_ip_configs (nm_dhcp_manager_get (), - nm_device_get_multi_index (self), - AF_INET, - ip_iface, - ip_ifindex, - nm_connection_get_uuid (connection), - nm_device_get_route_table (self, AF_INET, TRUE), - nm_device_get_route_metric (self, AF_INET)); - for (liter = leases; liter && !found; liter = liter->next) { - NMIP4Config *lease_config = liter->data; - const NMPlatformIP4Address *address = nm_ip4_config_get_first_address (lease_config); - const NMPObject *gw1, *gw2; - - g_assert (address); - if (!nm_ip4_config_address_exists (ext_ip4_config, address)) - continue; - gw1 = nm_ip4_config_best_default_route_get (lease_config); - if (!gw1) - continue; - gw2 = nm_ip4_config_best_default_route_get (ext_ip4_config); - if (!gw2) - continue; - if (NMP_OBJECT_CAST_IP4_ROUTE (gw1)->gateway != NMP_OBJECT_CAST_IP4_ROUTE (gw2)->gateway) - continue; - found = g_object_ref (lease_config); - } - - g_slist_free_full (leases, g_object_unref); - return found; -} - -static void -capture_lease_config (NMDevice *self, - NMIP4Config *ext_ip4_config, - NMIP4Config **out_ip4_config, - NMIP6Config *ext_ip6_config, - NMIP6Config **out_ip6_config) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMSettingsConnection *const*connections; - guint i; - gboolean dhcp_used = FALSE; - NMDedupMultiIter ipconf_iter; - - /* Ensure at least one address on the device has a non-infinite lifetime, - * otherwise DHCP cannot possibly be active on the device right now. - */ - if (ext_ip4_config && out_ip4_config) { - const NMPlatformIP4Address *addr; - - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, ext_ip4_config, &addr) { - if (addr->lifetime != NM_PLATFORM_LIFETIME_PERMANENT) { - dhcp_used = TRUE; - break; - } - } - } else if (ext_ip6_config && out_ip6_config) { - const NMPlatformIP6Address *addr; - - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, ext_ip6_config, &addr) { - if (addr->lifetime != NM_PLATFORM_LIFETIME_PERMANENT) { - dhcp_used = TRUE; - break; - } - } - } else { - g_return_if_fail ( (ext_ip6_config && out_ip6_config) - || (ext_ip4_config && out_ip4_config)); - } - - if (!dhcp_used) - return; - - connections = nm_settings_get_connections (priv->settings, NULL); - for (i = 0; connections[i]; i++) { - NMConnection *candidate = (NMConnection *) connections[i]; - const char *method; - - if (!nm_device_check_connection_compatible (self, candidate)) - continue; - - /* IPv4 leases */ - method = nm_utils_get_ip_config_method (candidate, NM_TYPE_SETTING_IP4_CONFIG); - if (out_ip4_config && strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0) { - *out_ip4_config = find_ip4_lease_config (self, candidate, ext_ip4_config); - if (*out_ip4_config) - return; - } - - /* IPv6 leases */ - method = nm_utils_get_ip_config_method (candidate, NM_TYPE_SETTING_IP6_CONFIG); - if (out_ip6_config && strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0) { - /* FIXME: implement find_ip6_lease_config() */ - } - } -} - static void intersect_ext_config (NMDevice *self, AppliedConfig *config) { @@ -11425,14 +11315,6 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean initial, gboolea ifindex, capture_resolv_conf); if (priv->ext_ip4_config) { - if (initial) { - applied_config_clear (&priv->dev_ip4_config); - capture_lease_config (self, - priv->ext_ip4_config, - (NMIP4Config **) &priv->dev_ip4_config.orig, - NULL, NULL); - } - if (intersect_configs) { /* This function was called upon external changes. Remove the configuration * (addresses,routes) that is no longer present externally from the internal From 454195c09db12413c7feab4cf29e67ec5c1cd528 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Mar 2018 18:43:53 +0100 Subject: [PATCH 14/28] device: don't capture resolve.conf for initial device config This was called by via ... - manager:recheck_assume_connection() - manager:get_existing_connection() - nm_device_capture_initial_config() - update_ext_ip_config(initial=TRUE) and would parse resolv.conf, and try to fill the device IP config with nameservers and dns-options. But why? It would only have effect if NM was started with nm_dns_manager_get_resolv_conf_explicit(), but is that really sensible? And it would only take effect on devices that have a default route. And for what is this information even used? Let's not do it this way. If we need this information for assuming or external sys-iface mode, then it should be explicitly loaded at the appropriate moment. For now, drop it and see what breaks. Then we can fix it properly. If it even matters. --- src/devices/nm-device.c | 29 +++++++++++------------------ src/nm-iface-helper.c | 4 ++-- src/nm-ip4-config.c | 21 +-------------------- src/nm-ip4-config.h | 2 +- src/nm-ip6-config.c | 21 +-------------------- src/nm-ip6-config.h | 2 +- 6 files changed, 17 insertions(+), 62 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 968d7a3cf6..3cedb7cf05 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -513,7 +513,7 @@ static const GDBusSignalInfo signal_info_state_changed; static void nm_device_set_proxy_config (NMDevice *self, const char *pac_url); -static gboolean update_ext_ip_config (NMDevice *self, int addr_family, gboolean initial, gboolean intersect_configs); +static gboolean update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_configs); static gboolean nm_device_set_ip4_config (NMDevice *self, NMIP4Config *config, @@ -6118,7 +6118,7 @@ ip4_config_merge_and_apply (NMDevice *self, if (commit) { if (priv->queued_ip4_config_id) - update_ext_ip_config (self, AF_INET, FALSE, FALSE); + update_ext_ip_config (self, AF_INET, FALSE); ensure_con_ip4_config (self); } @@ -6892,7 +6892,7 @@ ip6_config_merge_and_apply (NMDevice *self, if (commit) { if (priv->queued_ip6_config_id) - update_ext_ip_config (self, AF_INET6, FALSE, FALSE); + update_ext_ip_config (self, AF_INET6, FALSE); ensure_con_ip6_config (self); } @@ -8377,7 +8377,6 @@ act_stage3_ip6_config_start (NMDevice *self, priv->ext_ip6_config_captured = nm_ip6_config_capture (nm_device_get_multi_index (self), nm_device_get_platform (self), nm_device_get_ip_ifindex (self), - FALSE, NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); ip6_privacy = _ip6_privacy_get (self); @@ -11291,11 +11290,10 @@ intersect_ext_config (NMDevice *self, AppliedConfig *config) } static gboolean -update_ext_ip_config (NMDevice *self, int addr_family, gboolean initial, gboolean intersect_configs) +update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_configs) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); int ifindex; - gboolean capture_resolv_conf; GSList *iter; nm_assert_addr_family (addr_family); @@ -11304,16 +11302,12 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean initial, gboolea if (!ifindex) return FALSE; - capture_resolv_conf = initial - && nm_dns_manager_get_resolv_conf_explicit (nm_dns_manager_get ()); - if (addr_family == AF_INET) { g_clear_object (&priv->ext_ip4_config); priv->ext_ip4_config = nm_ip4_config_capture (nm_device_get_multi_index (self), nm_device_get_platform (self), - ifindex, - capture_resolv_conf); + ifindex); if (priv->ext_ip4_config) { if (intersect_configs) { /* This function was called upon external changes. Remove the configuration @@ -11361,7 +11355,6 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean initial, gboolea priv->ext_ip6_config_captured = nm_ip6_config_capture (nm_device_get_multi_index (self), nm_device_get_platform (self), ifindex, - capture_resolv_conf, NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); if (priv->ext_ip6_config_captured) { @@ -11416,13 +11409,13 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean initial, gboolea } static void -update_ip_config (NMDevice *self, int addr_family, gboolean initial) +update_ip_config (NMDevice *self, int addr_family) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); nm_assert_addr_family (addr_family); - if (update_ext_ip_config (self, addr_family, initial, TRUE)) { + if (update_ext_ip_config (self, addr_family, TRUE)) { if (addr_family == AF_INET) { if (priv->ext_ip4_config) ip4_config_merge_and_apply (self, FALSE); @@ -11436,8 +11429,8 @@ update_ip_config (NMDevice *self, int addr_family, gboolean initial) void nm_device_capture_initial_config (NMDevice *self) { - update_ip_config (self, AF_INET, TRUE); - update_ip_config (self, AF_INET6, TRUE); + update_ip_config (self, AF_INET); + update_ip_config (self, AF_INET6); } static gboolean @@ -11469,7 +11462,7 @@ queued_ip4_config_change (gpointer user_data) priv->queued_ip4_config_id = g_idle_add (queued_ip4_config_change, self); _LOGT (LOGD_DEVICE, "IP4 update was postponed"); } else - update_ip_config (self, AF_INET, FALSE); + update_ip_config (self, AF_INET); set_unmanaged_external_down (self, TRUE); @@ -11512,7 +11505,7 @@ queued_ip6_config_change (gpointer user_data) priv->queued_ip6_config_id = g_idle_add (queued_ip6_config_change, self); _LOGT (LOGD_DEVICE, "IP6 update was postponed"); } else { - update_ip_config (self, AF_INET6, FALSE); + update_ip_config (self, AF_INET6); /* Check whether we need to complete waiting for link-local. * We are also called from an idle handler, so no problem doing state transitions diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index c85a054ae9..601c72acac 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -125,7 +125,7 @@ dhcp4_state_changed (NMDhcpClient *client, g_assert (nm_ip4_config_get_ifindex (ip4_config) == gl.ifindex); existing = nm_ip4_config_capture (nm_platform_get_multi_idx (NM_PLATFORM_GET), - NM_PLATFORM_GET, gl.ifindex, FALSE); + NM_PLATFORM_GET, gl.ifindex); if (last_config) nm_ip4_config_subtract (existing, last_config, 0); @@ -171,7 +171,7 @@ ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_in NMIP6Config *existing; existing = nm_ip6_config_capture (nm_platform_get_multi_idx (NM_PLATFORM_GET), - NM_PLATFORM_GET, gl.ifindex, FALSE, global_opt.tempaddr); + NM_PLATFORM_GET, gl.ifindex, global_opt.tempaddr); if (ndisc_config) nm_ip6_config_subtract (existing, ndisc_config, 0); else { diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index fa7e78c18a..0a9591d28e 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -593,14 +593,13 @@ nm_ip4_config_clone (const NMIP4Config *self) } NMIP4Config * -nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, gboolean capture_resolv_conf) +nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex) { NMIP4Config *self; NMIP4ConfigPrivate *priv; const NMDedupMultiHeadEntry *head_entry; NMDedupMultiIter iter; const NMPObject *plobj = NULL; - gboolean has_addresses = FALSE; nm_assert (ifindex > 0); @@ -632,7 +631,6 @@ nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i nm_dedup_multi_head_entry_sort (head_entry, sort_captured_addresses, NULL); - has_addresses = TRUE; _notify_addresses (self); } @@ -644,23 +642,6 @@ nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i nmp_cache_iter_for_each (&iter, head_entry, &plobj) _add_route (self, plobj, NULL, NULL); - /* If the interface has the default route, and has IPv4 addresses, capture - * nameservers from /etc/resolv.conf. - */ - if ( has_addresses - && priv->best_default_route - && capture_resolv_conf) { - gs_free char *rc_contents = NULL; - - if (g_file_get_contents (_PATH_RESCONF, &rc_contents, NULL, NULL)) { - if (nm_utils_resolve_conf_parse (AF_INET, - rc_contents, - priv->nameservers, - priv->dns_options)) - _notify (self, PROP_NAMESERVERS); - } - } - return self; } diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index ec525526d2..171a564281 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -160,7 +160,7 @@ int nm_ip4_config_get_ifindex (const NMIP4Config *self); NMDedupMultiIndex *nm_ip4_config_get_multi_idx (const NMIP4Config *self); -NMIP4Config *nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, gboolean capture_resolv_conf); +NMIP4Config *nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex); void nm_ip4_config_add_dependent_routes (NMIP4Config *self, guint32 route_table, diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 5700f5e64e..c76da9951e 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -376,14 +376,13 @@ nm_ip6_config_clone (const NMIP6Config *self) } NMIP6Config * -nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary) +nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, NMSettingIP6ConfigPrivacy use_temporary) { NMIP6Config *self; NMIP6ConfigPrivate *priv; const NMDedupMultiHeadEntry *head_entry; NMDedupMultiIter iter; const NMPObject *plobj = NULL; - gboolean has_addresses = FALSE; nm_assert (ifindex > 0); @@ -409,7 +408,6 @@ nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i NULL, NULL)) nm_assert_not_reached (); - has_addresses = TRUE; } head_entry = nm_ip6_config_lookup_addresses (self); nm_assert (head_entry); @@ -426,23 +424,6 @@ nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i nmp_cache_iter_for_each (&iter, head_entry, &plobj) _add_route (self, plobj, NULL, NULL); - /* If the interface has the default route, and has IPv6 addresses, capture - * nameservers from /etc/resolv.conf. - */ - if ( has_addresses - && priv->best_default_route - && capture_resolv_conf) { - gs_free char *rc_contents = NULL; - - if (g_file_get_contents (_PATH_RESCONF, &rc_contents, NULL, NULL)) { - if (nm_utils_resolve_conf_parse (AF_INET6, - rc_contents, - priv->nameservers, - priv->dns_options)) - _notify (self, PROP_NAMESERVERS); - } - } - return self; } diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h index ef5e310520..cd01ed021b 100644 --- a/src/nm-ip6-config.h +++ b/src/nm-ip6-config.h @@ -106,7 +106,7 @@ int nm_ip6_config_get_ifindex (const NMIP6Config *self); struct _NMDedupMultiIndex *nm_ip6_config_get_multi_idx (const NMIP6Config *self); NMIP6Config *nm_ip6_config_capture (struct _NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, - gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary); + NMSettingIP6ConfigPrivacy use_temporary); void nm_ip6_config_add_dependent_routes (NMIP6Config *self, guint32 route_table, From 745d60c06ecccc7cbb0f916d5c62f3f72ac5e60b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Mar 2018 19:16:05 +0100 Subject: [PATCH 15/28] device: in nm_device_capture_initial_config() only update config once Now that there is no difference between initial capturing of the configuration, and a later update_ip_config() call during a signal from platform, we only need to make sure that the IP config instances are initialized at least once. In case we are called multiple times, there is nothing to do. --- src/devices/nm-device.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 3cedb7cf05..ad6bf835ec 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -263,6 +263,9 @@ typedef struct _NMDevicePrivate { bool queued_ip4_config_pending:1; bool queued_ip6_config_pending:1; + bool update_ip_config_completed_v4:1; + bool update_ip_config_completed_v6:1; + char * ip_iface; int ip_ifindex; NMDeviceType type; @@ -3626,6 +3629,9 @@ nm_device_realize_finish (NMDevice *self, const NMPlatformLink *plink) if (plink) device_recheck_slave_status (self, plink); + priv->update_ip_config_completed_v4 = FALSE; + priv->update_ip_config_completed_v6 = FALSE; + priv->real = TRUE; _notify (self, PROP_REAL); @@ -11415,6 +11421,11 @@ update_ip_config (NMDevice *self, int addr_family) nm_assert_addr_family (addr_family); + if (addr_family == AF_INET) + priv->update_ip_config_completed_v4 = TRUE; + else + priv->update_ip_config_completed_v6 = TRUE; + if (update_ext_ip_config (self, addr_family, TRUE)) { if (addr_family == AF_INET) { if (priv->ext_ip4_config) @@ -11429,8 +11440,12 @@ update_ip_config (NMDevice *self, int addr_family) void nm_device_capture_initial_config (NMDevice *self) { - update_ip_config (self, AF_INET); - update_ip_config (self, AF_INET6); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + + if (!priv->update_ip_config_completed_v4) + update_ip_config (self, AF_INET); + if (!priv->update_ip_config_completed_v6) + update_ip_config (self, AF_INET6); } static gboolean From 512fa33ef4915bef43d132af8e02fa10ef7a4cec Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Mar 2018 18:27:24 +0100 Subject: [PATCH 16/28] dhcp: remove unused nm_dhcp_manager_get_lease_ip_configs() function --- src/dhcp/nm-dhcp-client.h | 7 ------- src/dhcp/nm-dhcp-dhclient.c | 27 --------------------------- src/dhcp/nm-dhcp-dhcpcanon.c | 1 - src/dhcp/nm-dhcp-dhcpcd.c | 1 - src/dhcp/nm-dhcp-manager.c | 25 ------------------------- src/dhcp/nm-dhcp-manager.h | 9 --------- src/dhcp/nm-dhcp-systemd.c | 31 ------------------------------- 7 files changed, 101 deletions(-) diff --git a/src/dhcp/nm-dhcp-client.h b/src/dhcp/nm-dhcp-client.h index f389f534c2..0d92d74304 100644 --- a/src/dhcp/nm-dhcp-client.h +++ b/src/dhcp/nm-dhcp-client.h @@ -194,13 +194,6 @@ typedef struct { GType (*get_type)(void); const char *name; const char *(*get_path) (void); - GSList *(*get_lease_ip_configs) (struct _NMDedupMultiIndex *multi_idx, - int addr_family, - const char *iface, - int ifindex, - const char *uuid, - guint32 route_table, - guint32 route_metric); } NMDhcpClientFactory; extern const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcanon; diff --git a/src/dhcp/nm-dhcp-dhclient.c b/src/dhcp/nm-dhcp-dhclient.c index 56b74d43be..738e9f9184 100644 --- a/src/dhcp/nm-dhcp-dhclient.c +++ b/src/dhcp/nm-dhcp-dhclient.c @@ -158,32 +158,6 @@ get_dhclient_leasefile (int addr_family, return NULL; } -static GSList * -nm_dhcp_dhclient_get_lease_ip_configs (NMDedupMultiIndex *multi_idx, - int addr_family, - const char *iface, - int ifindex, - const char *uuid, - guint32 route_table, - guint32 route_metric) -{ - gs_free char *contents = NULL; - gs_free char *leasefile = NULL; - - leasefile = get_dhclient_leasefile (addr_family, iface, uuid, NULL); - if (!leasefile) - return NULL; - - if ( g_file_test (leasefile, G_FILE_TEST_EXISTS) - && g_file_get_contents (leasefile, &contents, NULL, NULL) - && contents - && contents[0]) { - return nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, addr_family, iface, ifindex, - route_table, route_metric, contents, NULL); - } - return NULL; -} - static gboolean merge_dhclient_config (NMDhcpDhclient *self, int addr_family, @@ -721,7 +695,6 @@ const NMDhcpClientFactory _nm_dhcp_client_factory_dhclient = { .name = "dhclient", .get_type = nm_dhcp_dhclient_get_type, .get_path = nm_dhcp_dhclient_get_path, - .get_lease_ip_configs = nm_dhcp_dhclient_get_lease_ip_configs, }; #endif /* WITH_DHCLIENT */ diff --git a/src/dhcp/nm-dhcp-dhcpcanon.c b/src/dhcp/nm-dhcp-dhcpcanon.c index 66ce45c638..82b3db4fe8 100644 --- a/src/dhcp/nm-dhcp-dhcpcanon.c +++ b/src/dhcp/nm-dhcp-dhcpcanon.c @@ -265,7 +265,6 @@ const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcanon = { .name = "dhcpcanon", .get_type = nm_dhcp_dhcpcanon_get_type, .get_path = nm_dhcp_dhcpcanon_get_path, - .get_lease_ip_configs = NULL, }; #endif /* WITH_DHCPCANON */ diff --git a/src/dhcp/nm-dhcp-dhcpcd.c b/src/dhcp/nm-dhcp-dhcpcd.c index 8e4ebb1968..c4bcb08437 100644 --- a/src/dhcp/nm-dhcp-dhcpcd.c +++ b/src/dhcp/nm-dhcp-dhcpcd.c @@ -251,7 +251,6 @@ const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcd = { .name = "dhcpcd", .get_type = nm_dhcp_dhcpcd_get_type, .get_path = nm_dhcp_dhcpcd_get_path, - .get_lease_ip_configs = NULL, }; #endif /* WITH_DHCPCD */ diff --git a/src/dhcp/nm-dhcp-manager.c b/src/dhcp/nm-dhcp-manager.c index 526dbfd796..bf22872d4e 100644 --- a/src/dhcp/nm-dhcp-manager.c +++ b/src/dhcp/nm-dhcp-manager.c @@ -333,31 +333,6 @@ nm_dhcp_manager_set_default_hostname (NMDhcpManager *manager, const char *hostna priv->default_hostname = g_strdup (hostname); } -GSList * -nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self, - NMDedupMultiIndex *multi_idx, - int addr_family, - const char *iface, - int ifindex, - const char *uuid, - guint32 route_table, - guint32 route_metric) -{ - NMDhcpManagerPrivate *priv; - - g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL); - g_return_val_if_fail (iface != NULL, NULL); - g_return_val_if_fail (ifindex >= -1, NULL); - g_return_val_if_fail (uuid != NULL, NULL); - g_return_val_if_fail (NM_IN_SET (addr_family, AF_INET, AF_INET6), NULL); - - priv = NM_DHCP_MANAGER_GET_PRIVATE (self); - if ( priv->client_factory - && priv->client_factory->get_lease_ip_configs) - return priv->client_factory->get_lease_ip_configs (multi_idx, addr_family, iface, ifindex, uuid, route_table, route_metric); - return NULL; -} - const char * nm_dhcp_manager_get_config (NMDhcpManager *self) { diff --git a/src/dhcp/nm-dhcp-manager.h b/src/dhcp/nm-dhcp-manager.h index 3cf8cf871b..f8a7e31d2d 100644 --- a/src/dhcp/nm-dhcp-manager.h +++ b/src/dhcp/nm-dhcp-manager.h @@ -78,15 +78,6 @@ NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager, NMSettingIP6ConfigPrivacy privacy, guint needed_prefixes); -GSList * nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self, - struct _NMDedupMultiIndex *multi_idx, - int addr_family, - const char *iface, - int ifindex, - const char *uuid, - guint32 route_table, - guint32 route_metric); - /* For testing only */ extern const char* nm_dhcp_helper_path; diff --git a/src/dhcp/nm-dhcp-systemd.c b/src/dhcp/nm-dhcp-systemd.c index db392c421b..1305f1a2a4 100644 --- a/src/dhcp/nm-dhcp-systemd.c +++ b/src/dhcp/nm-dhcp-systemd.c @@ -450,36 +450,6 @@ get_leasefile_path (int addr_family, const char *iface, const char *uuid) iface); } -static GSList * -nm_dhcp_systemd_get_lease_ip_configs (NMDedupMultiIndex *multi_idx, - int addr_family, - const char *iface, - int ifindex, - const char *uuid, - guint32 route_table, - guint32 route_metric) -{ - GSList *leases = NULL; - gs_free char *path = NULL; - sd_dhcp_lease *lease = NULL; - NMIP4Config *ip4_config; - int r; - - if (addr_family != AF_INET) - return NULL; - - path = get_leasefile_path (addr_family, iface, uuid); - r = dhcp_lease_load (&lease, path); - if (r == 0 && lease) { - ip4_config = lease_to_ip4_config (multi_idx, iface, ifindex, lease, NULL, route_table, route_metric, FALSE, NULL); - if (ip4_config) - leases = g_slist_append (leases, ip4_config); - sd_dhcp_lease_unref (lease); - } - - return leases; -} - /*****************************************************************************/ static void @@ -1091,5 +1061,4 @@ const NMDhcpClientFactory _nm_dhcp_client_factory_internal = { .name = "internal", .get_type = nm_dhcp_systemd_get_type, .get_path = NULL, - .get_lease_ip_configs = nm_dhcp_systemd_get_lease_ip_configs, }; From e762eba05a63a3ad7f3cfa3cb401c389ab080847 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Mar 2018 18:49:39 +0100 Subject: [PATCH 17/28] dns: remove unused nm_dns_manager_get_resolv_conf_explicit() function --- src/dns/nm-dns-manager.c | 17 ----------------- src/dns/nm-dns-manager.h | 2 -- 2 files changed, 19 deletions(-) diff --git a/src/dns/nm-dns-manager.c b/src/dns/nm-dns-manager.c index 9b5120e783..56be5aab35 100644 --- a/src/dns/nm-dns-manager.c +++ b/src/dns/nm-dns-manager.c @@ -1474,23 +1474,6 @@ nm_dns_manager_set_hostname (NMDnsManager *self, } } -gboolean -nm_dns_manager_get_resolv_conf_explicit (NMDnsManager *self) -{ - NMDnsManagerPrivate *priv; - - g_return_val_if_fail (NM_IS_DNS_MANAGER (self), FALSE); - - priv = NM_DNS_MANAGER_GET_PRIVATE (self); - - if ( NM_IN_SET (priv->rc_manager, NM_DNS_MANAGER_RESOLV_CONF_MAN_UNMANAGED, - NM_DNS_MANAGER_RESOLV_CONF_MAN_IMMUTABLE) - || priv->plugin) - return FALSE; - - return TRUE; -} - void nm_dns_manager_begin_updates (NMDnsManager *self, const char *func) { diff --git a/src/dns/nm-dns-manager.h b/src/dns/nm-dns-manager.h index 663a3ad258..5688936736 100644 --- a/src/dns/nm-dns-manager.h +++ b/src/dns/nm-dns-manager.h @@ -123,8 +123,6 @@ typedef enum { NM_DNS_MANAGER_RESOLV_CONF_MAN_NETCONFIG, } NMDnsManagerResolvConfManager; -gboolean nm_dns_manager_get_resolv_conf_explicit (NMDnsManager *self); - void nm_dns_manager_stop (NMDnsManager *self); #endif /* __NETWORKMANAGER_DNS_MANAGER_H__ */ From c77784b5eac2a063609063c6b00b14082666302b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Mar 2018 18:56:17 +0100 Subject: [PATCH 18/28] dhcp: remove unused nm_dhcp_dhclient_read_lease_ip_configs() function --- Makefile.am | 4 - src/dhcp/nm-dhcp-dhclient-utils.c | 256 ------------------------ src/dhcp/nm-dhcp-dhclient-utils.h | 9 - src/dhcp/tests/leases/basic.leases | 31 --- src/dhcp/tests/leases/malformed1.leases | 15 -- src/dhcp/tests/leases/malformed2.leases | 15 -- src/dhcp/tests/leases/malformed3.leases | 15 -- src/dhcp/tests/test-dhcp-dhclient.c | 145 -------------- 8 files changed, 490 deletions(-) delete mode 100644 src/dhcp/tests/leases/basic.leases delete mode 100644 src/dhcp/tests/leases/malformed1.leases delete mode 100644 src/dhcp/tests/leases/malformed2.leases delete mode 100644 src/dhcp/tests/leases/malformed3.leases diff --git a/Makefile.am b/Makefile.am index bb5b70cd8d..dac6ed926e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1791,10 +1791,6 @@ $(src_dhcp_tests_test_dhcp_utils_OBJECTS): $(libnm_core_lib_h_pub_mkenums) EXTRA_DIST += \ src/dhcp/tests/test-dhclient-duid.leases \ src/dhcp/tests/test-dhclient-commented-duid.leases \ - src/dhcp/tests/leases/basic.leases \ - src/dhcp/tests/leases/malformed1.leases \ - src/dhcp/tests/leases/malformed2.leases \ - src/dhcp/tests/leases/malformed3.leases \ src/dhcp/tests/meson.build ############################################################################### diff --git a/src/dhcp/nm-dhcp-dhclient-utils.c b/src/dhcp/nm-dhcp-dhclient-utils.c index 70d70fd60a..52923310b8 100644 --- a/src/dhcp/nm-dhcp-dhclient-utils.c +++ b/src/dhcp/nm-dhcp-dhclient-utils.c @@ -643,259 +643,3 @@ nm_dhcp_dhclient_save_duid (const char *leasefile, g_string_free (s, TRUE); return success; } - -static void -add_lease_option (GHashTable *hash, char *line) -{ - char *spc; - size_t len; - - /* Find the space after "option" */ - spc = strchr (line, ' '); - if (!spc) - return; - - /* Find the option tag's data, which is after the second space */ - if (g_str_has_prefix (line, "option ")) { - while (g_ascii_isspace (*spc)) - spc++; - spc = strchr (spc + 1, ' '); - if (!spc) - return; - } - - /* Split the line at the space */ - *spc = '\0'; - spc++; - - /* Kill the ';' at the end of the line, if any */ - len = strlen (spc); - if (*(spc + len - 1) == ';') - *(spc + len - 1) = '\0'; - - /* Strip leading quote */ - while (g_ascii_isspace (*spc)) - spc++; - if (*spc == '"') - spc++; - - /* Strip trailing quote */ - len = strlen (spc); - if (len > 0 && spc[len - 1] == '"') - spc[len - 1] = '\0'; - - if (spc[0]) - g_hash_table_insert (hash, g_strdup (line), g_strdup (spc)); -} - -#define LEASE_INVALID G_MININT64 -static GTimeSpan -lease_validity_span (const char *str_expire, GDateTime *now) -{ - GDateTime *expire = NULL; - struct tm expire_tm; - GTimeSpan span; - - g_return_val_if_fail (now != NULL, LEASE_INVALID); - g_return_val_if_fail (str_expire != NULL, LEASE_INVALID); - - /* Skip initial number (day of week?) */ - if (!isdigit (*str_expire++)) - return LEASE_INVALID; - if (!isspace (*str_expire++)) - return LEASE_INVALID; - /* Read lease expiration (in UTC) */ - if (!strptime (str_expire, "%t%Y/%m/%d %H:%M:%S", &expire_tm)) - return LEASE_INVALID; - - expire = g_date_time_new_utc (expire_tm.tm_year + 1900, - expire_tm.tm_mon + 1, - expire_tm.tm_mday, - expire_tm.tm_hour, - expire_tm.tm_min, - expire_tm.tm_sec); - if (!expire) - return LEASE_INVALID; - - span = g_date_time_difference (expire, now); - g_date_time_unref (expire); - - /* GDateTime only supports a range of less then 10000 years, so span can - * not overflow or be equal to LEASE_INVALID */ - return span; -} - -/** - * nm_dhcp_dhclient_read_lease_ip_configs: - * @multi_idx: the multi index instance for the ip config object - * @addr_family: whether to read IPv4 or IPv6 leases - * @iface: the interface name to match leases with - * @ifindex: interface index of @iface - * @route_table: the route table for the default route. - * @route_metric: the route metric for the default route. - * @contents: the contents of a dhclient leasefile - * @now: the current UTC date/time; pass %NULL to automatically use current - * UTC time. Testcases may need a different value for 'now' - * - * Reads dhclient leases from @contents and parses them into either - * #NMIP4Config or #NMIP6Config objects depending on the value of @addr_family. - * - * Returns: a #GSList of #NMIP4Config objects (if @addr_family is %AF_INET) or a list of - * #NMIP6Config objects (if @addr_family is %AF_INET6) containing the lease data. - */ -GSList * -nm_dhcp_dhclient_read_lease_ip_configs (NMDedupMultiIndex *multi_idx, - int addr_family, - const char *iface, - int ifindex, - guint32 route_table, - guint32 route_metric, - const char *contents, - GDateTime *now) -{ - GSList *parsed = NULL, *iter, *leases = NULL; - char **line, **split = NULL; - GHashTable *hash = NULL; - gint32 now_monotonic_ts; - - g_return_val_if_fail (contents != NULL, NULL); - nm_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6)); - - split = g_strsplit_set (contents, "\n\r", -1); - if (!split) - return NULL; - - for (line = split; line && *line; line++) { - *line = g_strstrip (*line); - - if (*line[0] == '#') { - /* Comment */ - } else if (!strcmp (*line, "}")) { - /* Lease ends */ - parsed = g_slist_append (parsed, hash); - hash = NULL; - } else if (!strcmp (*line, "lease {")) { - /* Beginning of a new lease */ - if (hash) { - /* Ignore malformed lease that doesn't end before new one starts */ - g_hash_table_destroy (hash); - } - - hash = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); - } else if (hash && strlen (*line)) - add_lease_option (hash, *line); - } - g_strfreev (split); - - /* Check if the last lease in the file was properly ended */ - if (hash) { - /* Ignore malformed lease that doesn't end before new one starts */ - g_hash_table_destroy (hash); - hash = NULL; - } - - if (now) - g_date_time_ref (now); - else - now = g_date_time_new_now_utc (); - now_monotonic_ts = nm_utils_get_monotonic_timestamp_s (); - - for (iter = parsed; iter; iter = g_slist_next (iter)) { - NMIP4Config *ip4; - NMPlatformIP4Address address; - const char *value; - GTimeSpan expiry; - guint32 tmp, gw = 0; - - hash = iter->data; - - /* Make sure this lease is for the interface we want */ - value = g_hash_table_lookup (hash, "interface"); - if (!value || strcmp (value, iface)) - continue; - - value = g_hash_table_lookup (hash, "expire"); - if (!value) - continue; - expiry = lease_validity_span (value, now); - if (expiry == LEASE_INVALID) - continue; - - /* scale expiry to seconds (and CLAMP into the range of guint32) */ - expiry = CLAMP (expiry / G_TIME_SPAN_SECOND, 0, NM_PLATFORM_LIFETIME_PERMANENT-1); - if (expiry <= 0) { - /* the address is already expired. Don't even add it. */ - continue; - } - - memset (&address, 0, sizeof (address)); - - /* IP4 address */ - value = g_hash_table_lookup (hash, "fixed-address"); - if (!value) - continue; - if (!inet_pton (AF_INET, value, &address.address)) - continue; - address.peer_address = address.address; - - /* Gateway */ - value = g_hash_table_lookup (hash, "option routers"); - if (!value) - continue; - if (!inet_pton (AF_INET, value, &gw)) - continue; - - /* Netmask */ - value = g_hash_table_lookup (hash, "option subnet-mask"); - if (value && inet_pton (AF_INET, value, &tmp)) - address.plen = nm_utils_ip4_netmask_to_prefix (tmp); - - /* Get default netmask for the IP according to appropriate class. */ - if (!address.plen) - address.plen = _nm_utils_ip4_get_default_prefix (address.address); - - address.timestamp = now_monotonic_ts; - address.lifetime = address.preferred = expiry; - address.addr_source = NM_IP_CONFIG_SOURCE_DHCP; - - ip4 = nm_ip4_config_new (multi_idx, ifindex); - nm_ip4_config_add_address (ip4, &address); - - { - const NMPlatformIP4Route r = { - .rt_source = NM_IP_CONFIG_SOURCE_DHCP, - .gateway = gw, - .table_coerced = nm_platform_route_table_coerce (route_table), - .metric = route_metric, - }; - - nm_ip4_config_add_route (ip4, &r, NULL); - } - - value = g_hash_table_lookup (hash, "option domain-name-servers"); - if (value) { - char **dns, **dns_iter; - - dns = g_strsplit_set (value, ",", -1); - for (dns_iter = dns; dns_iter && *dns_iter; dns_iter++) { - if (inet_pton (AF_INET, *dns_iter, &tmp)) - nm_ip4_config_add_nameserver (ip4, tmp); - } - if (dns) - g_strfreev (dns); - } - - value = g_hash_table_lookup (hash, "option domain-name"); - if (value && value[0]) - nm_ip4_config_add_domain (ip4, value); - - /* FIXME: static routes */ - - leases = g_slist_append (leases, ip4); - } - - g_date_time_unref (now); - g_slist_free_full (parsed, (GDestroyNotify) g_hash_table_destroy); - return leases; -} - diff --git a/src/dhcp/nm-dhcp-dhclient-utils.h b/src/dhcp/nm-dhcp-dhclient-utils.h index d67a4f35d3..fab9196a3b 100644 --- a/src/dhcp/nm-dhcp-dhclient-utils.h +++ b/src/dhcp/nm-dhcp-dhclient-utils.h @@ -43,15 +43,6 @@ gboolean nm_dhcp_dhclient_save_duid (const char *leasefile, const char *escaped_duid, GError **error); -GSList *nm_dhcp_dhclient_read_lease_ip_configs (struct _NMDedupMultiIndex *multi_idx, - int addr_family, - const char *iface, - int ifindex, - guint32 route_table, - guint32 route_metric, - const char *contents, - GDateTime *now); - GBytes *nm_dhcp_dhclient_get_client_id_from_config_file (const char *path); #endif /* __NETWORKMANAGER_DHCP_DHCLIENT_UTILS_H__ */ diff --git a/src/dhcp/tests/leases/basic.leases b/src/dhcp/tests/leases/basic.leases deleted file mode 100644 index 703d92479d..0000000000 --- a/src/dhcp/tests/leases/basic.leases +++ /dev/null @@ -1,31 +0,0 @@ -lease { - interface "wlan0"; - fixed-address 192.168.1.180; - option subnet-mask 255.255.255.0; - option routers 192.168.1.1; - option dhcp-lease-time 600; - option dhcp-message-type 5; - option domain-name-servers 192.168.1.1; - option dhcp-server-identifier 192.168.1.1; - option broadcast-address 192.168.1.255; - renew 5 2013/11/01 19:56:15; - rebind 5 2013/11/01 20:00:44; - expire 5 2013/11/01 20:01:59; -} -lease { - interface "wlan0"; - fixed-address 10.77.52.141; - option subnet-mask 255.0.0.0; - option dhcp-lease-time 1200; - option routers 10.77.52.254; - option dhcp-message-type 5; - option dhcp-server-identifier 10.77.52.254; - option domain-name-servers 8.8.8.8,8.8.4.4; - option dhcp-renewal-time 600; - option dhcp-rebinding-time 1050; - option domain-name "morriesguest.local"; - renew 5 2013/11/01 20:01:08; - rebind 5 2013/11/01 20:05:00; - expire 5 2013/11/01 20:06:15; -} - diff --git a/src/dhcp/tests/leases/malformed1.leases b/src/dhcp/tests/leases/malformed1.leases deleted file mode 100644 index 401d982ad4..0000000000 --- a/src/dhcp/tests/leases/malformed1.leases +++ /dev/null @@ -1,15 +0,0 @@ -# missing fixed-address option -lease { - interface "wlan0"; - option subnet-mask 255.255.255.0; - option routers 192.168.1.1; - option dhcp-lease-time 600; - option dhcp-message-type 5; - option domain-name-servers 192.168.1.1; - option dhcp-server-identifier 192.168.1.1; - option broadcast-address 192.168.1.255; - renew 5 2013/11/01 19:56:15; - rebind 5 2013/11/01 20:00:44; - expire 5 2013/11/01 20:01:59; -} - diff --git a/src/dhcp/tests/leases/malformed2.leases b/src/dhcp/tests/leases/malformed2.leases deleted file mode 100644 index adf5f6decc..0000000000 --- a/src/dhcp/tests/leases/malformed2.leases +++ /dev/null @@ -1,15 +0,0 @@ -# missing routers option -lease { - interface "wlan0"; - fixed-address 192.168.1.180; - option subnet-mask 255.255.255.0; - option dhcp-lease-time 600; - option dhcp-message-type 5; - option domain-name-servers 192.168.1.1; - option dhcp-server-identifier 192.168.1.1; - option broadcast-address 192.168.1.255; - renew 5 2013/11/01 19:56:15; - rebind 5 2013/11/01 20:00:44; - expire 5 2013/11/01 20:01:59; -} - diff --git a/src/dhcp/tests/leases/malformed3.leases b/src/dhcp/tests/leases/malformed3.leases deleted file mode 100644 index a2afc8b6c3..0000000000 --- a/src/dhcp/tests/leases/malformed3.leases +++ /dev/null @@ -1,15 +0,0 @@ -# missing expire time -lease { - interface "wlan0"; - fixed-address 192.168.1.180; - option subnet-mask 255.255.255.0; - option routers 192.168.1.1; - option dhcp-lease-time 600; - option dhcp-message-type 5; - option domain-name-servers 192.168.1.1; - option dhcp-server-identifier 192.168.1.1; - option broadcast-address 192.168.1.255; - renew 5 2013/11/01 19:56:15; - rebind 5 2013/11/01 20:00:44; -} - diff --git a/src/dhcp/tests/test-dhcp-dhclient.c b/src/dhcp/tests/test-dhcp-dhclient.c index f1b0a1a1b1..25af51a135 100644 --- a/src/dhcp/tests/test-dhcp-dhclient.c +++ b/src/dhcp/tests/test-dhcp-dhclient.c @@ -36,12 +36,6 @@ #include "nm-test-utils-core.h" -#define DEBUG 1 - -static const int IFINDEX = 5; -static const guint32 ROUTE_TABLE = RT_TABLE_MAIN; -static const guint32 ROUTE_METRIC = 100; - static void test_config (const char *orig, const char *expected, @@ -993,133 +987,6 @@ test_config_req_intf (void) /*****************************************************************************/ -static void -test_read_lease_ip4_config_basic (void) -{ - nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new (); - GError *error = NULL; - char *contents = NULL; - gboolean success; - const char *path = TESTDIR "/leases/basic.leases"; - GSList *leases; - GDateTime *now; - NMIP4Config *config; - const NMPlatformIP4Address *addr; - guint32 expected_addr; - - success = g_file_get_contents (path, &contents, NULL, &error); - g_assert_no_error (error); - g_assert (success); - - /* Date from before the least expiration */ - now = g_date_time_new_utc (2013, 11, 1, 19, 55, 32); - leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, ROUTE_TABLE, ROUTE_METRIC, contents, now); - g_assert_cmpint (g_slist_length (leases), ==, 2); - - /* IP4Config #1 */ - config = g_slist_nth_data (leases, 0); - g_assert (NM_IS_IP4_CONFIG (config)); - - /* Address */ - g_assert_cmpint (nm_ip4_config_get_num_addresses (config), ==, 1); - expected_addr = nmtst_inet4_from_string ("192.168.1.180"); - addr = _nmtst_ip4_config_get_address (config, 0); - g_assert_cmpint (addr->address, ==, expected_addr); - g_assert_cmpint (addr->peer_address, ==, expected_addr); - g_assert_cmpint (addr->plen, ==, 24); - - /* Gateway */ - expected_addr = nmtst_inet4_from_string ("192.168.1.1"); - g_assert_cmpint (nmtst_ip4_config_get_gateway (config), ==, expected_addr); - - /* DNS */ - g_assert_cmpint (nm_ip4_config_get_num_nameservers (config), ==, 1); - expected_addr = nmtst_inet4_from_string ("192.168.1.1"); - g_assert_cmpint (nm_ip4_config_get_nameserver (config, 0), ==, expected_addr); - - g_assert_cmpint (nm_ip4_config_get_num_domains (config), ==, 0); - - /* IP4Config #2 */ - config = g_slist_nth_data (leases, 1); - g_assert (NM_IS_IP4_CONFIG (config)); - - /* Address */ - g_assert_cmpint (nm_ip4_config_get_num_addresses (config), ==, 1); - expected_addr = nmtst_inet4_from_string ("10.77.52.141"); - addr = _nmtst_ip4_config_get_address (config, 0); - g_assert_cmpint (addr->address, ==, expected_addr); - g_assert_cmpint (addr->peer_address, ==, expected_addr); - g_assert_cmpint (addr->plen, ==, 8); - - /* Gateway */ - expected_addr = nmtst_inet4_from_string ("10.77.52.254"); - g_assert_cmpint (nmtst_ip4_config_get_gateway (config), ==, expected_addr); - - /* DNS */ - g_assert_cmpint (nm_ip4_config_get_num_nameservers (config), ==, 2); - expected_addr = nmtst_inet4_from_string ("8.8.8.8"); - g_assert_cmpint (nm_ip4_config_get_nameserver (config, 0), ==, expected_addr); - expected_addr = nmtst_inet4_from_string ("8.8.4.4"); - g_assert_cmpint (nm_ip4_config_get_nameserver (config, 1), ==, expected_addr); - - /* Domains */ - g_assert_cmpint (nm_ip4_config_get_num_domains (config), ==, 1); - g_assert_cmpstr (nm_ip4_config_get_domain (config, 0), ==, "morriesguest.local"); - - g_slist_free_full (leases, g_object_unref); - g_date_time_unref (now); - g_free (contents); -} - -static void -test_read_lease_ip4_config_expired (void) -{ - nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new (); - GError *error = NULL; - char *contents = NULL; - gboolean success; - const char *path = TESTDIR "/leases/basic.leases"; - GSList *leases; - GDateTime *now; - - success = g_file_get_contents (path, &contents, NULL, &error); - g_assert_no_error (error); - g_assert (success); - - /* Date from *after* the lease expiration */ - now = g_date_time_new_utc (2013, 12, 1, 19, 55, 32); - leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, ROUTE_TABLE, ROUTE_METRIC, contents, now); - g_assert (leases == NULL); - - g_date_time_unref (now); - g_free (contents); -} - -static void -test_read_lease_ip4_config_expect_failure (gconstpointer user_data) -{ - nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new (); - GError *error = NULL; - char *contents = NULL; - gboolean success; - GSList *leases; - GDateTime *now; - - success = g_file_get_contents ((const char *) user_data, &contents, NULL, &error); - g_assert_no_error (error); - g_assert (success); - - /* Date from before the least expiration */ - now = g_date_time_new_utc (2013, 11, 1, 1, 1, 1); - leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, ROUTE_TABLE, ROUTE_METRIC, contents, now); - g_assert (leases == NULL); - - g_date_time_unref (now); - g_free (contents); -} - -/*****************************************************************************/ - NMTST_DEFINE (); int @@ -1157,18 +1024,6 @@ main (int argc, char **argv) g_test_add_func ("/dhcp/dhclient/write_existing_duid", test_write_existing_duid); g_test_add_func ("/dhcp/dhclient/write_existing_commented_duid", test_write_existing_commented_duid); - g_test_add_func ("/dhcp/dhclient/leases/ip4-config/basic", test_read_lease_ip4_config_basic); - g_test_add_func ("/dhcp/dhclient/leases/ip4-config/expired", test_read_lease_ip4_config_expired); - g_test_add_data_func ("/dhcp/dhclient/leases/ip4-config/missing-address", - TESTDIR "/leases/malformed1.leases", - test_read_lease_ip4_config_expect_failure); - g_test_add_data_func ("/dhcp/dhclient/leases/ip4-config/missing-gateway", - TESTDIR "/leases/malformed2.leases", - test_read_lease_ip4_config_expect_failure); - g_test_add_data_func ("/dhcp/dhclient/leases/ip4-config/missing-expire", - TESTDIR "/leases/malformed3.leases", - test_read_lease_ip4_config_expect_failure); - return g_test_run (); } From 868c3cedfd859c9e496cda158a7252105eddf7d1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Mar 2018 18:56:17 +0100 Subject: [PATCH 19/28] dhcp: remove unused nm_utils_resolve_conf_parse() function --- .gitignore | 2 +- Makefile.am | 6 - src/nm-core-utils.c | 104 ---------- src/nm-core-utils.h | 5 - src/tests/meson.build | 1 - src/tests/test-resolvconf-capture.c | 298 ---------------------------- 6 files changed, 1 insertion(+), 415 deletions(-) delete mode 100644 src/tests/test-resolvconf-capture.c diff --git a/.gitignore b/.gitignore index f0613d6d42..371b93593c 100644 --- a/.gitignore +++ b/.gitignore @@ -266,7 +266,6 @@ test-*.trs /src/tests/test-general-with-expect /src/tests/test-ip4-config /src/tests/test-ip6-config -/src/tests/test-resolvconf-capture /src/tests/test-route-manager-fake /src/tests/test-route-manager-linux /src/tests/test-systemd @@ -313,3 +312,4 @@ test-*.trs /libnm-core/tests/test-setting-bond /libnm-core/tests/test-setting-dcb /src/settings/plugins/ifnet +/src/tests/test-resolvconf-capture diff --git a/Makefile.am b/Makefile.am index dac6ed926e..9d5d8e43ce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3097,7 +3097,6 @@ check_programs += \ src/tests/test-ip6-config \ src/tests/test-dcb \ src/tests/test-systemd \ - src/tests/test-resolvconf-capture \ src/tests/test-wired-defname \ src/tests/test-utils @@ -3113,10 +3112,6 @@ src_tests_test_dcb_CPPFLAGS = $(src_tests_cppflags) src_tests_test_dcb_LDFLAGS = $(src_tests_ldflags) src_tests_test_dcb_LDADD = $(src_tests_ldadd) -src_tests_test_resolvconf_capture_CPPFLAGS = $(src_tests_cppflags) -src_tests_test_resolvconf_capture_LDFLAGS = $(src_tests_ldflags) -src_tests_test_resolvconf_capture_LDADD = $(src_tests_ldadd) - src_tests_test_general_CPPFLAGS = $(src_tests_cppflags) src_tests_test_general_LDFLAGS = $(src_tests_ldflags) src_tests_test_general_LDADD = $(src_tests_ldadd) @@ -3136,7 +3131,6 @@ src_tests_test_utils_LDADD = $(src_tests_ldadd) $(src_tests_test_ip4_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(src_tests_test_ip6_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(src_tests_test_dcb_OBJECTS): $(libnm_core_lib_h_pub_mkenums) -$(src_tests_test_resolvconf_capture_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(src_tests_test_general_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(src_tests_test_general_with_expect_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(src_tests_test_wired_defname_OBJECTS): $(libnm_core_lib_h_pub_mkenums) diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index f3e9e5f75e..a9f9255be4 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -1877,110 +1877,6 @@ nm_utils_new_infiniband_name (char *name, const char *parent_name, int p_key) /*****************************************************************************/ -gboolean -nm_utils_resolve_conf_parse (int addr_family, - const char *rc_contents, - GArray *nameservers, - GPtrArray *dns_options) -{ - guint i; - gboolean changed = FALSE; - gs_free const char **lines = NULL; - gsize l; - - g_return_val_if_fail (rc_contents, FALSE); - g_return_val_if_fail (nameservers, FALSE); - g_return_val_if_fail ( ( addr_family == AF_INET - && g_array_get_element_size (nameservers) == sizeof (in_addr_t)) - || ( addr_family == AF_INET6 - && g_array_get_element_size (nameservers) == sizeof (struct in6_addr)), FALSE); - - lines = nm_utils_strsplit_set (rc_contents, "\r\n"); - if (!lines) - return FALSE; - -/* like glibc's MATCH() macro in resolv/res_init.c. */ -#define RC_MATCH(line, option, out_arg) \ - ({ \ - const char *const _line = (line); \ - gboolean _match = FALSE; \ - \ - if ( (strncmp (_line, option, NM_STRLEN (option)) == 0) \ - && (NM_IN_SET (_line[NM_STRLEN (option)], ' ', '\t'))) { \ - _match = TRUE;\ - (out_arg) = &_line[NM_STRLEN (option) + 1]; \ - } \ - _match; \ - }) - - for (l = 0; lines[l]; l++) { - const char *const line = lines[l]; - const char *s = NULL; - - if (RC_MATCH (line, "nameserver", s)) { - gs_free char *s_cpy = NULL; - NMIPAddr ns; - - s = nm_strstrip_avoid_copy (s, &s_cpy); - if (inet_pton (addr_family, s, &ns) != 1) - continue; - - if (addr_family == AF_INET) { - if (!ns.addr4) - continue; - for (i = 0; i < nameservers->len; i++) { - if (g_array_index (nameservers, guint32, i) == ns.addr4) - break; - } - } else { - if (IN6_IS_ADDR_UNSPECIFIED (&ns.addr6)) - continue; - for (i = 0; i < nameservers->len; i++) { - struct in6_addr *t = &g_array_index (nameservers, struct in6_addr, i); - - if (IN6_ARE_ADDR_EQUAL (t, &ns.addr6)) - break; - } - } - - if (i == nameservers->len) { - g_array_append_val (nameservers, ns); - changed = TRUE; - } - continue; - } - - if (RC_MATCH (line, "options", s)) { - if (!dns_options) - continue; - - s = nm_str_skip_leading_spaces (s); - if (s[0]) { - gs_free const char **tokens = NULL; - gsize i_tokens; - - tokens = nm_utils_strsplit_set (s, " \t"); - for (i_tokens = 0; tokens && tokens[i_tokens]; i_tokens++) { - gs_free char *t = g_strstrip (g_strdup (tokens[i_tokens])); - - if ( _nm_utils_dns_option_validate (t, NULL, NULL, - addr_family == AF_INET6, - _nm_utils_dns_option_descs) - && _nm_utils_dns_option_find_idx (dns_options, t) < 0) { - g_ptr_array_add (dns_options, g_steal_pointer (&t)); - changed = TRUE; - } - } - } - continue; - } - } - - return changed; -} - -/*****************************************************************************/ - /** * nm_utils_cmp_connection_by_autoconnect_priority: * @a: diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index 38f20b0522..d974c8af36 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -229,11 +229,6 @@ gboolean nm_utils_connection_has_default_route (NMConnection *connection, char *nm_utils_new_vlan_name (const char *parent_iface, guint32 vlan_id); const char *nm_utils_new_infiniband_name (char *name, const char *parent_name, int p_key); -gboolean nm_utils_resolve_conf_parse (int addr_family, - const char *rc_contents, - GArray *nameservers, - GPtrArray *dns_options); - int nm_utils_cmp_connection_by_autoconnect_priority (NMConnection *a, NMConnection *b); void nm_utils_log_connection_diff (NMConnection *connection, NMConnection *diff_base, guint32 level, guint64 domain, const char *name, const char *prefix); diff --git a/src/tests/meson.build b/src/tests/meson.build index 9e32a92965..b87da713da 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -6,7 +6,6 @@ test_units = [ 'test-ip4-config', 'test-ip6-config', 'test-dcb', - 'test-resolvconf-capture', 'test-wired-defname', 'test-utils' ] diff --git a/src/tests/test-resolvconf-capture.c b/src/tests/test-resolvconf-capture.c deleted file mode 100644 index 2c34ff74d9..0000000000 --- a/src/tests/test-resolvconf-capture.c +++ /dev/null @@ -1,298 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright (C) 2013 Red Hat, Inc. - * - */ - -#include "nm-default.h" - -#include -#include - -#include "NetworkManagerUtils.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" -#include "platform/nm-platform.h" - -#include "nm-test-utils-core.h" - -static void -test_capture_empty (void) -{ - GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32)); - GArray *ns6 = g_array_new (FALSE, FALSE, sizeof (struct in6_addr)); - - g_assert (!nm_utils_resolve_conf_parse (AF_INET, "", ns4, NULL)); - g_assert_cmpint (ns4->len, ==, 0); - - g_assert (!nm_utils_resolve_conf_parse (AF_INET6, "", ns6, NULL)); - g_assert_cmpint (ns6->len, ==, 0); - - g_array_free (ns4, TRUE); - g_array_free (ns6, TRUE); -} - -#define assert_dns4_entry(a, i, s) \ - g_assert_cmpint ((g_array_index ((a), guint32, (i))), ==, nmtst_inet4_from_string (s)); - -#define assert_dns6_entry(a, i, s) \ - g_assert (IN6_ARE_ADDR_EQUAL (&g_array_index ((a), struct in6_addr, (i)), nmtst_inet6_from_string (s))) - -#define assert_dns_option(a, i, s) \ - g_assert_cmpstr ((a)->pdata[(i)], ==, (s)); - -static void -test_capture_basic4 (void) -{ - GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32)); - const char *rc = -"# neato resolv.conf\r\n" -"domain foobar.com\r\n" -"search foobar.com\r\n" -"nameserver 4.2.2.1\r\n" -"nameserver 4.2.2.2\r\n"; - - g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, NULL)); - g_assert_cmpint (ns4->len, ==, 2); - assert_dns4_entry (ns4, 0, "4.2.2.1"); - assert_dns4_entry (ns4, 1, "4.2.2.2"); - - g_array_free (ns4, TRUE); -} - -static void -test_capture_dup4 (void) -{ - GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32)); - const char *rc = -"# neato resolv.conf\r\n" -"domain foobar.com\r\n" -"search foobar.com\r\n" -"nameserver 4.2.2.1\r\n" -"nameserver 4.2.2.1\r\n" -"nameserver 4.2.2.2\r\n"; - - /* Check that duplicates are ignored */ - g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, NULL)); - g_assert_cmpint (ns4->len, ==, 2); - assert_dns4_entry (ns4, 0, "4.2.2.1"); - assert_dns4_entry (ns4, 1, "4.2.2.2"); - - g_array_free (ns4, TRUE); -} - -static void -test_capture_basic6 (void) -{ - GArray *ns6 = g_array_new (FALSE, FALSE, sizeof (struct in6_addr)); - const char *rc = -"# neato resolv.conf\r\n" -"domain foobar.com\r\n" -"search foobar.com\r\n" -"nameserver 2001:4860:4860::8888\r\n" -"nameserver 2001:4860:4860::8844\r\n"; - - g_assert (nm_utils_resolve_conf_parse (AF_INET6, rc, ns6, NULL)); - g_assert_cmpint (ns6->len, ==, 2); - assert_dns6_entry (ns6, 0, "2001:4860:4860::8888"); - assert_dns6_entry (ns6, 1, "2001:4860:4860::8844"); - - g_array_free (ns6, TRUE); -} - -static void -test_capture_dup6 (void) -{ - GArray *ns6 = g_array_new (FALSE, FALSE, sizeof (struct in6_addr)); - const char *rc = -"# neato resolv.conf\r\n" -"domain foobar.com\r\n" -"search foobar.com\r\n" -"nameserver 2001:4860:4860::8888\r\n" -"nameserver 2001:4860:4860::8888\r\n" -"nameserver 2001:4860:4860::8844\r\n"; - - /* Check that duplicates are ignored */ - g_assert (nm_utils_resolve_conf_parse (AF_INET6, rc, ns6, NULL)); - g_assert_cmpint (ns6->len, ==, 2); - assert_dns6_entry (ns6, 0, "2001:4860:4860::8888"); - assert_dns6_entry (ns6, 1, "2001:4860:4860::8844"); - - g_array_free (ns6, TRUE); -} - -static void -test_capture_addr4_with_6 (void) -{ - GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32)); - const char *rc = -"# neato resolv.conf\r\n" -"domain foobar.com\r\n" -"search foobar.com\r\n" -"nameserver 4.2.2.1\r\n" -"nameserver 4.2.2.2\r\n" -"nameserver 2001:4860:4860::8888\r\n"; - - g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, NULL)); - g_assert_cmpint (ns4->len, ==, 2); - assert_dns4_entry (ns4, 0, "4.2.2.1"); - assert_dns4_entry (ns4, 1, "4.2.2.2"); - - g_array_free (ns4, TRUE); -} - -static void -test_capture_addr6_with_4 (void) -{ - GArray *ns6 = g_array_new (FALSE, FALSE, sizeof (struct in6_addr)); - const char *rc = -"# neato resolv.conf\r\n" -"domain foobar.com\r\n" -"search foobar.com\r\n" -"nameserver 4.2.2.1\r\n" -"nameserver 2001:4860:4860::8888\r\n" -"nameserver 2001:4860:4860::8844\r\n"; - - g_assert (nm_utils_resolve_conf_parse (AF_INET6, rc, ns6, NULL)); - g_assert_cmpint (ns6->len, ==, 2); - assert_dns6_entry (ns6, 0, "2001:4860:4860::8888"); - assert_dns6_entry (ns6, 1, "2001:4860:4860::8844"); - - g_array_free (ns6, TRUE); -} - -static void -test_capture_format (void) -{ - GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32)); - const char *rc = -" nameserver 4.2.2.1\r\n" /* bad */ -"nameserver4.2.2.1\r\n" /* bad */ -"nameserver 4.2.2.3\r" /* good */ -"nameserver\t\t4.2.2.4\r\n" /* good */ -"nameserver 4.2.2.5\t\t\r\n" /* good */ -"nameserver 4.2.2.6 \r\n"; /* good */ - - g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, NULL)); - g_assert_cmpint (ns4->len, ==, 4); - assert_dns4_entry (ns4, 0, "4.2.2.3"); - assert_dns4_entry (ns4, 1, "4.2.2.4"); - assert_dns4_entry (ns4, 2, "4.2.2.5"); - assert_dns4_entry (ns4, 3, "4.2.2.6"); - - g_array_free (ns4, TRUE); -} - -static void -test_capture_dns_options (void) -{ - GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32)); - GPtrArray *dns_options = g_ptr_array_new_with_free_func (g_free); - const char *rc = -"nameserver 4.2.2.1\r\n" -"options debug rotate timeout:5 \r\n" -"options edns0\r\n"; - - g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, dns_options)); - g_assert_cmpint (dns_options->len, ==, 4); - assert_dns_option (dns_options, 0, "debug"); - assert_dns_option (dns_options, 1, "rotate"); - assert_dns_option (dns_options, 2, "timeout:5"); - assert_dns_option (dns_options, 3, "edns0"); - - g_array_free (ns4, TRUE); - g_ptr_array_free (dns_options, TRUE); -} - -static void -test_capture_dns_options_dup (void) -{ - GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32)); - GPtrArray *dns_options = g_ptr_array_new_with_free_func (g_free); - const char *rc = -"options debug rotate timeout:3\r\n" -"options edns0 debug\r\n" -"options timeout:5\r\n"; - - g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, dns_options)); - g_assert_cmpint (dns_options->len, ==, 4); - assert_dns_option (dns_options, 0, "debug"); - assert_dns_option (dns_options, 1, "rotate"); - assert_dns_option (dns_options, 2, "timeout:3"); - assert_dns_option (dns_options, 3, "edns0"); - - g_array_free (ns4, TRUE); - g_ptr_array_free (dns_options, TRUE); -} - -static void -test_capture_dns_options_valid4 (void) -{ - GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32)); - GPtrArray *dns_options = g_ptr_array_new_with_free_func (g_free); - const char *rc = -"options debug: rotate:yes edns0 foobar : inet6\r\n"; - - g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, dns_options)); - g_assert_cmpint (dns_options->len, ==, 1); - assert_dns_option (dns_options, 0, "edns0"); - - g_array_free (ns4, TRUE); - g_ptr_array_free (dns_options, TRUE); -} - -static void -test_capture_dns_options_valid6 (void) -{ - GArray *ns6 = g_array_new (FALSE, FALSE, sizeof (struct in6_addr)); - GPtrArray *dns_options = g_ptr_array_new_with_free_func (g_free); - const char *rc = -"options inet6 debug foobar rotate:\r\n"; - - g_assert (nm_utils_resolve_conf_parse (AF_INET6, rc, ns6, dns_options)); - g_assert_cmpint (dns_options->len, ==, 2); - assert_dns_option (dns_options, 0, "inet6"); - assert_dns_option (dns_options, 1, "debug"); - - g_array_free (ns6, TRUE); - g_ptr_array_free (dns_options, TRUE); -} -/*****************************************************************************/ - -NMTST_DEFINE (); - -int -main (int argc, char **argv) -{ - nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); - - g_test_add_func ("/resolvconf-capture/empty", test_capture_empty); - g_test_add_func ("/resolvconf-capture/basic4", test_capture_basic4); - g_test_add_func ("/resolvconf-capture/dup4", test_capture_dup4); - g_test_add_func ("/resolvconf-capture/basic6", test_capture_basic6); - g_test_add_func ("/resolvconf-capture/dup6", test_capture_dup6); - g_test_add_func ("/resolvconf-capture/addr4-with-6", test_capture_addr4_with_6); - g_test_add_func ("/resolvconf-capture/addr6-with-4", test_capture_addr6_with_4); - g_test_add_func ("/resolvconf-capture/format", test_capture_format); - g_test_add_func ("/resolvconf-capture/dns-options", test_capture_dns_options); - g_test_add_func ("/resolvconf-capture/dns-options-dup", test_capture_dns_options_dup); - g_test_add_func ("/resolvconf-capture/dns-options-valid4", test_capture_dns_options_valid4); - g_test_add_func ("/resolvconf-capture/dns-options-valid6", test_capture_dns_options_valid6); - - return g_test_run (); -} - From d7d8611e728860c69d9747a1d0abdd968a1557d0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 Mar 2018 18:54:59 +0100 Subject: [PATCH 20/28] device: merge IPv4 and IPv6 versions of ip_config_merge_and_apply() (pt1) Functions like these are conceptually very similar. Commonly, what we want to do for one address family we also want to do for the other. Merge the two functions. This moves the similar parts closer to each other and stand beside it. This is only the first part of the merge, which is pretty trivial without larger changes (to keep the diff simple). More next. --- src/devices/nm-device.c | 495 ++++++++++++++++++++-------------------- 1 file changed, 246 insertions(+), 249 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index ad6bf835ec..90512ea7b7 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -522,14 +522,13 @@ static gboolean nm_device_set_ip4_config (NMDevice *self, NMIP4Config *config, gboolean commit, GPtrArray *ip4_dev_route_blacklist); -static gboolean ip4_config_merge_and_apply (NMDevice *self, - gboolean commit); +static gboolean ip_config_merge_and_apply (NMDevice *self, + int addr_family, + gboolean commit); static gboolean nm_device_set_ip6_config (NMDevice *self, NMIP6Config *config, gboolean commit); -static gboolean ip6_config_merge_and_apply (NMDevice *self, - gboolean commit); static gboolean nm_device_master_add_slave (NMDevice *self, NMDevice *slave, gboolean configure); static void nm_device_slave_notify_enslave (NMDevice *self, gboolean success); @@ -2166,10 +2165,10 @@ update_connectivity_state (NMDevice *self, NMConnectivityState state) if ( priv->state == NM_DEVICE_STATE_ACTIVATED && !nm_device_sys_iface_state_is_external (self)) { if ( nm_device_get_best_default_route (self, AF_INET) - && !ip4_config_merge_and_apply (self, TRUE)) + && !ip_config_merge_and_apply (self, AF_INET, TRUE)) _LOGW (LOGD_IP4, "Failed to update IPv4 route metric"); if ( nm_device_get_best_default_route (self, AF_INET6) - && !ip6_config_merge_and_apply (self, TRUE)) + && !ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP6, "Failed to update IPv6 route metric"); } } @@ -2974,11 +2973,11 @@ device_link_changed (NMDevice *self) /* the link was down and just came up. That happens for example, while changing MTU. * We must restore IP configuration. */ if (priv->ip4_state == IP_DONE) { - if (!ip4_config_merge_and_apply (self, TRUE)) + if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) _LOGW (LOGD_IP4, "failed applying IP4 config after link comes up again"); } if (priv->ip6_state == IP_DONE) { - if (!ip6_config_merge_and_apply (self, TRUE)) + if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP6, "failed applying IP6 config after link comes up again"); } } @@ -5908,7 +5907,7 @@ nm_device_handle_ipv4ll_event (sd_ipv4ll *ll, int event, void *data) nm_device_activate_schedule_ip4_config_result (self, config); } else if (priv->ip4_state == IP_DONE) { applied_config_init (&priv->dev_ip4_config, config); - if (!ip4_config_merge_and_apply (self, TRUE)) { + if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) { _LOGE (LOGD_AUTOIP4, "failed to update IP4 config for autoip change."); nm_device_ip_method_failed (self, AF_INET, NM_DEVICE_STATE_REASON_AUTOIP_FAILED); } @@ -6087,102 +6086,234 @@ dhcp4_cleanup (NMDevice *self, CleanupType cleanup_type, gboolean release) } static gboolean -ip4_config_merge_and_apply (NMDevice *self, - gboolean commit) +ip_config_merge_and_apply (NMDevice *self, + int addr_family, + gboolean commit) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMConnection *connection; - gboolean success; - NMIP4Config *composite, *config; - gboolean ignore_auto_routes = FALSE; - gboolean ignore_auto_dns = FALSE; - gboolean ignore_default_routes = FALSE; - GSList *iter; - gs_unref_ptrarray GPtrArray *ip4_dev_route_blacklist = NULL; + if (addr_family == AF_INET) { + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + NMConnection *connection; + gboolean success; + NMIP4Config *composite, *config; + gboolean ignore_auto_routes = FALSE; + gboolean ignore_auto_dns = FALSE; + gboolean ignore_default_routes = FALSE; + GSList *iter; + gs_unref_ptrarray GPtrArray *ip4_dev_route_blacklist = NULL; - if (nm_device_sys_iface_state_is_external (self)) - commit = 0; + if (nm_device_sys_iface_state_is_external (self)) + commit = 0; - /* Apply ignore-auto-routes and ignore-auto-dns settings */ - connection = nm_device_get_applied_connection (self); - if (connection) { - NMSettingIPConfig *s_ip4 = nm_connection_get_setting_ip4_config (connection); + /* Apply ignore-auto-routes and ignore-auto-dns settings */ + connection = nm_device_get_applied_connection (self); + if (connection) { + NMSettingIPConfig *s_ip4 = nm_connection_get_setting_ip4_config (connection); - if (s_ip4) { - ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip4); - ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip4); + if (s_ip4) { + ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip4); + ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip4); - /* if the connection has an explicit gateway, we also ignore - * the default routes from other sources. */ - ignore_default_routes = nm_setting_ip_config_get_never_default (s_ip4) - || nm_setting_ip_config_get_gateway (s_ip4); + /* if the connection has an explicit gateway, we also ignore + * the default routes from other sources. */ + ignore_default_routes = nm_setting_ip_config_get_never_default (s_ip4) + || nm_setting_ip_config_get_gateway (s_ip4); + } } + + composite = _ip4_config_new (self); + init_ip4_config_dns_priority (self, composite); + + if (commit) { + if (priv->queued_ip4_config_id) + update_ext_ip_config (self, AF_INET, FALSE); + ensure_con_ip4_config (self); + } + + if (commit) + priv->default_route_metric_penalty_ip4_has = default_route_metric_penalty_detect (self); + + config = (NMIP4Config *) applied_config_get_current (&priv->dev_ip4_config); + if (config) { + nm_ip4_config_merge (composite, config, + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), + default_route_metric_penalty_get (self, AF_INET)); + } + + for (iter = priv->vpn4_configs; iter; iter = iter->next) + nm_ip4_config_merge (composite, iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); + + if (priv->ext_ip4_config) + nm_ip4_config_merge (composite, priv->ext_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT, 0); + + /* Merge WWAN config *last* to ensure modem-given settings overwrite + * any external stuff set by pppd or other scripts. + */ + config = (NMIP4Config *) applied_config_get_current (&priv->wwan_ip4_config); + if (config) { + nm_ip4_config_merge (composite, config, + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), + default_route_metric_penalty_get (self, AF_INET)); + } + + /* Merge user overrides into the composite config. For assumed connections, + * con_ip4_config is empty. */ + if (priv->con_ip4_config) { + nm_ip4_config_merge (composite, priv->con_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT, + default_route_metric_penalty_get (self, AF_INET)); + } + + if (commit) { + nm_ip4_config_add_dependent_routes (composite, + nm_device_get_route_table (self, AF_INET, TRUE), + nm_device_get_route_metric (self, AF_INET), + &ip4_dev_route_blacklist); + } + + if (commit) { + if (NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit) + NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit (self, composite); + } + + success = nm_device_set_ip4_config (self, composite, commit, ip4_dev_route_blacklist); + g_object_unref (composite); + + if (commit) + priv->v4_commit_first_time = FALSE; + return success; + } else { + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + NMConnection *connection; + gboolean success; + NMIP6Config *composite, *config; + gboolean ignore_auto_routes = FALSE; + gboolean ignore_auto_dns = FALSE; + gboolean ignore_default_routes = FALSE; + const char *token = NULL; + GSList *iter; + + if (nm_device_sys_iface_state_is_external (self)) + commit = 0; + + /* Apply ignore-auto-routes and ignore-auto-dns settings */ + connection = nm_device_get_applied_connection (self); + if (connection) { + NMSettingIPConfig *s_ip6 = nm_connection_get_setting_ip6_config (connection); + + if (s_ip6) { + NMSettingIP6Config *ip6 = NM_SETTING_IP6_CONFIG (s_ip6); + + ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip6); + ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip6); + + /* if the connection has an explicit gateway, we also ignore + * the default routes from other sources. */ + ignore_default_routes = nm_setting_ip_config_get_never_default (s_ip6) + || nm_setting_ip_config_get_gateway (s_ip6); + + if (nm_setting_ip6_config_get_addr_gen_mode (ip6) == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64) + token = nm_setting_ip6_config_get_token (ip6); + } + } + + composite = _ip6_config_new (self); + nm_ip6_config_set_privacy (composite, + priv->ndisc ? + priv->ndisc_use_tempaddr : + NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); + init_ip6_config_dns_priority (self, composite); + + if (commit) { + if (priv->queued_ip6_config_id) + update_ext_ip_config (self, AF_INET6, FALSE); + ensure_con_ip6_config (self); + } + + if (commit) + priv->default_route_metric_penalty_ip6_has = default_route_metric_penalty_detect (self); + + /* Merge all the IP configs into the composite config */ + config = (NMIP6Config *) applied_config_get_current (&priv->ac_ip6_config); + if (config) { + nm_ip6_config_merge (composite, config, + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), + default_route_metric_penalty_get (self, AF_INET6)); + } + + config = (NMIP6Config *) applied_config_get_current (&priv->dhcp6.ip6_config); + if (config) { + nm_ip6_config_merge (composite, config, + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), + default_route_metric_penalty_get (self, AF_INET6)); + } + + for (iter = priv->vpn6_configs; iter; iter = iter->next) + nm_ip6_config_merge (composite, iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); + + if (priv->ext_ip6_config) + nm_ip6_config_merge (composite, priv->ext_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT, 0); + + /* Merge WWAN config *last* to ensure modem-given settings overwrite + * any external stuff set by pppd or other scripts. + */ + config = (NMIP6Config *) applied_config_get_current (&priv->wwan_ip6_config); + if (config) { + nm_ip6_config_merge (composite, config, + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), + default_route_metric_penalty_get (self, AF_INET6)); + } + + if (priv->rt6_temporary_not_available) { + const NMPObject *o; + GHashTableIter hiter; + + g_hash_table_iter_init (&hiter, priv->rt6_temporary_not_available); + while (g_hash_table_iter_next (&hiter, (gpointer *) &o, NULL)) { + nm_ip6_config_add_route (composite, + NMP_OBJECT_CAST_IP6_ROUTE (o), + NULL); + } + } + + /* Merge user overrides into the composite config. For assumed connections, + * con_ip6_config is empty. */ + if (priv->con_ip6_config) { + nm_ip6_config_merge (composite, priv->con_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT, + default_route_metric_penalty_get (self, AF_INET6)); + } + + if (commit) { + nm_ip6_config_add_dependent_routes (composite, + nm_device_get_route_table (self, AF_INET6, TRUE), + nm_device_get_route_metric (self, AF_INET6)); + } + + /* Allow setting MTU etc */ + if (commit) { + NMUtilsIPv6IfaceId iid; + + if (token && nm_utils_ipv6_interface_identifier_get_from_token (&iid, token)) { + nm_platform_link_set_ipv6_token (nm_device_get_platform (self), + nm_device_get_ip_ifindex (self), + iid); + } + } + + success = nm_device_set_ip6_config (self, composite, commit); + g_object_unref (composite); + if (commit) + priv->v6_commit_first_time = FALSE; + return success; } - - composite = _ip4_config_new (self); - init_ip4_config_dns_priority (self, composite); - - if (commit) { - if (priv->queued_ip4_config_id) - update_ext_ip_config (self, AF_INET, FALSE); - ensure_con_ip4_config (self); - } - - if (commit) - priv->default_route_metric_penalty_ip4_has = default_route_metric_penalty_detect (self); - - config = (NMIP4Config *) applied_config_get_current (&priv->dev_ip4_config); - if (config) { - nm_ip4_config_merge (composite, config, - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get (self, AF_INET)); - } - - for (iter = priv->vpn4_configs; iter; iter = iter->next) - nm_ip4_config_merge (composite, iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); - - if (priv->ext_ip4_config) - nm_ip4_config_merge (composite, priv->ext_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT, 0); - - /* Merge WWAN config *last* to ensure modem-given settings overwrite - * any external stuff set by pppd or other scripts. - */ - config = (NMIP4Config *) applied_config_get_current (&priv->wwan_ip4_config); - if (config) { - nm_ip4_config_merge (composite, config, - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get (self, AF_INET)); - } - - /* Merge user overrides into the composite config. For assumed connections, - * con_ip4_config is empty. */ - if (priv->con_ip4_config) { - nm_ip4_config_merge (composite, priv->con_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT, - default_route_metric_penalty_get (self, AF_INET)); - } - - if (commit) { - nm_ip4_config_add_dependent_routes (composite, - nm_device_get_route_table (self, AF_INET, TRUE), - nm_device_get_route_metric (self, AF_INET), - &ip4_dev_route_blacklist); - } - - if (commit) { - if (NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit) - NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit (self, composite); - } - - success = nm_device_set_ip4_config (self, composite, commit, ip4_dev_route_blacklist); - g_object_unref (composite); - - if (commit) - priv->v4_commit_first_time = FALSE; - return success; } static gboolean @@ -6194,7 +6325,7 @@ dhcp4_lease_change (NMDevice *self, NMIP4Config *config) applied_config_init (&priv->dev_ip4_config, config); - if (!ip4_config_merge_and_apply (self, TRUE)) { + if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) { _LOGW (LOGD_DHCP4, "failed to update IPv4 config for DHCP change."); return FALSE; } @@ -6851,140 +6982,6 @@ dhcp6_cleanup (NMDevice *self, CleanupType cleanup_type, gboolean release) } } -static gboolean -ip6_config_merge_and_apply (NMDevice *self, - gboolean commit) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMConnection *connection; - gboolean success; - NMIP6Config *composite, *config; - gboolean ignore_auto_routes = FALSE; - gboolean ignore_auto_dns = FALSE; - gboolean ignore_default_routes = FALSE; - const char *token = NULL; - GSList *iter; - - if (nm_device_sys_iface_state_is_external (self)) - commit = 0; - - /* Apply ignore-auto-routes and ignore-auto-dns settings */ - connection = nm_device_get_applied_connection (self); - if (connection) { - NMSettingIPConfig *s_ip6 = nm_connection_get_setting_ip6_config (connection); - - if (s_ip6) { - NMSettingIP6Config *ip6 = NM_SETTING_IP6_CONFIG (s_ip6); - - ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip6); - ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip6); - - /* if the connection has an explicit gateway, we also ignore - * the default routes from other sources. */ - ignore_default_routes = nm_setting_ip_config_get_never_default (s_ip6) - || nm_setting_ip_config_get_gateway (s_ip6); - - if (nm_setting_ip6_config_get_addr_gen_mode (ip6) == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64) - token = nm_setting_ip6_config_get_token (ip6); - } - } - - composite = _ip6_config_new (self); - nm_ip6_config_set_privacy (composite, - priv->ndisc ? - priv->ndisc_use_tempaddr : - NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); - init_ip6_config_dns_priority (self, composite); - - if (commit) { - if (priv->queued_ip6_config_id) - update_ext_ip_config (self, AF_INET6, FALSE); - ensure_con_ip6_config (self); - } - - if (commit) - priv->default_route_metric_penalty_ip6_has = default_route_metric_penalty_detect (self); - - /* Merge all the IP configs into the composite config */ - config = (NMIP6Config *) applied_config_get_current (&priv->ac_ip6_config); - if (config) { - nm_ip6_config_merge (composite, config, - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get (self, AF_INET6)); - } - - config = (NMIP6Config *) applied_config_get_current (&priv->dhcp6.ip6_config); - if (config) { - nm_ip6_config_merge (composite, config, - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get (self, AF_INET6)); - } - - for (iter = priv->vpn6_configs; iter; iter = iter->next) - nm_ip6_config_merge (composite, iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); - - if (priv->ext_ip6_config) - nm_ip6_config_merge (composite, priv->ext_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT, 0); - - /* Merge WWAN config *last* to ensure modem-given settings overwrite - * any external stuff set by pppd or other scripts. - */ - config = (NMIP6Config *) applied_config_get_current (&priv->wwan_ip6_config); - if (config) { - nm_ip6_config_merge (composite, config, - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get (self, AF_INET6)); - } - - if (priv->rt6_temporary_not_available) { - const NMPObject *o; - GHashTableIter hiter; - - g_hash_table_iter_init (&hiter, priv->rt6_temporary_not_available); - while (g_hash_table_iter_next (&hiter, (gpointer *) &o, NULL)) { - nm_ip6_config_add_route (composite, - NMP_OBJECT_CAST_IP6_ROUTE (o), - NULL); - } - } - - /* Merge user overrides into the composite config. For assumed connections, - * con_ip6_config is empty. */ - if (priv->con_ip6_config) { - nm_ip6_config_merge (composite, priv->con_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT, - default_route_metric_penalty_get (self, AF_INET6)); - } - - if (commit) { - nm_ip6_config_add_dependent_routes (composite, - nm_device_get_route_table (self, AF_INET6, TRUE), - nm_device_get_route_metric (self, AF_INET6)); - } - - /* Allow setting MTU etc */ - if (commit) { - NMUtilsIPv6IfaceId iid; - - if (token && nm_utils_ipv6_interface_identifier_get_from_token (&iid, token)) { - nm_platform_link_set_ipv6_token (nm_device_get_platform (self), - nm_device_get_ip_ifindex (self), - iid); - } - } - - success = nm_device_set_ip6_config (self, composite, commit); - g_object_unref (composite); - if (commit) - priv->v6_commit_first_time = FALSE; - return success; -} - static gboolean dhcp6_lease_change (NMDevice *self) { @@ -7002,7 +6999,7 @@ dhcp6_lease_change (NMDevice *self) g_assert (settings_connection); /* Apply the updated config */ - if (!ip6_config_merge_and_apply (self, TRUE)) { + if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) { _LOGW (LOGD_DHCP6, "failed to update IPv6 config in response to DHCP event"); return FALSE; } @@ -7362,7 +7359,7 @@ nm_device_use_ip6_subnet (NMDevice *self, const NMPlatformIP6Address *subnet) subnet->preferred); /* This also updates the ndisc if there are actual changes. */ - if (!ip6_config_merge_and_apply (self, TRUE)) + if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP6, "ipv6-pd: failed applying IP6 config for connection sharing"); } @@ -7400,7 +7397,7 @@ nm_device_copy_ip6_dns_config (NMDevice *self, NMDevice *from_device) nm_ip6_config_get_search (from_config, i)); } - if (!ip6_config_merge_and_apply (self, TRUE)) + if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP6, "ipv6-pd: failed applying DNS config for connection sharing"); } @@ -7990,7 +7987,7 @@ addrconf6_start_with_link_ready (NMDevice *self) } /* Apply any manual configuration before starting RA */ - if (!ip6_config_merge_and_apply (self, TRUE)) { + if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) { _LOGW (LOGD_IP6, "failed to apply manual IPv6 configuration"); g_clear_object (&priv->con_ip6_config); } @@ -8967,7 +8964,7 @@ activate_stage5_ip4_config_result (NMDevice *self) _LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self)); } - if (!ip4_config_merge_and_apply (self, TRUE)) { + if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) { _LOGD (LOGD_DEVICE | LOGD_IP4, "Activation: Stage 5 of 5 (IPv4 Commit) failed"); nm_device_ip_method_failed (self, AF_INET, NM_DEVICE_STATE_REASON_CONFIG_FAILED); return; @@ -9115,7 +9112,7 @@ activate_stage5_ip6_config_commit (NMDevice *self) _LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self)); } - if (ip6_config_merge_and_apply (self, TRUE)) { + if (ip_config_merge_and_apply (self, AF_INET6, TRUE)) { if ( priv->dhcp6.mode != NM_NDISC_DHCP_LEVEL_NONE && priv->ip6_state == IP_CONF) { if (applied_config_get_current (&priv->dhcp6.ip6_config)) { @@ -9514,7 +9511,7 @@ nm_device_reactivate_ip4_config (NMDevice *self, if (!nm_device_activate_stage3_ip4_start (self)) _LOGW (LOGD_IP4, "Failed to apply IPv4 configuration"); } else { - if (!ip4_config_merge_and_apply (self, TRUE)) + if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) _LOGW (LOGD_IP4, "Failed to reapply IPv4 configuration"); } } @@ -9556,7 +9553,7 @@ nm_device_reactivate_ip6_config (NMDevice *self, if (!nm_device_activate_stage3_ip6_start (self)) _LOGW (LOGD_IP6, "Failed to apply IPv6 configuration"); } else { - if (!ip6_config_merge_and_apply (self, TRUE)) + if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP4, "Failed to reapply IPv6 configuration"); } } @@ -10656,7 +10653,7 @@ nm_device_replace_vpn4_config (NMDevice *self, NMIP4Config *old, NMIP4Config *co return; /* NULL to use existing configs */ - if (!ip4_config_merge_and_apply (self, TRUE)) + if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) _LOGW (LOGD_IP4, "failed to set VPN routes for device"); } @@ -10666,7 +10663,7 @@ nm_device_set_wwan_ip4_config (NMDevice *self, NMIP4Config *config) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); applied_config_init (&priv->wwan_ip4_config, config); - if (!ip4_config_merge_and_apply (self, TRUE)) + if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) _LOGW (LOGD_IP4, "failed to set WWAN IPv4 configuration"); } @@ -10791,7 +10788,7 @@ nm_device_replace_vpn6_config (NMDevice *self, NMIP6Config *old, NMIP6Config *co return; /* NULL to use existing configs */ - if (!ip6_config_merge_and_apply (self, TRUE)) + if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP6, "failed to set VPN routes for device"); } @@ -10801,7 +10798,7 @@ nm_device_set_wwan_ip6_config (NMDevice *self, NMIP6Config *config) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); applied_config_init (&priv->wwan_ip6_config, config); - if (!ip6_config_merge_and_apply (self, TRUE)) + if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP6, "failed to set WWAN IPv6 configuration"); } @@ -11200,11 +11197,11 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) /* when the link comes up, we must restore IP configuration if necessary. */ if (priv->ip4_state == IP_DONE) { - if (!ip4_config_merge_and_apply (self, TRUE)) + if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) _LOGW (LOGD_IP4, "failed applying IP4 config after bringing link up"); } if (priv->ip6_state == IP_DONE) { - if (!ip6_config_merge_and_apply (self, TRUE)) + if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP6, "failed applying IP6 config after bringing link up"); } @@ -11429,10 +11426,10 @@ update_ip_config (NMDevice *self, int addr_family) if (update_ext_ip_config (self, addr_family, TRUE)) { if (addr_family == AF_INET) { if (priv->ext_ip4_config) - ip4_config_merge_and_apply (self, FALSE); + ip_config_merge_and_apply (self, AF_INET, FALSE); } else { if (priv->ext_ip6_config_captured) - ip6_config_merge_and_apply (self, FALSE); + ip_config_merge_and_apply (self, AF_INET6, FALSE); } } } From d77485e36bd36c323d992702e193732d82f2fe40 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 Mar 2018 13:52:18 +0100 Subject: [PATCH 21/28] core: add ip-config implementation for NMIP4Config vs. NMIP6Config --- src/nm-ip4-config.h | 70 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index 171a564281..1c5222df43 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -397,12 +397,38 @@ nm_ip_config_add_address (NMIPConfig *self, const NMPlatformIPAddress *address) _NM_IP_CONFIG_DISPATCH_VOID (self, nm_ip4_config_add_address, nm_ip6_config_add_address, (gconstpointer) address); } +static inline void +nm_ip_config_reset_addresses (NMIPConfig *self) +{ + _NM_IP_CONFIG_DISPATCH_VOID (self, nm_ip4_config_reset_addresses, nm_ip6_config_reset_addresses); +} + +static inline void +nm_ip_config_add_route (NMIPConfig *self, + const NMPlatformIPRoute *new, + const NMPObject **out_obj_new) +{ + _NM_IP_CONFIG_DISPATCH_VOID (self, nm_ip4_config_add_route, nm_ip6_config_add_route, (gpointer) new, out_obj_new); +} + +static inline void +nm_ip_config_reset_routes (NMIPConfig *self) +{ + _NM_IP_CONFIG_DISPATCH_VOID (self, nm_ip4_config_reset_routes, nm_ip6_config_reset_routes); +} + static inline int nm_ip_config_get_dns_priority (const NMIPConfig *self) { _NM_IP_CONFIG_DISPATCH (self, nm_ip4_config_get_dns_priority, nm_ip6_config_get_dns_priority); } +static inline void +nm_ip_config_set_dns_priority (NMIPConfig *self, gint priority) +{ + _NM_IP_CONFIG_DISPATCH_VOID (self, nm_ip4_config_set_dns_priority, nm_ip6_config_set_dns_priority, priority); +} + static inline void nm_ip_config_add_nameserver (NMIPConfig *self, const NMIPAddr *ns) { @@ -475,18 +501,17 @@ nm_ip_config_get_dns_option (const NMIPConfig *self, guint i) _NM_IP_CONFIG_DISPATCH (self, nm_ip4_config_get_dns_option, nm_ip6_config_get_dns_option, i); } -#define _NM_IP_CONFIG_DISPATCH_SET_OP(dst, src, v4_func, v6_func, ...) \ +#define _NM_IP_CONFIG_DISPATCH_SET_OP(_return, dst, src, v4_func, v6_func, ...) \ G_STMT_START { \ gpointer _dst = (dst); \ gconstpointer _src = (src); \ - int family = nm_ip_config_get_addr_family (_dst); \ \ - nm_assert (family == nm_ip_config_get_addr_family (_src)); \ - if (family == AF_INET) { \ - v4_func ((NMIP4Config *) _dst, (const NMIP4Config *) _src, ##__VA_ARGS__); \ + if (NM_IS_IP4_CONFIG (_dst)) { \ + nm_assert (NM_IS_IP4_CONFIG (_src)); \ + _return v4_func ((NMIP4Config *) _dst, (const NMIP4Config *) _src, ##__VA_ARGS__); \ } else { \ - nm_assert (family == AF_INET6); \ - v6_func ((NMIP6Config *) _dst, (const NMIP6Config *) _src, ##__VA_ARGS__); \ + nm_assert (NM_IS_IP6_CONFIG (_src)); \ + _return v6_func ((NMIP6Config *) _dst, (const NMIP6Config *) _src, ##__VA_ARGS__); \ } \ } G_STMT_END @@ -495,7 +520,7 @@ nm_ip_config_intersect (NMIPConfig *dst, const NMIPConfig *src, guint32 default_route_metric_penalty) { - _NM_IP_CONFIG_DISPATCH_SET_OP (dst, src, + _NM_IP_CONFIG_DISPATCH_SET_OP (, dst, src, nm_ip4_config_intersect, nm_ip6_config_intersect, default_route_metric_penalty); @@ -506,7 +531,7 @@ nm_ip_config_subtract (NMIPConfig *dst, const NMIPConfig *src, guint32 default_route_metric_penalty) { - _NM_IP_CONFIG_DISPATCH_SET_OP (dst, src, + _NM_IP_CONFIG_DISPATCH_SET_OP (, dst, src, nm_ip4_config_subtract, nm_ip6_config_subtract, default_route_metric_penalty); @@ -518,30 +543,41 @@ nm_ip_config_merge (NMIPConfig *dst, NMIPConfigMergeFlags merge_flags, guint32 default_route_metric_penalty) { - _NM_IP_CONFIG_DISPATCH_SET_OP (dst, src, + _NM_IP_CONFIG_DISPATCH_SET_OP (, dst, src, nm_ip4_config_merge, nm_ip6_config_merge, merge_flags, default_route_metric_penalty); } +static inline gboolean +nm_ip_config_replace (NMIPConfig *dst, + const NMIPConfig *src, + gboolean *relevant_changes) +{ + _NM_IP_CONFIG_DISPATCH_SET_OP (return, dst, src, + nm_ip4_config_replace, + nm_ip6_config_replace, + relevant_changes); +} + static inline NMIPConfig * nm_ip_config_intersect_alloc (const NMIPConfig *a, const NMIPConfig *b, guint32 default_route_metric_penalty) { - int family; - - family = nm_ip_config_get_addr_family (a); - nm_assert (family == nm_ip_config_get_addr_family (b)); - - if (family == AF_INET) + if (NM_IS_IP4_CONFIG (a)) { + nm_assert (NM_IS_IP4_CONFIG (b)); return (NMIPConfig *) nm_ip4_config_intersect_alloc ((const NMIP4Config *) a, (const NMIP4Config *) b, default_route_metric_penalty); - else + } else { + nm_assert (NM_IS_IP6_CONFIG (a)); + nm_assert (NM_IS_IP6_CONFIG (b)); return (NMIPConfig *) nm_ip6_config_intersect_alloc ((const NMIP6Config *) a, (const NMIP6Config *) b, default_route_metric_penalty); + } } + #endif /* __NETWORKMANAGER_IP4_CONFIG_H__ */ From 259cd24f482a12aaa38216070aaf3eac61d7d02b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 Mar 2018 18:54:59 +0100 Subject: [PATCH 22/28] device: merge IPv4 and IPv6 versions of ip_config_merge_and_apply() (pt2) --- src/devices/nm-device.c | 334 +++++++++++++++++++--------------------- 1 file changed, 160 insertions(+), 174 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 90512ea7b7..30d36629c5 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -931,29 +931,18 @@ nm_device_assume_state_reset (NMDevice *self) /*****************************************************************************/ static void -init_ip4_config_dns_priority (NMDevice *self, NMIP4Config *config) +init_ip_config_dns_priority (NMDevice *self, NMIPConfig *config) { gs_free char *value = NULL; gint priority; value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA, - "ipv4.dns-priority", + (nm_ip_config_get_addr_family (config) == AF_INET) + ? "ipv4.dns-priority" + : "ipv6.dns-priority", self); priority = _nm_utils_ascii_str_to_int64 (value, 10, G_MININT, G_MAXINT, 0); - nm_ip4_config_set_dns_priority (config, priority ?: NM_DNS_PRIORITY_DEFAULT_NORMAL); -} - -static void -init_ip6_config_dns_priority (NMDevice *self, NMIP6Config *config) -{ - gs_free char *value = NULL; - gint priority; - - value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA, - "ipv6.dns-priority", - self); - priority = _nm_utils_ascii_str_to_int64 (value, 10, G_MININT, G_MAXINT, 0); - nm_ip6_config_set_dns_priority (config, priority ?: NM_DNS_PRIORITY_DEFAULT_NORMAL); + nm_ip_config_set_dns_priority (config, priority ?: NM_DNS_PRIORITY_DEFAULT_NORMAL); } /*****************************************************************************/ @@ -6090,230 +6079,227 @@ ip_config_merge_and_apply (NMDevice *self, int addr_family, gboolean commit) { - if (addr_family == AF_INET) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMConnection *connection; - gboolean success; - NMIP4Config *composite, *config; - gboolean ignore_auto_routes = FALSE; - gboolean ignore_auto_dns = FALSE; - gboolean ignore_default_routes = FALSE; - GSList *iter; - gs_unref_ptrarray GPtrArray *ip4_dev_route_blacklist = NULL; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + gboolean success; + gs_unref_object NMIPConfig *composite = NULL; + NMIPConfig *config; + gs_unref_ptrarray GPtrArray *ip4_dev_route_blacklist = NULL; + NMConnection *connection; + gboolean ignore_auto_routes = FALSE; + gboolean ignore_auto_dns = FALSE; + gboolean ignore_default_routes = FALSE; + GSList *iter; + const char *ip6_addr_gen_token = NULL; + const gboolean IS_IPv4 = (addr_family == AF_INET); - if (nm_device_sys_iface_state_is_external (self)) - commit = 0; + if (nm_device_sys_iface_state_is_external (self)) + commit = FALSE; - /* Apply ignore-auto-routes and ignore-auto-dns settings */ - connection = nm_device_get_applied_connection (self); - if (connection) { - NMSettingIPConfig *s_ip4 = nm_connection_get_setting_ip4_config (connection); + connection = nm_device_get_applied_connection (self); - if (s_ip4) { - ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip4); - ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip4); + /* Apply ignore-auto-routes and ignore-auto-dns settings */ + if (connection) { + NMSettingIPConfig *s_ip = IS_IPv4 + ? nm_connection_get_setting_ip4_config (connection) + : nm_connection_get_setting_ip6_config (connection); - /* if the connection has an explicit gateway, we also ignore - * the default routes from other sources. */ - ignore_default_routes = nm_setting_ip_config_get_never_default (s_ip4) - || nm_setting_ip_config_get_gateway (s_ip4); + if (s_ip) { + ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip); + ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip); + + /* if the connection has an explicit gateway, we also ignore + * the default routes from other sources. */ + ignore_default_routes = nm_setting_ip_config_get_never_default (s_ip) + || nm_setting_ip_config_get_gateway (s_ip); + + if (!IS_IPv4) { + NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (s_ip); + + if (nm_setting_ip6_config_get_addr_gen_mode (s_ip6) == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64) + ip6_addr_gen_token = nm_setting_ip6_config_get_token (s_ip6); } } + } - composite = _ip4_config_new (self); - init_ip4_config_dns_priority (self, composite); + composite = _ip_config_new (self, addr_family); - if (commit) { + if (!IS_IPv4) { + nm_ip6_config_set_privacy (NM_IP6_CONFIG (composite), + priv->ndisc + ? priv->ndisc_use_tempaddr + : NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); + } + + init_ip_config_dns_priority (self, composite); + + if (commit) { + if (IS_IPv4) { if (priv->queued_ip4_config_id) - update_ext_ip_config (self, AF_INET, FALSE); + update_ext_ip_config (self, addr_family, FALSE); ensure_con_ip4_config (self); - } - - if (commit) - priv->default_route_metric_penalty_ip4_has = default_route_metric_penalty_detect (self); - - config = (NMIP4Config *) applied_config_get_current (&priv->dev_ip4_config); - if (config) { - nm_ip4_config_merge (composite, config, - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get (self, AF_INET)); - } - - for (iter = priv->vpn4_configs; iter; iter = iter->next) - nm_ip4_config_merge (composite, iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); - - if (priv->ext_ip4_config) - nm_ip4_config_merge (composite, priv->ext_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT, 0); - - /* Merge WWAN config *last* to ensure modem-given settings overwrite - * any external stuff set by pppd or other scripts. - */ - config = (NMIP4Config *) applied_config_get_current (&priv->wwan_ip4_config); - if (config) { - nm_ip4_config_merge (composite, config, - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get (self, AF_INET)); - } - - /* Merge user overrides into the composite config. For assumed connections, - * con_ip4_config is empty. */ - if (priv->con_ip4_config) { - nm_ip4_config_merge (composite, priv->con_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT, - default_route_metric_penalty_get (self, AF_INET)); - } - - if (commit) { - nm_ip4_config_add_dependent_routes (composite, - nm_device_get_route_table (self, AF_INET, TRUE), - nm_device_get_route_metric (self, AF_INET), - &ip4_dev_route_blacklist); - } - - if (commit) { - if (NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit) - NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit (self, composite); - } - - success = nm_device_set_ip4_config (self, composite, commit, ip4_dev_route_blacklist); - g_object_unref (composite); - - if (commit) - priv->v4_commit_first_time = FALSE; - return success; - } else { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMConnection *connection; - gboolean success; - NMIP6Config *composite, *config; - gboolean ignore_auto_routes = FALSE; - gboolean ignore_auto_dns = FALSE; - gboolean ignore_default_routes = FALSE; - const char *token = NULL; - GSList *iter; - - if (nm_device_sys_iface_state_is_external (self)) - commit = 0; - - /* Apply ignore-auto-routes and ignore-auto-dns settings */ - connection = nm_device_get_applied_connection (self); - if (connection) { - NMSettingIPConfig *s_ip6 = nm_connection_get_setting_ip6_config (connection); - - if (s_ip6) { - NMSettingIP6Config *ip6 = NM_SETTING_IP6_CONFIG (s_ip6); - - ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip6); - ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip6); - - /* if the connection has an explicit gateway, we also ignore - * the default routes from other sources. */ - ignore_default_routes = nm_setting_ip_config_get_never_default (s_ip6) - || nm_setting_ip_config_get_gateway (s_ip6); - - if (nm_setting_ip6_config_get_addr_gen_mode (ip6) == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64) - token = nm_setting_ip6_config_get_token (ip6); - } - } - - composite = _ip6_config_new (self); - nm_ip6_config_set_privacy (composite, - priv->ndisc ? - priv->ndisc_use_tempaddr : - NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); - init_ip6_config_dns_priority (self, composite); - - if (commit) { + } else { if (priv->queued_ip6_config_id) - update_ext_ip_config (self, AF_INET6, FALSE); + update_ext_ip_config (self, addr_family, FALSE); ensure_con_ip6_config (self); } + } - if (commit) - priv->default_route_metric_penalty_ip6_has = default_route_metric_penalty_detect (self); + if (commit) { + gboolean v; - /* Merge all the IP configs into the composite config */ - config = (NMIP6Config *) applied_config_get_current (&priv->ac_ip6_config); + v = default_route_metric_penalty_detect (self); + if (IS_IPv4) + priv->default_route_metric_penalty_ip4_has = v; + else + priv->default_route_metric_penalty_ip6_has = v; + } + + /* Merge all the IP configs into the composite config */ + + if (IS_IPv4) { + config = applied_config_get_current (&priv->dev_ip4_config); if (config) { - nm_ip6_config_merge (composite, config, + nm_ip4_config_merge (NM_IP4_CONFIG (composite), NM_IP4_CONFIG (config), (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get (self, AF_INET6)); + default_route_metric_penalty_get (self, addr_family)); } + } - config = (NMIP6Config *) applied_config_get_current (&priv->dhcp6.ip6_config); + if (!IS_IPv4) { + config = applied_config_get_current (&priv->ac_ip6_config); if (config) { - nm_ip6_config_merge (composite, config, + nm_ip6_config_merge (NM_IP6_CONFIG (composite), NM_IP6_CONFIG (config), (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get (self, AF_INET6)); + default_route_metric_penalty_get (self, addr_family)); } + } + if (!IS_IPv4) { + config = applied_config_get_current (&priv->dhcp6.ip6_config); + if (config) { + nm_ip6_config_merge (NM_IP6_CONFIG (composite), NM_IP6_CONFIG (config), + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), + default_route_metric_penalty_get (self, addr_family)); + } + } + + if (IS_IPv4) { + for (iter = priv->vpn4_configs; iter; iter = iter->next) + nm_ip4_config_merge (NM_IP4_CONFIG (composite), iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); + } else { for (iter = priv->vpn6_configs; iter; iter = iter->next) - nm_ip6_config_merge (composite, iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); + nm_ip6_config_merge (NM_IP6_CONFIG (composite), iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); + } + if (IS_IPv4) { + if (priv->ext_ip4_config) + nm_ip4_config_merge (NM_IP4_CONFIG (composite), priv->ext_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT, 0); + } else { if (priv->ext_ip6_config) - nm_ip6_config_merge (composite, priv->ext_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT, 0); + nm_ip6_config_merge (NM_IP6_CONFIG (composite), priv->ext_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT, 0); + } - /* Merge WWAN config *last* to ensure modem-given settings overwrite - * any external stuff set by pppd or other scripts. - */ - config = (NMIP6Config *) applied_config_get_current (&priv->wwan_ip6_config); + /* Merge WWAN config *last* to ensure modem-given settings overwrite + * any external stuff set by pppd or other scripts. + */ + if (IS_IPv4) { + config = applied_config_get_current (&priv->wwan_ip4_config); if (config) { - nm_ip6_config_merge (composite, config, + nm_ip4_config_merge (NM_IP4_CONFIG (composite), NM_IP4_CONFIG (config), (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get (self, AF_INET6)); + default_route_metric_penalty_get (self, addr_family)); } + } else { + config = applied_config_get_current (&priv->wwan_ip6_config); + if (config) { + nm_ip6_config_merge (NM_IP6_CONFIG (composite), NM_IP6_CONFIG (config), + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), + default_route_metric_penalty_get (self, addr_family)); + } + } + if (!IS_IPv4) { if (priv->rt6_temporary_not_available) { const NMPObject *o; GHashTableIter hiter; g_hash_table_iter_init (&hiter, priv->rt6_temporary_not_available); while (g_hash_table_iter_next (&hiter, (gpointer *) &o, NULL)) { - nm_ip6_config_add_route (composite, + nm_ip6_config_add_route (NM_IP6_CONFIG (composite), NMP_OBJECT_CAST_IP6_ROUTE (o), NULL); } } + } - /* Merge user overrides into the composite config. For assumed connections, - * con_ip6_config is empty. */ + /* Merge user overrides into the composite config. For assumed connections, + * con_ipx_config is empty. */ + if (IS_IPv4) { + if (priv->con_ip4_config) { + nm_ip4_config_merge (NM_IP4_CONFIG (composite), priv->con_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT, + default_route_metric_penalty_get (self, addr_family)); + } + } else { if (priv->con_ip6_config) { - nm_ip6_config_merge (composite, priv->con_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT, - default_route_metric_penalty_get (self, AF_INET6)); + nm_ip6_config_merge (NM_IP6_CONFIG (composite), priv->con_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT, + default_route_metric_penalty_get (self, addr_family)); } + } + if (commit) { + if (IS_IPv4) { + nm_ip4_config_add_dependent_routes (NM_IP4_CONFIG (composite), + nm_device_get_route_table (self, addr_family, TRUE), + nm_device_get_route_metric (self, addr_family), + &ip4_dev_route_blacklist); + } else { + nm_ip6_config_add_dependent_routes (NM_IP6_CONFIG (composite), + nm_device_get_route_table (self, addr_family, TRUE), + nm_device_get_route_metric (self, addr_family)); + } + } + + if (IS_IPv4) { if (commit) { - nm_ip6_config_add_dependent_routes (composite, - nm_device_get_route_table (self, AF_INET6, TRUE), - nm_device_get_route_metric (self, AF_INET6)); + if (NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit) + NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit (self, NM_IP4_CONFIG (composite)); } + } - /* Allow setting MTU etc */ + if (!IS_IPv4) { if (commit) { NMUtilsIPv6IfaceId iid; - if (token && nm_utils_ipv6_interface_identifier_get_from_token (&iid, token)) { + if ( ip6_addr_gen_token + && nm_utils_ipv6_interface_identifier_get_from_token (&iid, ip6_addr_gen_token)) { nm_platform_link_set_ipv6_token (nm_device_get_platform (self), nm_device_get_ip_ifindex (self), iid); } } + } - success = nm_device_set_ip6_config (self, composite, commit); - g_object_unref (composite); + if (IS_IPv4) { + success = nm_device_set_ip4_config (self, NM_IP4_CONFIG (composite), commit, ip4_dev_route_blacklist); + if (commit) + priv->v4_commit_first_time = FALSE; + } else { + success = nm_device_set_ip6_config (self, NM_IP6_CONFIG (composite), commit); if (commit) priv->v6_commit_first_time = FALSE; - return success; } + + return success; } static gboolean From d0de8cb6d17fbc011b67a3c8ac27ed8ec4c2711f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 Mar 2018 18:54:59 +0100 Subject: [PATCH 23/28] device: merge IPv4 and IPv6 versions of ip_config_merge_and_apply() (pt3) --- src/devices/nm-device.c | 178 ++++++++++++++++++---------------------- 1 file changed, 82 insertions(+), 96 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 30d36629c5..7725618576 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -234,8 +234,14 @@ typedef struct _NMDevicePrivate { NMDeviceStateReason reason; } queued_state; - guint queued_ip4_config_id; - guint queued_ip6_config_id; + union { + struct { + guint queued_ip6_config_id; + guint queued_ip4_config_id; + }; + guint queued_ipx_config_id[2]; + }; + GSList *pending_actions; GSList *dad6_failed_addrs; @@ -384,11 +390,43 @@ typedef struct _NMDevicePrivate { const IpState ip4_state; IpState ip4_state_; }; - NMIP4Config * con_ip4_config; /* config from the setting */ AppliedConfig dev_ip4_config; /* Config from DHCP, PPP, LLv4, etc */ - AppliedConfig wwan_ip4_config; /* WWAN configuration */ - NMIP4Config * ext_ip4_config; /* Stuff added outside NM */ - GSList * vpn4_configs; /* VPNs which use this device */ + + /* config from the setting */ + union { + struct { + NMIP6Config *con_ip6_config; + NMIP4Config *con_ip4_config; + }; + NMIPConfig *con_ipx_config[2]; + }; + + /* Stuff added outside NM */ + union { + struct { + NMIP6Config *ext_ip6_config; + NMIP4Config *ext_ip4_config; + }; + NMIPConfig *ext_ipx_config[2]; + }; + + /* VPNs which use this device */ + union { + struct { + GSList *vpn6_configs; + GSList *vpn4_configs; + }; + GSList *vpnx_configs[2]; + }; + + /* WWAN configuration */ + union { + struct { + AppliedConfig wwan_ip6_config; + AppliedConfig wwan_ip4_config; + }; + AppliedConfig wwan_ipx_config[2]; + }; bool v4_has_shadowed_routes; const char *ip4_rp_filter; @@ -439,12 +477,8 @@ typedef struct _NMDevicePrivate { const IpState ip6_state; IpState ip6_state_; }; - NMIP6Config * con_ip6_config; /* config from the setting */ - AppliedConfig wwan_ip6_config; AppliedConfig ac_ip6_config; /* config from IPv6 autoconfiguration */ - NMIP6Config * ext_ip6_config; /* Stuff added outside NM */ NMIP6Config * ext_ip6_config_captured; /* Configuration captured from platform. */ - GSList * vpn6_configs; /* VPNs which use this device */ NMIP6Config * dad6_ip6_config; GHashTable * rt6_temporary_not_available; @@ -5992,56 +6026,42 @@ ipv4ll_start (NMDevice *self) /*****************************************************************************/ static void -ensure_con_ip4_config (NMDevice *self) +ensure_con_ip_config (NMDevice *self, int addr_family) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMConnection *connection; + const gboolean IS_IPv4 = (addr_family == AF_INET); + NMIPConfig *con_ip_config; - if (priv->con_ip4_config) + if (priv->con_ipx_config[IS_IPv4]) return; connection = nm_device_get_applied_connection (self); if (!connection) return; - priv->con_ip4_config = _ip4_config_new (self); - nm_ip4_config_merge_setting (priv->con_ip4_config, - nm_connection_get_setting_ip4_config (connection), - _get_mdns (self), - nm_device_get_route_table (self, AF_INET, TRUE), - nm_device_get_route_metric (self, AF_INET)); + con_ip_config = _ip_config_new (self, addr_family); + + if (IS_IPv4) { + nm_ip4_config_merge_setting (NM_IP4_CONFIG (con_ip_config), + nm_connection_get_setting_ip4_config (connection), + _get_mdns (self), + nm_device_get_route_table (self, addr_family, TRUE), + nm_device_get_route_metric (self, addr_family)); + } else { + nm_ip6_config_merge_setting (NM_IP6_CONFIG (con_ip_config), + nm_connection_get_setting_ip6_config (connection), + nm_device_get_route_table (self, addr_family, TRUE), + nm_device_get_route_metric (self, addr_family)); + } if (nm_device_sys_iface_state_is_external_or_assume (self)) { /* For assumed connections ignore all addresses and routes. */ - nm_ip4_config_reset_addresses (priv->con_ip4_config); - nm_ip4_config_reset_routes (priv->con_ip4_config); + nm_ip_config_reset_addresses (con_ip_config); + nm_ip_config_reset_routes (con_ip_config); } -} -static void -ensure_con_ip6_config (NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMConnection *connection; - - if (priv->con_ip6_config) - return; - - connection = nm_device_get_applied_connection (self); - if (!connection) - return; - - priv->con_ip6_config = _ip6_config_new (self); - nm_ip6_config_merge_setting (priv->con_ip6_config, - nm_connection_get_setting_ip6_config (connection), - nm_device_get_route_table (self, AF_INET6, TRUE), - nm_device_get_route_metric (self, AF_INET6)); - - if (nm_device_sys_iface_state_is_external_or_assume (self)) { - /* For assumed connections ignore all addresses and routes. */ - nm_ip6_config_reset_addresses (priv->con_ip6_config); - nm_ip6_config_reset_routes (priv->con_ip6_config); - } + priv->con_ipx_config[IS_IPv4] = con_ip_config; } /*****************************************************************************/ @@ -6133,15 +6153,9 @@ ip_config_merge_and_apply (NMDevice *self, init_ip_config_dns_priority (self, composite); if (commit) { - if (IS_IPv4) { - if (priv->queued_ip4_config_id) - update_ext_ip_config (self, addr_family, FALSE); - ensure_con_ip4_config (self); - } else { - if (priv->queued_ip6_config_id) - update_ext_ip_config (self, addr_family, FALSE); - ensure_con_ip6_config (self); - } + if (priv->queued_ipx_config_id[IS_IPv4]) + update_ext_ip_config (self, addr_family, FALSE); + ensure_con_ip_config (self, addr_family); } if (commit) { @@ -6189,43 +6203,22 @@ ip_config_merge_and_apply (NMDevice *self, } } - if (IS_IPv4) { - for (iter = priv->vpn4_configs; iter; iter = iter->next) - nm_ip4_config_merge (NM_IP4_CONFIG (composite), iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); - } else { - for (iter = priv->vpn6_configs; iter; iter = iter->next) - nm_ip6_config_merge (NM_IP6_CONFIG (composite), iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); - } + for (iter = priv->vpnx_configs[IS_IPv4]; iter; iter = iter->next) + nm_ip_config_merge (composite, iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); - if (IS_IPv4) { - if (priv->ext_ip4_config) - nm_ip4_config_merge (NM_IP4_CONFIG (composite), priv->ext_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT, 0); - } else { - if (priv->ext_ip6_config) - nm_ip6_config_merge (NM_IP6_CONFIG (composite), priv->ext_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT, 0); - } + if (priv->ext_ipx_config[IS_IPv4]) + nm_ip_config_merge (composite, priv->ext_ipx_config[IS_IPv4], NM_IP_CONFIG_MERGE_DEFAULT, 0); /* Merge WWAN config *last* to ensure modem-given settings overwrite * any external stuff set by pppd or other scripts. */ - if (IS_IPv4) { - config = applied_config_get_current (&priv->wwan_ip4_config); - if (config) { - nm_ip4_config_merge (NM_IP4_CONFIG (composite), NM_IP4_CONFIG (config), - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get (self, addr_family)); - } - } else { - config = applied_config_get_current (&priv->wwan_ip6_config); - if (config) { - nm_ip6_config_merge (NM_IP6_CONFIG (composite), NM_IP6_CONFIG (config), - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get (self, addr_family)); - } + config = applied_config_get_current (&priv->wwan_ipx_config[IS_IPv4]); + if (config) { + nm_ip_config_merge (composite, config, + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), + default_route_metric_penalty_get (self, addr_family)); } if (!IS_IPv4) { @@ -6244,16 +6237,9 @@ ip_config_merge_and_apply (NMDevice *self, /* Merge user overrides into the composite config. For assumed connections, * con_ipx_config is empty. */ - if (IS_IPv4) { - if (priv->con_ip4_config) { - nm_ip4_config_merge (NM_IP4_CONFIG (composite), priv->con_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT, - default_route_metric_penalty_get (self, addr_family)); - } - } else { - if (priv->con_ip6_config) { - nm_ip6_config_merge (NM_IP6_CONFIG (composite), priv->con_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT, - default_route_metric_penalty_get (self, addr_family)); - } + if (priv->con_ipx_config[IS_IPv4]) { + nm_ip_config_merge (composite, priv->con_ipx_config[IS_IPv4], NM_IP_CONFIG_MERGE_DEFAULT, + default_route_metric_penalty_get (self, addr_family)); } if (commit) { From 7f0b43108d3f4c72c34711c0378d0d15e528d788 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 Mar 2018 20:17:32 +0100 Subject: [PATCH 24/28] device/trivial: rename IPv4/IPv6 related fields in NMDevicePrivate struct These fields have the same purpose for IPv4 and IPv6. Also, they have an alias with name _x, that can be indexed by an IS_IPv4 1/0 value. Rename the fields so that the distinguisher 4/6/x is at the end. The point is to make the name more similar. --- src/devices/nm-device.c | 341 ++++++++++++++++++++-------------------- 1 file changed, 173 insertions(+), 168 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 7725618576..618b7022c3 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -236,10 +236,10 @@ typedef struct _NMDevicePrivate { union { struct { - guint queued_ip6_config_id; - guint queued_ip4_config_id; + guint queued_ip_config_id_6; + guint queued_ip_config_id_4; }; - guint queued_ipx_config_id[2]; + guint queued_ip_config_id_x[2]; }; GSList *pending_actions; @@ -384,8 +384,15 @@ typedef struct _NMDevicePrivate { NMPacrunnerManager *pacrunner_manager; NMPacrunnerCallId *pacrunner_call_id; - /* IP4 configuration info */ - NMIP4Config * ip4_config; /* Combined config from VPN, settings, and device */ + /* IP configuration info. Combined config from VPN, settings, and device */ + union { + struct { + NMIP6Config *ip_config_6; + NMIP4Config *ip_config_4; + }; + NMIPConfig *ip_config_x[2]; + }; + union { const IpState ip4_state; IpState ip4_state_; @@ -395,37 +402,37 @@ typedef struct _NMDevicePrivate { /* config from the setting */ union { struct { - NMIP6Config *con_ip6_config; - NMIP4Config *con_ip4_config; + NMIP6Config *con_ip_config_6; + NMIP4Config *con_ip_config_4; }; - NMIPConfig *con_ipx_config[2]; + NMIPConfig *con_ip_config_x[2]; }; /* Stuff added outside NM */ union { struct { - NMIP6Config *ext_ip6_config; - NMIP4Config *ext_ip4_config; + NMIP6Config *ext_ip_config_6; + NMIP4Config *ext_ip_config_4; }; - NMIPConfig *ext_ipx_config[2]; + NMIPConfig *ext_ip_config_x[2]; }; /* VPNs which use this device */ union { struct { - GSList *vpn6_configs; - GSList *vpn4_configs; + GSList *vpn_configs_6; + GSList *vpn_configs_4; }; - GSList *vpnx_configs[2]; + GSList *vpn_configs_x[2]; }; /* WWAN configuration */ union { struct { - AppliedConfig wwan_ip6_config; - AppliedConfig wwan_ip4_config; + AppliedConfig wwan_ip_config_6; + AppliedConfig wwan_ip_config_4; }; - AppliedConfig wwan_ipx_config[2]; + AppliedConfig wwan_ip_config_x[2]; }; bool v4_has_shadowed_routes; @@ -471,8 +478,6 @@ typedef struct _NMDevicePrivate { NMArpingManager * announcing; } arping; - /* IP6 configuration info */ - NMIP6Config * ip6_config; union { const IpState ip6_state; IpState ip6_state_; @@ -2037,12 +2042,12 @@ nm_device_get_best_default_route (NMDevice *self, switch (addr_family) { case AF_INET: - return priv->ip4_config ? nm_ip4_config_best_default_route_get (priv->ip4_config) : NULL; + return priv->ip_config_4 ? nm_ip4_config_best_default_route_get (priv->ip_config_4) : NULL; case AF_INET6: - return priv->ip6_config ? nm_ip6_config_best_default_route_get (priv->ip6_config) : NULL; + return priv->ip_config_6 ? nm_ip6_config_best_default_route_get (priv->ip_config_6) : NULL; case AF_UNSPEC: - return (priv->ip4_config ? nm_ip4_config_best_default_route_get (priv->ip4_config) : NULL) - ?: (priv->ip6_config ? nm_ip6_config_best_default_route_get (priv->ip6_config) : NULL); + return (priv->ip_config_4 ? nm_ip4_config_best_default_route_get (priv->ip_config_4) : NULL) + ?: (priv->ip_config_6 ? nm_ip6_config_best_default_route_get (priv->ip_config_6) : NULL); default: g_return_val_if_reached (NULL); } @@ -2404,7 +2409,7 @@ nm_device_master_enslave_slave (NMDevice *self, NMDevice *slave, NMConnection *c /* Since slave devices don't have their own IP configuration, * set the MTU here. */ - _commit_mtu (slave, NM_DEVICE_GET_PRIVATE (slave)->ip4_config); + _commit_mtu (slave, NM_DEVICE_GET_PRIVATE (slave)->ip_config_4); return success; } @@ -2810,7 +2815,7 @@ ndisc_set_router_config (NMNDisc *ndisc, NMDevice *self) now = nm_utils_get_monotonic_timestamp_s (); - head_entry = nm_ip6_config_lookup_addresses (priv->ip6_config); + head_entry = nm_ip6_config_lookup_addresses (priv->ip_config_6); addresses = g_array_sized_new (FALSE, TRUE, sizeof (NMNDiscAddress), head_entry ? head_entry->len : 0); nm_dedup_multi_iter_for_each (&ipconf_iter, head_entry) { @@ -2853,11 +2858,11 @@ ndisc_set_router_config (NMNDisc *ndisc, NMDevice *self) ndisc_addr->preferred = preferred; } - len = nm_ip6_config_get_num_nameservers (priv->ip6_config); + len = nm_ip6_config_get_num_nameservers (priv->ip_config_6); dns_servers = g_array_sized_new (FALSE, TRUE, sizeof (NMNDiscDNSServer), len); g_array_set_size (dns_servers, len); for (i = 0; i < len; i++) { - const struct in6_addr *nameserver = nm_ip6_config_get_nameserver (priv->ip6_config, i); + const struct in6_addr *nameserver = nm_ip6_config_get_nameserver (priv->ip_config_6, i); NMNDiscDNSServer *ndisc_nameserver; ndisc_nameserver = &g_array_index (dns_servers, NMNDiscDNSServer, i); @@ -2866,11 +2871,11 @@ ndisc_set_router_config (NMNDisc *ndisc, NMDevice *self) ndisc_nameserver->lifetime = NM_NDISC_ROUTER_LIFETIME; } - len = nm_ip6_config_get_num_searches (priv->ip6_config); + len = nm_ip6_config_get_num_searches (priv->ip_config_6); dns_domains = g_array_sized_new (FALSE, TRUE, sizeof (NMNDiscDNSDomain), len); g_array_set_size (dns_domains, len); for (i = 0; i < len; i++) { - const char *search = nm_ip6_config_get_search (priv->ip6_config, i); + const char *search = nm_ip6_config_get_search (priv->ip_config_6, i); NMNDiscDNSDomain *ndisc_search; ndisc_search = &g_array_index (dns_domains, NMNDiscDNSDomain, i); @@ -3504,8 +3509,8 @@ realize_start_setup (NMDevice *self, g_return_if_fail (nm_device_get_unmanaged_flags (self, NM_UNMANAGED_PLATFORM_INIT)); g_return_if_fail (priv->ip_ifindex <= 0); g_return_if_fail (priv->ip_iface == NULL); - g_return_if_fail (!priv->queued_ip4_config_id); - g_return_if_fail (!priv->queued_ip6_config_id); + g_return_if_fail (!priv->queued_ip_config_id_4); + g_return_if_fail (!priv->queued_ip_config_id_6); _LOGD (LOGD_DEVICE, "start setup of %s, kernel ifindex %d", G_OBJECT_TYPE_NAME (self), plink ? plink->ifindex : 0); @@ -4610,9 +4615,9 @@ device_has_config (NMDevice *self) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); /* Check for IP configuration. */ - if (priv->ip4_config && nm_ip4_config_get_num_addresses (priv->ip4_config)) + if (priv->ip_config_4 && nm_ip4_config_get_num_addresses (priv->ip_config_4)) return TRUE; - if (priv->ip6_config && nm_ip6_config_get_num_addresses (priv->ip6_config)) + if (priv->ip_config_6 && nm_ip6_config_get_num_addresses (priv->ip_config_6)) return TRUE; /* The existence of a software device is good enough. */ @@ -4737,10 +4742,10 @@ nm_device_generate_connection (NMDevice *self, } } else { /* Only regular and master devices get IP configuration; slaves do not */ - s_ip4 = nm_ip4_config_create_setting (priv->ip4_config); + s_ip4 = nm_ip4_config_create_setting (priv->ip_config_4); nm_connection_add_setting (connection, s_ip4); - s_ip6 = nm_ip6_config_create_setting (priv->ip6_config); + s_ip6 = nm_ip6_config_create_setting (priv->ip_config_6); nm_connection_add_setting (connection, s_ip6); nm_connection_add_setting (connection, nm_setting_proxy_new ()); @@ -6033,7 +6038,7 @@ ensure_con_ip_config (NMDevice *self, int addr_family) const gboolean IS_IPv4 = (addr_family == AF_INET); NMIPConfig *con_ip_config; - if (priv->con_ipx_config[IS_IPv4]) + if (priv->con_ip_config_x[IS_IPv4]) return; connection = nm_device_get_applied_connection (self); @@ -6061,7 +6066,7 @@ ensure_con_ip_config (NMDevice *self, int addr_family) nm_ip_config_reset_routes (con_ip_config); } - priv->con_ipx_config[IS_IPv4] = con_ip_config; + priv->con_ip_config_x[IS_IPv4] = con_ip_config; } /*****************************************************************************/ @@ -6153,7 +6158,7 @@ ip_config_merge_and_apply (NMDevice *self, init_ip_config_dns_priority (self, composite); if (commit) { - if (priv->queued_ipx_config_id[IS_IPv4]) + if (priv->queued_ip_config_id_x[IS_IPv4]) update_ext_ip_config (self, addr_family, FALSE); ensure_con_ip_config (self, addr_family); } @@ -6203,16 +6208,16 @@ ip_config_merge_and_apply (NMDevice *self, } } - for (iter = priv->vpnx_configs[IS_IPv4]; iter; iter = iter->next) + for (iter = priv->vpn_configs_x[IS_IPv4]; iter; iter = iter->next) nm_ip_config_merge (composite, iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); - if (priv->ext_ipx_config[IS_IPv4]) - nm_ip_config_merge (composite, priv->ext_ipx_config[IS_IPv4], NM_IP_CONFIG_MERGE_DEFAULT, 0); + if (priv->ext_ip_config_x[IS_IPv4]) + nm_ip_config_merge (composite, priv->ext_ip_config_x[IS_IPv4], NM_IP_CONFIG_MERGE_DEFAULT, 0); /* Merge WWAN config *last* to ensure modem-given settings overwrite * any external stuff set by pppd or other scripts. */ - config = applied_config_get_current (&priv->wwan_ipx_config[IS_IPv4]); + config = applied_config_get_current (&priv->wwan_ip_config_x[IS_IPv4]); if (config) { nm_ip_config_merge (composite, config, (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) @@ -6236,9 +6241,9 @@ ip_config_merge_and_apply (NMDevice *self, } /* Merge user overrides into the composite config. For assumed connections, - * con_ipx_config is empty. */ - if (priv->con_ipx_config[IS_IPv4]) { - nm_ip_config_merge (composite, priv->con_ipx_config[IS_IPv4], NM_IP_CONFIG_MERGE_DEFAULT, + * con_ip_config_x is empty. */ + if (priv->con_ip_config_x[IS_IPv4]) { + nm_ip_config_merge (composite, priv->con_ip_config_x[IS_IPv4], NM_IP_CONFIG_MERGE_DEFAULT, default_route_metric_penalty_get (self, addr_family)); } @@ -6337,8 +6342,8 @@ dhcp4_fail (NMDevice *self, gboolean timeout) * on the interface. */ if ( priv->ip4_state == IP_DONE - && priv->con_ip4_config - && nm_ip4_config_get_num_addresses (priv->con_ip4_config) > 0) + && priv->con_ip_config_4 + && nm_ip4_config_get_num_addresses (priv->con_ip_config_4) > 0) goto clear_config; /* Fail the method in case of timeout or failure during initial @@ -7015,8 +7020,8 @@ dhcp6_fail (NMDevice *self, gboolean timeout) * on the interface. */ if ( priv->ip6_state == IP_DONE - && priv->con_ip6_config - && nm_ip6_config_get_num_addresses (priv->con_ip6_config)) + && priv->con_ip_config_6 + && nm_ip6_config_get_num_addresses (priv->con_ip_config_6)) goto clear_config; /* Fail the method in case of timeout or failure during initial @@ -7789,7 +7794,7 @@ nm_device_commit_mtu (NMDevice *self) if ( state >= NM_DEVICE_STATE_CONFIG && state < NM_DEVICE_STATE_DEACTIVATING) { _LOGT (LOGD_DEVICE, "mtu: commit-mtu..."); - _commit_mtu (self, NM_DEVICE_GET_PRIVATE (self)->ip4_config); + _commit_mtu (self, NM_DEVICE_GET_PRIVATE (self)->ip_config_4); } else _LOGT (LOGD_DEVICE, "mtu: commit-mtu... skip due to state %s", nm_device_state_to_str (state)); } @@ -7929,10 +7934,10 @@ ndisc_ra_timeout (NMNDisc *ndisc, NMDevice *self) * config, consider that sufficient for IPv6 success. * * FIXME: it doesn't seem correct to determine this based on which - * addresses we find inside priv->ip6_config. + * addresses we find inside priv->ip_config_6. */ - if ( priv->ip6_config - && nm_ip6_config_find_first_address (priv->ip6_config, + if ( priv->ip_config_6 + && nm_ip6_config_find_first_address (priv->ip_config_6, NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL | NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY)) nm_device_activate_schedule_ip6_config_result (self); @@ -7961,7 +7966,7 @@ addrconf6_start_with_link_ready (NMDevice *self) /* Apply any manual configuration before starting RA */ if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) { _LOGW (LOGD_IP6, "failed to apply manual IPv6 configuration"); - g_clear_object (&priv->con_ip6_config); + g_clear_object (&priv->con_ip_config_6); } /* FIXME: These sysctls would probably be better set by the lndp ndisc itself. */ @@ -8331,7 +8336,7 @@ act_stage3_ip6_config_start (NMDevice *self, * expose any ipv6 sysctls or allow presence of any addresses on the interface, * including LL, which * would make it impossible to autoconfigure MTU to a * correct value. */ - _commit_mtu (self, priv->ip4_config); + _commit_mtu (self, priv->ip_config_4); /* Any method past this point requires an IPv6LL address. Use NM-controlled * IPv6LL if this is not an assumed connection, since assumed connections @@ -8948,7 +8953,7 @@ activate_stage5_ip4_config_result (NMDevice *self) if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) { gs_free_error GError *error = NULL; - if (!start_sharing (self, priv->ip4_config, &error)) { + if (!start_sharing (self, priv->ip_config_4, &error)) { _LOGW (LOGD_SHARING, "Activation: Stage 5 of 5 (IPv4 Commit) start sharing failed: %s", error->message); nm_device_ip_method_failed (self, AF_INET, NM_DEVICE_STATE_REASON_SHARED_START_FAILED); return; @@ -9019,8 +9024,8 @@ dad6_get_pending_addresses (NMDevice *self) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMIP6Config *confs[] = { (NMIP6Config *) applied_config_get_current (&priv->ac_ip6_config), (NMIP6Config *) applied_config_get_current (&priv->dhcp6.ip6_config), - priv->con_ip6_config, - (NMIP6Config *) applied_config_get_current (&priv->wwan_ip6_config) }; + priv->con_ip_config_6, + (NMIP6Config *) applied_config_get_current (&priv->wwan_ip_config_6) }; const NMPlatformIP6Address *addr, *pl_addr; NMIP6Config *dad6_config = NULL; NMDedupMultiIter ipconf_iter; @@ -9254,9 +9259,9 @@ _update_ip4_address (NMDevice *self) g_return_if_fail (NM_IS_DEVICE (self)); - if ( priv->ip4_config + if ( priv->ip_config_4 && ip_config_valid (priv->state) - && (address = nm_ip4_config_get_first_address (priv->ip4_config))) { + && (address = nm_ip4_config_get_first_address (priv->ip_config_4))) { if (address->address != priv->ip4_address) { priv->ip4_address = address->address; _notify (self, PROP_IP4_ADDRESS); @@ -9356,7 +9361,7 @@ _cleanup_ip4_pre (NMDevice *self, CleanupType cleanup_type) _set_ip_state (self, AF_INET, IP_NONE); - if (nm_clear_g_source (&priv->queued_ip4_config_id)) + if (nm_clear_g_source (&priv->queued_ip_config_id_4)) _LOGD (LOGD_DEVICE, "clearing queued IP4 config change"); priv->queued_ip4_config_pending = FALSE; @@ -9373,7 +9378,7 @@ _cleanup_ip6_pre (NMDevice *self, CleanupType cleanup_type) _set_ip_state (self, AF_INET6, IP_NONE); - if (nm_clear_g_source (&priv->queued_ip6_config_id)) + if (nm_clear_g_source (&priv->queued_ip_config_id_6)) _LOGD (LOGD_DEVICE, "clearing queued IP6 config change"); priv->queued_ip6_config_pending = FALSE; @@ -9459,12 +9464,12 @@ nm_device_reactivate_ip4_config (NMDevice *self, priv = NM_DEVICE_GET_PRIVATE (self); if (priv->ip4_state != IP_NONE) { - g_clear_object (&priv->con_ip4_config); - g_clear_object (&priv->ext_ip4_config); + g_clear_object (&priv->con_ip_config_4); + g_clear_object (&priv->ext_ip_config_4); g_clear_object (&priv->dev_ip4_config.current); - g_clear_object (&priv->wwan_ip4_config.current); - priv->con_ip4_config = _ip4_config_new (self); - nm_ip4_config_merge_setting (priv->con_ip4_config, + g_clear_object (&priv->wwan_ip_config_4.current); + priv->con_ip_config_4 = _ip4_config_new (self); + nm_ip4_config_merge_setting (priv->con_ip_config_4, s_ip4_new, _get_mdns (self), nm_device_get_route_table (self, AF_INET, TRUE), @@ -9501,13 +9506,13 @@ nm_device_reactivate_ip6_config (NMDevice *self, priv = NM_DEVICE_GET_PRIVATE (self); if (priv->ip6_state != IP_NONE) { - g_clear_object (&priv->con_ip6_config); - g_clear_object (&priv->ext_ip6_config); + g_clear_object (&priv->con_ip_config_6); + g_clear_object (&priv->ext_ip_config_6); g_clear_object (&priv->ac_ip6_config.current); g_clear_object (&priv->dhcp6.ip6_config.current); - g_clear_object (&priv->wwan_ip6_config.current); - priv->con_ip6_config = _ip6_config_new (self); - nm_ip6_config_merge_setting (priv->con_ip6_config, + g_clear_object (&priv->wwan_ip_config_6.current); + priv->con_ip_config_6 = _ip6_config_new (self); + nm_ip6_config_merge_setting (priv->con_ip_config_6, s_ip6_new, nm_device_get_route_table (self, AF_INET6, TRUE), nm_device_get_route_metric (self, AF_INET6)); @@ -10465,7 +10470,7 @@ nm_device_get_ip4_config (NMDevice *self) { g_return_val_if_fail (NM_IS_DEVICE (self), NULL); - return NM_DEVICE_GET_PRIVATE (self)->ip4_config; + return NM_DEVICE_GET_PRIVATE (self)->ip_config_4; } @@ -10496,7 +10501,7 @@ nm_device_set_ip4_config (NMDevice *self, priv = NM_DEVICE_GET_PRIVATE (self); - old_config = priv->ip4_config; + old_config = priv->ip_config_4; /* Always commit to nm-platform to update lifetimes */ if (commit && new_config) { @@ -10522,7 +10527,7 @@ nm_device_set_ip4_config (NMDevice *self, } } else { has_changes = TRUE; - priv->ip4_config = g_object_ref (new_config); + priv->ip_config_4 = g_object_ref (new_config); if (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) nm_dbus_object_export (NM_DBUS_OBJECT (new_config)); @@ -10532,7 +10537,7 @@ nm_device_set_ip4_config (NMDevice *self, } } else if (old_config) { has_changes = TRUE; - priv->ip4_config = NULL; + priv->ip_config_4 = NULL; _LOGD (LOGD_IP4, "ip4-config: clear IP4Config instance (%s)", nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); /* Device config is invalid if combined config is invalid */ @@ -10549,11 +10554,11 @@ nm_device_set_ip4_config (NMDevice *self, _update_ip4_address (self); - if (old_config != priv->ip4_config) + if (old_config != priv->ip_config_4) _notify (self, PROP_IP4_CONFIG); - g_signal_emit (self, signals[IP4_CONFIG_CHANGED], 0, priv->ip4_config, old_config); + g_signal_emit (self, signals[IP4_CONFIG_CHANGED], 0, priv->ip_config_4, old_config); - if (old_config != priv->ip4_config) + if (old_config != priv->ip_config_4) nm_dbus_object_clear_and_unexport (&old_config); if ( nm_device_sys_iface_state_is_external (self) @@ -10566,7 +10571,7 @@ nm_device_set_ip4_config (NMDevice *self, g_object_freeze_notify (G_OBJECT (settings_connection)); nm_connection_remove_setting (NM_CONNECTION (settings_connection), NM_TYPE_SETTING_IP4_CONFIG); - s_ip4 = nm_ip4_config_create_setting (priv->ip4_config); + s_ip4 = nm_ip4_config_create_setting (priv->ip_config_4); nm_connection_add_setting (NM_CONNECTION (settings_connection), s_ip4); g_object_thaw_notify (G_OBJECT (settings_connection)); @@ -10621,7 +10626,7 @@ nm_device_replace_vpn4_config (NMDevice *self, NMIP4Config *old, NMIP4Config *co nm_assert (!old || nm_ip4_config_get_ifindex (old) == nm_device_get_ip_ifindex (self)); nm_assert (!config || nm_ip4_config_get_ifindex (config) == nm_device_get_ip_ifindex (self)); - if (!_replace_vpn_config_in_list (&priv->vpn4_configs, (GObject *) old, (GObject *) config)) + if (!_replace_vpn_config_in_list (&priv->vpn_configs_4, (GObject *) old, (GObject *) config)) return; /* NULL to use existing configs */ @@ -10634,7 +10639,7 @@ nm_device_set_wwan_ip4_config (NMDevice *self, NMIP4Config *config) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - applied_config_init (&priv->wwan_ip4_config, config); + applied_config_init (&priv->wwan_ip_config_4, config); if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) _LOGW (LOGD_IP4, "failed to set WWAN IPv4 configuration"); } @@ -10665,13 +10670,13 @@ nm_device_set_ip6_config (NMDevice *self, priv = NM_DEVICE_GET_PRIVATE (self); - old_config = priv->ip6_config; + old_config = priv->ip_config_6; /* Always commit to nm-platform to update lifetimes */ if (commit && new_config) { gs_unref_ptrarray GPtrArray *temporary_not_available = NULL; - _commit_mtu (self, priv->ip4_config); + _commit_mtu (self, priv->ip_config_4); success = nm_ip6_config_commit (new_config, nm_device_get_platform (self), @@ -10695,7 +10700,7 @@ nm_device_set_ip6_config (NMDevice *self, } } else { has_changes = TRUE; - priv->ip6_config = g_object_ref (new_config); + priv->ip_config_6 = g_object_ref (new_config); if (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) nm_dbus_object_export (NM_DBUS_OBJECT (new_config)); @@ -10705,7 +10710,7 @@ nm_device_set_ip6_config (NMDevice *self, } } else if (old_config) { has_changes = TRUE; - priv->ip6_config = NULL; + priv->ip_config_6 = NULL; priv->needs_ip6_subnet = FALSE; _LOGD (LOGD_IP6, "ip6-config: clear IP6Config instance (%s)", nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); @@ -10714,11 +10719,11 @@ nm_device_set_ip6_config (NMDevice *self, if (has_changes) { NMSettingsConnection *settings_connection; - if (old_config != priv->ip6_config) + if (old_config != priv->ip_config_6) _notify (self, PROP_IP6_CONFIG); - g_signal_emit (self, signals[IP6_CONFIG_CHANGED], 0, priv->ip6_config, old_config); + g_signal_emit (self, signals[IP6_CONFIG_CHANGED], 0, priv->ip_config_6, old_config); - if (old_config != priv->ip6_config) + if (old_config != priv->ip_config_6) nm_dbus_object_clear_and_unexport (&old_config); if ( nm_device_sys_iface_state_is_external (self) @@ -10731,7 +10736,7 @@ nm_device_set_ip6_config (NMDevice *self, g_object_freeze_notify (G_OBJECT (settings_connection)); nm_connection_remove_setting (NM_CONNECTION (settings_connection), NM_TYPE_SETTING_IP6_CONFIG); - s_ip6 = nm_ip6_config_create_setting (priv->ip6_config); + s_ip6 = nm_ip6_config_create_setting (priv->ip_config_6); nm_connection_add_setting (NM_CONNECTION (settings_connection), s_ip6); g_object_thaw_notify (G_OBJECT (settings_connection)); @@ -10756,7 +10761,7 @@ nm_device_replace_vpn6_config (NMDevice *self, NMIP6Config *old, NMIP6Config *co nm_assert (!old || nm_ip6_config_get_ifindex (old) == nm_device_get_ip_ifindex (self)); nm_assert (!config || nm_ip6_config_get_ifindex (config) == nm_device_get_ip_ifindex (self)); - if (!_replace_vpn_config_in_list (&priv->vpn6_configs, (GObject *) old, (GObject *) config)) + if (!_replace_vpn_config_in_list (&priv->vpn_configs_6, (GObject *) old, (GObject *) config)) return; /* NULL to use existing configs */ @@ -10769,7 +10774,7 @@ nm_device_set_wwan_ip6_config (NMDevice *self, NMIP6Config *config) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - applied_config_init (&priv->wwan_ip6_config, config); + applied_config_init (&priv->wwan_ip_config_6, config); if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP6, "failed to set WWAN IPv6 configuration"); } @@ -10787,7 +10792,7 @@ nm_device_get_ip6_config (NMDevice *self) { g_return_val_if_fail (NM_IS_DEVICE (self), NULL); - return NM_DEVICE_GET_PRIVATE (self)->ip6_config; + return NM_DEVICE_GET_PRIVATE (self)->ip_config_6; } /*****************************************************************************/ @@ -11021,15 +11026,15 @@ nm_device_start_ip_check (NMDevice *self) if (timeout) { const NMPObject *gw; - if (priv->ip4_config && priv->ip4_state == IP_DONE) { - gw = nm_ip4_config_best_default_route_get (priv->ip4_config); + if (priv->ip_config_4 && priv->ip4_state == IP_DONE) { + gw = nm_ip4_config_best_default_route_get (priv->ip_config_4); if (gw) { nm_utils_inet4_ntop (NMP_OBJECT_CAST_IP4_ROUTE (gw)->gateway, buf); ping_binary = nm_utils_find_helper ("ping", "/usr/bin/ping", NULL); log_domain = LOGD_IP4; } - } else if (priv->ip6_config && priv->ip6_state == IP_DONE) { - gw = nm_ip6_config_best_default_route_get (priv->ip6_config); + } else if (priv->ip_config_6 && priv->ip6_state == IP_DONE) { + gw = nm_ip6_config_best_default_route_get (priv->ip_config_6); if (gw) { nm_utils_inet6_ntop (&NMP_OBJECT_CAST_IP6_ROUTE (gw)->gateway, buf); ping_binary = nm_utils_find_helper ("ping6", "/usr/bin/ping6", NULL); @@ -11252,8 +11257,8 @@ intersect_ext_config (NMDevice *self, AppliedConfig *config) family = nm_ip_config_get_addr_family (config->orig); penalty = default_route_metric_penalty_get (self, family); ext = family == AF_INET - ? (NMIPConfig *) priv->ext_ip4_config - : (NMIPConfig *) priv->ext_ip6_config; + ? (NMIPConfig *) priv->ext_ip_config_4 + : (NMIPConfig *) priv->ext_ip_config_6; if (config->current) nm_ip_config_intersect (config->current, ext, penalty); @@ -11279,53 +11284,53 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_config if (addr_family == AF_INET) { - g_clear_object (&priv->ext_ip4_config); - priv->ext_ip4_config = nm_ip4_config_capture (nm_device_get_multi_index (self), + g_clear_object (&priv->ext_ip_config_4); + priv->ext_ip_config_4 = nm_ip4_config_capture (nm_device_get_multi_index (self), nm_device_get_platform (self), ifindex); - if (priv->ext_ip4_config) { + if (priv->ext_ip_config_4) { if (intersect_configs) { /* This function was called upon external changes. Remove the configuration * (addresses,routes) that is no longer present externally from the internal * config. This way, we don't re-add addresses that were manually removed * by the user. */ - if (priv->con_ip4_config) { - nm_ip4_config_intersect (priv->con_ip4_config, priv->ext_ip4_config, + if (priv->con_ip_config_4) { + nm_ip4_config_intersect (priv->con_ip_config_4, priv->ext_ip_config_4, default_route_metric_penalty_get (self, AF_INET)); } intersect_ext_config (self, &priv->dev_ip4_config); - intersect_ext_config (self, &priv->wwan_ip4_config); + intersect_ext_config (self, &priv->wwan_ip_config_4); - for (iter = priv->vpn4_configs; iter; iter = iter->next) - nm_ip4_config_intersect (iter->data, priv->ext_ip4_config, 0); + for (iter = priv->vpn_configs_4; iter; iter = iter->next) + nm_ip4_config_intersect (iter->data, priv->ext_ip_config_4, 0); } - /* Remove parts from ext_ip4_config to only contain the information that + /* Remove parts from ext_ip_config_4 to only contain the information that * was configured externally -- we already have the same configuration from * internal origins. */ - if (priv->con_ip4_config) { - nm_ip4_config_subtract (priv->ext_ip4_config, priv->con_ip4_config, + if (priv->con_ip_config_4) { + nm_ip4_config_subtract (priv->ext_ip_config_4, priv->con_ip_config_4, default_route_metric_penalty_get (self, AF_INET)); } if (applied_config_get_current (&priv->dev_ip4_config)) { - nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip4_config, + nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip_config_4, applied_config_get_current (&priv->dev_ip4_config), default_route_metric_penalty_get (self, AF_INET)); } - if (applied_config_get_current (&priv->wwan_ip4_config)) { - nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip4_config, - applied_config_get_current (&priv->wwan_ip4_config), + if (applied_config_get_current (&priv->wwan_ip_config_4)) { + nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip_config_4, + applied_config_get_current (&priv->wwan_ip_config_4), default_route_metric_penalty_get (self, AF_INET)); } - for (iter = priv->vpn4_configs; iter; iter = iter->next) - nm_ip4_config_subtract (priv->ext_ip4_config, iter->data, 0); + for (iter = priv->vpn_configs_4; iter; iter = iter->next) + nm_ip4_config_subtract (priv->ext_ip_config_4, iter->data, 0); } } else { nm_assert (addr_family == AF_INET6); - g_clear_object (&priv->ext_ip6_config); + g_clear_object (&priv->ext_ip_config_6); g_clear_object (&priv->ext_ip6_config_captured); priv->ext_ip6_config_captured = nm_ip6_config_capture (nm_device_get_multi_index (self), nm_device_get_platform (self), @@ -11333,50 +11338,50 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_config NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); if (priv->ext_ip6_config_captured) { - priv->ext_ip6_config = nm_ip6_config_new_cloned (priv->ext_ip6_config_captured); + priv->ext_ip_config_6 = nm_ip6_config_new_cloned (priv->ext_ip6_config_captured); if (intersect_configs) { /* This function was called upon external changes. Remove the configuration * (addresses,routes) that is no longer present externally from the internal * config. This way, we don't re-add addresses that were manually removed * by the user. */ - if (priv->con_ip6_config) { - nm_ip6_config_intersect (priv->con_ip6_config, priv->ext_ip6_config, + if (priv->con_ip_config_6) { + nm_ip6_config_intersect (priv->con_ip_config_6, priv->ext_ip_config_6, default_route_metric_penalty_get (self, AF_INET6)); } intersect_ext_config (self, &priv->ac_ip6_config); intersect_ext_config (self, &priv->dhcp6.ip6_config); - intersect_ext_config (self, &priv->wwan_ip6_config); + intersect_ext_config (self, &priv->wwan_ip_config_6); - for (iter = priv->vpn6_configs; iter; iter = iter->next) - nm_ip6_config_intersect (iter->data, priv->ext_ip6_config, 0); + for (iter = priv->vpn_configs_6; iter; iter = iter->next) + nm_ip6_config_intersect (iter->data, priv->ext_ip_config_6, 0); } - /* Remove parts from ext_ip6_config to only contain the information that + /* Remove parts from ext_ip_config_6 to only contain the information that * was configured externally -- we already have the same configuration from * internal origins. */ - if (priv->con_ip6_config) { - nm_ip6_config_subtract (priv->ext_ip6_config, priv->con_ip6_config, + if (priv->con_ip_config_6) { + nm_ip6_config_subtract (priv->ext_ip_config_6, priv->con_ip_config_6, default_route_metric_penalty_get (self, AF_INET6)); } if (applied_config_get_current (&priv->ac_ip6_config)) { - nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip6_config, + nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip_config_6, applied_config_get_current (&priv->ac_ip6_config), default_route_metric_penalty_get (self, AF_INET6)); } if (applied_config_get_current (&priv->dhcp6.ip6_config)) { - nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip6_config, + nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip_config_6, applied_config_get_current (&priv->dhcp6.ip6_config), default_route_metric_penalty_get (self, AF_INET6)); } - if (applied_config_get_current (&priv->wwan_ip6_config)) { - nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip6_config, - applied_config_get_current (&priv->wwan_ip6_config), + if (applied_config_get_current (&priv->wwan_ip_config_6)) { + nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip_config_6, + applied_config_get_current (&priv->wwan_ip_config_6), default_route_metric_penalty_get (self, AF_INET6)); } - for (iter = priv->vpn6_configs; iter; iter = iter->next) - nm_ip6_config_subtract (priv->ext_ip6_config, iter->data, 0); + for (iter = priv->vpn_configs_6; iter; iter = iter->next) + nm_ip6_config_subtract (priv->ext_ip_config_6, iter->data, 0); } } @@ -11397,7 +11402,7 @@ update_ip_config (NMDevice *self, int addr_family) if (update_ext_ip_config (self, addr_family, TRUE)) { if (addr_family == AF_INET) { - if (priv->ext_ip4_config) + if (priv->ext_ip_config_4) ip_config_merge_and_apply (self, AF_INET, FALSE); } else { if (priv->ext_ip6_config_captured) @@ -11433,7 +11438,7 @@ queued_ip4_config_change (gpointer user_data) if (priv->queued_state.id) return TRUE; - priv->queued_ip4_config_id = 0; + priv->queued_ip_config_id_4 = 0; /* If a commit is scheduled, this function would potentially interfere with * it changing IP configurations before they are applied. Postpone the @@ -11443,7 +11448,7 @@ queued_ip4_config_change (gpointer user_data) activate_stage5_ip4_config_result, AF_INET)) { priv->queued_ip4_config_pending = FALSE; - priv->queued_ip4_config_id = g_idle_add (queued_ip4_config_change, self); + priv->queued_ip_config_id_4 = g_idle_add (queued_ip4_config_change, self); _LOGT (LOGD_DEVICE, "IP4 update was postponed"); } else update_ip_config (self, AF_INET); @@ -11476,7 +11481,7 @@ queued_ip6_config_change (gpointer user_data) if (priv->queued_state.id) return G_SOURCE_CONTINUE; - priv->queued_ip6_config_id = 0; + priv->queued_ip_config_id_6 = 0; /* If a commit is scheduled, this function would potentially interfere with * it changing IP configurations before they are applied. Postpone the @@ -11486,7 +11491,7 @@ queued_ip6_config_change (gpointer user_data) activate_stage5_ip6_config_commit, AF_INET6)) { priv->queued_ip6_config_pending = FALSE; - priv->queued_ip6_config_id = g_idle_add (queued_ip6_config_change, self); + priv->queued_ip_config_id_6 = g_idle_add (queued_ip6_config_change, self); _LOGT (LOGD_DEVICE, "IP6 update was postponed"); } else { update_ip_config (self, AF_INET6); @@ -11527,8 +11532,8 @@ queued_ip6_config_change (gpointer user_data) * ("Addressing Model"): "All interfaces are required to have at least * one link-local unicast address". */ - if ( priv->ip6_config - && nm_ip6_config_get_num_addresses (priv->ip6_config)) + if ( priv->ip_config_6 + && nm_ip6_config_get_num_addresses (priv->ip_config_6)) need_ipv6ll = TRUE; if (need_ipv6ll) @@ -11580,10 +11585,10 @@ device_ipx_changed (NMPlatform *platform, case NMP_OBJECT_TYPE_IP4_ROUTE: if (nm_device_get_unmanaged_flags (self, NM_UNMANAGED_PLATFORM_INIT)) { priv->queued_ip4_config_pending = TRUE; - nm_assert_se (!nm_clear_g_source (&priv->queued_ip4_config_id)); - } else if (!priv->queued_ip4_config_id) { + nm_assert_se (!nm_clear_g_source (&priv->queued_ip_config_id_4)); + } else if (!priv->queued_ip_config_id_4) { priv->queued_ip4_config_pending = FALSE; - priv->queued_ip4_config_id = g_idle_add (queued_ip4_config_change, self); + priv->queued_ip_config_id_4 = g_idle_add (queued_ip4_config_change, self); _LOGD (LOGD_DEVICE, "queued IP4 config change"); } break; @@ -11600,10 +11605,10 @@ device_ipx_changed (NMPlatform *platform, case NMP_OBJECT_TYPE_IP6_ROUTE: if (nm_device_get_unmanaged_flags (self, NM_UNMANAGED_PLATFORM_INIT)) { priv->queued_ip6_config_pending = TRUE; - nm_assert_se (!nm_clear_g_source (&priv->queued_ip6_config_id)); - } else if (!priv->queued_ip6_config_id) { + nm_assert_se (!nm_clear_g_source (&priv->queued_ip_config_id_6)); + } else if (!priv->queued_ip_config_id_6) { priv->queued_ip6_config_pending = FALSE; - priv->queued_ip6_config_id = g_idle_add (queued_ip6_config_change, self); + priv->queued_ip_config_id_6 = g_idle_add (queued_ip6_config_change, self); _LOGD (LOGD_DEVICE, "queued IP6 config change"); } break; @@ -11871,14 +11876,14 @@ _set_unmanaged_flags (NMDevice *self, if (priv->queued_ip4_config_pending) { priv->queued_ip4_config_pending = FALSE; - nm_assert_se (!nm_clear_g_source (&priv->queued_ip4_config_id)); - priv->queued_ip4_config_id = g_idle_add (queued_ip4_config_change, self); + nm_assert_se (!nm_clear_g_source (&priv->queued_ip_config_id_4)); + priv->queued_ip_config_id_4 = g_idle_add (queued_ip4_config_change, self); } if (priv->queued_ip6_config_pending) { priv->queued_ip6_config_pending = FALSE; - nm_assert_se (!nm_clear_g_source (&priv->queued_ip6_config_id)); - priv->queued_ip6_config_id = g_idle_add (queued_ip6_config_change, self); + nm_assert_se (!nm_clear_g_source (&priv->queued_ip_config_id_6)); + priv->queued_ip_config_id_6 = g_idle_add (queued_ip6_config_change, self); } if (!priv->pending_actions) { @@ -12212,9 +12217,9 @@ nm_device_update_metered (NMDevice *self) /* Try to guess a value using the metered flag in IP configuration */ if (value == NM_METERED_INVALID) { - if ( priv->ip4_config + if ( priv->ip_config_4 && priv->ip4_state == IP_DONE - && nm_ip4_config_get_metered (priv->ip4_config)) + && nm_ip4_config_get_metered (priv->ip_config_4)) value = NM_METERED_GUESS_YES; } @@ -12735,26 +12740,26 @@ _cleanup_generic_post (NMDevice *self, CleanupType cleanup_type) nm_device_set_ip4_config (self, NULL, TRUE, NULL); nm_device_set_ip6_config (self, NULL, TRUE); g_clear_object (&priv->proxy_config); - g_clear_object (&priv->con_ip4_config); + g_clear_object (&priv->con_ip_config_4); applied_config_clear (&priv->dev_ip4_config); - applied_config_clear (&priv->wwan_ip4_config); - g_clear_object (&priv->ext_ip4_config); - g_clear_object (&priv->ip4_config); - g_clear_object (&priv->con_ip6_config); + applied_config_clear (&priv->wwan_ip_config_4); + g_clear_object (&priv->ext_ip_config_4); + g_clear_object (&priv->ip_config_4); + g_clear_object (&priv->con_ip_config_6); applied_config_clear (&priv->ac_ip6_config); - g_clear_object (&priv->ext_ip6_config); + g_clear_object (&priv->ext_ip_config_6); g_clear_object (&priv->ext_ip6_config_captured); - applied_config_clear (&priv->wwan_ip6_config); - g_clear_object (&priv->ip6_config); + applied_config_clear (&priv->wwan_ip_config_6); + g_clear_object (&priv->ip_config_6); g_clear_object (&priv->dad6_ip6_config); g_clear_pointer (&priv->rt6_temporary_not_available, g_hash_table_unref); nm_clear_g_source (&priv->rt6_temporary_not_available_id); - g_slist_free_full (priv->vpn4_configs, g_object_unref); - priv->vpn4_configs = NULL; - g_slist_free_full (priv->vpn6_configs, g_object_unref); - priv->vpn6_configs = NULL; + g_slist_free_full (priv->vpn_configs_4, g_object_unref); + priv->vpn_configs_4 = NULL; + g_slist_free_full (priv->vpn_configs_6, g_object_unref); + priv->vpn_configs_6 = NULL; /* We no longer accept the delegations. nm_device_set_ip6_config(NULL) * above disables them. */ @@ -12906,10 +12911,10 @@ find_dhcp4_address (NMDevice *self) const NMPlatformIP4Address *a; NMDedupMultiIter ipconf_iter; - if (!priv->ip4_config) + if (!priv->ip_config_4) return NULL; - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, priv->ip4_config, &a) { + nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, priv->ip_config_4, &a) { if (a->addr_source == NM_IP_CONFIG_SOURCE_DHCP) return g_strdup (nm_utils_inet4_ntop (a->address, NULL)); } @@ -14859,13 +14864,13 @@ get_property (GObject *object, guint prop_id, g_value_set_uint (value, priv->mtu); break; case PROP_IP4_CONFIG: - nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->ip4_config : NULL); + nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->ip_config_4 : NULL); break; case PROP_DHCP4_CONFIG: nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->dhcp4.config : NULL); break; case PROP_IP6_CONFIG: - nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->ip6_config : NULL); + nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->ip_config_6 : NULL); break; case PROP_DHCP6_CONFIG: nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->dhcp6.config : NULL); From 3de79deb1a021219e81121a5c536e883d7637b7a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 Mar 2018 18:54:59 +0100 Subject: [PATCH 25/28] device: merge IPv4 and IPv6 versions of nm_device_set_ip_config() (pt1) Almost on change, just merge the functions in one, with a top-level if/else. --- src/devices/nm-device.c | 436 ++++++++++++++++++++-------------------- 1 file changed, 218 insertions(+), 218 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 618b7022c3..014c3adde6 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -557,18 +557,16 @@ static void nm_device_set_proxy_config (NMDevice *self, const char *pac_url); static gboolean update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_configs); -static gboolean nm_device_set_ip4_config (NMDevice *self, - NMIP4Config *config, - gboolean commit, - GPtrArray *ip4_dev_route_blacklist); +static gboolean nm_device_set_ip_config (NMDevice *self, + int addr_family, + NMIPConfig *config, + gboolean commit, + GPtrArray *ip4_dev_route_blacklist); + static gboolean ip_config_merge_and_apply (NMDevice *self, int addr_family, gboolean commit); -static gboolean nm_device_set_ip6_config (NMDevice *self, - NMIP6Config *config, - gboolean commit); - static gboolean nm_device_master_add_slave (NMDevice *self, NMDevice *slave, gboolean configure); static void nm_device_slave_notify_enslave (NMDevice *self, gboolean success); static void nm_device_slave_notify_release (NMDevice *self, NMDeviceStateReason reason); @@ -4362,8 +4360,8 @@ nm_device_removed (NMDevice *self, gboolean unconfigure_ip_config) if (!unconfigure_ip_config) return; - nm_device_set_ip4_config (self, NULL, FALSE, NULL); - nm_device_set_ip6_config (self, NULL, FALSE); + nm_device_set_ip_config (self, AF_INET, NULL, FALSE, NULL); + nm_device_set_ip_config (self, AF_INET6, NULL, FALSE, NULL); } static gboolean @@ -6280,13 +6278,11 @@ ip_config_merge_and_apply (NMDevice *self, } } - if (IS_IPv4) { - success = nm_device_set_ip4_config (self, NM_IP4_CONFIG (composite), commit, ip4_dev_route_blacklist); - if (commit) + success = nm_device_set_ip_config (self, addr_family, composite, commit, ip4_dev_route_blacklist); + if (commit) { + if (IS_IPv4) priv->v4_commit_first_time = FALSE; - } else { - success = nm_device_set_ip6_config (self, NM_IP6_CONFIG (composite), commit); - if (commit) + else priv->v6_commit_first_time = FALSE; } @@ -10475,112 +10471,223 @@ nm_device_get_ip4_config (NMDevice *self) static gboolean -nm_device_set_ip4_config (NMDevice *self, - NMIP4Config *new_config, - gboolean commit, - GPtrArray *ip4_dev_route_blacklist) +nm_device_set_ip_config (NMDevice *self, + int addr_family, + NMIPConfig *_new_config, + gboolean commit, + GPtrArray *ip4_dev_route_blacklist) { - NMDevicePrivate *priv; - NMIP4Config *old_config = NULL; - gboolean has_changes = FALSE; - gboolean success = TRUE; + const gboolean IS_IPv4 = (addr_family == AF_INET); - g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); + nm_assert_addr_family (addr_family); + nm_assert (!_new_config || nm_ip_config_get_addr_family (_new_config) == addr_family); - _LOGD (LOGD_IP4, "ip4-config: update (commit=%d, new-config=%p)", - commit, new_config); + if (IS_IPv4) { + NMIP4Config *new_config = NM_IP4_CONFIG (_new_config); + NMDevicePrivate *priv; + NMIP4Config *old_config = NULL; + gboolean has_changes = FALSE; + gboolean success = TRUE; - nm_assert ( !new_config - || ( new_config - && ({ - int ip_ifindex = nm_device_get_ip_ifindex (self); + g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); - ( ip_ifindex > 0 - && ip_ifindex == nm_ip4_config_get_ifindex (new_config)); - }))); + _LOGD (LOGD_IP4, "ip4-config: update (commit=%d, new-config=%p)", + commit, new_config); - priv = NM_DEVICE_GET_PRIVATE (self); + nm_assert ( !new_config + || ( new_config + && ({ + int ip_ifindex = nm_device_get_ip_ifindex (self); - old_config = priv->ip_config_4; + ( ip_ifindex > 0 + && ip_ifindex == nm_ip4_config_get_ifindex (new_config)); + }))); - /* Always commit to nm-platform to update lifetimes */ - if (commit && new_config) { - _commit_mtu (self, new_config); - success = nm_ip4_config_commit (new_config, - nm_device_get_platform (self), - nm_device_get_route_table (self, AF_INET, FALSE) - ? NM_IP_ROUTE_TABLE_SYNC_MODE_FULL - : NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN); - nm_platform_ip4_dev_route_blacklist_set (nm_device_get_platform (self), - nm_ip4_config_get_ifindex (new_config), - ip4_dev_route_blacklist); - } + priv = NM_DEVICE_GET_PRIVATE (self); - if (new_config) { - if (old_config) { - /* has_changes is set only on relevant changes, because when the configuration changes, - * this causes a re-read and reset. This should only happen for relevant changes */ - nm_ip4_config_replace (old_config, new_config, &has_changes); - if (has_changes) { - _LOGD (LOGD_IP4, "ip4-config: update IP4Config instance (%s)", - nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); + old_config = priv->ip_config_4; + + /* Always commit to nm-platform to update lifetimes */ + if (commit && new_config) { + _commit_mtu (self, new_config); + success = nm_ip4_config_commit (new_config, + nm_device_get_platform (self), + nm_device_get_route_table (self, AF_INET, FALSE) + ? NM_IP_ROUTE_TABLE_SYNC_MODE_FULL + : NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN); + nm_platform_ip4_dev_route_blacklist_set (nm_device_get_platform (self), + nm_ip4_config_get_ifindex (new_config), + ip4_dev_route_blacklist); + } + + if (new_config) { + if (old_config) { + /* has_changes is set only on relevant changes, because when the configuration changes, + * this causes a re-read and reset. This should only happen for relevant changes */ + nm_ip4_config_replace (old_config, new_config, &has_changes); + if (has_changes) { + _LOGD (LOGD_IP4, "ip4-config: update IP4Config instance (%s)", + nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); + } + } else { + has_changes = TRUE; + priv->ip_config_4 = g_object_ref (new_config); + + if (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) + nm_dbus_object_export (NM_DBUS_OBJECT (new_config)); + + _LOGD (LOGD_IP4, "ip4-config: set IP4Config instance (%s)", + nm_dbus_object_get_path (NM_DBUS_OBJECT (new_config))); } - } else { + } else if (old_config) { has_changes = TRUE; - priv->ip_config_4 = g_object_ref (new_config); - - if (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) - nm_dbus_object_export (NM_DBUS_OBJECT (new_config)); - - _LOGD (LOGD_IP4, "ip4-config: set IP4Config instance (%s)", - nm_dbus_object_get_path (NM_DBUS_OBJECT (new_config))); - } - } else if (old_config) { - has_changes = TRUE; - priv->ip_config_4 = NULL; - _LOGD (LOGD_IP4, "ip4-config: clear IP4Config instance (%s)", - nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); - /* Device config is invalid if combined config is invalid */ - applied_config_clear (&priv->dev_ip4_config); - } - - concheck_periodic_update (self); - - if (!nm_device_sys_iface_state_is_external_or_assume (self)) - ip4_rp_filter_update (self); - - if (has_changes) { - NMSettingsConnection *settings_connection; - - _update_ip4_address (self); - - if (old_config != priv->ip_config_4) - _notify (self, PROP_IP4_CONFIG); - g_signal_emit (self, signals[IP4_CONFIG_CHANGED], 0, priv->ip_config_4, old_config); - - if (old_config != priv->ip_config_4) - nm_dbus_object_clear_and_unexport (&old_config); - - if ( nm_device_sys_iface_state_is_external (self) - && (settings_connection = nm_device_get_settings_connection (self)) - && NM_FLAGS_HAS (nm_settings_connection_get_flags (settings_connection), - NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED) - && nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request)) == NM_ACTIVATION_TYPE_EXTERNAL) { - NMSetting *s_ip4; - - g_object_freeze_notify (G_OBJECT (settings_connection)); - - nm_connection_remove_setting (NM_CONNECTION (settings_connection), NM_TYPE_SETTING_IP4_CONFIG); - s_ip4 = nm_ip4_config_create_setting (priv->ip_config_4); - nm_connection_add_setting (NM_CONNECTION (settings_connection), s_ip4); - - g_object_thaw_notify (G_OBJECT (settings_connection)); + priv->ip_config_4 = NULL; + _LOGD (LOGD_IP4, "ip4-config: clear IP4Config instance (%s)", + nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); + /* Device config is invalid if combined config is invalid */ + applied_config_clear (&priv->dev_ip4_config); } - nm_device_queue_recheck_assume (self); - } + concheck_periodic_update (self); - return success; + if (!nm_device_sys_iface_state_is_external_or_assume (self)) + ip4_rp_filter_update (self); + + if (has_changes) { + NMSettingsConnection *settings_connection; + + _update_ip4_address (self); + + if (old_config != priv->ip_config_4) + _notify (self, PROP_IP4_CONFIG); + g_signal_emit (self, signals[IP4_CONFIG_CHANGED], 0, priv->ip_config_4, old_config); + + if (old_config != priv->ip_config_4) + nm_dbus_object_clear_and_unexport (&old_config); + + if ( nm_device_sys_iface_state_is_external (self) + && (settings_connection = nm_device_get_settings_connection (self)) + && NM_FLAGS_HAS (nm_settings_connection_get_flags (settings_connection), + NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED) + && nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request)) == NM_ACTIVATION_TYPE_EXTERNAL) { + NMSetting *s_ip4; + + g_object_freeze_notify (G_OBJECT (settings_connection)); + + nm_connection_remove_setting (NM_CONNECTION (settings_connection), NM_TYPE_SETTING_IP4_CONFIG); + s_ip4 = nm_ip4_config_create_setting (priv->ip_config_4); + nm_connection_add_setting (NM_CONNECTION (settings_connection), s_ip4); + + g_object_thaw_notify (G_OBJECT (settings_connection)); + } + + nm_device_queue_recheck_assume (self); + } + + return success; + } else { + NMIP6Config *new_config = NM_IP6_CONFIG (_new_config); + NMDevicePrivate *priv; + NMIP6Config *old_config = NULL; + gboolean has_changes = FALSE; + gboolean success = TRUE; + + g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); + + _LOGD (LOGD_IP6, "ip6-config: update (commit=%d, new-config=%p)", + commit, new_config); + + nm_assert ( !new_config + || ( new_config + && ({ + int ip_ifindex = nm_device_get_ip_ifindex (self); + + ( ip_ifindex > 0 + && ip_ifindex == nm_ip6_config_get_ifindex (new_config)); + }))); + + priv = NM_DEVICE_GET_PRIVATE (self); + + old_config = priv->ip_config_6; + + /* Always commit to nm-platform to update lifetimes */ + if (commit && new_config) { + gs_unref_ptrarray GPtrArray *temporary_not_available = NULL; + + _commit_mtu (self, priv->ip_config_4); + + success = nm_ip6_config_commit (new_config, + nm_device_get_platform (self), + nm_device_get_route_table (self, AF_INET6, FALSE) + ? NM_IP_ROUTE_TABLE_SYNC_MODE_FULL + : NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN, + &temporary_not_available); + + if (!_rt6_temporary_not_available_set (self, temporary_not_available)) + success = FALSE; + } + + if (new_config) { + if (old_config) { + /* has_changes is set only on relevant changes, because when the configuration changes, + * this causes a re-read and reset. This should only happen for relevant changes */ + nm_ip6_config_replace (old_config, new_config, &has_changes); + if (has_changes) { + _LOGD (LOGD_IP6, "ip6-config: update IP6Config instance (%s)", + nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); + } + } else { + has_changes = TRUE; + priv->ip_config_6 = g_object_ref (new_config); + + if (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) + nm_dbus_object_export (NM_DBUS_OBJECT (new_config)); + + _LOGD (LOGD_IP6, "ip6-config: set IP6Config instance (%s)", + nm_dbus_object_get_path (NM_DBUS_OBJECT (new_config))); + } + } else if (old_config) { + has_changes = TRUE; + priv->ip_config_6 = NULL; + priv->needs_ip6_subnet = FALSE; + _LOGD (LOGD_IP6, "ip6-config: clear IP6Config instance (%s)", + nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); + } + + if (has_changes) { + NMSettingsConnection *settings_connection; + + if (old_config != priv->ip_config_6) + _notify (self, PROP_IP6_CONFIG); + g_signal_emit (self, signals[IP6_CONFIG_CHANGED], 0, priv->ip_config_6, old_config); + + if (old_config != priv->ip_config_6) + nm_dbus_object_clear_and_unexport (&old_config); + + if ( nm_device_sys_iface_state_is_external (self) + && (settings_connection = nm_device_get_settings_connection (self)) + && NM_FLAGS_HAS (nm_settings_connection_get_flags (settings_connection), + NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED) + && nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request)) == NM_ACTIVATION_TYPE_EXTERNAL) { + NMSetting *s_ip6; + + g_object_freeze_notify (G_OBJECT (settings_connection)); + + nm_connection_remove_setting (NM_CONNECTION (settings_connection), NM_TYPE_SETTING_IP6_CONFIG); + s_ip6 = nm_ip6_config_create_setting (priv->ip_config_6); + nm_connection_add_setting (NM_CONNECTION (settings_connection), s_ip6); + + g_object_thaw_notify (G_OBJECT (settings_connection)); + } + + nm_device_queue_recheck_assume (self); + + if (priv->ndisc) + ndisc_set_router_config (priv->ndisc, self); + } + + return success; + } } static gboolean @@ -10644,113 +10751,6 @@ nm_device_set_wwan_ip4_config (NMDevice *self, NMIP4Config *config) _LOGW (LOGD_IP4, "failed to set WWAN IPv4 configuration"); } -static gboolean -nm_device_set_ip6_config (NMDevice *self, - NMIP6Config *new_config, - gboolean commit) -{ - NMDevicePrivate *priv; - NMIP6Config *old_config = NULL; - gboolean has_changes = FALSE; - gboolean success = TRUE; - - g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); - - _LOGD (LOGD_IP6, "ip6-config: update (commit=%d, new-config=%p)", - commit, new_config); - - nm_assert ( !new_config - || ( new_config - && ({ - int ip_ifindex = nm_device_get_ip_ifindex (self); - - ( ip_ifindex > 0 - && ip_ifindex == nm_ip6_config_get_ifindex (new_config)); - }))); - - priv = NM_DEVICE_GET_PRIVATE (self); - - old_config = priv->ip_config_6; - - /* Always commit to nm-platform to update lifetimes */ - if (commit && new_config) { - gs_unref_ptrarray GPtrArray *temporary_not_available = NULL; - - _commit_mtu (self, priv->ip_config_4); - - success = nm_ip6_config_commit (new_config, - nm_device_get_platform (self), - nm_device_get_route_table (self, AF_INET6, FALSE) - ? NM_IP_ROUTE_TABLE_SYNC_MODE_FULL - : NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN, - &temporary_not_available); - - if (!_rt6_temporary_not_available_set (self, temporary_not_available)) - success = FALSE; - } - - if (new_config) { - if (old_config) { - /* has_changes is set only on relevant changes, because when the configuration changes, - * this causes a re-read and reset. This should only happen for relevant changes */ - nm_ip6_config_replace (old_config, new_config, &has_changes); - if (has_changes) { - _LOGD (LOGD_IP6, "ip6-config: update IP6Config instance (%s)", - nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); - } - } else { - has_changes = TRUE; - priv->ip_config_6 = g_object_ref (new_config); - - if (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) - nm_dbus_object_export (NM_DBUS_OBJECT (new_config)); - - _LOGD (LOGD_IP6, "ip6-config: set IP6Config instance (%s)", - nm_dbus_object_get_path (NM_DBUS_OBJECT (new_config))); - } - } else if (old_config) { - has_changes = TRUE; - priv->ip_config_6 = NULL; - priv->needs_ip6_subnet = FALSE; - _LOGD (LOGD_IP6, "ip6-config: clear IP6Config instance (%s)", - nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); - } - - if (has_changes) { - NMSettingsConnection *settings_connection; - - if (old_config != priv->ip_config_6) - _notify (self, PROP_IP6_CONFIG); - g_signal_emit (self, signals[IP6_CONFIG_CHANGED], 0, priv->ip_config_6, old_config); - - if (old_config != priv->ip_config_6) - nm_dbus_object_clear_and_unexport (&old_config); - - if ( nm_device_sys_iface_state_is_external (self) - && (settings_connection = nm_device_get_settings_connection (self)) - && NM_FLAGS_HAS (nm_settings_connection_get_flags (settings_connection), - NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED) - && nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request)) == NM_ACTIVATION_TYPE_EXTERNAL) { - NMSetting *s_ip6; - - g_object_freeze_notify (G_OBJECT (settings_connection)); - - nm_connection_remove_setting (NM_CONNECTION (settings_connection), NM_TYPE_SETTING_IP6_CONFIG); - s_ip6 = nm_ip6_config_create_setting (priv->ip_config_6); - nm_connection_add_setting (NM_CONNECTION (settings_connection), s_ip6); - - g_object_thaw_notify (G_OBJECT (settings_connection)); - } - - nm_device_queue_recheck_assume (self); - - if (priv->ndisc) - ndisc_set_router_config (priv->ndisc, self); - } - - return success; -} - void nm_device_replace_vpn6_config (NMDevice *self, NMIP6Config *old, NMIP6Config *config) { @@ -12737,8 +12737,8 @@ _cleanup_generic_post (NMDevice *self, CleanupType cleanup_type) /* Clean up IP configs; this does not actually deconfigure the * interface; the caller must flush routes and addresses explicitly. */ - nm_device_set_ip4_config (self, NULL, TRUE, NULL); - nm_device_set_ip6_config (self, NULL, TRUE); + nm_device_set_ip_config (self, AF_INET, NULL, TRUE, NULL); + nm_device_set_ip_config (self, AF_INET6, NULL, TRUE, NULL); g_clear_object (&priv->proxy_config); g_clear_object (&priv->con_ip_config_4); applied_config_clear (&priv->dev_ip4_config); @@ -12761,7 +12761,7 @@ _cleanup_generic_post (NMDevice *self, CleanupType cleanup_type) g_slist_free_full (priv->vpn_configs_6, g_object_unref); priv->vpn_configs_6 = NULL; - /* We no longer accept the delegations. nm_device_set_ip6_config(NULL) + /* We no longer accept the delegations. nm_device_set_ip_config(NULL) * above disables them. */ nm_assert (priv->needs_ip6_subnet == FALSE); From 9c330ab3203f242b7a82d2fb365d396b7820903f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 17 Mar 2018 15:21:56 +0100 Subject: [PATCH 26/28] device: merge IPv4 and IPv6 versions of nm_device_set_ip_config() (pt2) --- src/devices/nm-device.c | 274 +++++++++++++++------------------------- 1 file changed, 102 insertions(+), 172 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 014c3adde6..8518fd624b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -10473,152 +10473,58 @@ nm_device_get_ip4_config (NMDevice *self) static gboolean nm_device_set_ip_config (NMDevice *self, int addr_family, - NMIPConfig *_new_config, + NMIPConfig *new_config, gboolean commit, GPtrArray *ip4_dev_route_blacklist) { + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); const gboolean IS_IPv4 = (addr_family == AF_INET); + NMIPConfig *old_config; + gboolean has_changes = FALSE; + gboolean success = TRUE; + NMSettingsConnection *settings_connection; nm_assert_addr_family (addr_family); - nm_assert (!_new_config || nm_ip_config_get_addr_family (_new_config) == addr_family); + nm_assert (!new_config || nm_ip_config_get_addr_family (new_config) == addr_family); + nm_assert ( !new_config + || ( new_config + && ({ + int ip_ifindex = nm_device_get_ip_ifindex (self); - if (IS_IPv4) { - NMIP4Config *new_config = NM_IP4_CONFIG (_new_config); - NMDevicePrivate *priv; - NMIP4Config *old_config = NULL; - gboolean has_changes = FALSE; - gboolean success = TRUE; + ( ip_ifindex > 0 + && ip_ifindex == nm_ip_config_get_ifindex (new_config)); + }))); + nm_assert (IS_IPv4 || !ip4_dev_route_blacklist); - g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); + _LOGD (LOGD_IP_from_af (addr_family), + "ip%c-config: update (commit=%d, new-config=%p)", + nm_utils_addr_family_to_char (addr_family), + commit, + new_config); - _LOGD (LOGD_IP4, "ip4-config: update (commit=%d, new-config=%p)", - commit, new_config); + /* Always commit to nm-platform to update lifetimes */ + if (commit && new_config) { - nm_assert ( !new_config - || ( new_config - && ({ - int ip_ifindex = nm_device_get_ip_ifindex (self); + _commit_mtu (self, + IS_IPv4 + ? NM_IP4_CONFIG (new_config) + : priv->ip_config_4); - ( ip_ifindex > 0 - && ip_ifindex == nm_ip4_config_get_ifindex (new_config)); - }))); - - priv = NM_DEVICE_GET_PRIVATE (self); - - old_config = priv->ip_config_4; - - /* Always commit to nm-platform to update lifetimes */ - if (commit && new_config) { - _commit_mtu (self, new_config); - success = nm_ip4_config_commit (new_config, + if (IS_IPv4) { + success = nm_ip4_config_commit (NM_IP4_CONFIG (new_config), nm_device_get_platform (self), - nm_device_get_route_table (self, AF_INET, FALSE) + nm_device_get_route_table (self, addr_family, FALSE) ? NM_IP_ROUTE_TABLE_SYNC_MODE_FULL : NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN); nm_platform_ip4_dev_route_blacklist_set (nm_device_get_platform (self), - nm_ip4_config_get_ifindex (new_config), + nm_ip_config_get_ifindex (new_config), ip4_dev_route_blacklist); - } - - if (new_config) { - if (old_config) { - /* has_changes is set only on relevant changes, because when the configuration changes, - * this causes a re-read and reset. This should only happen for relevant changes */ - nm_ip4_config_replace (old_config, new_config, &has_changes); - if (has_changes) { - _LOGD (LOGD_IP4, "ip4-config: update IP4Config instance (%s)", - nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); - } - } else { - has_changes = TRUE; - priv->ip_config_4 = g_object_ref (new_config); - - if (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) - nm_dbus_object_export (NM_DBUS_OBJECT (new_config)); - - _LOGD (LOGD_IP4, "ip4-config: set IP4Config instance (%s)", - nm_dbus_object_get_path (NM_DBUS_OBJECT (new_config))); - } - } else if (old_config) { - has_changes = TRUE; - priv->ip_config_4 = NULL; - _LOGD (LOGD_IP4, "ip4-config: clear IP4Config instance (%s)", - nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); - /* Device config is invalid if combined config is invalid */ - applied_config_clear (&priv->dev_ip4_config); - } - - concheck_periodic_update (self); - - if (!nm_device_sys_iface_state_is_external_or_assume (self)) - ip4_rp_filter_update (self); - - if (has_changes) { - NMSettingsConnection *settings_connection; - - _update_ip4_address (self); - - if (old_config != priv->ip_config_4) - _notify (self, PROP_IP4_CONFIG); - g_signal_emit (self, signals[IP4_CONFIG_CHANGED], 0, priv->ip_config_4, old_config); - - if (old_config != priv->ip_config_4) - nm_dbus_object_clear_and_unexport (&old_config); - - if ( nm_device_sys_iface_state_is_external (self) - && (settings_connection = nm_device_get_settings_connection (self)) - && NM_FLAGS_HAS (nm_settings_connection_get_flags (settings_connection), - NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED) - && nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request)) == NM_ACTIVATION_TYPE_EXTERNAL) { - NMSetting *s_ip4; - - g_object_freeze_notify (G_OBJECT (settings_connection)); - - nm_connection_remove_setting (NM_CONNECTION (settings_connection), NM_TYPE_SETTING_IP4_CONFIG); - s_ip4 = nm_ip4_config_create_setting (priv->ip_config_4); - nm_connection_add_setting (NM_CONNECTION (settings_connection), s_ip4); - - g_object_thaw_notify (G_OBJECT (settings_connection)); - } - - nm_device_queue_recheck_assume (self); - } - - return success; - } else { - NMIP6Config *new_config = NM_IP6_CONFIG (_new_config); - NMDevicePrivate *priv; - NMIP6Config *old_config = NULL; - gboolean has_changes = FALSE; - gboolean success = TRUE; - - g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); - - _LOGD (LOGD_IP6, "ip6-config: update (commit=%d, new-config=%p)", - commit, new_config); - - nm_assert ( !new_config - || ( new_config - && ({ - int ip_ifindex = nm_device_get_ip_ifindex (self); - - ( ip_ifindex > 0 - && ip_ifindex == nm_ip6_config_get_ifindex (new_config)); - }))); - - priv = NM_DEVICE_GET_PRIVATE (self); - - old_config = priv->ip_config_6; - - /* Always commit to nm-platform to update lifetimes */ - if (commit && new_config) { + } else { gs_unref_ptrarray GPtrArray *temporary_not_available = NULL; - _commit_mtu (self, priv->ip_config_4); - - success = nm_ip6_config_commit (new_config, + success = nm_ip6_config_commit (NM_IP6_CONFIG (new_config), nm_device_get_platform (self), - nm_device_get_route_table (self, AF_INET6, FALSE) + nm_device_get_route_table (self, addr_family, FALSE) ? NM_IP_ROUTE_TABLE_SYNC_MODE_FULL : NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN, &temporary_not_available); @@ -10626,68 +10532,92 @@ nm_device_set_ip_config (NMDevice *self, if (!_rt6_temporary_not_available_set (self, temporary_not_available)) success = FALSE; } + } - if (new_config) { - if (old_config) { - /* has_changes is set only on relevant changes, because when the configuration changes, - * this causes a re-read and reset. This should only happen for relevant changes */ - nm_ip6_config_replace (old_config, new_config, &has_changes); - if (has_changes) { - _LOGD (LOGD_IP6, "ip6-config: update IP6Config instance (%s)", - nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); - } - } else { - has_changes = TRUE; - priv->ip_config_6 = g_object_ref (new_config); + old_config = priv->ip_config_x[IS_IPv4]; - if (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) - nm_dbus_object_export (NM_DBUS_OBJECT (new_config)); - - _LOGD (LOGD_IP6, "ip6-config: set IP6Config instance (%s)", - nm_dbus_object_get_path (NM_DBUS_OBJECT (new_config))); - } - } else if (old_config) { - has_changes = TRUE; - priv->ip_config_6 = NULL; - priv->needs_ip6_subnet = FALSE; - _LOGD (LOGD_IP6, "ip6-config: clear IP6Config instance (%s)", + if (new_config && old_config) { + /* has_changes is set only on relevant changes, because when the configuration changes, + * this causes a re-read and reset. This should only happen for relevant changes */ + nm_ip_config_replace (old_config, new_config, &has_changes); + if (has_changes) { + _LOGD (LOGD_IP_from_af (addr_family), + "ip%c-config: update IP Config instance (%s)", + nm_utils_addr_family_to_char (addr_family), nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); } + } else if (new_config /*&& !old_config*/) { + has_changes = TRUE; + priv->ip_config_x[IS_IPv4] = g_object_ref (new_config); + if (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (new_config))) + nm_dbus_object_export (NM_DBUS_OBJECT (new_config)); - if (has_changes) { - NMSettingsConnection *settings_connection; + _LOGD (LOGD_IP_from_af (addr_family), + "ip%c-config: set IP Config instance (%s)", + nm_utils_addr_family_to_char (addr_family), + nm_dbus_object_get_path (NM_DBUS_OBJECT (new_config))); + } else if (old_config /*&& !new_config*/) { + has_changes = TRUE; + priv->ip_config_x[IS_IPv4] = NULL; + _LOGD (LOGD_IP_from_af (addr_family), + "ip%c-config: clear IP Config instance (%s)", + nm_utils_addr_family_to_char (addr_family), + nm_dbus_object_get_path (NM_DBUS_OBJECT (old_config))); + if (IS_IPv4) { + /* Device config is invalid if combined config is invalid */ + applied_config_clear (&priv->dev_ip4_config); + } else + priv->needs_ip6_subnet = FALSE; + } - if (old_config != priv->ip_config_6) - _notify (self, PROP_IP6_CONFIG); - g_signal_emit (self, signals[IP6_CONFIG_CHANGED], 0, priv->ip_config_6, old_config); + if (IS_IPv4) { + concheck_periodic_update (self); - if (old_config != priv->ip_config_6) - nm_dbus_object_clear_and_unexport (&old_config); + if (!nm_device_sys_iface_state_is_external_or_assume (self)) + ip4_rp_filter_update (self); + } - if ( nm_device_sys_iface_state_is_external (self) - && (settings_connection = nm_device_get_settings_connection (self)) - && NM_FLAGS_HAS (nm_settings_connection_get_flags (settings_connection), - NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED) - && nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request)) == NM_ACTIVATION_TYPE_EXTERNAL) { - NMSetting *s_ip6; + if (has_changes) { - g_object_freeze_notify (G_OBJECT (settings_connection)); + if (IS_IPv4) + _update_ip4_address (self); - nm_connection_remove_setting (NM_CONNECTION (settings_connection), NM_TYPE_SETTING_IP6_CONFIG); - s_ip6 = nm_ip6_config_create_setting (priv->ip_config_6); - nm_connection_add_setting (NM_CONNECTION (settings_connection), s_ip6); + if (old_config != priv->ip_config_x[IS_IPv4]) + _notify (self, IS_IPv4 ? PROP_IP4_CONFIG : PROP_IP6_CONFIG); - g_object_thaw_notify (G_OBJECT (settings_connection)); - } + g_signal_emit (self, + signals[IS_IPv4 ? IP4_CONFIG_CHANGED : IP6_CONFIG_CHANGED], + 0, + priv->ip_config_x[IS_IPv4], + old_config); - nm_device_queue_recheck_assume (self); + if (old_config != priv->ip_config_x[IS_IPv4]) + nm_dbus_object_clear_and_unexport (&old_config); + if ( nm_device_sys_iface_state_is_external (self) + && (settings_connection = nm_device_get_settings_connection (self)) + && NM_FLAGS_HAS (nm_settings_connection_get_flags (settings_connection), + NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED) + && nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request)) == NM_ACTIVATION_TYPE_EXTERNAL) { + g_object_freeze_notify (G_OBJECT (settings_connection)); + nm_connection_add_setting (NM_CONNECTION (settings_connection), + IS_IPv4 + ? nm_ip4_config_create_setting (priv->ip_config_4) + : nm_ip6_config_create_setting (priv->ip_config_6)); + g_object_thaw_notify (G_OBJECT (settings_connection)); + } + + nm_device_queue_recheck_assume (self); + + if (!IS_IPv4) { if (priv->ndisc) ndisc_set_router_config (priv->ndisc, self); } - - return success; } + + nm_assert (!old_config || old_config == priv->ip_config_x[IS_IPv4]); + + return success; } static gboolean From b95f9741440027254a50d321657301d397f7f847 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 17 Mar 2018 15:21:56 +0100 Subject: [PATCH 27/28] device: merge IPv4 and IPv6 versions of queued_ip_config_change() --- src/devices/nm-device.c | 190 +++++++++++++++++++--------------------- 1 file changed, 90 insertions(+), 100 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 8518fd624b..96a110cfd6 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -11353,145 +11353,135 @@ nm_device_capture_initial_config (NMDevice *self) } static gboolean -queued_ip4_config_change (gpointer user_data) +queued_ip_config_change (NMDevice *self, int addr_family) { - NMDevice *self = user_data; - NMDevicePrivate *priv; - - g_return_val_if_fail (NM_IS_DEVICE (self), G_SOURCE_REMOVE); - - priv = NM_DEVICE_GET_PRIVATE (self); - - nm_assert (!priv->queued_ip4_config_pending); - - /* Wait for any queued state changes */ - if (priv->queued_state.id) - return TRUE; - - priv->queued_ip_config_id_4 = 0; - - /* If a commit is scheduled, this function would potentially interfere with - * it changing IP configurations before they are applied. Postpone the - * update in such case. - */ - if (activation_source_is_scheduled (self, - activate_stage5_ip4_config_result, - AF_INET)) { - priv->queued_ip4_config_pending = FALSE; - priv->queued_ip_config_id_4 = g_idle_add (queued_ip4_config_change, self); - _LOGT (LOGD_DEVICE, "IP4 update was postponed"); - } else - update_ip_config (self, AF_INET); - - set_unmanaged_external_down (self, TRUE); - - if (!nm_device_sys_iface_state_is_external_or_assume (self)) { - priv->v4_has_shadowed_routes = _v4_has_shadowed_routes_detect (self);; - ip4_rp_filter_update (self); - } - - return FALSE; -} - -static gboolean -queued_ip6_config_change (gpointer user_data) -{ - NMDevice *self = user_data; NMDevicePrivate *priv; gboolean need_ipv6ll = FALSE; + const gboolean IS_IPv4 = (addr_family == AF_INET); NMPlatform *platform; g_return_val_if_fail (NM_IS_DEVICE (self), G_SOURCE_REMOVE); priv = NM_DEVICE_GET_PRIVATE (self); - nm_assert (!priv->queued_ip6_config_pending); + nm_assert (IS_IPv4 ? !priv->queued_ip4_config_pending : !priv->queued_ip6_config_pending); /* Wait for any queued state changes */ if (priv->queued_state.id) return G_SOURCE_CONTINUE; - priv->queued_ip_config_id_6 = 0; + priv->queued_ip_config_id_x[IS_IPv4] = 0; /* If a commit is scheduled, this function would potentially interfere with * it changing IP configurations before they are applied. Postpone the * update in such case. */ if (activation_source_is_scheduled (self, - activate_stage5_ip6_config_commit, - AF_INET6)) { - priv->queued_ip6_config_pending = FALSE; - priv->queued_ip_config_id_6 = g_idle_add (queued_ip6_config_change, self); - _LOGT (LOGD_DEVICE, "IP6 update was postponed"); + IS_IPv4 + ? activate_stage5_ip4_config_result + : activate_stage5_ip6_config_commit, + addr_family)) { + if (IS_IPv4) { + priv->queued_ip4_config_pending = FALSE; + priv->queued_ip_config_id_4 = g_idle_add (queued_ip4_config_change, self); + } else { + priv->queued_ip6_config_pending = FALSE; + priv->queued_ip_config_id_6 = g_idle_add (queued_ip6_config_change, self); + } + _LOGT (LOGD_DEVICE, "IP%c update was postponed", + nm_utils_addr_family_to_char (addr_family)); } else { - update_ip_config (self, AF_INET6); + update_ip_config (self, addr_family); - /* Check whether we need to complete waiting for link-local. - * We are also called from an idle handler, so no problem doing state transitions - * now. */ - linklocal6_check_complete (self); + if (!IS_IPv4) { + /* Check whether we need to complete waiting for link-local. + * We are also called from an idle handler, so no problem doing state transitions + * now. */ + linklocal6_check_complete (self); + } } - if ( priv->state < NM_DEVICE_STATE_DEACTIVATING - && (platform = nm_device_get_platform (self)) - && nm_platform_link_get (platform, priv->ifindex)) { - /* Handle DAD failures */ - while (priv->dad6_failed_addrs) { - nm_auto_nmpobj const NMPObject *obj = NULL; - const NMPlatformIP6Address *addr; + if (!IS_IPv4) { + if ( priv->state < NM_DEVICE_STATE_DEACTIVATING + && (platform = nm_device_get_platform (self)) + && nm_platform_link_get (platform, priv->ifindex)) { + /* Handle DAD failures */ + while (priv->dad6_failed_addrs) { + nm_auto_nmpobj const NMPObject *obj = NULL; + const NMPlatformIP6Address *addr; - obj = priv->dad6_failed_addrs->data; - priv->dad6_failed_addrs = g_slist_delete_link (priv->dad6_failed_addrs, priv->dad6_failed_addrs); + obj = priv->dad6_failed_addrs->data; + priv->dad6_failed_addrs = g_slist_delete_link (priv->dad6_failed_addrs, priv->dad6_failed_addrs); - if (!nm_ndisc_dad_addr_is_fail_candidate (platform, obj)) - continue; + if (!nm_ndisc_dad_addr_is_fail_candidate (platform, obj)) + continue; - addr = NMP_OBJECT_CAST_IP6_ADDRESS (obj); + addr = NMP_OBJECT_CAST_IP6_ADDRESS (obj); - _LOGI (LOGD_IP6, "ipv6: duplicate address check failed for the %s address", - nm_platform_ip6_address_to_string (addr, NULL, 0)); + _LOGI (LOGD_IP6, "ipv6: duplicate address check failed for the %s address", + nm_platform_ip6_address_to_string (addr, NULL, 0)); - if (IN6_IS_ADDR_LINKLOCAL (&addr->address)) + if (IN6_IS_ADDR_LINKLOCAL (&addr->address)) + need_ipv6ll = TRUE; + else if (priv->ndisc) + nm_ndisc_dad_failed (priv->ndisc, &addr->address); + } + + /* If no IPv6 link-local address exists but other addresses do then we + * must add the LL address to remain conformant with RFC 3513 chapter 2.1 + * ("Addressing Model"): "All interfaces are required to have at least + * one link-local unicast address". + */ + if ( priv->ip_config_6 + && nm_ip6_config_get_num_addresses (priv->ip_config_6)) need_ipv6ll = TRUE; - else if (priv->ndisc) - nm_ndisc_dad_failed (priv->ndisc, &addr->address); + + if (need_ipv6ll) + check_and_add_ipv6ll_addr (self); + } else { + g_slist_free_full (priv->dad6_failed_addrs, (GDestroyNotify) nmp_object_unref); + priv->dad6_failed_addrs = NULL; } - /* If no IPv6 link-local address exists but other addresses do then we - * must add the LL address to remain conformant with RFC 3513 chapter 2.1 - * ("Addressing Model"): "All interfaces are required to have at least - * one link-local unicast address". - */ - if ( priv->ip_config_6 - && nm_ip6_config_get_num_addresses (priv->ip_config_6)) - need_ipv6ll = TRUE; - - if (need_ipv6ll) - check_and_add_ipv6ll_addr (self); - } else { - g_slist_free_full (priv->dad6_failed_addrs, (GDestroyNotify) nmp_object_unref); - priv->dad6_failed_addrs = NULL; - } - - /* Check if DAD is still pending */ - if ( priv->ip6_state == IP_CONF - && priv->dad6_ip6_config - && priv->ext_ip6_config_captured - && !nm_ip6_config_has_any_dad_pending (priv->ext_ip6_config_captured, - priv->dad6_ip6_config)) { - _LOGD (LOGD_DEVICE | LOGD_IP6, "IPv6 DAD terminated"); - g_clear_object (&priv->dad6_ip6_config); - _set_ip_state (self, AF_INET6, IP_DONE); - check_ip_state (self, FALSE, TRUE); - if (priv->rt6_temporary_not_available) - nm_device_activate_schedule_ip6_config_result (self); + /* Check if DAD is still pending */ + if ( priv->ip6_state == IP_CONF + && priv->dad6_ip6_config + && priv->ext_ip6_config_captured + && !nm_ip6_config_has_any_dad_pending (priv->ext_ip6_config_captured, + priv->dad6_ip6_config)) { + _LOGD (LOGD_DEVICE | LOGD_IP6, "IPv6 DAD terminated"); + g_clear_object (&priv->dad6_ip6_config); + _set_ip_state (self, addr_family, IP_DONE); + check_ip_state (self, FALSE, TRUE); + if (priv->rt6_temporary_not_available) + nm_device_activate_schedule_ip6_config_result (self); + } } set_unmanaged_external_down (self, TRUE); + if (IS_IPv4) { + if (!nm_device_sys_iface_state_is_external_or_assume (self)) { + priv->v4_has_shadowed_routes = _v4_has_shadowed_routes_detect (self);; + ip4_rp_filter_update (self); + } + } + return G_SOURCE_REMOVE; } +static gboolean +queued_ip4_config_change (gpointer user_data) +{ + return queued_ip_config_change (user_data, AF_INET); +} + +static gboolean +queued_ip6_config_change (gpointer user_data) +{ + return queued_ip_config_change (user_data, AF_INET6); +} + static void device_ipx_changed (NMPlatform *platform, int obj_type_i, From 1010cc777fc94404ab2b387e85756360fa6b883e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 17 Mar 2018 16:28:07 +0100 Subject: [PATCH 28/28] device: merge IPv4 and IPv6 versions of _cleanup_ip_pre() --- src/devices/nm-device.c | 58 ++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 96a110cfd6..fc7c76b94d 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -9351,37 +9351,31 @@ delete_on_deactivate_check_and_schedule (NMDevice *self, int ifindex) } static void -_cleanup_ip4_pre (NMDevice *self, CleanupType cleanup_type) +_cleanup_ip_pre (NMDevice *self, int addr_family, CleanupType cleanup_type) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + const gboolean IS_IPv4 = (addr_family == AF_INET); - _set_ip_state (self, AF_INET, IP_NONE); + _set_ip_state (self, addr_family, IP_NONE); - if (nm_clear_g_source (&priv->queued_ip_config_id_4)) - _LOGD (LOGD_DEVICE, "clearing queued IP4 config change"); - priv->queued_ip4_config_pending = FALSE; + if (nm_clear_g_source (&priv->queued_ip_config_id_x[IS_IPv4])) { + _LOGD (LOGD_DEVICE, "clearing queued IP%c config change", + nm_utils_addr_family_to_char (addr_family)); + } - dhcp4_cleanup (self, cleanup_type, FALSE); - arp_cleanup (self); - dnsmasq_cleanup (self); - ipv4ll_cleanup (self); -} - -static void -_cleanup_ip6_pre (NMDevice *self, CleanupType cleanup_type) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - - _set_ip_state (self, AF_INET6, IP_NONE); - - if (nm_clear_g_source (&priv->queued_ip_config_id_6)) - _LOGD (LOGD_DEVICE, "clearing queued IP6 config change"); - priv->queued_ip6_config_pending = FALSE; - - g_clear_object (&priv->dad6_ip6_config); - dhcp6_cleanup (self, cleanup_type, FALSE); - nm_clear_g_source (&priv->linklocal6_timeout_id); - addrconf6_cleanup (self); + if (IS_IPv4) { + priv->queued_ip4_config_pending = FALSE; + dhcp4_cleanup (self, cleanup_type, FALSE); + arp_cleanup (self); + dnsmasq_cleanup (self); + ipv4ll_cleanup (self); + } else { + priv->queued_ip6_config_pending = FALSE; + g_clear_object (&priv->dad6_ip6_config); + dhcp6_cleanup (self, cleanup_type, FALSE); + nm_clear_g_source (&priv->linklocal6_timeout_id); + addrconf6_cleanup (self); + } } gboolean @@ -9479,7 +9473,7 @@ nm_device_reactivate_ip4_config (NMDevice *self, : NM_SETTING_IP4_CONFIG_METHOD_DISABLED; if (!nm_streq0 (method_old, method_new)) { - _cleanup_ip4_pre (self, CLEANUP_TYPE_DECONFIGURE); + _cleanup_ip_pre (self, AF_INET, CLEANUP_TYPE_DECONFIGURE); _set_ip_state (self, AF_INET, IP_WAIT); if (!nm_device_activate_stage3_ip4_start (self)) _LOGW (LOGD_IP4, "Failed to apply IPv4 configuration"); @@ -9521,7 +9515,7 @@ nm_device_reactivate_ip6_config (NMDevice *self, : NM_SETTING_IP6_CONFIG_METHOD_IGNORE; if (!nm_streq0 (method_old, method_new)) { - _cleanup_ip6_pre (self, CLEANUP_TYPE_DECONFIGURE); + _cleanup_ip_pre (self, AF_INET6, CLEANUP_TYPE_DECONFIGURE); _set_ip_state (self, AF_INET6, IP_WAIT); if (!nm_device_activate_stage3_ip6_start (self)) _LOGW (LOGD_IP6, "Failed to apply IPv6 configuration"); @@ -12634,8 +12628,8 @@ _cleanup_generic_pre (NMDevice *self, CleanupType cleanup_type) queued_state_clear (self); - _cleanup_ip4_pre (self, cleanup_type); - _cleanup_ip6_pre (self, cleanup_type); + _cleanup_ip_pre (self, AF_INET, cleanup_type); + _cleanup_ip_pre (self, AF_INET6, cleanup_type); } static void @@ -13249,8 +13243,8 @@ _set_state_full (NMDevice *self, /* Clean up any half-done IP operations if the device's layer2 * finds out it needs authentication during IP config. */ - _cleanup_ip4_pre (self, CLEANUP_TYPE_DECONFIGURE); - _cleanup_ip6_pre (self, CLEANUP_TYPE_DECONFIGURE); + _cleanup_ip_pre (self, AF_INET, CLEANUP_TYPE_DECONFIGURE); + _cleanup_ip_pre (self, AF_INET6, CLEANUP_TYPE_DECONFIGURE); } break; default: