From be107c75c9eca0f306e79e1e15355166a0db44bd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 4 Mar 2019 15:50:52 +0100 Subject: [PATCH 01/16] core: accept %NULL as source argument for nm_utils_ipx_address_clear_host_address() Just for convenience. --- src/NetworkManagerUtils.c | 4 ++-- src/nm-core-utils.c | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 0fac5eff25..4819846ddb 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -404,8 +404,8 @@ route_compare (NMIPRoute *route1, NMIPRoute *route2, gint64 default_metric) nm_assert_not_reached (); if (!inet_pton (family, nm_ip_route_get_dest (route2), &a2)) nm_assert_not_reached (); - nm_utils_ipx_address_clear_host_address (family, &a1, &a1, plen); - nm_utils_ipx_address_clear_host_address (family, &a2, &a2, plen); + nm_utils_ipx_address_clear_host_address (family, &a1, NULL, plen); + nm_utils_ipx_address_clear_host_address (family, &a2, NULL, plen); NM_CMP_DIRECT_MEMCMP (&a1, &a2, nm_utils_addr_family_to_size (family)); return 0; diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 809e98a10c..b851f0a254 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -244,16 +244,20 @@ nm_ethernet_address_is_valid (gconstpointer addr, gssize len) gconstpointer nm_utils_ipx_address_clear_host_address (int family, gpointer dst, gconstpointer src, guint8 plen) { - g_return_val_if_fail (src, NULL); g_return_val_if_fail (dst, NULL); switch (family) { case AF_INET: g_return_val_if_fail (plen <= 32, NULL); + + if (!src) { + /* allow "self-assignment", by specifying %NULL as source. */ + src = dst; + } + *((guint32 *) dst) = nm_utils_ip4_address_clear_host_address (*((guint32 *) src), plen); break; case AF_INET6: - g_return_val_if_fail (plen <= 128, NULL); nm_utils_ip6_address_clear_host_address (dst, src, plen); break; default: @@ -4017,7 +4021,7 @@ nm_utils_get_reverse_dns_domains_ip6 (const struct in6_addr *ip, guint8 plen, GP return; memcpy (&addr, ip, sizeof (struct in6_addr)); - nm_utils_ip6_address_clear_host_address (&addr, &addr, plen); + nm_utils_ip6_address_clear_host_address (&addr, NULL, plen); /* Number of nibbles to include in domains */ nibbles = (plen - 1) / 4 + 1; From 02964c22a6986266d06e3ffff79765d306e2be05 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 2 Mar 2019 22:17:49 +0100 Subject: [PATCH 02/16] libnm-core: add nm_connection_get_setting_ip_config() helper --- libnm-core/nm-connection.c | 12 ++++++++++++ libnm-core/nm-core-internal.h | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index e958aff06d..a43e71258f 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -230,6 +230,18 @@ nm_connection_get_setting (NMConnection *connection, GType setting_type) return _connection_get_setting_check (connection, setting_type); } +NMSettingIPConfig * +nm_connection_get_setting_ip_config (NMConnection *connection, + int addr_family) +{ + nm_assert_addr_family (addr_family); + + return NM_SETTING_IP_CONFIG (_connection_get_setting (connection, + (addr_family == AF_INET) + ? NM_TYPE_SETTING_IP4_CONFIG + : NM_TYPE_SETTING_IP6_CONFIG)); +} + /** * nm_connection_get_setting_by_name: * @connection: a #NMConnection diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index b737e747f8..168ae9978e 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -449,6 +449,11 @@ gboolean _nm_utils_generate_mac_address_mask_parse (const char *value, /*****************************************************************************/ +NMSettingIPConfig *nm_connection_get_setting_ip_config (NMConnection *connection, + int addr_family); + +/*****************************************************************************/ + typedef enum { NM_BOND_OPTION_TYPE_INT, NM_BOND_OPTION_TYPE_STRING, From 2be022ad68158acd544704244a7d3193aa6545a7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 2 Mar 2019 22:17:49 +0100 Subject: [PATCH 03/16] core: use nm_connection_get_setting_ip_config() helper --- src/NetworkManagerUtils.c | 5 +---- src/devices/nm-device.c | 36 ++++++++---------------------------- src/vpn/nm-vpn-connection.c | 6 +----- 3 files changed, 10 insertions(+), 37 deletions(-) diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 4819846ddb..71bfbf7c10 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -212,10 +212,7 @@ nm_utils_connection_has_default_route (NMConnection *connection, if (!connection) goto out; - if (addr_family == AF_INET) - s_ip = nm_connection_get_setting_ip4_config (connection); - else - s_ip = nm_connection_get_setting_ip6_config (connection); + s_ip = nm_connection_get_setting_ip_config (connection, addr_family); if (!s_ip) goto out; if (nm_setting_ip_config_get_never_default (s_ip)) { diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 68bc805529..5aa0c21aee 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -2152,9 +2152,7 @@ nm_device_get_route_metric (NMDevice *self, connection = nm_device_get_applied_connection (self); if (connection) { - s_ip = addr_family == AF_INET - ? nm_connection_get_setting_ip4_config (connection) - : nm_connection_get_setting_ip6_config (connection); + s_ip = nm_connection_get_setting_ip_config (connection, addr_family); /* Slave interfaces don't have IP settings, but we may get here when * external changes are made or when noticing IP changes when starting @@ -2259,11 +2257,7 @@ nm_device_get_route_table (NMDevice *self, connection = nm_device_get_applied_connection (self); if (connection) { - if (addr_family == AF_INET) - s_ip = nm_connection_get_setting_ip4_config (connection); - else - s_ip = nm_connection_get_setting_ip6_config (connection); - + s_ip = nm_connection_get_setting_ip_config (connection, addr_family); if (s_ip) route_table = nm_setting_ip_config_get_route_table (s_ip); @@ -4894,21 +4888,11 @@ static gboolean get_ip_config_may_fail (NMDevice *self, int addr_family) { NMConnection *connection; - NMSettingIPConfig *s_ip = NULL; + NMSettingIPConfig *s_ip; connection = nm_device_get_applied_connection (self); - /* Fail the connection if the failed IP method is required to complete */ - switch (addr_family) { - case AF_INET: - s_ip = nm_connection_get_setting_ip4_config (connection); - break; - case AF_INET6: - s_ip = nm_connection_get_setting_ip6_config (connection); - break; - default: - nm_assert_not_reached (); - } + s_ip = nm_connection_get_setting_ip_config (connection, addr_family); return !s_ip || nm_setting_ip_config_get_may_fail (s_ip); } @@ -7094,10 +7078,9 @@ ip_config_merge_and_apply (NMDevice *self, /* 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); + NMSettingIPConfig *s_ip; + s_ip = nm_connection_get_setting_ip_config (connection, addr_family); 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); @@ -7487,10 +7470,7 @@ get_dhcp_timeout (NMDevice *self, int addr_family) connection = nm_device_get_applied_connection (self); - if (addr_family == AF_INET) - s_ip = nm_connection_get_setting_ip4_config (connection); - else - s_ip = nm_connection_get_setting_ip6_config (connection); + s_ip = nm_connection_get_setting_ip_config (connection, addr_family); timeout = nm_setting_ip_config_get_dhcp_timeout (s_ip); if (timeout) @@ -14566,7 +14546,7 @@ nm_device_spawn_iface_helper (NMDevice *self) NMSettingIPConfig *s_ip4; s_ip4 = nm_connection_get_setting_ip4_config (connection); - g_assert (s_ip4); + nm_assert (s_ip4); g_ptr_array_add (argv, g_strdup ("--priority4")); g_ptr_array_add (argv, g_strdup_printf ("%u", nm_device_get_route_metric (self, AF_INET))); diff --git a/src/vpn/nm-vpn-connection.c b/src/vpn/nm-vpn-connection.c index b2ed6999bd..5acf491a2c 100644 --- a/src/vpn/nm-vpn-connection.c +++ b/src/vpn/nm-vpn-connection.c @@ -1456,11 +1456,7 @@ get_route_table (NMVpnConnection *self, connection = _get_applied_connection (self); if (connection) { - if (addr_family == AF_INET) - s_ip = nm_connection_get_setting_ip4_config (connection); - else - s_ip = nm_connection_get_setting_ip6_config (connection); - + s_ip = nm_connection_get_setting_ip_config (connection, addr_family); if (s_ip) route_table = nm_setting_ip_config_get_route_table (s_ip); } From 1585eaf4730c1c49b7a3f3511bd01dda303efc78 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Mar 2019 17:18:49 +0100 Subject: [PATCH 04/16] device: unify IPv4 and IPv6 device methods for IP configs It is preferable to treat IPv4 and IPv6 in a similar manner. This moves the places where we differ down the call-stack. It also make it clearer how IPv6 behaves differently. I think this is a bug, but leave it for now. + /* If IP had previously failed, move it back to IP_CONF since we + * clearly now have configuration. + */ + if (priv->ip6_state == IP_FAIL) + _set_ip_state (self, AF_INET6, IP_CONF); --- src/devices/adsl/nm-device-adsl.c | 6 +- src/devices/bluetooth/nm-device-bt.c | 7 +- src/devices/nm-device-ethernet.c | 5 +- src/devices/nm-device-ppp.c | 3 +- src/devices/nm-device-private.h | 9 +- src/devices/nm-device.c | 167 +++++++++++++-------------- src/devices/wwan/nm-device-modem.c | 10 +- 7 files changed, 101 insertions(+), 106 deletions(-) diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index 89de6e76ca..be81c26bcd 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -30,6 +30,7 @@ #include #include +#include "nm-ip4-config.h" #include "devices/nm-device-private.h" #include "platform/nm-platform.h" #include "ppp/nm-ppp-manager-call.h" @@ -447,9 +448,8 @@ ppp_ip4_config (NMPPPManager *ppp_manager, NMDevice *device = NM_DEVICE (user_data); /* Ignore PPP IP4 events that come in after initial configuration */ - if (nm_device_activate_ip4_state_in_conf (device)) { - nm_device_activate_schedule_ip4_config_result (device, config); - } + if (nm_device_activate_ip4_state_in_conf (device)) + nm_device_activate_schedule_ip_config_result (device, AF_INET, NM_IP_CONFIG_CAST (config)); } static NMActStageReturn diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index 5dcafee9ed..0037766ef2 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -38,6 +38,7 @@ #include "settings/nm-settings-connection.h" #include "nm-utils.h" #include "nm-bt-error.h" +#include "nm-ip4-config.h" #include "platform/nm-platform.h" #include "devices/wwan/nm-modem-manager.h" @@ -397,9 +398,9 @@ ppp_failed (NMModem *modem, case NM_DEVICE_STATE_SECONDARIES: case NM_DEVICE_STATE_ACTIVATED: if (nm_device_activate_ip4_state_in_conf (device)) - nm_device_activate_schedule_ip4_config_timeout (device); + nm_device_activate_schedule_ip_config_timeout (device, AF_INET); else if (nm_device_activate_ip6_state_in_conf (device)) - nm_device_activate_schedule_ip6_config_timeout (device); + nm_device_activate_schedule_ip_config_timeout (device, AF_INET6); else if (nm_device_activate_ip4_state_done (device)) { nm_device_ip_method_failed (device, AF_INET, @@ -541,7 +542,7 @@ modem_ip4_config_result (NMModem *modem, AF_INET, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); } else - nm_device_activate_schedule_ip4_config_result (device, config); + nm_device_activate_schedule_ip_config_result (device, AF_INET, NM_IP_CONFIG_CAST (config)); } static void diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index f93ff1a483..a3aa0f4c19 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -982,9 +982,8 @@ ppp_ip4_config (NMPPPManager *ppp_manager, NMDevice *device = NM_DEVICE (user_data); /* Ignore PPP IP4 events that come in after initial configuration */ - if (nm_device_activate_ip4_state_in_conf (device)) { - nm_device_activate_schedule_ip4_config_result (device, config); - } + if (nm_device_activate_ip4_state_in_conf (device)) + nm_device_activate_schedule_ip_config_result (device, AF_INET, NM_IP_CONFIG_CAST (config)); } static NMActStageReturn diff --git a/src/devices/nm-device-ppp.c b/src/devices/nm-device-ppp.c index 2f565d4b1f..4dd921cac9 100644 --- a/src/devices/nm-device-ppp.c +++ b/src/devices/nm-device-ppp.c @@ -16,6 +16,7 @@ #include "nm-device-ppp.h" +#include "nm-ip4-config.h" #include "nm-act-request.h" #include "nm-device-factory.h" #include "nm-device-private.h" @@ -106,7 +107,7 @@ ppp_ip4_config (NMPPPManager *ppp_manager, if (nm_device_get_state (device) == NM_DEVICE_STATE_IP_CONFIG) { if (nm_device_activate_ip4_state_in_conf (device)) { - nm_device_activate_schedule_ip4_config_result (device, config); + nm_device_activate_schedule_ip_config_result (device, AF_INET, NM_IP_CONFIG_CAST (config)); return; } } else { diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index 6c0f473d53..4fd3576f49 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -75,11 +75,12 @@ void nm_device_set_firmware_missing (NMDevice *self, gboolean missing); void nm_device_activate_schedule_stage1_device_prepare (NMDevice *device); void nm_device_activate_schedule_stage2_device_config (NMDevice *device); -void nm_device_activate_schedule_ip4_config_result(NMDevice *device, NMIP4Config *config); -void nm_device_activate_schedule_ip4_config_timeout (NMDevice *device); +void nm_device_activate_schedule_ip_config_result (NMDevice *device, + int addr_family, + NMIPConfig *config); -void nm_device_activate_schedule_ip6_config_result (NMDevice *device); -void nm_device_activate_schedule_ip6_config_timeout (NMDevice *device); +void nm_device_activate_schedule_ip_config_timeout (NMDevice *device, + int addr_family); gboolean nm_device_activate_ip4_state_in_conf (NMDevice *device); gboolean nm_device_activate_ip4_state_in_wait (NMDevice *device); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 5aa0c21aee..95453876a3 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -648,6 +648,22 @@ static void concheck_update_state (NMDevice *self, NMConnectivityState state, gboolean is_periodic); +static void activate_stage4_ip_config_timeout_4 (NMDevice *self); +static void activate_stage4_ip_config_timeout_6 (NMDevice *self); + +static void (*const activate_stage4_ip_config_timeout_x[2]) (NMDevice *self) = { + activate_stage4_ip_config_timeout_6, + activate_stage4_ip_config_timeout_4, +}; + +static void activate_stage5_ip_config_result_4 (NMDevice *self); +static void activate_stage5_ip_config_result_6 (NMDevice *self); + +static void (*const activate_stage5_ip_config_result_x[2]) (NMDevice *self) = { + activate_stage5_ip_config_result_6, + activate_stage5_ip_config_result_4, +}; + /*****************************************************************************/ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (queued_state_to_string, NMDeviceState, @@ -905,6 +921,12 @@ applied_config_clear (AppliedConfig *config) static void applied_config_init (AppliedConfig *config, gpointer ip_config) { + nm_assert ( !ip_config + || (!config->orig && !config->current) + || nm_ip_config_get_addr_family (ip_config) == nm_ip_config_get_addr_family (config->orig ?: config->current)); + nm_assert ( !ip_config + || NM_IS_IP_CONFIG (ip_config, AF_UNSPEC)); + nm_g_object_ref (ip_config); applied_config_clear (config); config->orig = ip_config; @@ -6646,7 +6668,6 @@ ipv4_manual_method_apply (NMDevice *self, NMIP4Config **configs, gboolean succes { NMConnection *connection; const char *method; - NMIP4Config *empty; connection = nm_device_get_applied_connection (self); nm_assert (connection); @@ -6662,9 +6683,10 @@ ipv4_manual_method_apply (NMDevice *self, NMIP4Config **configs, gboolean succes } if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) { + gs_unref_object NMIP4Config *empty = NULL; + empty = _ip4_config_new (self); - nm_device_activate_schedule_ip4_config_result (self, empty); - g_object_unref (empty); + nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (empty)); } else { if (NM_DEVICE_GET_PRIVATE (self)->ip4_state != IP_DONE) ip_config_merge_and_apply (self, AF_INET, TRUE); @@ -6883,7 +6905,7 @@ nm_device_handle_ipv4ll_event (sd_ipv4ll *ll, int event, void *data) if (priv->ip4_state == IP_CONF) { nm_clear_g_source (&priv->ipv4ll_timeout); - nm_device_activate_schedule_ip4_config_result (self, config); + nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (config)); } else if (priv->ip4_state == IP_DONE) { applied_config_init (&priv->dev_ip4_config, config); if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) { @@ -6913,7 +6935,7 @@ ipv4ll_timeout_cb (gpointer user_data) ipv4ll_cleanup (self); if (priv->ip4_state == IP_CONF) - nm_device_activate_schedule_ip4_config_timeout (self); + nm_device_activate_schedule_ip_config_timeout (self, AF_INET); } return FALSE; @@ -7332,7 +7354,7 @@ dhcp4_fail (NMDevice *self, NMDhcpState dhcp_state) if ( dhcp_state == NM_DHCP_STATE_TERMINATED || (!priv->dhcp4.was_active && priv->ip4_state == IP_CONF)) { dhcp4_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); - nm_device_activate_schedule_ip4_config_timeout (self); + nm_device_activate_schedule_ip_config_timeout (self, AF_INET); return; } @@ -7364,7 +7386,7 @@ static void dhcp4_dad_cb (NMDevice *self, NMIP4Config **configs, gboolean success) { if (success) - nm_device_activate_schedule_ip4_config_result (self, configs[1]); + nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (configs[1])); else { nm_device_ip_method_failed (self, AF_INET, NM_DEVICE_STATE_REASON_IP_ADDRESS_DUPLICATE); @@ -8074,7 +8096,7 @@ dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state) if ( dhcp_state == NM_DHCP_STATE_TERMINATED || (!priv->dhcp6.was_active && priv->ip6_state == IP_CONF)) { dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); - nm_device_activate_schedule_ip6_config_timeout (self); + nm_device_activate_schedule_ip_config_timeout (self, AF_INET6); return; } @@ -8095,7 +8117,7 @@ dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state) /* not a hard failure; just live with the RA info */ dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); if (priv->ip6_state == IP_CONF) - nm_device_activate_schedule_ip6_config_result (self); + nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); } return; @@ -8162,7 +8184,7 @@ dhcp6_state_changed (NMDhcpClient *client, nm_device_ip_method_failed (self, AF_INET6, NM_DEVICE_STATE_REASON_DHCP_FAILED); break; } - nm_device_activate_schedule_ip6_config_result (self); + nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); } else if (priv->ip6_state == IP_DONE) if (!dhcp6_lease_change (self)) dhcp6_fail (self, state); @@ -8174,7 +8196,7 @@ dhcp6_state_changed (NMDhcpClient *client, /* not a hard failure; just live with the RA info */ dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); if (priv->ip6_state == IP_CONF) - nm_device_activate_schedule_ip6_config_result (self); + nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); } break; case NM_DHCP_STATE_EXPIRE: @@ -8755,7 +8777,7 @@ linklocal6_failed (NMDevice *self) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); nm_clear_g_source (&priv->linklocal6_timeout_id); - nm_device_activate_schedule_ip6_config_timeout (self); + nm_device_activate_schedule_ip_config_timeout (self, AF_INET6); } static gboolean @@ -8803,10 +8825,10 @@ linklocal6_check_complete (NMDevice *self) else if (nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { 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); + nm_device_activate_schedule_ip_config_timeout (self, AF_INET6); } } else if (nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) - nm_device_activate_schedule_ip6_config_result (self); + nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); else g_return_if_fail (FALSE); } @@ -9318,7 +9340,7 @@ ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_in } } - nm_device_activate_schedule_ip6_config_result (self); + nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); } static void @@ -9345,9 +9367,9 @@ ndisc_ra_timeout (NMNDisc *ndisc, NMDevice *self) && 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); + nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); else - nm_device_activate_schedule_ip6_config_timeout (self); + nm_device_activate_schedule_ip_config_timeout (self, AF_INET6); } } @@ -9384,7 +9406,7 @@ addrconf6_start_with_link_ready (NMDevice *self) case NM_NDISC_NODE_TYPE_ROUTER: /* We're the router. */ nm_device_sysctl_ip_conf_set (self, AF_INET6, "forwarding", "1"); - nm_device_activate_schedule_ip6_config_result (self); + nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); priv->needs_ip6_subnet = TRUE; g_signal_emit (self, signals[IP6_SUBNET_NEEDED], 0); break; @@ -9818,7 +9840,7 @@ nm_device_activate_stage3_ip4_start (NMDevice *self) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMActStageReturn ret; NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; - NMIP4Config *ip4_config = NULL; + gs_unref_object NMIP4Config *ip4_config = NULL; g_assert (priv->ip4_state == IP_WAIT); @@ -9833,8 +9855,7 @@ nm_device_activate_stage3_ip4_start (NMDevice *self) if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { if (!ip4_config) ip4_config = _ip4_config_new (self); - nm_device_activate_schedule_ip4_config_result (self, ip4_config); - g_object_unref (ip4_config); + nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (ip4_config)); } else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) { _set_ip_state (self, AF_INET, IP_DONE); check_ip_state (self, FALSE, TRUE); @@ -9885,7 +9906,7 @@ nm_device_activate_stage3_ip6_start (NMDevice *self) */ nm_assert (!applied_config_get_current (&priv->ac_ip6_config)); applied_config_init (&priv->ac_ip6_config, ip6_config); - nm_device_activate_schedule_ip6_config_result (self); + nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); } else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) { _set_ip_state (self, AF_INET6, IP_DONE); check_ip_state (self, FALSE, TRUE); @@ -10064,7 +10085,7 @@ act_stage4_ip4_config_timeout (NMDevice *self, NMDeviceStateReason *out_failure_ * */ static void -activate_stage4_ip4_config_timeout (NMDevice *self) +activate_stage4_ip_config_timeout_4 (NMDevice *self) { NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; @@ -10083,23 +10104,21 @@ activate_stage4_ip4_config_timeout (NMDevice *self) check_ip_state (self, FALSE, TRUE); } -/* - * nm_device_activate_schedule_ip4_config_timeout - * - * Deal with a timeout of the IPv4 configuration - * - */ void -nm_device_activate_schedule_ip4_config_timeout (NMDevice *self) +nm_device_activate_schedule_ip_config_timeout (NMDevice *self, + int addr_family) { NMDevicePrivate *priv; + const gboolean IS_IPv4 = (addr_family == AF_INET); g_return_if_fail (NM_IS_DEVICE (self)); + g_return_if_fail (NM_IN_SET (addr_family, AF_INET, AF_INET6)); priv = NM_DEVICE_GET_PRIVATE (self); + g_return_if_fail (priv->act_request.obj); - activation_source_schedule (self, activate_stage4_ip4_config_timeout, AF_INET); + activation_source_schedule (self, activate_stage4_ip_config_timeout_x[IS_IPv4], addr_family); } static NMActStageReturn @@ -10113,14 +10132,8 @@ act_stage4_ip6_config_timeout (NMDevice *self, NMDeviceStateReason *out_failure_ return NM_ACT_STAGE_RETURN_SUCCESS; } -/* - * activate_stage4_ip6_config_timeout - * - * Time out on retrieving the IPv6 config. - * - */ static void -activate_stage4_ip6_config_timeout (NMDevice *self) +activate_stage4_ip_config_timeout_6 (NMDevice *self) { NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; @@ -10139,25 +10152,6 @@ activate_stage4_ip6_config_timeout (NMDevice *self) check_ip_state (self, FALSE, TRUE); } -/* - * nm_device_activate_schedule_ip6_config_timeout - * - * Deal with a timeout of the IPv6 configuration - * - */ -void -nm_device_activate_schedule_ip6_config_timeout (NMDevice *self) -{ - NMDevicePrivate *priv; - - g_return_if_fail (NM_IS_DEVICE (self)); - - priv = NM_DEVICE_GET_PRIVATE (self); - g_return_if_fail (priv->act_request.obj); - - activation_source_schedule (self, activate_stage4_ip6_config_timeout, AF_INET6); -} - static gboolean share_init (NMDevice *self, GError **error) { @@ -10357,7 +10351,7 @@ nm_device_arp_announce (NMDevice *self) } static void -activate_stage5_ip4_config_result (NMDevice *self) +activate_stage5_ip_config_result_4 (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMActRequest *req; @@ -10439,15 +10433,32 @@ activate_stage5_ip4_config_result (NMDevice *self) } void -nm_device_activate_schedule_ip4_config_result (NMDevice *self, NMIP4Config *config) +nm_device_activate_schedule_ip_config_result (NMDevice *self, + int addr_family, + NMIPConfig *config) { NMDevicePrivate *priv; + const gboolean IS_IPv4 = (addr_family == AF_INET); g_return_if_fail (NM_IS_DEVICE (self)); + g_return_if_fail (NM_IN_SET (addr_family, AF_INET, AF_INET6)); + g_return_if_fail ( !config + || ( addr_family == AF_INET + && nm_ip_config_get_addr_family (config) == AF_INET)); + priv = NM_DEVICE_GET_PRIVATE (self); - applied_config_init (&priv->dev_ip4_config, config); - activation_source_schedule (self, activate_stage5_ip4_config_result, AF_INET); + if (IS_IPv4) { + applied_config_init (&priv->dev_ip4_config, config); + } else { + /* If IP had previously failed, move it back to IP_CONF since we + * clearly now have configuration. + */ + if (priv->ip6_state == IP_FAIL) + _set_ip_state (self, AF_INET6, IP_CONF); + } + + activation_source_schedule (self, activate_stage5_ip_config_result_x[IS_IPv4], addr_family); } gboolean @@ -10549,7 +10560,7 @@ dad6_get_pending_addresses (NMDevice *self) } static void -activate_stage5_ip6_config_commit (NMDevice *self) +activate_stage5_ip_config_result_6 (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMActRequest *req; @@ -10619,22 +10630,6 @@ activate_stage5_ip6_config_commit (NMDevice *self) } } -void -nm_device_activate_schedule_ip6_config_result (NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - - g_return_if_fail (NM_IS_DEVICE (self)); - - /* If IP had previously failed, move it back to IP_CONF since we - * clearly now have configuration. - */ - if (priv->ip6_state == IP_FAIL) - _set_ip_state (self, AF_INET6, IP_CONF); - - activation_source_schedule (self, activate_stage5_ip6_config_commit, AF_INET6); -} - gboolean nm_device_activate_ip6_state_in_conf (NMDevice *self) { @@ -11551,7 +11546,7 @@ _rt6_temporary_not_available_timeout (gpointer user_data) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); priv->rt6_temporary_not_available_id = 0; - nm_device_activate_schedule_ip6_config_result (self); + nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); return G_SOURCE_REMOVE; } @@ -12947,9 +12942,7 @@ queued_ip_config_change (NMDevice *self, int addr_family) * update in such case. */ if (activation_source_is_scheduled (self, - IS_IPv4 - ? activate_stage5_ip4_config_result - : activate_stage5_ip6_config_commit, + activate_stage5_ip_config_result_x[IS_IPv4], addr_family)) return G_SOURCE_CONTINUE; @@ -13028,7 +13021,7 @@ queued_ip_config_change (NMDevice *self, int addr_family) _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); + nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); } } @@ -16056,10 +16049,10 @@ _activation_func_to_string (ActivationHandleFunc func) FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage1_device_prepare); FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage2_device_config); FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage3_ip_config_start); - FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage4_ip4_config_timeout); - FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage4_ip6_config_timeout); - FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage5_ip4_config_result); - FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage5_ip6_config_commit); + FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage4_ip_config_timeout_4); + FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage4_ip_config_timeout_6); + FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage5_ip_config_result_4); + FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage5_ip_config_result_6); g_return_val_if_reached ("unknown"); } diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index a98c0ce916..0fd2fab81d 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -83,9 +83,9 @@ ppp_failed (NMModem *modem, case NM_DEVICE_STATE_SECONDARIES: case NM_DEVICE_STATE_ACTIVATED: if (nm_device_activate_ip4_state_in_conf (device)) - nm_device_activate_schedule_ip4_config_timeout (device); + nm_device_activate_schedule_ip_config_timeout (device, AF_INET); else if (nm_device_activate_ip6_state_in_conf (device)) - nm_device_activate_schedule_ip6_config_timeout (device); + nm_device_activate_schedule_ip_config_timeout (device, AF_INET6); else if (nm_device_activate_ip4_state_done (device)) { nm_device_ip_method_failed (device, AF_INET, @@ -212,7 +212,7 @@ modem_ip4_config_result (NMModem *modem, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); } else { nm_device_set_wwan_ip4_config (device, config); - nm_device_activate_schedule_ip4_config_result (device, NULL); + nm_device_activate_schedule_ip_config_result (device, AF_INET, NULL); } } @@ -249,7 +249,7 @@ modem_ip6_config_result (NMModem *modem, if (do_slaac == FALSE) { if (got_config) - nm_device_activate_schedule_ip6_config_result (device); + nm_device_activate_schedule_ip_config_result (device, AF_INET6, NULL); else { _LOGW (LOGD_MB | LOGD_IP6, "retrieving IPv6 configuration failed: SLAAC not requested and no addresses"); nm_device_ip_method_failed (device, @@ -268,7 +268,7 @@ modem_ip6_config_result (NMModem *modem, break; case NM_ACT_STAGE_RETURN_IP_FAIL: /* all done */ - nm_device_activate_schedule_ip6_config_result (device); + nm_device_activate_schedule_ip_config_result (device, AF_INET6, NULL); break; case NM_ACT_STAGE_RETURN_POSTPONE: /* let SLAAC run */ From 2076550d8f9daa55303029817ef1887b3cf6438b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Mar 2019 17:26:56 +0100 Subject: [PATCH 05/16] device/trivial: rename IpState to NMDeviceIPState It will be moved to a header file. --- src/devices/nm-device.c | 206 ++++++++++++++++++++-------------------- 1 file changed, 103 insertions(+), 103 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 95453876a3..6f576f0552 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -114,12 +114,12 @@ typedef enum { } CleanupType; typedef enum { - IP_NONE = 0, - IP_WAIT, - IP_CONF, - IP_DONE, - IP_FAIL -} IpState; + NM_DEVICE_IP_STATE_NONE = 0, + NM_DEVICE_IP_STATE_WAIT, + NM_DEVICE_IP_STATE_CONF, + NM_DEVICE_IP_STATE_DONE, + NM_DEVICE_IP_STATE_FAIL +} NMDeviceIPState; typedef struct { CList lst_slave; @@ -417,8 +417,8 @@ typedef struct _NMDevicePrivate { }; union { - const IpState ip4_state; - IpState ip4_state_; + const NMDeviceIPState ip4_state; + NMDeviceIPState ip4_state_; }; AppliedConfig dev_ip4_config; /* Config from DHCP, PPP, LLv4, etc */ @@ -500,8 +500,8 @@ typedef struct _NMDevicePrivate { } acd; union { - const IpState ip6_state; - IpState ip6_state_; + const NMDeviceIPState ip6_state; + NMDeviceIPState ip6_state_; }; AppliedConfig ac_ip6_config; /* config from IPv6 autoconfiguration */ NMIP6Config * ext_ip6_config_captured; /* Configuration captured from platform. */ @@ -1338,19 +1338,19 @@ _get_stable_id (NMDevice *self, /*****************************************************************************/ -NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_ip_state_to_string, IpState, +NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_ip_state_to_string, NMDeviceIPState, NM_UTILS_LOOKUP_DEFAULT_WARN ("unknown"), - NM_UTILS_LOOKUP_STR_ITEM (IP_NONE, "none"), - NM_UTILS_LOOKUP_STR_ITEM (IP_WAIT, "wait"), - NM_UTILS_LOOKUP_STR_ITEM (IP_CONF, "conf"), - NM_UTILS_LOOKUP_STR_ITEM (IP_DONE, "done"), - NM_UTILS_LOOKUP_STR_ITEM (IP_FAIL, "fail"), + NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_IP_STATE_NONE, "none"), + NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_IP_STATE_WAIT, "wait"), + NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_IP_STATE_CONF, "conf"), + NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_IP_STATE_DONE, "done"), + NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_IP_STATE_FAIL, "fail"), ); static void -_set_ip_state (NMDevice *self, int addr_family, IpState new_state) +_set_ip_state (NMDevice *self, int addr_family, NMDeviceIPState new_state) { - IpState *p; + NMDeviceIPState *p; NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); nm_assert_addr_family (addr_family); @@ -1366,9 +1366,9 @@ _set_ip_state (NMDevice *self, int addr_family, IpState new_state) _ip_state_to_string (new_state)); *p = new_state; - if (new_state == IP_DONE) { - /* we only set the IPx_READY flag once we reach IP_DONE state. We don't - * ever clear it, even if we later enter IP_FAIL state. + if (new_state == NM_DEVICE_IP_STATE_DONE) { + /* we only set the IPx_READY flag once we reach NM_DEVICE_IP_STATE_DONE state. We don't + * ever clear it, even if we later enter NM_DEVICE_IP_STATE_FAIL state. * * This is not documented/guaranteed behavior, but seems to make sense for now. */ _active_connection_set_state_flags (self, @@ -3249,7 +3249,7 @@ nm_device_master_enslave_slave (NMDevice *self, NMDevice *slave, NMConnection *c nm_device_update_hw_address (self); /* Send ARP announcements if did not yet and have addresses. */ - if ( priv->ip4_state == IP_DONE + if ( priv->ip4_state == NM_DEVICE_IP_STATE_DONE && !priv->acd.announcing) nm_device_arp_announce (self); @@ -3258,10 +3258,10 @@ nm_device_master_enslave_slave (NMDevice *self, NMDevice *slave, NMConnection *c * new address. */ if (success) { - if (priv->ip4_state == IP_WAIT) + if (priv->ip4_state == NM_DEVICE_IP_STATE_WAIT) nm_device_activate_stage3_ip4_start (self); - if (priv->ip6_state == IP_WAIT) + if (priv->ip6_state == NM_DEVICE_IP_STATE_WAIT) nm_device_activate_stage3_ip6_start (self); } @@ -3884,11 +3884,11 @@ device_link_changed (NMDevice *self) if (priv->up && (!was_up || seen_down)) { /* 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 (priv->ip4_state == NM_DEVICE_IP_STATE_DONE) { 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 (priv->ip6_state == NM_DEVICE_IP_STATE_DONE) { if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP6, "failed applying IP6 config after link comes up again"); } @@ -4958,22 +4958,22 @@ check_ip_state (NMDevice *self, gboolean may_fail, gboolean full_state_update) NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) ip6_ignore = TRUE; - if ( priv->ip4_state == IP_DONE - && priv->ip6_state == IP_DONE) { + if ( priv->ip4_state == NM_DEVICE_IP_STATE_DONE + && priv->ip6_state == NM_DEVICE_IP_STATE_DONE) { /* Both method completed (or disabled), proceed with activation */ nm_device_state_changed (self, NM_DEVICE_STATE_IP_CHECK, NM_DEVICE_STATE_REASON_NONE); return; } - if ( (priv->ip4_state == IP_FAIL || (ip4_disabled && priv->ip4_state == IP_DONE)) - && (priv->ip6_state == IP_FAIL || (ip6_ignore && priv->ip6_state == IP_DONE))) { + if ( (priv->ip4_state == NM_DEVICE_IP_STATE_FAIL || (ip4_disabled && priv->ip4_state == NM_DEVICE_IP_STATE_DONE)) + && (priv->ip6_state == NM_DEVICE_IP_STATE_FAIL || (ip6_ignore && priv->ip6_state == NM_DEVICE_IP_STATE_DONE))) { /* Either both methods failed, or only one failed and the other is * disabled */ if (nm_device_sys_iface_state_is_external_or_assume (self)) { /* We have assumed configuration, but couldn't redo it. No problem, * move to check state. */ - _set_ip_state (self, AF_INET, IP_DONE); - _set_ip_state (self, AF_INET6, IP_DONE); + _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_DONE); + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_DONE); state = NM_DEVICE_STATE_IP_CHECK; } else if ( may_fail && get_ip_config_may_fail (self, AF_INET) @@ -4996,14 +4996,14 @@ check_ip_state (NMDevice *self, gboolean may_fail, gboolean full_state_update) } /* If a method is still pending but required, wait */ - if (priv->ip4_state != IP_DONE && !get_ip_config_may_fail (self, AF_INET)) + if (priv->ip4_state != NM_DEVICE_IP_STATE_DONE && !get_ip_config_may_fail (self, AF_INET)) return; - if (priv->ip6_state != IP_DONE && !get_ip_config_may_fail (self, AF_INET6)) + if (priv->ip6_state != NM_DEVICE_IP_STATE_DONE && !get_ip_config_may_fail (self, AF_INET6)) return; /* If at least a method has completed, proceed with activation */ - if ( (priv->ip4_state == IP_DONE && !ip4_disabled) - || (priv->ip6_state == IP_DONE && !ip6_ignore)) { + if ( (priv->ip4_state == NM_DEVICE_IP_STATE_DONE && !ip4_disabled) + || (priv->ip6_state == NM_DEVICE_IP_STATE_DONE && !ip6_ignore)) { if (full_state_update) nm_device_state_changed (self, NM_DEVICE_STATE_IP_CHECK, NM_DEVICE_STATE_REASON_NONE); return; @@ -6320,8 +6320,8 @@ activate_stage1_device_prepare (NMDevice *self) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMActStageReturn ret = NM_ACT_STAGE_RETURN_SUCCESS; - _set_ip_state (self, AF_INET, IP_NONE); - _set_ip_state (self, AF_INET6, IP_NONE); + _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_NONE); + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_NONE); /* Notify the new ActiveConnection along with the state change */ nm_dbus_track_obj_path_set (&priv->act_request, @@ -6617,7 +6617,7 @@ nm_device_ip_method_failed (NMDevice *self, g_return_if_fail (NM_IS_DEVICE (self)); g_return_if_fail (NM_IN_SET (addr_family, AF_INET, AF_INET6)); - _set_ip_state (self, addr_family, IP_FAIL); + _set_ip_state (self, addr_family, NM_DEVICE_IP_STATE_FAIL); if (get_ip_config_may_fail (self, addr_family)) check_ip_state (self, FALSE, (nm_device_get_state (self) == NM_DEVICE_STATE_IP_CONFIG)); @@ -6688,7 +6688,7 @@ ipv4_manual_method_apply (NMDevice *self, NMIP4Config **configs, gboolean succes empty = _ip4_config_new (self); nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (empty)); } else { - if (NM_DEVICE_GET_PRIVATE (self)->ip4_state != IP_DONE) + if (NM_DEVICE_GET_PRIVATE (self)->ip4_state != NM_DEVICE_IP_STATE_DONE) ip_config_merge_and_apply (self, AF_INET, TRUE); } } @@ -6903,10 +6903,10 @@ nm_device_handle_ipv4ll_event (sd_ipv4ll *ll, int event, void *data) return; } - if (priv->ip4_state == IP_CONF) { + if (priv->ip4_state == NM_DEVICE_IP_STATE_CONF) { nm_clear_g_source (&priv->ipv4ll_timeout); nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (config)); - } else if (priv->ip4_state == IP_DONE) { + } else if (priv->ip4_state == NM_DEVICE_IP_STATE_DONE) { applied_config_init (&priv->dev_ip4_config, config); if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) { _LOGE (LOGD_AUTOIP4, "failed to update IP4 config for autoip change."); @@ -6934,7 +6934,7 @@ ipv4ll_timeout_cb (gpointer user_data) priv->ipv4ll_timeout = 0; ipv4ll_cleanup (self); - if (priv->ip4_state == IP_CONF) + if (priv->ip4_state == NM_DEVICE_IP_STATE_CONF) nm_device_activate_schedule_ip_config_timeout (self, AF_INET); } @@ -7340,7 +7340,7 @@ dhcp4_fail (NMDevice *self, NMDhcpState dhcp_state) /* Keep client running if there are static addresses configured * on the interface. */ - if ( priv->ip4_state == IP_DONE + if ( priv->ip4_state == NM_DEVICE_IP_STATE_DONE && priv->con_ip_config_4 && nm_ip4_config_get_num_addresses (priv->con_ip_config_4) > 0) goto clear_config; @@ -7352,7 +7352,7 @@ dhcp4_fail (NMDevice *self, NMDhcpState dhcp_state) * not active before. */ if ( dhcp_state == NM_DHCP_STATE_TERMINATED - || (!priv->dhcp4.was_active && priv->ip4_state == IP_CONF)) { + || (!priv->dhcp4.was_active && priv->ip4_state == NM_DEVICE_IP_STATE_CONF)) { dhcp4_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); nm_device_activate_schedule_ip_config_timeout (self, AF_INET); return; @@ -7424,8 +7424,8 @@ dhcp4_state_changed (NMDhcpClient *client, /* After some failures, we have been able to renew the lease: * update the ip state */ - if (priv->ip4_state == IP_FAIL) - _set_ip_state (self, AF_INET, IP_CONF); + if (priv->ip4_state == NM_DEVICE_IP_STATE_FAIL) + _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_CONF); g_free (priv->dhcp4.pac_url); priv->dhcp4.pac_url = g_strdup (g_hash_table_lookup (options, "wpad")); @@ -7437,7 +7437,7 @@ dhcp4_state_changed (NMDhcpClient *client, nm_dhcp4_config_set_options (priv->dhcp4.config, options); _notify (self, PROP_DHCP4_CONFIG); - if (priv->ip4_state == IP_CONF) { + if (priv->ip4_state == NM_DEVICE_IP_STATE_CONF) { connection = nm_device_get_applied_connection (self); g_assert (connection); @@ -7454,7 +7454,7 @@ dhcp4_state_changed (NMDhcpClient *client, configs[1] = g_object_ref (ip4_config); ipv4_dad_start (self, configs, dhcp4_dad_cb); - } else if (priv->ip4_state == IP_DONE) { + } else if (priv->ip4_state == NM_DEVICE_IP_STATE_DONE) { if (dhcp4_lease_change (self, ip4_config)) nm_device_update_metered (self); else @@ -7466,7 +7466,7 @@ dhcp4_state_changed (NMDhcpClient *client, break; case NM_DHCP_STATE_EXPIRE: /* Ignore expiry before we even have a lease (NAK, old lease, etc) */ - if (priv->ip4_state == IP_CONF) + if (priv->ip4_state == NM_DEVICE_IP_STATE_CONF) break; /* fall through */ case NM_DHCP_STATE_DONE: @@ -8082,7 +8082,7 @@ dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state) /* Keep client running if there are static addresses configured * on the interface. */ - if ( priv->ip6_state == IP_DONE + if ( priv->ip6_state == NM_DEVICE_IP_STATE_DONE && priv->con_ip_config_6 && nm_ip6_config_get_num_addresses (priv->con_ip_config_6)) goto clear_config; @@ -8094,7 +8094,7 @@ dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state) * not active before. */ if ( dhcp_state == NM_DHCP_STATE_TERMINATED - || (!priv->dhcp6.was_active && priv->ip6_state == IP_CONF)) { + || (!priv->dhcp6.was_active && priv->ip6_state == NM_DEVICE_IP_STATE_CONF)) { dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); nm_device_activate_schedule_ip_config_timeout (self, AF_INET6); return; @@ -8116,7 +8116,7 @@ dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state) } else { /* not a hard failure; just live with the RA info */ dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); - if (priv->ip6_state == IP_CONF) + if (priv->ip6_state == NM_DEVICE_IP_STATE_CONF) nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); } return; @@ -8176,16 +8176,16 @@ dhcp6_state_changed (NMDhcpClient *client, /* After long time we have been able to renew the lease: * update the ip state */ - if (priv->ip6_state == IP_FAIL) - _set_ip_state (self, AF_INET6, IP_CONF); + if (priv->ip6_state == NM_DEVICE_IP_STATE_FAIL) + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_CONF); - if (priv->ip6_state == IP_CONF) { + if (priv->ip6_state == NM_DEVICE_IP_STATE_CONF) { if (!applied_config_get_current (&priv->dhcp6.ip6_config)) { nm_device_ip_method_failed (self, AF_INET6, NM_DEVICE_STATE_REASON_DHCP_FAILED); break; } nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); - } else if (priv->ip6_state == IP_DONE) + } else if (priv->ip6_state == NM_DEVICE_IP_STATE_DONE) if (!dhcp6_lease_change (self)) dhcp6_fail (self, state); break; @@ -8195,13 +8195,13 @@ dhcp6_state_changed (NMDhcpClient *client, else { /* not a hard failure; just live with the RA info */ dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); - if (priv->ip6_state == IP_CONF) + if (priv->ip6_state == NM_DEVICE_IP_STATE_CONF) nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); } break; case NM_DHCP_STATE_EXPIRE: /* Ignore expiry before we even have a lease (NAK, old lease, etc) */ - if (priv->ip6_state != IP_CONF) + if (priv->ip6_state != NM_DEVICE_IP_STATE_CONF) dhcp6_fail (self, state); break; case NM_DHCP_STATE_TERMINATED: @@ -9354,7 +9354,7 @@ ndisc_ra_timeout (NMNDisc *ndisc, NMDevice *self) */ _LOGD (LOGD_IP6, "timed out waiting for IPv6 router advertisement"); - if (priv->ip6_state == IP_CONF) { + if (priv->ip6_state == NM_DEVICE_IP_STATE_CONF) { /* If RA is our only source of addressing information and we don't * ever receive one, then time out IPv6. But if there is other * IPv6 configuration, like manual IPv6 addresses or external IPv6 @@ -9842,32 +9842,32 @@ nm_device_activate_stage3_ip4_start (NMDevice *self) NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; gs_unref_object NMIP4Config *ip4_config = NULL; - g_assert (priv->ip4_state == IP_WAIT); + g_assert (priv->ip4_state == NM_DEVICE_IP_STATE_WAIT); if (nm_device_sys_iface_state_is_external (self)) { - _set_ip_state (self, AF_INET, IP_DONE); + _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_DONE); check_ip_state (self, FALSE, TRUE); return TRUE; } - _set_ip_state (self, AF_INET, IP_CONF); + _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_CONF); ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip4_config_start (self, &ip4_config, &failure_reason); if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { if (!ip4_config) ip4_config = _ip4_config_new (self); nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (ip4_config)); } else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) { - _set_ip_state (self, AF_INET, IP_DONE); + _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_DONE); check_ip_state (self, FALSE, TRUE); } else if (ret == NM_ACT_STAGE_RETURN_FAILURE) { nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, failure_reason); return FALSE; } else if (ret == NM_ACT_STAGE_RETURN_IP_FAIL) { /* Activation not wanted */ - _set_ip_state (self, AF_INET, IP_FAIL); + _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_FAIL); } else if (ret == NM_ACT_STAGE_RETURN_IP_WAIT) { /* Wait for something to try IP config again */ - _set_ip_state (self, AF_INET, IP_WAIT); + _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_WAIT); } else g_assert (ret == NM_ACT_STAGE_RETURN_POSTPONE); @@ -9888,15 +9888,15 @@ nm_device_activate_stage3_ip6_start (NMDevice *self) NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; NMIP6Config *ip6_config = NULL; - g_assert (priv->ip6_state == IP_WAIT); + g_assert (priv->ip6_state == NM_DEVICE_IP_STATE_WAIT); if (nm_device_sys_iface_state_is_external (self)) { - _set_ip_state (self, AF_INET6, IP_DONE); + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_DONE); check_ip_state (self, FALSE, TRUE); return TRUE; } - _set_ip_state (self, AF_INET6, IP_CONF); + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_CONF); ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip6_config_start (self, &ip6_config, &failure_reason); if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { if (!ip6_config) @@ -9908,17 +9908,17 @@ nm_device_activate_stage3_ip6_start (NMDevice *self) applied_config_init (&priv->ac_ip6_config, ip6_config); nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); } else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) { - _set_ip_state (self, AF_INET6, IP_DONE); + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_DONE); check_ip_state (self, FALSE, TRUE); } else if (ret == NM_ACT_STAGE_RETURN_FAILURE) { nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, failure_reason); return FALSE; } else if (ret == NM_ACT_STAGE_RETURN_IP_FAIL) { /* Activation not wanted */ - _set_ip_state (self, AF_INET6, IP_FAIL); + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_FAIL); } else if (ret == NM_ACT_STAGE_RETURN_IP_WAIT) { /* Wait for something to try IP config again */ - _set_ip_state (self, AF_INET6, IP_WAIT); + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_WAIT); } else g_assert (ret == NM_ACT_STAGE_RETURN_POSTPONE); @@ -9936,8 +9936,8 @@ activate_stage3_ip_config_start (NMDevice *self) { int ifindex; - _set_ip_state (self, AF_INET, IP_WAIT); - _set_ip_state (self, AF_INET6, IP_WAIT); + _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_WAIT); + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_WAIT); _active_connection_set_state_flags (self, NM_ACTIVATION_STATE_FLAG_LAYER2_READY); @@ -9992,7 +9992,7 @@ fw_change_zone_cb (NMFirewallManager *firewall_manager, break; case FIREWALL_STATE_WAIT_IP_CONFIG: priv->fw_state = FIREWALL_STATE_INITIALIZED; - if (priv->ip4_state == IP_DONE || priv->ip6_state == IP_DONE) + if (priv->ip4_state == NM_DEVICE_IP_STATE_DONE || priv->ip6_state == NM_DEVICE_IP_STATE_DONE) nm_device_start_ip_check (self); break; case FIREWALL_STATE_INITIALIZED: @@ -10099,7 +10099,7 @@ activate_stage4_ip_config_timeout_4 (NMDevice *self) } g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS); - _set_ip_state (self, AF_INET, IP_FAIL); + _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_FAIL); check_ip_state (self, FALSE, TRUE); } @@ -10147,7 +10147,7 @@ activate_stage4_ip_config_timeout_6 (NMDevice *self) } g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS); - _set_ip_state (self, AF_INET6, IP_FAIL); + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_FAIL); check_ip_state (self, FALSE, TRUE); } @@ -10428,7 +10428,7 @@ activate_stage5_ip_config_result_4 (NMDevice *self) nm_device_remove_pending_action (self, NM_PENDING_ACTION_DHCP4, FALSE); /* Enter the IP_CHECK state if this is the first method to complete */ - _set_ip_state (self, AF_INET, IP_DONE); + _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_DONE); check_ip_state (self, FALSE, TRUE); } @@ -10451,11 +10451,11 @@ nm_device_activate_schedule_ip_config_result (NMDevice *self, if (IS_IPv4) { applied_config_init (&priv->dev_ip4_config, config); } else { - /* If IP had previously failed, move it back to IP_CONF since we + /* If IP had previously failed, move it back to NM_DEVICE_IP_STATE_CONF since we * clearly now have configuration. */ - if (priv->ip6_state == IP_FAIL) - _set_ip_state (self, AF_INET6, IP_CONF); + if (priv->ip6_state == NM_DEVICE_IP_STATE_FAIL) + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_CONF); } activation_source_schedule (self, activate_stage5_ip_config_result_x[IS_IPv4], addr_family); @@ -10465,21 +10465,21 @@ gboolean nm_device_activate_ip4_state_in_conf (NMDevice *self) { g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip4_state == IP_CONF; + return NM_DEVICE_GET_PRIVATE (self)->ip4_state == NM_DEVICE_IP_STATE_CONF; } gboolean nm_device_activate_ip4_state_in_wait (NMDevice *self) { g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip4_state == IP_WAIT; + return NM_DEVICE_GET_PRIVATE (self)->ip4_state == NM_DEVICE_IP_STATE_WAIT; } gboolean nm_device_activate_ip4_state_done (NMDevice *self) { g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip4_state == IP_DONE; + return NM_DEVICE_GET_PRIVATE (self)->ip4_state == NM_DEVICE_IP_STATE_DONE; } static void @@ -10583,7 +10583,7 @@ activate_stage5_ip_config_result_6 (NMDevice *self) if (ip_config_merge_and_apply (self, AF_INET6, TRUE)) { if ( priv->dhcp6.mode != NM_NDISC_DHCP_LEVEL_NONE - && priv->ip6_state == IP_CONF) { + && priv->ip6_state == NM_DEVICE_IP_STATE_CONF) { if (applied_config_get_current (&priv->dhcp6.ip6_config)) { /* If IPv6 wasn't the first IP to complete, and DHCP was used, * then ensure dispatcher scripts get the DHCP lease information. @@ -10611,7 +10611,7 @@ activate_stage5_ip_config_result_6 (NMDevice *self) } /* Check if we have to wait for DAD */ - if (priv->ip6_state == IP_CONF && !priv->dad6_ip6_config) { + if (priv->ip6_state == NM_DEVICE_IP_STATE_CONF && !priv->dad6_ip6_config) { if (!priv->carrier && priv->ignore_carrier && get_ip_config_may_fail (self, AF_INET6)) _LOGI (LOGD_DEVICE | LOGD_IP6, "IPv6 DAD: carrier missing and ignored, not delaying activation"); else @@ -10620,7 +10620,7 @@ activate_stage5_ip_config_result_6 (NMDevice *self) if (priv->dad6_ip6_config) { _LOGD (LOGD_DEVICE | LOGD_IP6, "IPv6 DAD: awaiting termination"); } else { - _set_ip_state (self, AF_INET6, IP_DONE); + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_DONE); check_ip_state (self, FALSE, TRUE); } } @@ -10634,21 +10634,21 @@ gboolean nm_device_activate_ip6_state_in_conf (NMDevice *self) { g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip6_state == IP_CONF; + return NM_DEVICE_GET_PRIVATE (self)->ip6_state == NM_DEVICE_IP_STATE_CONF; } gboolean nm_device_activate_ip6_state_in_wait (NMDevice *self) { g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip6_state == IP_WAIT; + return NM_DEVICE_GET_PRIVATE (self)->ip6_state == NM_DEVICE_IP_STATE_WAIT; } gboolean nm_device_activate_ip6_state_done (NMDevice *self) { g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip6_state == IP_DONE; + return NM_DEVICE_GET_PRIVATE (self)->ip6_state == NM_DEVICE_IP_STATE_DONE; } /*****************************************************************************/ @@ -10816,7 +10816,7 @@ _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, addr_family, IP_NONE); + _set_ip_state (self, addr_family, NM_DEVICE_IP_STATE_NONE); if (nm_clear_g_source (&priv->queued_ip_config_id_x[IS_IPv4])) { _LOGD (LOGD_DEVICE, "clearing queued IP%c config change", @@ -10918,7 +10918,7 @@ nm_device_reactivate_ip4_config (NMDevice *self, g_return_if_fail (NM_IS_DEVICE (self)); priv = NM_DEVICE_GET_PRIVATE (self); - if (priv->ip4_state != IP_NONE) { + if (priv->ip4_state != NM_DEVICE_IP_STATE_NONE) { g_clear_object (&priv->con_ip_config_4); g_clear_object (&priv->ext_ip_config_4); g_clear_object (&priv->dev_ip4_config.current); @@ -10940,7 +10940,7 @@ nm_device_reactivate_ip4_config (NMDevice *self, if (!nm_streq0 (method_old, method_new)) { _cleanup_ip_pre (self, AF_INET, CLEANUP_TYPE_DECONFIGURE); - _set_ip_state (self, AF_INET, IP_WAIT); + _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_WAIT); if (!nm_device_activate_stage3_ip4_start (self)) _LOGW (LOGD_IP4, "Failed to apply IPv4 configuration"); return; @@ -10990,7 +10990,7 @@ nm_device_reactivate_ip6_config (NMDevice *self, g_return_if_fail (NM_IS_DEVICE (self)); priv = NM_DEVICE_GET_PRIVATE (self); - if (priv->ip6_state != IP_NONE) { + if (priv->ip6_state != NM_DEVICE_IP_STATE_NONE) { g_clear_object (&priv->con_ip_config_6); g_clear_object (&priv->ext_ip_config_6); g_clear_object (&priv->ac_ip6_config.current); @@ -11014,7 +11014,7 @@ nm_device_reactivate_ip6_config (NMDevice *self, if (!nm_streq0 (method_old, method_new)) { _cleanup_ip_pre (self, AF_INET6, CLEANUP_TYPE_DECONFIGURE); - _set_ip_state (self, AF_INET6, IP_WAIT); + _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_WAIT); if (!nm_device_activate_stage3_ip6_start (self)) _LOGW (LOGD_IP6, "Failed to apply IPv6 configuration"); return; @@ -12502,7 +12502,7 @@ nm_device_start_ip_check (NMDevice *self) g_return_if_fail (!priv->gw_ping.watch); g_return_if_fail (!priv->gw_ping.timeout); g_return_if_fail (!priv->gw_ping.pid); - g_return_if_fail (priv->ip4_state == IP_DONE || priv->ip6_state == IP_DONE); + g_return_if_fail (priv->ip4_state == NM_DEVICE_IP_STATE_DONE || priv->ip6_state == NM_DEVICE_IP_STATE_DONE); connection = nm_device_get_applied_connection (self); g_assert (connection); @@ -12515,14 +12515,14 @@ nm_device_start_ip_check (NMDevice *self) if (timeout) { const NMPObject *gw; - if (priv->ip_config_4 && priv->ip4_state == IP_DONE) { + if (priv->ip_config_4 && priv->ip4_state == NM_DEVICE_IP_STATE_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->ip_config_6 && priv->ip6_state == IP_DONE) { + } else if (priv->ip_config_6 && priv->ip6_state == NM_DEVICE_IP_STATE_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); @@ -12662,11 +12662,11 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) _update_ip4_address (self); /* when the link comes up, we must restore IP configuration if necessary. */ - if (priv->ip4_state == IP_DONE) { + if (priv->ip4_state == NM_DEVICE_IP_STATE_DONE) { 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 (priv->ip6_state == NM_DEVICE_IP_STATE_DONE) { if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP6, "failed applying IP6 config after bringing link up"); } @@ -13011,14 +13011,14 @@ queued_ip_config_change (NMDevice *self, int addr_family) if (!IS_IPv4) { /* Check if DAD is still pending */ - if ( priv->ip6_state == IP_CONF + if ( priv->ip6_state == NM_DEVICE_IP_STATE_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); + _set_ip_state (self, addr_family, NM_DEVICE_IP_STATE_DONE); check_ip_state (self, FALSE, TRUE); if (priv->rt6_temporary_not_available) nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); @@ -13693,7 +13693,7 @@ 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->ip_config_4 - && priv->ip4_state == IP_DONE + && priv->ip4_state == NM_DEVICE_IP_STATE_DONE && nm_ip4_config_get_metered (priv->ip_config_4)) value = NM_METERED_GUESS_YES; } From ca14df5619ff75fb9e230fbf2df089196ba3b6c0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Mar 2019 20:38:44 +0100 Subject: [PATCH 06/16] device/trivial: rename ip-state fields in NMDevicePrivate Now they follow the naming pattern of ending in "_4" / "_6". We will merge them and alias them to an "_x" array, like done for similar fields. --- src/devices/nm-device.c | 122 ++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 6f576f0552..6b18a1c06c 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -417,8 +417,8 @@ typedef struct _NMDevicePrivate { }; union { - const NMDeviceIPState ip4_state; - NMDeviceIPState ip4_state_; + const NMDeviceIPState ip_state_4; + NMDeviceIPState ip_state_4_; }; AppliedConfig dev_ip4_config; /* Config from DHCP, PPP, LLv4, etc */ @@ -500,8 +500,8 @@ typedef struct _NMDevicePrivate { } acd; union { - const NMDeviceIPState ip6_state; - NMDeviceIPState ip6_state_; + const NMDeviceIPState ip_state_6; + NMDeviceIPState ip_state_6_; }; AppliedConfig ac_ip6_config; /* config from IPv6 autoconfiguration */ NMIP6Config * ext_ip6_config_captured; /* Configuration captured from platform. */ @@ -1356,8 +1356,8 @@ _set_ip_state (NMDevice *self, int addr_family, NMDeviceIPState new_state) nm_assert_addr_family (addr_family); p = (addr_family == AF_INET) - ? &priv->ip4_state_ - : &priv->ip6_state_; + ? &priv->ip_state_4_ + : &priv->ip_state_6_; if (*p != new_state) { _LOGT (LOGD_DEVICE, "ip%c-state: set to %d (%s)", @@ -3249,7 +3249,7 @@ nm_device_master_enslave_slave (NMDevice *self, NMDevice *slave, NMConnection *c nm_device_update_hw_address (self); /* Send ARP announcements if did not yet and have addresses. */ - if ( priv->ip4_state == NM_DEVICE_IP_STATE_DONE + if ( priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE && !priv->acd.announcing) nm_device_arp_announce (self); @@ -3258,10 +3258,10 @@ nm_device_master_enslave_slave (NMDevice *self, NMDevice *slave, NMConnection *c * new address. */ if (success) { - if (priv->ip4_state == NM_DEVICE_IP_STATE_WAIT) + if (priv->ip_state_4 == NM_DEVICE_IP_STATE_WAIT) nm_device_activate_stage3_ip4_start (self); - if (priv->ip6_state == NM_DEVICE_IP_STATE_WAIT) + if (priv->ip_state_6 == NM_DEVICE_IP_STATE_WAIT) nm_device_activate_stage3_ip6_start (self); } @@ -3884,11 +3884,11 @@ device_link_changed (NMDevice *self) if (priv->up && (!was_up || seen_down)) { /* the link was down and just came up. That happens for example, while changing MTU. * We must restore IP configuration. */ - if (priv->ip4_state == NM_DEVICE_IP_STATE_DONE) { + if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) { 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 == NM_DEVICE_IP_STATE_DONE) { + if (priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE) { if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP6, "failed applying IP6 config after link comes up again"); } @@ -4958,15 +4958,15 @@ check_ip_state (NMDevice *self, gboolean may_fail, gboolean full_state_update) NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) ip6_ignore = TRUE; - if ( priv->ip4_state == NM_DEVICE_IP_STATE_DONE - && priv->ip6_state == NM_DEVICE_IP_STATE_DONE) { + if ( priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE + && priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE) { /* Both method completed (or disabled), proceed with activation */ nm_device_state_changed (self, NM_DEVICE_STATE_IP_CHECK, NM_DEVICE_STATE_REASON_NONE); return; } - if ( (priv->ip4_state == NM_DEVICE_IP_STATE_FAIL || (ip4_disabled && priv->ip4_state == NM_DEVICE_IP_STATE_DONE)) - && (priv->ip6_state == NM_DEVICE_IP_STATE_FAIL || (ip6_ignore && priv->ip6_state == NM_DEVICE_IP_STATE_DONE))) { + if ( (priv->ip_state_4 == NM_DEVICE_IP_STATE_FAIL || (ip4_disabled && priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE)) + && (priv->ip_state_6 == NM_DEVICE_IP_STATE_FAIL || (ip6_ignore && priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE))) { /* Either both methods failed, or only one failed and the other is * disabled */ if (nm_device_sys_iface_state_is_external_or_assume (self)) { @@ -4996,14 +4996,14 @@ check_ip_state (NMDevice *self, gboolean may_fail, gboolean full_state_update) } /* If a method is still pending but required, wait */ - if (priv->ip4_state != NM_DEVICE_IP_STATE_DONE && !get_ip_config_may_fail (self, AF_INET)) + if (priv->ip_state_4 != NM_DEVICE_IP_STATE_DONE && !get_ip_config_may_fail (self, AF_INET)) return; - if (priv->ip6_state != NM_DEVICE_IP_STATE_DONE && !get_ip_config_may_fail (self, AF_INET6)) + if (priv->ip_state_6 != NM_DEVICE_IP_STATE_DONE && !get_ip_config_may_fail (self, AF_INET6)) return; /* If at least a method has completed, proceed with activation */ - if ( (priv->ip4_state == NM_DEVICE_IP_STATE_DONE && !ip4_disabled) - || (priv->ip6_state == NM_DEVICE_IP_STATE_DONE && !ip6_ignore)) { + if ( (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE && !ip4_disabled) + || (priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE && !ip6_ignore)) { if (full_state_update) nm_device_state_changed (self, NM_DEVICE_STATE_IP_CHECK, NM_DEVICE_STATE_REASON_NONE); return; @@ -6688,7 +6688,7 @@ ipv4_manual_method_apply (NMDevice *self, NMIP4Config **configs, gboolean succes empty = _ip4_config_new (self); nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (empty)); } else { - if (NM_DEVICE_GET_PRIVATE (self)->ip4_state != NM_DEVICE_IP_STATE_DONE) + if (NM_DEVICE_GET_PRIVATE (self)->ip_state_4 != NM_DEVICE_IP_STATE_DONE) ip_config_merge_and_apply (self, AF_INET, TRUE); } } @@ -6903,10 +6903,10 @@ nm_device_handle_ipv4ll_event (sd_ipv4ll *ll, int event, void *data) return; } - if (priv->ip4_state == NM_DEVICE_IP_STATE_CONF) { + if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) { nm_clear_g_source (&priv->ipv4ll_timeout); nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (config)); - } else if (priv->ip4_state == NM_DEVICE_IP_STATE_DONE) { + } else if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) { applied_config_init (&priv->dev_ip4_config, config); if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) { _LOGE (LOGD_AUTOIP4, "failed to update IP4 config for autoip change."); @@ -6934,7 +6934,7 @@ ipv4ll_timeout_cb (gpointer user_data) priv->ipv4ll_timeout = 0; ipv4ll_cleanup (self); - if (priv->ip4_state == NM_DEVICE_IP_STATE_CONF) + if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) nm_device_activate_schedule_ip_config_timeout (self, AF_INET); } @@ -7334,13 +7334,13 @@ dhcp4_fail (NMDevice *self, NMDhcpState dhcp_state) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); _LOGD (LOGD_DHCP4, "DHCPv4 failed (ip_state %s, was_active %d)", - _ip_state_to_string (priv->ip4_state), + _ip_state_to_string (priv->ip_state_4), priv->dhcp4.was_active); /* Keep client running if there are static addresses configured * on the interface. */ - if ( priv->ip4_state == NM_DEVICE_IP_STATE_DONE + if ( priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE && priv->con_ip_config_4 && nm_ip4_config_get_num_addresses (priv->con_ip_config_4) > 0) goto clear_config; @@ -7352,7 +7352,7 @@ dhcp4_fail (NMDevice *self, NMDhcpState dhcp_state) * not active before. */ if ( dhcp_state == NM_DHCP_STATE_TERMINATED - || (!priv->dhcp4.was_active && priv->ip4_state == NM_DEVICE_IP_STATE_CONF)) { + || (!priv->dhcp4.was_active && priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF)) { dhcp4_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); nm_device_activate_schedule_ip_config_timeout (self, AF_INET); return; @@ -7424,7 +7424,7 @@ dhcp4_state_changed (NMDhcpClient *client, /* After some failures, we have been able to renew the lease: * update the ip state */ - if (priv->ip4_state == NM_DEVICE_IP_STATE_FAIL) + if (priv->ip_state_4 == NM_DEVICE_IP_STATE_FAIL) _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_CONF); g_free (priv->dhcp4.pac_url); @@ -7437,7 +7437,7 @@ dhcp4_state_changed (NMDhcpClient *client, nm_dhcp4_config_set_options (priv->dhcp4.config, options); _notify (self, PROP_DHCP4_CONFIG); - if (priv->ip4_state == NM_DEVICE_IP_STATE_CONF) { + if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) { connection = nm_device_get_applied_connection (self); g_assert (connection); @@ -7454,7 +7454,7 @@ dhcp4_state_changed (NMDhcpClient *client, configs[1] = g_object_ref (ip4_config); ipv4_dad_start (self, configs, dhcp4_dad_cb); - } else if (priv->ip4_state == NM_DEVICE_IP_STATE_DONE) { + } else if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) { if (dhcp4_lease_change (self, ip4_config)) nm_device_update_metered (self); else @@ -7466,7 +7466,7 @@ dhcp4_state_changed (NMDhcpClient *client, break; case NM_DHCP_STATE_EXPIRE: /* Ignore expiry before we even have a lease (NAK, old lease, etc) */ - if (priv->ip4_state == NM_DEVICE_IP_STATE_CONF) + if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) break; /* fall through */ case NM_DHCP_STATE_DONE: @@ -8073,7 +8073,7 @@ dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state) gboolean is_dhcp_managed; _LOGD (LOGD_DHCP6, "DHCPv6 failed (ip_state %s, was_active %d)", - _ip_state_to_string (priv->ip6_state), + _ip_state_to_string (priv->ip_state_6), priv->dhcp6.was_active); is_dhcp_managed = (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_MANAGED); @@ -8082,7 +8082,7 @@ dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state) /* Keep client running if there are static addresses configured * on the interface. */ - if ( priv->ip6_state == NM_DEVICE_IP_STATE_DONE + if ( priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE && priv->con_ip_config_6 && nm_ip6_config_get_num_addresses (priv->con_ip_config_6)) goto clear_config; @@ -8094,7 +8094,7 @@ dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state) * not active before. */ if ( dhcp_state == NM_DHCP_STATE_TERMINATED - || (!priv->dhcp6.was_active && priv->ip6_state == NM_DEVICE_IP_STATE_CONF)) { + || (!priv->dhcp6.was_active && priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF)) { dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); nm_device_activate_schedule_ip_config_timeout (self, AF_INET6); return; @@ -8116,7 +8116,7 @@ dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state) } else { /* not a hard failure; just live with the RA info */ dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); - if (priv->ip6_state == NM_DEVICE_IP_STATE_CONF) + if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF) nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); } return; @@ -8176,16 +8176,16 @@ dhcp6_state_changed (NMDhcpClient *client, /* After long time we have been able to renew the lease: * update the ip state */ - if (priv->ip6_state == NM_DEVICE_IP_STATE_FAIL) + if (priv->ip_state_6 == NM_DEVICE_IP_STATE_FAIL) _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_CONF); - if (priv->ip6_state == NM_DEVICE_IP_STATE_CONF) { + if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF) { if (!applied_config_get_current (&priv->dhcp6.ip6_config)) { nm_device_ip_method_failed (self, AF_INET6, NM_DEVICE_STATE_REASON_DHCP_FAILED); break; } nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); - } else if (priv->ip6_state == NM_DEVICE_IP_STATE_DONE) + } else if (priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE) if (!dhcp6_lease_change (self)) dhcp6_fail (self, state); break; @@ -8195,13 +8195,13 @@ dhcp6_state_changed (NMDhcpClient *client, else { /* not a hard failure; just live with the RA info */ dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); - if (priv->ip6_state == NM_DEVICE_IP_STATE_CONF) + if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF) nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); } break; case NM_DHCP_STATE_EXPIRE: /* Ignore expiry before we even have a lease (NAK, old lease, etc) */ - if (priv->ip6_state != NM_DEVICE_IP_STATE_CONF) + if (priv->ip_state_6 != NM_DEVICE_IP_STATE_CONF) dhcp6_fail (self, state); break; case NM_DHCP_STATE_TERMINATED: @@ -9354,7 +9354,7 @@ ndisc_ra_timeout (NMNDisc *ndisc, NMDevice *self) */ _LOGD (LOGD_IP6, "timed out waiting for IPv6 router advertisement"); - if (priv->ip6_state == NM_DEVICE_IP_STATE_CONF) { + if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF) { /* If RA is our only source of addressing information and we don't * ever receive one, then time out IPv6. But if there is other * IPv6 configuration, like manual IPv6 addresses or external IPv6 @@ -9842,7 +9842,7 @@ nm_device_activate_stage3_ip4_start (NMDevice *self) NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; gs_unref_object NMIP4Config *ip4_config = NULL; - g_assert (priv->ip4_state == NM_DEVICE_IP_STATE_WAIT); + g_assert (priv->ip_state_4 == NM_DEVICE_IP_STATE_WAIT); if (nm_device_sys_iface_state_is_external (self)) { _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_DONE); @@ -9888,7 +9888,7 @@ nm_device_activate_stage3_ip6_start (NMDevice *self) NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; NMIP6Config *ip6_config = NULL; - g_assert (priv->ip6_state == NM_DEVICE_IP_STATE_WAIT); + g_assert (priv->ip_state_6 == NM_DEVICE_IP_STATE_WAIT); if (nm_device_sys_iface_state_is_external (self)) { _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_DONE); @@ -9992,7 +9992,7 @@ fw_change_zone_cb (NMFirewallManager *firewall_manager, break; case FIREWALL_STATE_WAIT_IP_CONFIG: priv->fw_state = FIREWALL_STATE_INITIALIZED; - if (priv->ip4_state == NM_DEVICE_IP_STATE_DONE || priv->ip6_state == NM_DEVICE_IP_STATE_DONE) + if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE || priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE) nm_device_start_ip_check (self); break; case FIREWALL_STATE_INITIALIZED: @@ -10454,7 +10454,7 @@ nm_device_activate_schedule_ip_config_result (NMDevice *self, /* If IP had previously failed, move it back to NM_DEVICE_IP_STATE_CONF since we * clearly now have configuration. */ - if (priv->ip6_state == NM_DEVICE_IP_STATE_FAIL) + if (priv->ip_state_6 == NM_DEVICE_IP_STATE_FAIL) _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_CONF); } @@ -10465,21 +10465,21 @@ gboolean nm_device_activate_ip4_state_in_conf (NMDevice *self) { g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip4_state == NM_DEVICE_IP_STATE_CONF; + return NM_DEVICE_GET_PRIVATE (self)->ip_state_4 == NM_DEVICE_IP_STATE_CONF; } gboolean nm_device_activate_ip4_state_in_wait (NMDevice *self) { g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip4_state == NM_DEVICE_IP_STATE_WAIT; + return NM_DEVICE_GET_PRIVATE (self)->ip_state_4 == NM_DEVICE_IP_STATE_WAIT; } gboolean nm_device_activate_ip4_state_done (NMDevice *self) { g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip4_state == NM_DEVICE_IP_STATE_DONE; + return NM_DEVICE_GET_PRIVATE (self)->ip_state_4 == NM_DEVICE_IP_STATE_DONE; } static void @@ -10583,7 +10583,7 @@ activate_stage5_ip_config_result_6 (NMDevice *self) if (ip_config_merge_and_apply (self, AF_INET6, TRUE)) { if ( priv->dhcp6.mode != NM_NDISC_DHCP_LEVEL_NONE - && priv->ip6_state == NM_DEVICE_IP_STATE_CONF) { + && priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF) { if (applied_config_get_current (&priv->dhcp6.ip6_config)) { /* If IPv6 wasn't the first IP to complete, and DHCP was used, * then ensure dispatcher scripts get the DHCP lease information. @@ -10611,7 +10611,7 @@ activate_stage5_ip_config_result_6 (NMDevice *self) } /* Check if we have to wait for DAD */ - if (priv->ip6_state == NM_DEVICE_IP_STATE_CONF && !priv->dad6_ip6_config) { + if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF && !priv->dad6_ip6_config) { if (!priv->carrier && priv->ignore_carrier && get_ip_config_may_fail (self, AF_INET6)) _LOGI (LOGD_DEVICE | LOGD_IP6, "IPv6 DAD: carrier missing and ignored, not delaying activation"); else @@ -10634,21 +10634,21 @@ gboolean nm_device_activate_ip6_state_in_conf (NMDevice *self) { g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip6_state == NM_DEVICE_IP_STATE_CONF; + return NM_DEVICE_GET_PRIVATE (self)->ip_state_6 == NM_DEVICE_IP_STATE_CONF; } gboolean nm_device_activate_ip6_state_in_wait (NMDevice *self) { g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip6_state == NM_DEVICE_IP_STATE_WAIT; + return NM_DEVICE_GET_PRIVATE (self)->ip_state_6 == NM_DEVICE_IP_STATE_WAIT; } gboolean nm_device_activate_ip6_state_done (NMDevice *self) { g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip6_state == NM_DEVICE_IP_STATE_DONE; + return NM_DEVICE_GET_PRIVATE (self)->ip_state_6 == NM_DEVICE_IP_STATE_DONE; } /*****************************************************************************/ @@ -10918,7 +10918,7 @@ nm_device_reactivate_ip4_config (NMDevice *self, g_return_if_fail (NM_IS_DEVICE (self)); priv = NM_DEVICE_GET_PRIVATE (self); - if (priv->ip4_state != NM_DEVICE_IP_STATE_NONE) { + if (priv->ip_state_4 != NM_DEVICE_IP_STATE_NONE) { g_clear_object (&priv->con_ip_config_4); g_clear_object (&priv->ext_ip_config_4); g_clear_object (&priv->dev_ip4_config.current); @@ -10990,7 +10990,7 @@ nm_device_reactivate_ip6_config (NMDevice *self, g_return_if_fail (NM_IS_DEVICE (self)); priv = NM_DEVICE_GET_PRIVATE (self); - if (priv->ip6_state != NM_DEVICE_IP_STATE_NONE) { + if (priv->ip_state_6 != NM_DEVICE_IP_STATE_NONE) { g_clear_object (&priv->con_ip_config_6); g_clear_object (&priv->ext_ip_config_6); g_clear_object (&priv->ac_ip6_config.current); @@ -12502,7 +12502,7 @@ nm_device_start_ip_check (NMDevice *self) g_return_if_fail (!priv->gw_ping.watch); g_return_if_fail (!priv->gw_ping.timeout); g_return_if_fail (!priv->gw_ping.pid); - g_return_if_fail (priv->ip4_state == NM_DEVICE_IP_STATE_DONE || priv->ip6_state == NM_DEVICE_IP_STATE_DONE); + g_return_if_fail (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE || priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE); connection = nm_device_get_applied_connection (self); g_assert (connection); @@ -12515,14 +12515,14 @@ nm_device_start_ip_check (NMDevice *self) if (timeout) { const NMPObject *gw; - if (priv->ip_config_4 && priv->ip4_state == NM_DEVICE_IP_STATE_DONE) { + if (priv->ip_config_4 && priv->ip_state_4 == NM_DEVICE_IP_STATE_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->ip_config_6 && priv->ip6_state == NM_DEVICE_IP_STATE_DONE) { + } else if (priv->ip_config_6 && priv->ip_state_6 == NM_DEVICE_IP_STATE_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); @@ -12662,11 +12662,11 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) _update_ip4_address (self); /* when the link comes up, we must restore IP configuration if necessary. */ - if (priv->ip4_state == NM_DEVICE_IP_STATE_DONE) { + if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) { 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 == NM_DEVICE_IP_STATE_DONE) { + if (priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE) { if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) _LOGW (LOGD_IP6, "failed applying IP6 config after bringing link up"); } @@ -13011,7 +13011,7 @@ queued_ip_config_change (NMDevice *self, int addr_family) if (!IS_IPv4) { /* Check if DAD is still pending */ - if ( priv->ip6_state == NM_DEVICE_IP_STATE_CONF + if ( priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF && priv->dad6_ip6_config && priv->ext_ip6_config_captured && !nm_ip6_config_has_any_dad_pending (priv->ext_ip6_config_captured, @@ -13693,7 +13693,7 @@ 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->ip_config_4 - && priv->ip4_state == NM_DEVICE_IP_STATE_DONE + && priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE && nm_ip4_config_get_metered (priv->ip_config_4)) value = NM_METERED_GUESS_YES; } From 515e003effd1b5a75594aef0e0a1151521cae923 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Mar 2019 20:50:12 +0100 Subject: [PATCH 07/16] device: unify IPv4 and IPv6 handling of IP state of device --- src/devices/nm-device-private.h | 51 ++++++++++++++-- src/devices/nm-device.c | 105 +++++++++++--------------------- 2 files changed, 79 insertions(+), 77 deletions(-) diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index 4fd3576f49..54cc151983 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -26,6 +26,14 @@ /* This file should only be used by subclasses of NMDevice */ +typedef enum { + NM_DEVICE_IP_STATE_NONE, + NM_DEVICE_IP_STATE_WAIT, + NM_DEVICE_IP_STATE_CONF, + NM_DEVICE_IP_STATE_DONE, + NM_DEVICE_IP_STATE_FAIL, +} NMDeviceIPState; + enum NMActStageReturn { NM_ACT_STAGE_RETURN_FAILURE = 0, /* Hard failure of activation */ NM_ACT_STAGE_RETURN_SUCCESS, /* Activation stage done */ @@ -82,13 +90,44 @@ void nm_device_activate_schedule_ip_config_result (NMDevice *device, void nm_device_activate_schedule_ip_config_timeout (NMDevice *device, int addr_family); -gboolean nm_device_activate_ip4_state_in_conf (NMDevice *device); -gboolean nm_device_activate_ip4_state_in_wait (NMDevice *device); -gboolean nm_device_activate_ip4_state_done (NMDevice *device); +NMDeviceIPState nm_device_activate_get_ip_state (NMDevice *self, + int addr_family); -gboolean nm_device_activate_ip6_state_in_conf (NMDevice *device); -gboolean nm_device_activate_ip6_state_in_wait (NMDevice *device); -gboolean nm_device_activate_ip6_state_done (NMDevice *device); +static inline gboolean +nm_device_activate_ip4_state_in_conf (NMDevice *self) +{ + return nm_device_activate_get_ip_state (self, AF_INET) == NM_DEVICE_IP_STATE_CONF; +} + +static inline gboolean +nm_device_activate_ip4_state_in_wait (NMDevice *self) +{ + return nm_device_activate_get_ip_state (self, AF_INET) == NM_DEVICE_IP_STATE_WAIT; +} + +static inline gboolean +nm_device_activate_ip4_state_done (NMDevice *self) +{ + return nm_device_activate_get_ip_state (self, AF_INET) == NM_DEVICE_IP_STATE_DONE; +} + +static inline gboolean +nm_device_activate_ip6_state_in_conf (NMDevice *self) +{ + return nm_device_activate_get_ip_state (self, AF_INET6) == NM_DEVICE_IP_STATE_CONF; +} + +static inline gboolean +nm_device_activate_ip6_state_in_wait (NMDevice *self) +{ + return nm_device_activate_get_ip_state (self, AF_INET6) == NM_DEVICE_IP_STATE_WAIT; +} + +static inline gboolean +nm_device_activate_ip6_state_done (NMDevice *self) +{ + return nm_device_activate_get_ip_state (self, AF_INET6) == NM_DEVICE_IP_STATE_DONE; +} void nm_device_set_dhcp_anycast_address (NMDevice *device, const char *addr); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 6b18a1c06c..9b6479a8db 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -113,14 +113,6 @@ typedef enum { CLEANUP_TYPE_DECONFIGURE, } CleanupType; -typedef enum { - NM_DEVICE_IP_STATE_NONE = 0, - NM_DEVICE_IP_STATE_WAIT, - NM_DEVICE_IP_STATE_CONF, - NM_DEVICE_IP_STATE_DONE, - NM_DEVICE_IP_STATE_FAIL -} NMDeviceIPState; - typedef struct { CList lst_slave; NMDevice *slave; @@ -416,10 +408,6 @@ typedef struct _NMDevicePrivate { NMIPConfig *ip_config_x[2]; }; - union { - const NMDeviceIPState ip_state_4; - NMDeviceIPState ip_state_4_; - }; AppliedConfig dev_ip4_config; /* Config from DHCP, PPP, LLv4, etc */ /* config from the setting */ @@ -500,9 +488,16 @@ typedef struct _NMDevicePrivate { } acd; union { - const NMDeviceIPState ip_state_6; - NMDeviceIPState ip_state_6_; + struct { + const NMDeviceIPState ip_state_6; + const NMDeviceIPState ip_state_4; + }; + union { + const NMDeviceIPState ip_state_x[2]; + NMDeviceIPState ip_state_x_[2]; + }; }; + AppliedConfig ac_ip6_config; /* config from IPv6 autoconfiguration */ NMIP6Config * ext_ip6_config_captured; /* Configuration captured from platform. */ NMIP6Config * dad6_ip6_config; @@ -1350,32 +1345,30 @@ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_ip_state_to_string, NMDeviceIPState, static void _set_ip_state (NMDevice *self, int addr_family, NMDeviceIPState new_state) { - NMDeviceIPState *p; NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + const gboolean IS_IPv4 = (addr_family == AF_INET); nm_assert_addr_family (addr_family); - p = (addr_family == AF_INET) - ? &priv->ip_state_4_ - : &priv->ip_state_6_; + if (priv->ip_state_x[IS_IPv4] == new_state) + return; - if (*p != new_state) { - _LOGT (LOGD_DEVICE, "ip%c-state: set to %d (%s)", - nm_utils_addr_family_to_char (addr_family), - (int) new_state, - _ip_state_to_string (new_state)); - *p = new_state; + _LOGT (LOGD_DEVICE, "ip%c-state: set to %d (%s)", + nm_utils_addr_family_to_char (addr_family), + (int) new_state, + _ip_state_to_string (new_state)); - if (new_state == NM_DEVICE_IP_STATE_DONE) { - /* we only set the IPx_READY flag once we reach NM_DEVICE_IP_STATE_DONE state. We don't - * ever clear it, even if we later enter NM_DEVICE_IP_STATE_FAIL state. - * - * This is not documented/guaranteed behavior, but seems to make sense for now. */ - _active_connection_set_state_flags (self, - addr_family == AF_INET - ? NM_ACTIVATION_STATE_FLAG_IP4_READY - : NM_ACTIVATION_STATE_FLAG_IP6_READY); - } + priv->ip_state_x_[IS_IPv4] = new_state; + + if (new_state == NM_DEVICE_IP_STATE_DONE) { + /* we only set the IPx_READY flag once we reach NM_DEVICE_IP_STATE_DONE state. We don't + * ever clear it, even if we later enter NM_DEVICE_IP_STATE_FAIL state. + * + * This is not documented/guaranteed behavior, but seems to make sense for now. */ + _active_connection_set_state_flags (self, + addr_family == AF_INET + ? NM_ACTIVATION_STATE_FLAG_IP4_READY + : NM_ACTIVATION_STATE_FLAG_IP6_READY); } } @@ -10461,25 +10454,16 @@ nm_device_activate_schedule_ip_config_result (NMDevice *self, activation_source_schedule (self, activate_stage5_ip_config_result_x[IS_IPv4], addr_family); } -gboolean -nm_device_activate_ip4_state_in_conf (NMDevice *self) +NMDeviceIPState +nm_device_activate_get_ip_state (NMDevice *self, + int addr_family) { - g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip_state_4 == NM_DEVICE_IP_STATE_CONF; -} + const gboolean IS_IPv4 = (addr_family == AF_INET); -gboolean -nm_device_activate_ip4_state_in_wait (NMDevice *self) -{ - g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip_state_4 == NM_DEVICE_IP_STATE_WAIT; -} + g_return_val_if_fail (NM_IS_DEVICE (self), NM_DEVICE_IP_STATE_NONE); + g_return_val_if_fail (NM_IN_SET (addr_family, AF_INET, AF_INET6), NM_DEVICE_IP_STATE_NONE); -gboolean -nm_device_activate_ip4_state_done (NMDevice *self) -{ - g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip_state_4 == NM_DEVICE_IP_STATE_DONE; + return NM_DEVICE_GET_PRIVATE (self)->ip_state_x[IS_IPv4]; } static void @@ -10630,27 +10614,6 @@ activate_stage5_ip_config_result_6 (NMDevice *self) } } -gboolean -nm_device_activate_ip6_state_in_conf (NMDevice *self) -{ - g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip_state_6 == NM_DEVICE_IP_STATE_CONF; -} - -gboolean -nm_device_activate_ip6_state_in_wait (NMDevice *self) -{ - g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip_state_6 == NM_DEVICE_IP_STATE_WAIT; -} - -gboolean -nm_device_activate_ip6_state_done (NMDevice *self) -{ - g_return_val_if_fail (self != NULL, FALSE); - return NM_DEVICE_GET_PRIVATE (self)->ip_state_6 == NM_DEVICE_IP_STATE_DONE; -} - /*****************************************************************************/ static void From 2f88523eef55ee6717bc336ac072db1fa2076bca Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Mar 2019 21:04:28 +0100 Subject: [PATCH 08/16] device/trivial: rename dev_ip4_config field So that it follows the naming pattern of similar fields, that exist in a variant for IPv4 and IPv6. --- src/devices/nm-device.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 9b6479a8db..a3bd671317 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -408,7 +408,8 @@ typedef struct _NMDevicePrivate { NMIPConfig *ip_config_x[2]; }; - AppliedConfig dev_ip4_config; /* Config from DHCP, PPP, LLv4, etc */ + /* Config from DHCP, PPP, LLv4, etc */ + AppliedConfig dev_ip_config_4; /* config from the setting */ union { @@ -6900,7 +6901,7 @@ nm_device_handle_ipv4ll_event (sd_ipv4ll *ll, int event, void *data) nm_clear_g_source (&priv->ipv4ll_timeout); nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (config)); } else if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) { - applied_config_init (&priv->dev_ip4_config, config); + applied_config_init (&priv->dev_ip_config_4, config); 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); @@ -7166,7 +7167,7 @@ ip_config_merge_and_apply (NMDevice *self, /* Merge all the IP configs into the composite config */ if (IS_IPv4) { - config = applied_config_get_current (&priv->dev_ip4_config); + config = applied_config_get_current (&priv->dev_ip_config_4); if (config) { nm_ip4_config_merge (NM_IP4_CONFIG (composite), NM_IP4_CONFIG (config), (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) @@ -7288,7 +7289,7 @@ dhcp4_lease_change (NMDevice *self, NMIP4Config *config) g_return_val_if_fail (config, FALSE); - applied_config_init (&priv->dev_ip4_config, config); + applied_config_init (&priv->dev_ip_config_4, config); if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) { _LOGW (LOGD_DHCP4, "failed to update IPv4 config for DHCP change."); @@ -10442,7 +10443,7 @@ nm_device_activate_schedule_ip_config_result (NMDevice *self, priv = NM_DEVICE_GET_PRIVATE (self); if (IS_IPv4) { - applied_config_init (&priv->dev_ip4_config, config); + applied_config_init (&priv->dev_ip_config_4, config); } else { /* If IP had previously failed, move it back to NM_DEVICE_IP_STATE_CONF since we * clearly now have configuration. @@ -10884,7 +10885,7 @@ nm_device_reactivate_ip4_config (NMDevice *self, if (priv->ip_state_4 != NM_DEVICE_IP_STATE_NONE) { 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->dev_ip_config_4.current); 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, @@ -10922,8 +10923,8 @@ nm_device_reactivate_ip4_config (NMDevice *self, metric_new = nm_setting_ip_config_get_route_metric (s_ip4_new); if (metric_old != metric_new) { - if (priv->dev_ip4_config.orig) { - nm_ip4_config_update_routes_metric ((NMIP4Config *) priv->dev_ip4_config.orig, + if (priv->dev_ip_config_4.orig) { + nm_ip4_config_update_routes_metric ((NMIP4Config *) priv->dev_ip_config_4.orig, nm_device_get_route_metric (self, AF_INET)); } if (priv->wwan_ip_config_4.orig) { @@ -12093,7 +12094,7 @@ nm_device_set_ip_config (NMDevice *self, 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); + applied_config_clear (&priv->dev_ip_config_4); } else priv->needs_ip6_subnet = FALSE; } @@ -12758,7 +12759,7 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_config default_route_metric_penalty_get (self, AF_INET)); } - intersect_ext_config (self, &priv->dev_ip4_config, is_up); + intersect_ext_config (self, &priv->dev_ip_config_4, is_up); intersect_ext_config (self, &priv->wwan_ip_config_4, is_up); for (iter = priv->vpn_configs_4; iter; iter = iter->next) @@ -12772,9 +12773,9 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_config 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)) { + if (applied_config_get_current (&priv->dev_ip_config_4)) { nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip_config_4, - applied_config_get_current (&priv->dev_ip4_config), + applied_config_get_current (&priv->dev_ip_config_4), default_route_metric_penalty_get (self, AF_INET)); } if (applied_config_get_current (&priv->wwan_ip_config_4)) { @@ -14257,7 +14258,7 @@ _cleanup_generic_post (NMDevice *self, CleanupType cleanup_type) 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); + applied_config_clear (&priv->dev_ip_config_4); applied_config_clear (&priv->wwan_ip_config_4); g_clear_object (&priv->ext_ip_config_4); g_clear_object (&priv->ip_config_4); From ee63e008d152bec1c3c8a4895ce4ca719255cafa Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 2 Mar 2019 18:21:27 +0100 Subject: [PATCH 09/16] device: avoid setting an empty dev_ip_config_4 for activate_schedule_ip_config_result() An empty NMIP4Config instance should have the same effect as %NULL. Don't create it. --- src/devices/nm-device.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index a3bd671317..cda047faec 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -6676,12 +6676,9 @@ ipv4_manual_method_apply (NMDevice *self, NMIP4Config **configs, gboolean succes return; } - if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) { - gs_unref_object NMIP4Config *empty = NULL; - - empty = _ip4_config_new (self); - nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (empty)); - } else { + if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) + nm_device_activate_schedule_ip_config_result (self, AF_INET, NULL); + else { if (NM_DEVICE_GET_PRIVATE (self)->ip_state_4 != NM_DEVICE_IP_STATE_DONE) ip_config_merge_and_apply (self, AF_INET, TRUE); } @@ -9846,11 +9843,9 @@ nm_device_activate_stage3_ip4_start (NMDevice *self) _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_CONF); ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip4_config_start (self, &ip4_config, &failure_reason); - if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { - if (!ip4_config) - ip4_config = _ip4_config_new (self); + if (ret == NM_ACT_STAGE_RETURN_SUCCESS) nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (ip4_config)); - } else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) { + else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) { _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_DONE); check_ip_state (self, FALSE, TRUE); } else if (ret == NM_ACT_STAGE_RETURN_FAILURE) { From 99abcf0105286684f25525a468b7cb0670b621a5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 2 Mar 2019 18:34:09 +0100 Subject: [PATCH 10/16] device: merge IPv4 and IPv6 variant of nm_device_set_wwan_ip_config() --- src/devices/nm-device-private.h | 5 +++-- src/devices/nm-device.c | 32 ++++++++++++++++-------------- src/devices/wwan/nm-device-modem.c | 5 +++-- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index 54cc151983..9a9929692d 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -146,8 +146,9 @@ void nm_device_queue_recheck_available (NMDevice *device, NMDeviceStateReason available_reason, NMDeviceStateReason unavailable_reason); -void nm_device_set_wwan_ip4_config (NMDevice *device, NMIP4Config *config); -void nm_device_set_wwan_ip6_config (NMDevice *device, NMIP6Config *config); +void nm_device_set_wwan_ip_config (NMDevice *device, + int addr_family, + NMIPConfig *config); gboolean nm_device_hw_addr_is_explict (NMDevice *device); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index cda047faec..f5bce0410b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -12190,13 +12190,25 @@ nm_device_replace_vpn4_config (NMDevice *self, NMIP4Config *old, NMIP4Config *co } void -nm_device_set_wwan_ip4_config (NMDevice *self, NMIP4Config *config) +nm_device_set_wwan_ip_config (NMDevice *self, + int addr_family, + NMIPConfig *config) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + NMDevicePrivate *priv; + const gboolean IS_IPv4 = (addr_family == AF_INET); - 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"); + g_return_if_fail (NM_IS_DEVICE (self)); + g_return_if_fail (NM_IN_SET (addr_family, AF_INET, AF_INET6)); + g_return_if_fail ( !config + || nm_ip_config_get_addr_family (config) == addr_family); + + priv = NM_DEVICE_GET_PRIVATE (self); + + applied_config_init (&priv->wwan_ip_config_x[IS_IPv4], config); + if (!ip_config_merge_and_apply (self, addr_family, TRUE)) { + _LOGW (LOGD_IP, "failed to set WWAN IPv%c configuration", + nm_utils_addr_family_to_char (addr_family)); + } } void @@ -12217,16 +12229,6 @@ nm_device_replace_vpn6_config (NMDevice *self, NMIP6Config *old, NMIP6Config *co _LOGW (LOGD_IP6, "failed to set VPN routes for device"); } -void -nm_device_set_wwan_ip6_config (NMDevice *self, NMIP6Config *config) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - - 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"); -} - NMDhcp6Config * nm_device_get_dhcp6_config (NMDevice *self) { diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index 0fd2fab81d..36fb2e8b5c 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -23,6 +23,7 @@ #include "nm-device-modem.h" #include "nm-modem.h" +#include "nm-ip4-config.h" #include "devices/nm-device-private.h" #include "nm-rfkill-manager.h" #include "settings/nm-settings-connection.h" @@ -211,7 +212,7 @@ modem_ip4_config_result (NMModem *modem, AF_INET, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); } else { - nm_device_set_wwan_ip4_config (device, config); + nm_device_set_wwan_ip_config (device, AF_INET, NM_IP_CONFIG_CAST (config)); nm_device_activate_schedule_ip_config_result (device, AF_INET, NULL); } } @@ -245,7 +246,7 @@ modem_ip6_config_result (NMModem *modem, nm_device_sysctl_ip_conf_set (device, AF_INET6, "disable_ipv6", "0"); if (config) - nm_device_set_wwan_ip6_config (device, config); + nm_device_set_wwan_ip_config (device, AF_INET6, NM_IP_CONFIG_CAST (config)); if (do_slaac == FALSE) { if (got_config) From 03b708f7f72be8e6872d554e81c397b42489fdd5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 2 Mar 2019 18:41:31 +0100 Subject: [PATCH 11/16] device/trivial: rename wwan_ip_config to dev2_ip_config dev2_ip_config (formerly wwan_ip_config) is only set by nm_device_set_dev2_ip_config() (formerly nm_device_set_wwan_ip_config()), which is only called by NMDeviceModem. For NMDeviceWireGuard we will also inject additional configuration in the parent class. Rename and give it a wider purpose. The new name merely indicates that this IP configuration is injected by a subclass of NMDevice. --- src/devices/nm-device-private.h | 2 +- src/devices/nm-device.c | 47 +++++++++++++++--------------- src/devices/wwan/nm-device-modem.c | 4 +-- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index 9a9929692d..ce63c46790 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -146,7 +146,7 @@ void nm_device_queue_recheck_available (NMDevice *device, NMDeviceStateReason available_reason, NMDeviceStateReason unavailable_reason); -void nm_device_set_wwan_ip_config (NMDevice *device, +void nm_device_set_dev2_ip_config (NMDevice *device, int addr_family, NMIPConfig *config); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index f5bce0410b..ed55b246ef 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -438,13 +438,14 @@ typedef struct _NMDevicePrivate { GSList *vpn_configs_x[2]; }; - /* WWAN configuration */ + /* Extra device configuration, injected by the subclass of NMDevice. + * This is used for example by NMDeviceModem for WWAN configuration. */ union { struct { - AppliedConfig wwan_ip_config_6; - AppliedConfig wwan_ip_config_4; + AppliedConfig dev2_ip_config_6; + AppliedConfig dev2_ip_config_4; }; - AppliedConfig wwan_ip_config_x[2]; + AppliedConfig dev2_ip_config_x[2]; }; /* DHCPv4 tracking */ @@ -7205,7 +7206,7 @@ ip_config_merge_and_apply (NMDevice *self, /* 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_ip_config_x[IS_IPv4]); + config = applied_config_get_current (&priv->dev2_ip_config_x[IS_IPv4]); if (config) { nm_ip_config_merge (composite, config, (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) @@ -10499,7 +10500,7 @@ dad6_get_pending_addresses (NMDevice *self) NMIP6Config *confs[] = { (NMIP6Config *) applied_config_get_current (&priv->ac_ip6_config), (NMIP6Config *) applied_config_get_current (&priv->dhcp6.ip6_config), priv->con_ip_config_6, - (NMIP6Config *) applied_config_get_current (&priv->wwan_ip_config_6) }; + (NMIP6Config *) applied_config_get_current (&priv->dev2_ip_config_6) }; const NMPlatformIP6Address *addr; NMIP6Config *dad6_config = NULL; NMDedupMultiIter ipconf_iter; @@ -10881,7 +10882,7 @@ nm_device_reactivate_ip4_config (NMDevice *self, g_clear_object (&priv->con_ip_config_4); g_clear_object (&priv->ext_ip_config_4); g_clear_object (&priv->dev_ip_config_4.current); - g_clear_object (&priv->wwan_ip_config_4.current); + g_clear_object (&priv->dev2_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, @@ -10922,8 +10923,8 @@ nm_device_reactivate_ip4_config (NMDevice *self, nm_ip4_config_update_routes_metric ((NMIP4Config *) priv->dev_ip_config_4.orig, nm_device_get_route_metric (self, AF_INET)); } - if (priv->wwan_ip_config_4.orig) { - nm_ip4_config_update_routes_metric ((NMIP4Config *) priv->wwan_ip_config_4.orig, + if (priv->dev2_ip_config_4.orig) { + nm_ip4_config_update_routes_metric ((NMIP4Config *) priv->dev2_ip_config_4.orig, nm_device_get_route_metric (self, AF_INET)); } if (priv->dhcp4.client) { @@ -10954,7 +10955,7 @@ nm_device_reactivate_ip6_config (NMDevice *self, 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_ip_config_6.current); + g_clear_object (&priv->dev2_ip_config_6.current); if ( priv->ipv6ll_handle && !IN6_IS_ADDR_UNSPECIFIED (&priv->ipv6ll_addr)) priv->ipv6ll_has = TRUE; @@ -10995,8 +10996,8 @@ nm_device_reactivate_ip6_config (NMDevice *self, nm_ip6_config_update_routes_metric ((NMIP6Config *) priv->dhcp6.ip6_config.orig, nm_device_get_route_metric (self, AF_INET6)); } - if (priv->wwan_ip_config_6.orig) { - nm_ip6_config_update_routes_metric ((NMIP6Config *) priv->wwan_ip_config_6.orig, + if (priv->dev2_ip_config_6.orig) { + nm_ip6_config_update_routes_metric ((NMIP6Config *) priv->dev2_ip_config_6.orig, nm_device_get_route_metric (self, AF_INET6)); } if (priv->dhcp6.client) { @@ -12190,7 +12191,7 @@ nm_device_replace_vpn4_config (NMDevice *self, NMIP4Config *old, NMIP4Config *co } void -nm_device_set_wwan_ip_config (NMDevice *self, +nm_device_set_dev2_ip_config (NMDevice *self, int addr_family, NMIPConfig *config) { @@ -12204,9 +12205,9 @@ nm_device_set_wwan_ip_config (NMDevice *self, priv = NM_DEVICE_GET_PRIVATE (self); - applied_config_init (&priv->wwan_ip_config_x[IS_IPv4], config); + applied_config_init (&priv->dev2_ip_config_x[IS_IPv4], config); if (!ip_config_merge_and_apply (self, addr_family, TRUE)) { - _LOGW (LOGD_IP, "failed to set WWAN IPv%c configuration", + _LOGW (LOGD_IP, "failed to set extra device IPv%c configuration", nm_utils_addr_family_to_char (addr_family)); } } @@ -12757,7 +12758,7 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_config } intersect_ext_config (self, &priv->dev_ip_config_4, is_up); - intersect_ext_config (self, &priv->wwan_ip_config_4, is_up); + intersect_ext_config (self, &priv->dev2_ip_config_4, is_up); for (iter = priv->vpn_configs_4; iter; iter = iter->next) nm_ip4_config_intersect (iter->data, priv->ext_ip_config_4, is_up, 0); @@ -12775,9 +12776,9 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_config applied_config_get_current (&priv->dev_ip_config_4), default_route_metric_penalty_get (self, AF_INET)); } - if (applied_config_get_current (&priv->wwan_ip_config_4)) { + if (applied_config_get_current (&priv->dev2_ip_config_4)) { nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip_config_4, - applied_config_get_current (&priv->wwan_ip_config_4), + applied_config_get_current (&priv->dev2_ip_config_4), default_route_metric_penalty_get (self, AF_INET)); } for (iter = priv->vpn_configs_4; iter; iter = iter->next) @@ -12810,7 +12811,7 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_config intersect_ext_config (self, &priv->ac_ip6_config, is_up); intersect_ext_config (self, &priv->dhcp6.ip6_config, is_up); - intersect_ext_config (self, &priv->wwan_ip_config_6, is_up); + intersect_ext_config (self, &priv->dev2_ip_config_6, is_up); for (iter = priv->vpn_configs_6; iter; iter = iter->next) nm_ip6_config_intersect (iter->data, priv->ext_ip_config_6, is_up, 0); @@ -12837,9 +12838,9 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_config applied_config_get_current (&priv->dhcp6.ip6_config), default_route_metric_penalty_get (self, AF_INET6)); } - if (applied_config_get_current (&priv->wwan_ip_config_6)) { + if (applied_config_get_current (&priv->dev2_ip_config_6)) { nm_ip_config_subtract ((NMIPConfig *) priv->ext_ip_config_6, - applied_config_get_current (&priv->wwan_ip_config_6), + applied_config_get_current (&priv->dev2_ip_config_6), default_route_metric_penalty_get (self, AF_INET6)); } for (iter = priv->vpn_configs_6; iter; iter = iter->next) @@ -14256,14 +14257,14 @@ _cleanup_generic_post (NMDevice *self, CleanupType cleanup_type) g_clear_object (&priv->proxy_config); g_clear_object (&priv->con_ip_config_4); applied_config_clear (&priv->dev_ip_config_4); - applied_config_clear (&priv->wwan_ip_config_4); + applied_config_clear (&priv->dev2_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_ip_config_6); g_clear_object (&priv->ext_ip6_config_captured); - applied_config_clear (&priv->wwan_ip_config_6); + applied_config_clear (&priv->dev2_ip_config_6); g_clear_object (&priv->ip_config_6); g_clear_object (&priv->dad6_ip6_config); priv->ipv6ll_has = FALSE; diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index 36fb2e8b5c..7d25cba5ae 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -212,7 +212,7 @@ modem_ip4_config_result (NMModem *modem, AF_INET, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); } else { - nm_device_set_wwan_ip_config (device, AF_INET, NM_IP_CONFIG_CAST (config)); + nm_device_set_dev2_ip_config (device, AF_INET, NM_IP_CONFIG_CAST (config)); nm_device_activate_schedule_ip_config_result (device, AF_INET, NULL); } } @@ -246,7 +246,7 @@ modem_ip6_config_result (NMModem *modem, nm_device_sysctl_ip_conf_set (device, AF_INET6, "disable_ipv6", "0"); if (config) - nm_device_set_wwan_ip_config (device, AF_INET6, NM_IP_CONFIG_CAST (config)); + nm_device_set_dev2_ip_config (device, AF_INET6, NM_IP_CONFIG_CAST (config)); if (do_slaac == FALSE) { if (got_config) From 5e71f016057a72e3c0374bdbf2b855b4f58e0a8f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 2 Mar 2019 19:05:39 +0100 Subject: [PATCH 12/16] device: merge stage3 and stage4 ip-config function for IPv4 and IPv6 --- src/devices/adsl/nm-device-adsl.c | 14 +- src/devices/bluetooth/nm-device-bt.c | 41 +-- src/devices/nm-device-ethernet.c | 23 +- src/devices/nm-device-ppp.c | 36 +- src/devices/nm-device.c | 428 ++++++++++------------ src/devices/nm-device.h | 17 +- src/devices/ovs/nm-device-ovs-bridge.c | 18 +- src/devices/ovs/nm-device-ovs-interface.c | 32 +- src/devices/ovs/nm-device-ovs-port.c | 18 +- src/devices/wifi/nm-device-wifi-p2p.c | 55 +-- src/devices/wifi/nm-device-wifi.c | 163 +++----- src/devices/wwan/nm-device-modem.c | 48 +-- src/devices/wwan/nm-modem.c | 2 +- 13 files changed, 378 insertions(+), 517 deletions(-) diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index be81c26bcd..b3b87dc7e9 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -518,6 +518,18 @@ act_stage3_ip4_config_start (NMDevice *device, return NM_ACT_STAGE_RETURN_POSTPONE; } +static NMActStageReturn +act_stage3_ip_config_start (NMDevice *device, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason) +{ + if (addr_family == AF_INET) + return act_stage3_ip4_config_start (device, (NMIP4Config **) out_config, out_failure_reason); + + return NM_DEVICE_CLASS (nm_device_adsl_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); +} + static void adsl_cleanup (NMDeviceAdsl *self) { @@ -687,7 +699,7 @@ nm_device_adsl_class_init (NMDeviceAdslClass *klass) device_class->complete_connection = complete_connection; device_class->act_stage2_config = act_stage2_config; - device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; + device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; device_class->deactivate = deactivate; obj_properties[PROP_ATM_INDEX] = diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index 0037766ef2..e79251ced3 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -899,33 +899,29 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) } static NMActStageReturn -act_stage3_ip4_config_start (NMDevice *device, - NMIP4Config **out_config, - NMDeviceStateReason *out_failure_reason) +act_stage3_ip_config_start (NMDevice *device, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE ((NMDeviceBt *) device); + nm_assert_addr_family (addr_family); + if (priv->bt_type == NM_BT_CAPABILITY_DUN) { - return nm_modem_stage3_ip4_config_start (priv->modem, - device, - NM_DEVICE_CLASS (nm_device_bt_parent_class), - out_failure_reason); + if (addr_family == AF_INET) { + return nm_modem_stage3_ip4_config_start (priv->modem, + device, + NM_DEVICE_CLASS (nm_device_bt_parent_class), + out_failure_reason); + } else { + return nm_modem_stage3_ip6_config_start (priv->modem, + device, + out_failure_reason); + } } - return NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip4_config_start (device, out_config, out_failure_reason); -} - -static NMActStageReturn -act_stage3_ip6_config_start (NMDevice *device, - NMIP6Config **out_config, - NMDeviceStateReason *out_failure_reason) -{ - NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE ((NMDeviceBt *) device); - - if (priv->bt_type == NM_BT_CAPABILITY_DUN) - return nm_modem_stage3_ip6_config_start (priv->modem, device, out_failure_reason); - - return NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip6_config_start (device, out_config, out_failure_reason); + return NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); } static void @@ -1204,8 +1200,7 @@ nm_device_bt_class_init (NMDeviceBtClass *klass) device_class->can_auto_connect = can_auto_connect; device_class->deactivate = deactivate; device_class->act_stage2_config = act_stage2_config; - device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; - device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start; + device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; device_class->check_connection_compatible = check_connection_compatible; device_class->check_connection_available = check_connection_available; device_class->complete_connection = complete_connection; diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index a3aa0f4c19..24c99f76f4 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -1314,22 +1314,25 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) } static NMActStageReturn -act_stage3_ip4_config_start (NMDevice *device, - NMIP4Config **out_config, - NMDeviceStateReason *out_failure_reason) +act_stage3_ip_config_start (NMDevice *device, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason) { NMSettingConnection *s_con; const char *connection_type; - s_con = nm_device_get_applied_setting (device, NM_TYPE_SETTING_CONNECTION); + if (addr_family == AF_INET) { + s_con = nm_device_get_applied_setting (device, NM_TYPE_SETTING_CONNECTION); - g_return_val_if_fail (s_con, NM_ACT_STAGE_RETURN_FAILURE); + g_return_val_if_fail (s_con, NM_ACT_STAGE_RETURN_FAILURE); - connection_type = nm_setting_connection_get_connection_type (s_con); - if (!strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME)) - return pppoe_stage3_ip4_config_start (NM_DEVICE_ETHERNET (device), out_failure_reason); + connection_type = nm_setting_connection_get_connection_type (s_con); + if (!strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME)) + return pppoe_stage3_ip4_config_start (NM_DEVICE_ETHERNET (device), out_failure_reason); + } - return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->act_stage3_ip4_config_start (device, out_config, out_failure_reason); + return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); } static guint32 @@ -1791,7 +1794,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass) device_class->act_stage1_prepare = act_stage1_prepare; device_class->act_stage2_config = act_stage2_config; - device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; + device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; device_class->get_configured_mtu = get_configured_mtu; device_class->deactivate = deactivate; device_class->get_s390_subchannels = get_s390_subchannels; diff --git a/src/devices/nm-device-ppp.c b/src/devices/nm-device-ppp.c index 4dd921cac9..3c310146bf 100644 --- a/src/devices/nm-device-ppp.c +++ b/src/devices/nm-device-ppp.c @@ -173,23 +173,31 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) } static NMActStageReturn -act_stage3_ip4_config_start (NMDevice *device, - NMIP4Config **out_config, - NMDeviceStateReason *out_failure_reason) +act_stage3_ip_config_start (NMDevice *device, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason) { - NMDevicePpp *self = NM_DEVICE_PPP (device); - NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self); + if (addr_family == AF_INET) { + NMDevicePpp *self = NM_DEVICE_PPP (device); + NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self); - if (priv->ip4_config) { - if (out_config) - *out_config = g_steal_pointer (&priv->ip4_config); - else - g_clear_object (&priv->ip4_config); - return NM_ACT_STAGE_RETURN_SUCCESS; + if (priv->ip4_config) { + if (out_config) + *out_config = g_steal_pointer (&priv->ip4_config); + else + g_clear_object (&priv->ip4_config); + return NM_ACT_STAGE_RETURN_SUCCESS; + } + + /* Wait IPCP termination */ + return NM_ACT_STAGE_RETURN_POSTPONE; } - /* Wait IPCP termination */ - return NM_ACT_STAGE_RETURN_POSTPONE; + return NM_DEVICE_CLASS (nm_device_ppp_parent_class)->act_stage3_ip_config_start (device, + addr_family, + out_config, + out_failure_reason); } static gboolean @@ -271,7 +279,7 @@ nm_device_ppp_class_init (NMDevicePppClass *klass) device_class->link_types = NM_DEVICE_DEFINE_LINK_TYPES (NM_LINK_TYPE_PPP); device_class->act_stage2_config = act_stage2_config; - device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; + device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; device_class->create_and_realize = create_and_realize; device_class->deactivate = deactivate; device_class->get_generic_capabilities = get_generic_capabilities; diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index ed55b246ef..b0c5f1f4cc 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -7785,25 +7785,21 @@ shared4_new_config (NMDevice *self, NMConnection *connection) /*****************************************************************************/ static gboolean -connection_ip4_method_requires_carrier (NMConnection *connection, - gboolean *out_ip4_enabled) +connection_ip_method_requires_carrier (NMConnection *connection, + int addr_family, + gboolean *out_ip_enabled) { const char *method; - method = nm_utils_get_ip_config_method (connection, AF_INET); - NM_SET_OUT (out_ip4_enabled, !nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)); - return NM_IN_STRSET (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL); -} + method = nm_utils_get_ip_config_method (connection, addr_family); -static gboolean -connection_ip6_method_requires_carrier (NMConnection *connection, - gboolean *out_ip6_enabled) -{ - const char *method; + if (addr_family == AF_INET) { + NM_SET_OUT (out_ip_enabled, !nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)); + return NM_IN_STRSET (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL); + } - method = nm_utils_get_ip_config_method (connection, AF_INET6); - NM_SET_OUT (out_ip6_enabled, !nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)); + NM_SET_OUT (out_ip_enabled, !nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)); return NM_IN_STRSET (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NM_SETTING_IP6_CONFIG_METHOD_DHCP, NM_SETTING_IP6_CONFIG_METHOD_SHARED, @@ -7824,7 +7820,7 @@ connection_requires_carrier (NMConnection *connection) if (nm_setting_connection_get_master (s_con)) return FALSE; - ip4_carrier_wanted = connection_ip4_method_requires_carrier (connection, &ip4_used); + ip4_carrier_wanted = connection_ip_method_requires_carrier (connection, AF_INET, &ip4_used); if (ip4_carrier_wanted) { /* If IPv4 wants a carrier and cannot fail, the whole connection * requires a carrier regardless of the IPv6 method. @@ -7834,7 +7830,7 @@ connection_requires_carrier (NMConnection *connection) return TRUE; } - ip6_carrier_wanted = connection_ip6_method_requires_carrier (connection, &ip6_used); + ip6_carrier_wanted = connection_ip_method_requires_carrier (connection, AF_INET6, &ip6_used); if (ip6_carrier_wanted) { /* If IPv6 wants a carrier and cannot fail, the whole connection * requires a carrier regardless of the IPv4 method. @@ -7875,108 +7871,6 @@ have_any_ready_slaves (NMDevice *self) return FALSE; } -static gboolean -ip4_requires_slaves (NMDevice *self) -{ - const char *method; - - method = nm_device_get_effective_ip_config_method (self, AF_INET); - return nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO); -} - -static NMActStageReturn -act_stage3_ip4_config_start (NMDevice *self, - NMIP4Config **out_config, - NMDeviceStateReason *out_failure_reason) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMConnection *connection; - NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; - const char *method; - - connection = nm_device_get_applied_connection (self); - g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE); - - if ( connection_ip4_method_requires_carrier (connection, NULL) - && nm_device_is_master (self) - && !priv->carrier) { - _LOGI (LOGD_IP4 | LOGD_DEVICE, - "IPv4 config waiting until carrier is on"); - return NM_ACT_STAGE_RETURN_IP_WAIT; - } - - if (nm_device_is_master (self) && ip4_requires_slaves (self)) { - /* If the master has no ready slaves, and depends on slaves for - * a successful IPv4 attempt, then postpone IPv4 addressing. - */ - if (!have_any_ready_slaves (self)) { - _LOGI (LOGD_DEVICE | LOGD_IP4, - "IPv4 config waiting until slaves are ready"); - return NM_ACT_STAGE_RETURN_IP_WAIT; - } - } - - method = nm_device_get_effective_ip_config_method (self, AF_INET); - _LOGD (LOGD_IP4 | LOGD_DEVICE, "IPv4 config method is %s", method); - - if (NM_IN_STRSET (method, - NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) { - NMSettingIPConfig *s_ip4; - NMIP4Config **configs, *config; - guint num_addresses; - - s_ip4 = nm_connection_get_setting_ip4_config (connection); - g_return_val_if_fail (s_ip4, NM_ACT_STAGE_RETURN_FAILURE); - num_addresses = nm_setting_ip_config_get_num_addresses (s_ip4); - - if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { - ret = dhcp4_start (self); - if (ret == NM_ACT_STAGE_RETURN_FAILURE) { - NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_DHCP_START_FAILED); - return ret; - } - } else { - g_return_val_if_fail (num_addresses != 0, NM_ACT_STAGE_RETURN_FAILURE); - ret = NM_ACT_STAGE_RETURN_POSTPONE; - } - - if (num_addresses) { - config = _ip4_config_new (self); - nm_ip4_config_merge_setting (config, - nm_connection_get_setting_ip4_config (connection), - NM_SETTING_CONNECTION_MDNS_DEFAULT, - NM_SETTING_CONNECTION_LLMNR_DEFAULT, - nm_device_get_route_table (self, AF_INET, TRUE), - nm_device_get_route_metric (self, AF_INET)); - configs = g_new0 (NMIP4Config *, 2); - configs[0] = config; - ipv4_dad_start (self, configs, ipv4_manual_method_apply); - } - } else if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) { - ret = ipv4ll_start (self); - if (ret == NM_ACT_STAGE_RETURN_FAILURE) - NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED); - } else if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) { - if (out_config) { - *out_config = shared4_new_config (self, connection); - if (*out_config) { - priv->dnsmasq_manager = nm_dnsmasq_manager_new (nm_device_get_ip_iface (self)); - ret = NM_ACT_STAGE_RETURN_SUCCESS; - } else { - NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - ret = NM_ACT_STAGE_RETURN_FAILURE; - } - } else - g_return_val_if_reached (NM_ACT_STAGE_RETURN_FAILURE); - } else if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) - ret = NM_ACT_STAGE_RETURN_SUCCESS; - else - _LOGW (LOGD_IP4, "unhandled IPv4 config method '%s'; will fail", method); - - return ret; -} - /*****************************************************************************/ /* DHCPv6 stuff */ @@ -9682,11 +9576,14 @@ _ip6_privacy_get (NMDevice *self) /*****************************************************************************/ static gboolean -ip6_requires_slaves (NMDevice *self) +ip_requires_slaves (NMDevice *self, int addr_family) { const char *method; - method = nm_device_get_effective_ip_config_method (self, AF_INET6); + method = nm_device_get_effective_ip_config_method (self, addr_family); + + if (addr_family == AF_INET) + return nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO); /* SLAAC, DHCP, and Link-Local depend on connectivity (and thus slaves) * to complete addressing. SLAAC and DHCP need a peer to provide a prefix. @@ -9696,128 +9593,202 @@ ip6_requires_slaves (NMDevice *self) } static NMActStageReturn -act_stage3_ip6_config_start (NMDevice *self, - NMIP6Config **out_config, - NMDeviceStateReason *out_failure_reason) +act_stage3_ip_config_start (NMDevice *self, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason) { + const gboolean IS_IPv4 = (addr_family == AF_INET); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMConnection *connection; + NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; const char *method; - NMSettingIP6ConfigPrivacy ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; - const char *ip6_privacy_str = "0"; + + nm_assert_addr_family (addr_family); connection = nm_device_get_applied_connection (self); + g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE); - if ( connection_ip6_method_requires_carrier (connection, NULL) + if ( connection_ip_method_requires_carrier (connection, addr_family, NULL) && nm_device_is_master (self) && !priv->carrier) { - _LOGI (LOGD_IP6 | LOGD_DEVICE, - "IPv6 config waiting until carrier is on"); + _LOGI (LOGD_IP | LOGD_DEVICE, + "IPv%c config waiting until carrier is on", + nm_utils_addr_family_to_char (addr_family)); return NM_ACT_STAGE_RETURN_IP_WAIT; } - if (nm_device_is_master (self) && ip6_requires_slaves (self)) { + if ( nm_device_is_master (self) + && ip_requires_slaves (self, addr_family)) { /* If the master has no ready slaves, and depends on slaves for - * a successful IPv6 attempt, then postpone IPv6 addressing. + * a successful IP configuration attempt, then postpone IP addressing. */ if (!have_any_ready_slaves (self)) { - _LOGI (LOGD_DEVICE | LOGD_IP6, - "IPv6 config waiting until slaves are ready"); + _LOGI (LOGD_DEVICE | LOGD_IP, + "IPv%c config waiting until slaves are ready", + nm_utils_addr_family_to_char (addr_family)); return NM_ACT_STAGE_RETURN_IP_WAIT; } } - priv->dhcp6.mode = NM_NDISC_DHCP_LEVEL_NONE; - method = nm_device_get_effective_ip_config_method (self, AF_INET6); - if (nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { - if ( !priv->master - && !nm_device_sys_iface_state_is_external (self)) { - gboolean ipv6ll_handle_old = priv->ipv6ll_handle; + if (!IS_IPv4) + priv->dhcp6.mode = NM_NDISC_DHCP_LEVEL_NONE; - /* 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 (ipv6ll_handle_old) - nm_device_sysctl_ip_conf_set (self, AF_INET6, "disable_ipv6", "1"); - restore_ip6_properties (self); + method = nm_device_get_effective_ip_config_method (self, addr_family); + + _LOGD (LOGD_IP | LOGD_DEVICE, "IPv%c config method is %s", + nm_utils_addr_family_to_char (addr_family), method); + + if (IS_IPv4) { + if (NM_IN_STRSET (method, + NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) { + NMSettingIPConfig *s_ip4; + NMIP4Config **configs, *config; + guint num_addresses; + + s_ip4 = nm_connection_get_setting_ip4_config (connection); + g_return_val_if_fail (s_ip4, NM_ACT_STAGE_RETURN_FAILURE); + num_addresses = nm_setting_ip_config_get_num_addresses (s_ip4); + + if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { + ret = dhcp4_start (self); + if (ret == NM_ACT_STAGE_RETURN_FAILURE) { + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_DHCP_START_FAILED); + return ret; + } + } else { + g_return_val_if_fail (num_addresses != 0, NM_ACT_STAGE_RETURN_FAILURE); + ret = NM_ACT_STAGE_RETURN_POSTPONE; + } + + if (num_addresses) { + config = _ip4_config_new (self); + nm_ip4_config_merge_setting (config, + nm_connection_get_setting_ip4_config (connection), + NM_SETTING_CONNECTION_MDNS_DEFAULT, + NM_SETTING_CONNECTION_LLMNR_DEFAULT, + nm_device_get_route_table (self, AF_INET, TRUE), + nm_device_get_route_metric (self, AF_INET)); + configs = g_new0 (NMIP4Config *, 2); + configs[0] = config; + ipv4_dad_start (self, configs, ipv4_manual_method_apply); + } + } else if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) { + ret = ipv4ll_start (self); + if (ret == NM_ACT_STAGE_RETURN_FAILURE) + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED); + } else if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) { + if (out_config) { + *out_config = shared4_new_config (self, connection); + if (*out_config) { + priv->dnsmasq_manager = nm_dnsmasq_manager_new (nm_device_get_ip_iface (self)); + ret = NM_ACT_STAGE_RETURN_SUCCESS; + } else { + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); + ret = NM_ACT_STAGE_RETURN_FAILURE; + } + } else + g_return_val_if_reached (NM_ACT_STAGE_RETURN_FAILURE); + } else if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) + ret = NM_ACT_STAGE_RETURN_SUCCESS; + else + _LOGW (LOGD_IP4, "unhandled IPv4 config method '%s'; will fail", method); + + return ret; + } else { + NMSettingIP6ConfigPrivacy ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; + const char *ip6_privacy_str = "0"; + + if (nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { + if ( !priv->master + && !nm_device_sys_iface_state_is_external (self)) { + 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 (ipv6ll_handle_old) + nm_device_sysctl_ip_conf_set (self, AF_INET6, "disable_ipv6", "1"); + restore_ip6_properties (self); + } + return NM_ACT_STAGE_RETURN_IP_DONE; } - return NM_ACT_STAGE_RETURN_IP_DONE; - } - /* Ensure the MTU makes sense. If it was below 1280 the kernel would not - * 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->ip_config_4); + /* Ensure the MTU makes sense. If it was below 1280 the kernel would not + * 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->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 - * will already have IPv6 set up. - */ - if (!nm_device_sys_iface_state_is_external_or_assume (self)) - set_nm_ipv6ll (self, TRUE); + /* Any method past this point requires an IPv6LL address. Use NM-controlled + * IPv6LL if this is not an assumed connection, since assumed connections + * will already have IPv6 set up. + */ + if (!nm_device_sys_iface_state_is_external_or_assume (self)) + set_nm_ipv6ll (self, TRUE); - /* Re-enable IPv6 on the interface */ - set_disable_ipv6 (self, "0"); + /* Re-enable IPv6 on the interface */ + set_disable_ipv6 (self, "0"); - /* Synchronize external IPv6 configuration with kernel, since - * linklocal6_start() uses the information there to determine if we can - * proceed with the selected method (SLAAC, DHCP, link-local). - */ - nm_platform_process_events (nm_device_get_platform (self)); - 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), - nm_device_get_ip_ifindex (self), - NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); + /* Synchronize external IPv6 configuration with kernel, since + * linklocal6_start() uses the information there to determine if we can + * proceed with the selected method (SLAAC, DHCP, link-local). + */ + nm_platform_process_events (nm_device_get_platform (self)); + 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), + nm_device_get_ip_ifindex (self), + NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); - ip6_privacy = _ip6_privacy_get (self); + ip6_privacy = _ip6_privacy_get (self); - if (NM_IN_STRSET (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NM_SETTING_IP6_CONFIG_METHOD_SHARED)) { - if (!addrconf6_start (self, ip6_privacy)) { - /* IPv6 might be disabled; allow IPv4 to proceed */ - ret = NM_ACT_STAGE_RETURN_IP_FAIL; - } else - ret = NM_ACT_STAGE_RETURN_POSTPONE; - } else if (nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) { - ret = linklocal6_start (self) - ? NM_ACT_STAGE_RETURN_SUCCESS - : NM_ACT_STAGE_RETURN_POSTPONE; - } else if (nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { - priv->dhcp6.mode = NM_NDISC_DHCP_LEVEL_MANAGED; - if (!dhcp6_start (self, TRUE)) { - /* IPv6 might be disabled; allow IPv4 to proceed */ - ret = NM_ACT_STAGE_RETURN_IP_FAIL; - } else - ret = NM_ACT_STAGE_RETURN_POSTPONE; - } else if (nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) - ret = NM_ACT_STAGE_RETURN_SUCCESS; - else - _LOGW (LOGD_IP6, "unhandled IPv6 config method '%s'; will fail", method); + if (NM_IN_STRSET (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NM_SETTING_IP6_CONFIG_METHOD_SHARED)) { + if (!addrconf6_start (self, ip6_privacy)) { + /* IPv6 might be disabled; allow IPv4 to proceed */ + ret = NM_ACT_STAGE_RETURN_IP_FAIL; + } else + ret = NM_ACT_STAGE_RETURN_POSTPONE; + } else if (nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) { + ret = linklocal6_start (self) + ? NM_ACT_STAGE_RETURN_SUCCESS + : NM_ACT_STAGE_RETURN_POSTPONE; + } else if (nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { + priv->dhcp6.mode = NM_NDISC_DHCP_LEVEL_MANAGED; + if (!dhcp6_start (self, TRUE)) { + /* IPv6 might be disabled; allow IPv4 to proceed */ + ret = NM_ACT_STAGE_RETURN_IP_FAIL; + } else + ret = NM_ACT_STAGE_RETURN_POSTPONE; + } else if (nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) + ret = NM_ACT_STAGE_RETURN_SUCCESS; + else + _LOGW (LOGD_IP6, "unhandled IPv6 config method '%s'; will fail", method); - if ( ret != NM_ACT_STAGE_RETURN_FAILURE - && !nm_device_sys_iface_state_is_external_or_assume (self)) { - switch (ip6_privacy) { - case NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN: - case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED: - ip6_privacy_str = "0"; - break; - case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR: - ip6_privacy_str = "1"; - break; - case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR: - ip6_privacy_str = "2"; - break; + if ( ret != NM_ACT_STAGE_RETURN_FAILURE + && !nm_device_sys_iface_state_is_external_or_assume (self)) { + switch (ip6_privacy) { + case NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN: + case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED: + ip6_privacy_str = "0"; + break; + case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR: + ip6_privacy_str = "1"; + break; + case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR: + ip6_privacy_str = "2"; + break; + } + nm_device_sysctl_ip_conf_set (self, AF_INET6, "use_tempaddr", ip6_privacy_str); } - nm_device_sysctl_ip_conf_set (self, AF_INET6, "use_tempaddr", ip6_privacy_str); - } - return ret; + return ret; + } } /** @@ -9843,7 +9814,7 @@ nm_device_activate_stage3_ip4_start (NMDevice *self) } _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_CONF); - ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip4_config_start (self, &ip4_config, &failure_reason); + ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip_config_start (self, AF_INET, (gpointer *) &ip4_config, &failure_reason); if (ret == NM_ACT_STAGE_RETURN_SUCCESS) nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (ip4_config)); else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) { @@ -9887,7 +9858,7 @@ nm_device_activate_stage3_ip6_start (NMDevice *self) } _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_CONF); - ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip6_config_start (self, &ip6_config, &failure_reason); + ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip_config_start (self, AF_INET6, (gpointer *) &ip6_config, &failure_reason); if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { if (!ip6_config) ip6_config = _ip6_config_new (self); @@ -10059,15 +10030,21 @@ nm_device_activate_schedule_stage3_ip_config_start (NMDevice *self) } static NMActStageReturn -act_stage4_ip4_config_timeout (NMDevice *self, NMDeviceStateReason *out_failure_reason) +act_stage4_ip_config_timeout (NMDevice *self, + int addr_family, + NMDeviceStateReason *out_failure_reason) { - if (!get_ip_config_may_fail (self, AF_INET)) { + nm_assert_addr_family (addr_family); + + if (!get_ip_config_may_fail (self, addr_family)) { NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); return NM_ACT_STAGE_RETURN_FAILURE; } + return NM_ACT_STAGE_RETURN_SUCCESS; } + /* * nm_device_activate_stage4_ip4_config_timeout * @@ -10080,7 +10057,7 @@ activate_stage4_ip_config_timeout_4 (NMDevice *self) NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; - ret = NM_DEVICE_GET_CLASS (self)->act_stage4_ip4_config_timeout (self, &failure_reason); + ret = NM_DEVICE_GET_CLASS (self)->act_stage4_ip_config_timeout (self, AF_INET6, &failure_reason); if (ret == NM_ACT_STAGE_RETURN_POSTPONE) return; else if (ret == NM_ACT_STAGE_RETURN_FAILURE) { @@ -10111,24 +10088,13 @@ nm_device_activate_schedule_ip_config_timeout (NMDevice *self, activation_source_schedule (self, activate_stage4_ip_config_timeout_x[IS_IPv4], addr_family); } -static NMActStageReturn -act_stage4_ip6_config_timeout (NMDevice *self, NMDeviceStateReason *out_failure_reason) -{ - if (!get_ip_config_may_fail (self, AF_INET6)) { - NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - return NM_ACT_STAGE_RETURN_FAILURE; - } - - return NM_ACT_STAGE_RETURN_SUCCESS; -} - static void activate_stage4_ip_config_timeout_6 (NMDevice *self) { NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; - ret = NM_DEVICE_GET_CLASS (self)->act_stage4_ip6_config_timeout (self, &failure_reason); + ret = NM_DEVICE_GET_CLASS (self)->act_stage4_ip_config_timeout (self, AF_INET6, &failure_reason); if (ret == NM_ACT_STAGE_RETURN_POSTPONE) return; if (ret == NM_ACT_STAGE_RETURN_FAILURE) { @@ -16710,10 +16676,8 @@ nm_device_class_init (NMDeviceClass *klass) klass->is_available = is_available; klass->act_stage1_prepare = act_stage1_prepare; klass->act_stage2_config = act_stage2_config; - klass->act_stage3_ip4_config_start = act_stage3_ip4_config_start; - klass->act_stage3_ip6_config_start = act_stage3_ip6_config_start; - klass->act_stage4_ip4_config_timeout = act_stage4_ip4_config_timeout; - klass->act_stage4_ip6_config_timeout = act_stage4_ip6_config_timeout; + klass->act_stage3_ip_config_start = act_stage3_ip_config_start; + klass->act_stage4_ip_config_timeout = act_stage4_ip_config_timeout; klass->get_type_description = get_type_description; klass->can_auto_connect = can_auto_connect; diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 303b92325b..45c9dda00c 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -369,16 +369,13 @@ typedef struct _NMDeviceClass { NMDeviceStateReason *out_failure_reason); NMActStageReturn (* act_stage2_config) (NMDevice *self, NMDeviceStateReason *out_failure_reason); - NMActStageReturn (* act_stage3_ip4_config_start) (NMDevice *self, - NMIP4Config **out_config, - NMDeviceStateReason *out_failure_reason); - NMActStageReturn (* act_stage3_ip6_config_start) (NMDevice *self, - NMIP6Config **out_config, - NMDeviceStateReason *out_failure_reason); - NMActStageReturn (* act_stage4_ip4_config_timeout) (NMDevice *self, - NMDeviceStateReason *out_failure_reason); - NMActStageReturn (* act_stage4_ip6_config_timeout) (NMDevice *self, - NMDeviceStateReason *out_failure_reason); + NMActStageReturn (* act_stage3_ip_config_start) (NMDevice *self, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason); + NMActStageReturn (* act_stage4_ip_config_timeout) (NMDevice *self, + int addr_family, + NMDeviceStateReason *out_failure_reason); void (* ip4_config_pre_commit) (NMDevice *self, NMIP4Config *config); diff --git a/src/devices/ovs/nm-device-ovs-bridge.c b/src/devices/ovs/nm-device-ovs-bridge.c index eff355a3ef..be707e7a8f 100644 --- a/src/devices/ovs/nm-device-ovs-bridge.c +++ b/src/devices/ovs/nm-device-ovs-bridge.c @@ -77,17 +77,10 @@ get_generic_capabilities (NMDevice *device) } static NMActStageReturn -act_stage3_ip4_config_start (NMDevice *device, - NMIP4Config **out_config, - NMDeviceStateReason *out_failure_reason) -{ - return NM_ACT_STAGE_RETURN_IP_FAIL; -} - -static NMActStageReturn -act_stage3_ip6_config_start (NMDevice *device, - NMIP6Config **out_config, - NMDeviceStateReason *out_failure_reason) +act_stage3_ip_config_start (NMDevice *device, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason) { return NM_ACT_STAGE_RETURN_IP_FAIL; } @@ -146,8 +139,7 @@ nm_device_ovs_bridge_class_init (NMDeviceOvsBridgeClass *klass) device_class->create_and_realize = create_and_realize; device_class->unrealize = unrealize; device_class->get_generic_capabilities = get_generic_capabilities; - device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; - device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start; + device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; device_class->enslave_slave = enslave_slave; device_class->release_slave = release_slave; } diff --git a/src/devices/ovs/nm-device-ovs-interface.c b/src/devices/ovs/nm-device-ovs-interface.c index 960b8f3582..e3d3f9ee5f 100644 --- a/src/devices/ovs/nm-device-ovs-interface.c +++ b/src/devices/ovs/nm-device-ovs-interface.c @@ -131,39 +131,22 @@ _is_internal_interface (NMDevice *device) } static NMActStageReturn -act_stage3_ip4_config_start (NMDevice *device, - NMIP4Config **out_config, - NMDeviceStateReason *out_failure_reason) +act_stage3_ip_config_start (NMDevice *device, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason) { NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE (device); if (!_is_internal_interface (device)) return NM_ACT_STAGE_RETURN_IP_FAIL; - if (!nm_device_get_ip_ifindex (device)) { + if (nm_device_get_ip_ifindex (device) <= 0) { priv->waiting_for_interface = TRUE; return NM_ACT_STAGE_RETURN_POSTPONE; } - return NM_DEVICE_CLASS (nm_device_ovs_interface_parent_class)->act_stage3_ip4_config_start (device, out_config, out_failure_reason); -} - -static NMActStageReturn -act_stage3_ip6_config_start (NMDevice *device, - NMIP6Config **out_config, - NMDeviceStateReason *out_failure_reason) -{ - NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE (device); - - if (!_is_internal_interface (device)) - return NM_ACT_STAGE_RETURN_IP_FAIL; - - if (!nm_device_get_ip_ifindex (device)) { - priv->waiting_for_interface = TRUE; - return NM_ACT_STAGE_RETURN_POSTPONE; - } - - return NM_DEVICE_CLASS (nm_device_ovs_interface_parent_class)->act_stage3_ip6_config_start (device, out_config, out_failure_reason); + return NM_DEVICE_CLASS (nm_device_ovs_interface_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); } static gboolean @@ -207,7 +190,6 @@ nm_device_ovs_interface_class_init (NMDeviceOvsInterfaceClass *klass) device_class->is_available = is_available; device_class->check_connection_compatible = check_connection_compatible; device_class->link_changed = link_changed; - device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; - device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start; + device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; device_class->can_unmanaged_external_down = can_unmanaged_external_down; } diff --git a/src/devices/ovs/nm-device-ovs-port.c b/src/devices/ovs/nm-device-ovs-port.c index 1f9afbab5b..b96eba686a 100644 --- a/src/devices/ovs/nm-device-ovs-port.c +++ b/src/devices/ovs/nm-device-ovs-port.c @@ -71,17 +71,10 @@ get_generic_capabilities (NMDevice *device) } static NMActStageReturn -act_stage3_ip4_config_start (NMDevice *device, - NMIP4Config **out_config, - NMDeviceStateReason *out_failure_reason) -{ - return NM_ACT_STAGE_RETURN_IP_FAIL; -} - -static NMActStageReturn -act_stage3_ip6_config_start (NMDevice *device, - NMIP6Config **out_config, - NMDeviceStateReason *out_failure_reason) +act_stage3_ip_config_start (NMDevice *device, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason) { return NM_ACT_STAGE_RETURN_IP_FAIL; } @@ -186,8 +179,7 @@ nm_device_ovs_port_class_init (NMDeviceOvsPortClass *klass) device_class->get_type_description = get_type_description; device_class->create_and_realize = create_and_realize; device_class->get_generic_capabilities = get_generic_capabilities; - device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; - device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start; + device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; device_class->enslave_slave = enslave_slave; device_class->release_slave = release_slave; } diff --git a/src/devices/wifi/nm-device-wifi-p2p.c b/src/devices/wifi/nm-device-wifi-p2p.c index a429539642..ea5919aa1a 100644 --- a/src/devices/wifi/nm-device-wifi-p2p.c +++ b/src/devices/wifi/nm-device-wifi-p2p.c @@ -583,50 +583,30 @@ remove_all_peers (NMDeviceWifiP2P *self) static NMActStageReturn -act_stage3_ip4_config_start (NMDevice *device, - NMIP4Config **out_config, - NMDeviceStateReason *out_failure_reason) +act_stage3_ip_config_start (NMDevice *device, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason) { + gboolean indicate_addressing_running; NMConnection *connection; - NMSettingIPConfig *s_ip4; - const char *method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; + const char *method; connection = nm_device_get_applied_connection (device); - g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE); - s_ip4 = nm_connection_get_setting_ip4_config (connection); - if (s_ip4) - method = nm_setting_ip_config_get_method (s_ip4); + method = nm_utils_get_ip_config_method (connection, addr_family); - /* Indicate that a critical protocol is about to start */ - if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) + if (addr_family == AF_INET) + indicate_addressing_running = NM_IN_STRSET (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + else { + indicate_addressing_running = NM_IN_STRSET (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NM_SETTING_IP6_CONFIG_METHOD_DHCP); + } + + if (indicate_addressing_running) nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), TRUE); - return NM_DEVICE_CLASS (nm_device_wifi_p2p_parent_class)->act_stage3_ip4_config_start (device, out_config, out_failure_reason); -} - -static NMActStageReturn -act_stage3_ip6_config_start (NMDevice *device, - NMIP6Config **out_config, - NMDeviceStateReason *out_failure_reason) -{ - NMConnection *connection; - NMSettingIPConfig *s_ip6; - const char *method = NM_SETTING_IP6_CONFIG_METHOD_AUTO; - - connection = nm_device_get_applied_connection (device); - g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE); - - s_ip6 = nm_connection_get_setting_ip6_config (connection); - if (s_ip6) - method = nm_setting_ip_config_get_method (s_ip6); - - /* Indicate that a critical protocol is about to start */ - if (NM_IN_STRSET (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO - NM_SETTING_IP6_CONFIG_METHOD_DHCP)) - nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), TRUE); - - return NM_DEVICE_CLASS (nm_device_wifi_p2p_parent_class)->act_stage3_ip6_config_start (device, out_config, out_failure_reason); + return NM_DEVICE_CLASS (nm_device_wifi_p2p_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); } static void @@ -1315,8 +1295,7 @@ nm_device_wifi_p2p_class_init (NMDeviceWifiP2PClass *klass) device_class->act_stage2_config = act_stage2_config; device_class->get_configured_mtu = get_configured_mtu; device_class->get_auto_ip_config_method = get_auto_ip_config_method; - device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; - device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start; + device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; device_class->deactivate = deactivate; device_class->unmanaged_on_quit = unmanaged_on_quit; diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 25f7b9f502..e469c0755e 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -2874,52 +2874,29 @@ out: } static NMActStageReturn -act_stage3_ip4_config_start (NMDevice *device, - NMIP4Config **out_config, - NMDeviceStateReason *out_failure_reason) +act_stage3_ip_config_start (NMDevice *device, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason) { + gboolean indicate_addressing_running; NMConnection *connection; - NMSettingIPConfig *s_ip4; - const char *method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; + const char *method; connection = nm_device_get_applied_connection (device); - g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE); + method = nm_utils_get_ip_config_method (connection, addr_family); + if (addr_family == AF_INET) + indicate_addressing_running = NM_IN_STRSET (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + else { + indicate_addressing_running = NM_IN_STRSET (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NM_SETTING_IP6_CONFIG_METHOD_DHCP); + } - s_ip4 = nm_connection_get_setting_ip4_config (connection); - if (s_ip4) - method = nm_setting_ip_config_get_method (s_ip4); + if (indicate_addressing_running) + nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), TRUE); - /* Indicate that a critical protocol is about to start */ - if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0) - nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ifindex (device), TRUE); - - return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip4_config_start (device, out_config, out_failure_reason); -} - -static NMActStageReturn -act_stage3_ip6_config_start (NMDevice *device, - NMIP6Config **out_config, - NMDeviceStateReason *out_failure_reason) -{ - NMConnection *connection; - NMSettingIPConfig *s_ip6; - const char *method = NM_SETTING_IP6_CONFIG_METHOD_AUTO; - - connection = nm_device_get_applied_connection (device); - - g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE); - - s_ip6 = nm_connection_get_setting_ip6_config (connection); - if (s_ip6) - method = nm_setting_ip_config_get_method (s_ip6); - - /* Indicate that a critical protocol is about to start */ - if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0 || - strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) - nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ifindex (device), TRUE); - - return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip6_config_start (device, out_config, out_failure_reason); + return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); } static guint32 @@ -2954,19 +2931,27 @@ is_static_wep (NMConnection *connection) } static NMActStageReturn -handle_ip_config_timeout (NMDeviceWifi *self, - NMConnection *connection, - gboolean may_fail, - gboolean *chain_up, - NMDeviceStateReason *out_failure_reason) +act_stage4_ip_config_timeout (NMDevice *device, + int addr_family, + NMDeviceStateReason *out_failure_reason) { - NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; + NMDeviceWifi *self = NM_DEVICE_WIFI (device); + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); + NMConnection *connection; + NMSettingIPConfig *s_ip; + gboolean may_fail; - g_return_val_if_fail (connection != NULL, NM_ACT_STAGE_RETURN_FAILURE); + connection = nm_device_get_applied_connection (device); + s_ip = nm_connection_get_setting_ip4_config (connection); + may_fail = nm_setting_ip_config_get_may_fail (s_ip); - if (NM_DEVICE_WIFI_GET_PRIVATE (self)->mode == NM_802_11_MODE_AP) { - *chain_up = TRUE; - return NM_ACT_STAGE_RETURN_FAILURE; + if (priv->mode == NM_802_11_MODE_AP) + goto call_parent; + + if ( may_fail + && !is_static_wep (connection)) { + /* Not static WEP or failure allowed; let superclass handle it */ + goto call_parent; } /* If IP configuration times out and it's a static WEP connection, that @@ -2975,71 +2960,23 @@ handle_ip_config_timeout (NMDeviceWifi *self, * to wait for DHCP to fail to figure it out. For all other Wi-Fi security * types (open, WPA, 802.1x, etc) if the secrets/certs were wrong the * connection would have failed before IP configuration. - */ - if (!may_fail && is_static_wep (connection)) { - /* Activation failed, we must have bad encryption key */ - _LOGW (LOGD_DEVICE | LOGD_WIFI, - "Activation: (wifi) could not get IP configuration for connection '%s'.", - nm_connection_get_id (connection)); + * + * Activation failed, we must have bad encryption key */ + _LOGW (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) could not get IP configuration for connection '%s'.", + nm_connection_get_id (connection)); - if (handle_auth_or_fail (self, NULL, TRUE)) { - _LOGI (LOGD_DEVICE | LOGD_WIFI, - "Activation: (wifi) asking for new secrets"); - ret = NM_ACT_STAGE_RETURN_POSTPONE; - } else { - NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_NO_SECRETS); - ret = NM_ACT_STAGE_RETURN_FAILURE; - } - } else { - /* Not static WEP or failure allowed; let superclass handle it */ - *chain_up = TRUE; + if (!handle_auth_or_fail (self, NULL, TRUE)) { + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_NO_SECRETS); + return NM_ACT_STAGE_RETURN_FAILURE; } - return ret; -} + _LOGI (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) asking for new secrets"); + return NM_ACT_STAGE_RETURN_POSTPONE; -static NMActStageReturn -act_stage4_ip4_config_timeout (NMDevice *device, NMDeviceStateReason *out_failure_reason) -{ - NMConnection *connection; - NMSettingIPConfig *s_ip4; - gboolean may_fail = FALSE, chain_up = FALSE; - NMActStageReturn ret; - - connection = nm_device_get_applied_connection (device); - - g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE); - - s_ip4 = nm_connection_get_setting_ip4_config (connection); - may_fail = nm_setting_ip_config_get_may_fail (s_ip4); - - ret = handle_ip_config_timeout (NM_DEVICE_WIFI (device), connection, may_fail, &chain_up, out_failure_reason); - if (chain_up) - ret = NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage4_ip4_config_timeout (device, out_failure_reason); - - return ret; -} - -static NMActStageReturn -act_stage4_ip6_config_timeout (NMDevice *device, NMDeviceStateReason *out_failure_reason) -{ - NMConnection *connection; - NMSettingIPConfig *s_ip6; - gboolean may_fail = FALSE, chain_up = FALSE; - NMActStageReturn ret; - - connection = nm_device_get_applied_connection (device); - - g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE); - - s_ip6 = nm_connection_get_setting_ip6_config (connection); - may_fail = nm_setting_ip_config_get_may_fail (s_ip6); - - ret = handle_ip_config_timeout (NM_DEVICE_WIFI (device), connection, may_fail, &chain_up, out_failure_reason); - if (chain_up) - ret = NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage4_ip6_config_timeout (device, out_failure_reason); - - return ret; +call_parent: + return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage4_ip_config_timeout (device, addr_family, out_failure_reason); } static void @@ -3447,10 +3384,8 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) device_class->act_stage1_prepare = act_stage1_prepare; device_class->act_stage2_config = act_stage2_config; device_class->get_configured_mtu = get_configured_mtu; - device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; - device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start; - device_class->act_stage4_ip4_config_timeout = act_stage4_ip4_config_timeout; - device_class->act_stage4_ip6_config_timeout = act_stage4_ip6_config_timeout; + device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; + device_class->act_stage4_ip_config_timeout = act_stage4_ip_config_timeout; device_class->deactivate = deactivate; device_class->deactivate_reset_hw_addr = deactivate_reset_hw_addr; device_class->unmanaged_on_quit = unmanaged_on_quit; diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index 7d25cba5ae..1e31628080 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -228,7 +228,7 @@ modem_ip6_config_result (NMModem *modem, NMDevice *device = NM_DEVICE (self); NMActStageReturn ret; NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; - NMIP6Config *ignored = NULL; + gs_unref_object NMIP6Config *ignored = NULL; gboolean got_config = !!config; g_return_if_fail (nm_device_activate_ip6_state_in_conf (device) == TRUE); @@ -261,8 +261,10 @@ modem_ip6_config_result (NMModem *modem, } /* Start SLAAC now that we have a link-local address from the modem */ - ret = NM_DEVICE_CLASS (nm_device_modem_parent_class)->act_stage3_ip6_config_start (device, &ignored, &failure_reason); - g_assert (ignored == NULL); + ret = NM_DEVICE_CLASS (nm_device_modem_parent_class)->act_stage3_ip_config_start (device, AF_INET6, (gpointer *) &ignored, &failure_reason); + + nm_assert (ignored == NULL); + switch (ret) { case NM_ACT_STAGE_RETURN_FAILURE: nm_device_ip_method_failed (device, AF_INET6, failure_reason); @@ -278,7 +280,7 @@ modem_ip6_config_result (NMModem *modem, /* Should never get here since we've assured that the IPv6 method * will either be "auto" or "ignored" when starting IPv6 configuration. */ - g_assert_not_reached (); + nm_assert_not_reached (); } } @@ -569,14 +571,25 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) } static NMActStageReturn -act_stage3_ip4_config_start (NMDevice *device, - NMIP4Config **out_config, - NMDeviceStateReason *out_failure_reason) +act_stage3_ip_config_start (NMDevice *device, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason) { - return nm_modem_stage3_ip4_config_start (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) device)->modem, - device, - NM_DEVICE_CLASS (nm_device_modem_parent_class), - out_failure_reason); + NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (device); + + nm_assert_addr_family (addr_family); + + if (addr_family == AF_INET) { + return nm_modem_stage3_ip4_config_start (priv->modem, + device, + NM_DEVICE_CLASS (nm_device_modem_parent_class), + out_failure_reason); + } else { + return nm_modem_stage3_ip6_config_start (priv->modem, + device, + out_failure_reason); + } } static void @@ -585,16 +598,6 @@ ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) nm_modem_ip4_pre_commit (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) device)->modem, device, config); } -static NMActStageReturn -act_stage3_ip6_config_start (NMDevice *device, - NMIP6Config **out_config, - NMDeviceStateReason *out_failure_reason) -{ - return nm_modem_stage3_ip6_config_start (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) device)->modem, - device, - out_failure_reason); -} - static gboolean get_ip_iface_identifier (NMDevice *device, NMUtilsIPv6IfaceId *out_iid) { @@ -824,8 +827,7 @@ nm_device_modem_class_init (NMDeviceModemClass *klass) device_class->deactivate = deactivate; device_class->act_stage1_prepare = act_stage1_prepare; device_class->act_stage2_config = act_stage2_config; - device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; - device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start; + device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; device_class->ip4_config_pre_commit = ip4_config_pre_commit; device_class->get_enabled = get_enabled; device_class->set_enabled = set_enabled; diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 74c212ae29..2217f2a2df 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -728,7 +728,7 @@ nm_modem_stage3_ip4_config_start (NMModem *self, break; case NM_MODEM_IP_METHOD_AUTO: _LOGD ("MODEM_IP_METHOD_AUTO"); - ret = device_class->act_stage3_ip4_config_start (device, NULL, out_failure_reason); + ret = device_class->act_stage3_ip_config_start (device, AF_INET, NULL, out_failure_reason); break; default: _LOGI ("IPv4 configuration disabled"); From 096247e60b9ec961c1d82950e6af8b4b5f2a5161 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 2 Mar 2019 20:21:50 +0100 Subject: [PATCH 13/16] device: expose nm_device_ip_config_new() as internal API --- src/devices/nm-device-private.h | 6 ++++++ src/devices/nm-device.c | 38 ++++++++++++++++----------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index ce63c46790..6e2372abf9 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -159,6 +159,12 @@ gboolean nm_device_sysctl_ip_conf_set (NMDevice *self, const char *property, const char *value); +NMIP4Config *nm_device_ip4_config_new (NMDevice *self); + +NMIP6Config *nm_device_ip6_config_new (NMDevice *self); + +NMIPConfig *nm_device_ip_config_new (NMDevice *self, int addr_family); + /*****************************************************************************/ gint64 nm_device_get_configured_mtu_from_connection_default (NMDevice *self, diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index b0c5f1f4cc..cf4bb4d971 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -884,28 +884,28 @@ concheck_get_mgr (NMDevice *self) return priv->concheck_mgr; } -static NMIP4Config * -_ip4_config_new (NMDevice *self) +NMIP4Config * +nm_device_ip4_config_new (NMDevice *self) { return nm_ip4_config_new (nm_device_get_multi_index (self), nm_device_get_ip_ifindex (self)); } -static NMIP6Config * -_ip6_config_new (NMDevice *self) +NMIP6Config * +nm_device_ip6_config_new (NMDevice *self) { return nm_ip6_config_new (nm_device_get_multi_index (self), nm_device_get_ip_ifindex (self)); } -static NMIPConfig * -_ip_config_new (NMDevice *self, int addr_family) +NMIPConfig * +nm_device_ip_config_new (NMDevice *self, int addr_family) { nm_assert_addr_family (addr_family); return addr_family == AF_INET - ? (gpointer) _ip4_config_new (self) - : (gpointer) _ip6_config_new (self); + ? (gpointer) nm_device_ip4_config_new (self) + : (gpointer) nm_device_ip6_config_new (self); } static void @@ -932,7 +932,7 @@ applied_config_init (AppliedConfig *config, gpointer ip_config) static void applied_config_init_new (AppliedConfig *config, NMDevice *self, int addr_family) { - gs_unref_object NMIPConfig *c = _ip_config_new (self, addr_family); + gs_unref_object NMIPConfig *c = nm_device_ip_config_new (self, addr_family); applied_config_init (config, c); } @@ -6835,7 +6835,7 @@ ipv4ll_get_ip4_config (NMDevice *self, guint32 lla) NMPlatformIP4Address address; NMPlatformIP4Route route; - config = _ip4_config_new (self); + config = nm_device_ip4_config_new (self); g_assert (config); memset (&address, 0, sizeof (address)); @@ -7010,7 +7010,7 @@ ensure_con_ip_config (NMDevice *self, int addr_family) if (!connection) return; - con_ip_config = _ip_config_new (self, addr_family); + con_ip_config = nm_device_ip_config_new (self, addr_family); if (IS_IPv4) { nm_ip4_config_merge_setting (NM_IP4_CONFIG (con_ip_config), @@ -7113,7 +7113,7 @@ ip_config_merge_and_apply (NMDevice *self, } } - composite = _ip_config_new (self, addr_family); + composite = nm_device_ip_config_new (self, addr_family); if (!IS_IPv4) { nm_ip6_config_set_privacy (NM_IP6_CONFIG (composite), @@ -7433,7 +7433,7 @@ dhcp4_state_changed (NMDhcpClient *client, connection = nm_device_get_applied_connection (self); g_assert (connection); - manual = _ip4_config_new (self); + manual = nm_device_ip4_config_new (self); nm_ip4_config_merge_setting (manual, nm_connection_get_setting_ip4_config (connection), NM_SETTING_CONNECTION_MDNS_DEFAULT, @@ -7771,7 +7771,7 @@ shared4_new_config (NMDevice *self, NMConnection *connection) is_generated = TRUE; } - config = _ip4_config_new (self); + config = nm_device_ip4_config_new (self); nm_ip4_config_add_address (config, &address); if (is_generated) { /* Remove the address lock when the object gets disposed */ @@ -9664,7 +9664,7 @@ act_stage3_ip_config_start (NMDevice *self, } if (num_addresses) { - config = _ip4_config_new (self); + config = nm_device_ip4_config_new (self); nm_ip4_config_merge_setting (config, nm_connection_get_setting_ip4_config (connection), NM_SETTING_CONNECTION_MDNS_DEFAULT, @@ -9861,7 +9861,7 @@ nm_device_activate_stage3_ip6_start (NMDevice *self) ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip_config_start (self, AF_INET6, (gpointer *) &ip6_config, &failure_reason); if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { if (!ip6_config) - ip6_config = _ip6_config_new (self); + ip6_config = nm_device_ip6_config_new (self); /* Here we get a static IPv6 config, like for Shared where it's * autogenerated or from modems where it comes from ModemManager. */ @@ -10449,7 +10449,7 @@ dad6_add_pending_address (NMDevice *self, nm_platform_ip6_address_to_string (pl_addr, NULL, 0)); if (!*dad6_config) - *dad6_config = _ip6_config_new (self); + *dad6_config = nm_device_ip6_config_new (self); nm_ip6_config_add_address (*dad6_config, pl_addr); } @@ -10849,7 +10849,7 @@ nm_device_reactivate_ip4_config (NMDevice *self, g_clear_object (&priv->ext_ip_config_4); g_clear_object (&priv->dev_ip_config_4.current); g_clear_object (&priv->dev2_ip_config_4.current); - priv->con_ip_config_4 = _ip4_config_new (self); + priv->con_ip_config_4 = nm_device_ip4_config_new (self); nm_ip4_config_merge_setting (priv->con_ip_config_4, s_ip4_new, _get_mdns (self), @@ -10925,7 +10925,7 @@ nm_device_reactivate_ip6_config (NMDevice *self, if ( priv->ipv6ll_handle && !IN6_IS_ADDR_UNSPECIFIED (&priv->ipv6ll_addr)) priv->ipv6ll_has = TRUE; - priv->con_ip_config_6 = _ip6_config_new (self); + priv->con_ip_config_6 = nm_device_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), From d5e93ae613fd355351bdf37530cae3d3dfb4e5ba Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 2 Mar 2019 23:33:15 +0100 Subject: [PATCH 14/16] wireguard: add "mtu" setting for WireGuard profiles This adds new API for 1.16.0 and is an ABI break since 1.16-rc1. --- clients/common/nm-meta-setting-desc.c | 3 ++ clients/common/settings-docs.h.in | 1 + libnm-core/nm-setting-wireguard.c | 71 +++++++++++++++++++++------ libnm-core/nm-setting-wireguard.h | 15 ++++-- libnm/libnm.ver | 1 + man/NetworkManager.conf.xml | 3 ++ src/devices/nm-device-wireguard.c | 42 +++++++++++++++- src/devices/nm-device.c | 4 ++ 8 files changed, 119 insertions(+), 21 deletions(-) diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 5bfb76fb4c..1857602133 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -7536,6 +7536,9 @@ static const NMMetaPropertyInfo *const property_infos_WIREGUARD[] = { .base = 16, ), ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_MTU, + .property_type = &_pt_gobject_mtu, + ), NULL }; diff --git a/clients/common/settings-docs.h.in b/clients/common/settings-docs.h.in index 235a9c7f30..2bdff62d10 100644 --- a/clients/common/settings-docs.h.in +++ b/clients/common/settings-docs.h.in @@ -364,6 +364,7 @@ #define DESCRIBE_DOC_NM_SETTING_WIMAX_NETWORK_NAME N_("Network Service Provider (NSP) name of the WiMAX network this connection should use. Deprecated: 1") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_FWMARK N_("The use of fwmark is optional and is by default off. Setting it to 0 disables it. Otherwise it is a 32-bit fwmark for outgoing packets.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_LISTEN_PORT N_("The listen-port. If listen-port is not specified, the port will be chosen randomly when the interface comes up.") +#define DESCRIBE_DOC_NM_SETTING_WIREGUARD_MTU N_("If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple fragments. If zero a default MTU is used. Note that contrary to wg-quick's MTU setting, this does not take into account the current routes at the time of activation.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_PRIVATE_KEY N_("The 256 bit private-key in base64 encoding.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS N_("Flags indicating how to handle the \"private-key\" property.") #define DESCRIBE_DOC_NM_SETTING_WPAN_CHANNEL N_("IEEE 802.15.4 channel. A positive integer or -1, meaning \"do not set, use whatever the device is already set to\".") diff --git a/libnm-core/nm-setting-wireguard.c b/libnm-core/nm-setting-wireguard.c index 19b418547d..317f30f845 100644 --- a/libnm-core/nm-setting-wireguard.c +++ b/libnm-core/nm-setting-wireguard.c @@ -850,10 +850,11 @@ typedef struct { /*****************************************************************************/ NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_FWMARK, + PROP_LISTEN_PORT, + PROP_MTU, PROP_PRIVATE_KEY, PROP_PRIVATE_KEY_FLAGS, - PROP_LISTEN_PORT, - PROP_FWMARK, ); typedef struct { @@ -862,6 +863,7 @@ typedef struct { GHashTable *peers_hash; NMSettingSecretFlags private_key_flags; guint32 fwmark; + guint32 mtu; guint16 listen_port; bool private_key_valid:1; } NMSettingWireGuardPrivate; @@ -978,6 +980,22 @@ nm_setting_wireguard_get_listen_port (NMSettingWireGuard *self) return NM_SETTING_WIREGUARD_GET_PRIVATE (self)->listen_port; } +/** + * nm_setting_wireguard_get_mtu: + * @self: the #NMSettingWireGuard instance + * + * Returns: the MTU of the setting. + * + * Since: 1.16 + */ +guint32 +nm_setting_wireguard_get_mtu (NMSettingWireGuard *self) +{ + g_return_val_if_fail (NM_IS_SETTING_WIREGUARD (self), 0); + + return NM_SETTING_WIREGUARD_GET_PRIVATE (self)->mtu; +} + /*****************************************************************************/ static void @@ -2160,18 +2178,21 @@ get_property (GObject *object, guint prop_id, NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE (setting); switch (prop_id) { + case PROP_FWMARK: + g_value_set_uint (value, priv->fwmark); + break; + case PROP_LISTEN_PORT: + g_value_set_uint (value, priv->listen_port); + break; + case PROP_MTU: + g_value_set_uint (value, priv->mtu); + break; case PROP_PRIVATE_KEY: g_value_set_string (value, priv->private_key); break; case PROP_PRIVATE_KEY_FLAGS: g_value_set_flags (value, priv->private_key_flags); break; - case PROP_LISTEN_PORT: - g_value_set_uint (value, priv->listen_port); - break; - case PROP_FWMARK: - g_value_set_uint (value, priv->fwmark); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -2186,6 +2207,15 @@ set_property (GObject *object, guint prop_id, const char *str; switch (prop_id) { + case PROP_FWMARK: + priv->fwmark = g_value_get_uint (value); + break; + case PROP_LISTEN_PORT: + priv->listen_port = g_value_get_uint (value); + break; + case PROP_MTU: + priv->mtu = g_value_get_uint (value); + break; case PROP_PRIVATE_KEY: nm_clear_pointer (&priv->private_key, nm_free_secret); str = g_value_get_string (value); @@ -2203,12 +2233,6 @@ set_property (GObject *object, guint prop_id, case PROP_PRIVATE_KEY_FLAGS: priv->private_key_flags = g_value_get_flags (value); break; - case PROP_LISTEN_PORT: - priv->listen_port = g_value_get_uint (value); - break; - case PROP_FWMARK: - priv->fwmark = g_value_get_uint (value); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -2338,6 +2362,25 @@ nm_setting_wireguard_class_init (NMSettingWireGuardClass *klass) | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + /** + * NMSettingWireGuard:mtu: + * + * If non-zero, only transmit packets of the specified size or smaller, + * breaking larger packets up into multiple fragments. + * + * If zero a default MTU is used. Note that contrary to wg-quick's MTU + * setting, this does not take into account the current routes at the + * time of activation. + * + * Since: 1.16 + **/ + obj_properties[PROP_MTU] = + g_param_spec_uint (NM_SETTING_WIREGUARD_MTU, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READWRITE + | NM_SETTING_PARAM_INFERRABLE + | G_PARAM_STATIC_STRINGS); + /* ---dbus--- * property: peers * format: array of 'a{sv}' diff --git a/libnm-core/nm-setting-wireguard.h b/libnm-core/nm-setting-wireguard.h index 3810aa3048..257439267c 100644 --- a/libnm-core/nm-setting-wireguard.h +++ b/libnm-core/nm-setting-wireguard.h @@ -126,19 +126,21 @@ int nm_wireguard_peer_cmp (const NMWireGuardPeer *a, #define NM_SETTING_WIREGUARD_SETTING_NAME "wireguard" +#define NM_SETTING_WIREGUARD_FWMARK "fwmark" +#define NM_SETTING_WIREGUARD_LISTEN_PORT "listen-port" #define NM_SETTING_WIREGUARD_PRIVATE_KEY "private-key" #define NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS "private-key-flags" -#define NM_SETTING_WIREGUARD_LISTEN_PORT "listen-port" -#define NM_SETTING_WIREGUARD_FWMARK "fwmark" #define NM_SETTING_WIREGUARD_PEERS "peers" -#define NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY "public-key" +#define NM_SETTING_WIREGUARD_MTU "mtu" + +#define NM_WIREGUARD_PEER_ATTR_ALLOWED_IPS "allowed-ips" #define NM_WIREGUARD_PEER_ATTR_ENDPOINT "endpoint" +#define NM_WIREGUARD_PEER_ATTR_PERSISTENT_KEEPALIVE "persistent-keepalive" #define NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY "preshared-key" #define NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY_FLAGS "preshared-key-flags" -#define NM_WIREGUARD_PEER_ATTR_ALLOWED_IPS "allowed-ips" -#define NM_WIREGUARD_PEER_ATTR_PERSISTENT_KEEPALIVE "persistent-keepalive" +#define NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY "public-key" /*****************************************************************************/ @@ -194,6 +196,9 @@ gboolean nm_setting_wireguard_remove_peer (NMSettingWireGuard *self, NM_AVAILABLE_IN_1_16 guint nm_setting_wireguard_clear_peers (NMSettingWireGuard *self); +NM_AVAILABLE_IN_1_16 +guint32 nm_setting_wireguard_get_mtu (NMSettingWireGuard *self); + /*****************************************************************************/ G_END_DECLS diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 136b0009de..cd523dae04 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1466,6 +1466,7 @@ global: nm_setting_wireguard_clear_peers; nm_setting_wireguard_get_fwmark; nm_setting_wireguard_get_listen_port; + nm_setting_wireguard_get_mtu; nm_setting_wireguard_get_peer; nm_setting_wireguard_get_peer_by_public_key; nm_setting_wireguard_get_peers_len; diff --git a/man/NetworkManager.conf.xml b/man/NetworkManager.conf.xml index b6577aed50..289342473a 100644 --- a/man/NetworkManager.conf.xml +++ b/man/NetworkManager.conf.xml @@ -827,6 +827,9 @@ ipv6.ip6-privacy=0 wifi.wake-on-wlan + + wireguard.mtu + diff --git a/src/devices/nm-device-wireguard.c b/src/devices/nm-device-wireguard.c index d08d6ad7af..4e8d630e48 100644 --- a/src/devices/nm-device-wireguard.c +++ b/src/devices/nm-device-wireguard.c @@ -1247,6 +1247,34 @@ act_stage2_config (NMDevice *device, return NM_ACT_STAGE_RETURN_FAILURE; } +static guint32 +get_configured_mtu (NMDevice *device, NMDeviceMtuSource *out_source) +{ + /* When "MTU" for `wg-quick up` is unset, it calls `ip route get` for + * each configured endpoint, to determine the suitable MTU how to reach + * each endpoint. + * For `wg-quick` this works very well, because whenever the script runs it + * determines the best setting at that point in time. It's simply not concerned + * with what happens later (and it's not around anyway). + * + * NetworkManager sticks around, so the right MTU would need to be re-determined + * whenever anything relevant changes. Which basically means, to re-evaluate whenever + * something related to addresses or routing changes (which happens all the time). + * + * The correct MTU indeed depends on the MTU setting of other interfaces (or routes). + * But it's still odd, that activating/deactivating a seemingly unrelated interface + * would trigger an MTU change. It's odd to explain/document and odd to implemented + * -- despite this being the reality. + * + * For now, only support configuring an explicit MTU, or leave the setting untouched. + * The same limitiation also applies to other "ip-tunnel" types, where we could use + * similar smarts for autodetecting the MTU. + */ + return nm_device_get_configured_mtu_from_connection (device, + NM_TYPE_SETTING_WIREGUARD, + out_source); +} + static void device_state_changed (NMDevice *device, NMDeviceState new_state, @@ -1275,8 +1303,17 @@ can_reapply_change (NMDevice *device, GError **error) { if (nm_streq (setting_name, NM_SETTING_WIREGUARD_SETTING_NAME)) { - /* we allow reapplying all WireGuard settings. */ - return TRUE; + /* Most, but not all WireGuard settings can be reapplied. Whitelist. + * + * MTU cannot be reapplied. */ + return nm_device_hash_check_invalid_keys (diffs, + NM_SETTING_WIREGUARD_SETTING_NAME, + error, + NM_SETTING_WIREGUARD_FWMARK, + NM_SETTING_WIREGUARD_LISTEN_PORT, + NM_SETTING_WIREGUARD_PEERS, + NM_SETTING_WIREGUARD_PRIVATE_KEY, + NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS); } return NM_DEVICE_CLASS (nm_device_wireguard_parent_class)->can_reapply_change (device, @@ -1451,6 +1488,7 @@ nm_device_wireguard_class_init (NMDeviceWireGuardClass *klass) device_class->update_connection = update_connection; device_class->can_reapply_change = can_reapply_change; device_class->reapply_connection = reapply_connection; + device_class->get_configured_mtu = get_configured_mtu; obj_properties[PROP_PUBLIC_KEY] = g_param_spec_variant (NM_DEVICE_WIREGUARD_PUBLIC_KEY, diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index cf4bb4d971..b24c9a7731 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -8871,6 +8871,10 @@ nm_device_get_configured_mtu_from_connection (NMDevice *self, if (setting) mtu = nm_setting_ip_tunnel_get_mtu (NM_SETTING_IP_TUNNEL (setting)); global_property_name = NM_CON_DEFAULT ("ip-tunnel.mtu"); + } else if (setting_type == NM_TYPE_SETTING_WIREGUARD) { + if (setting) + mtu = nm_setting_wireguard_get_mtu (NM_SETTING_WIREGUARD (setting)); + global_property_name = NM_CON_DEFAULT ("wireguard.mtu"); } else g_return_val_if_reached (0); From d719ad31f096583c501af3bea01a01ffd72337d5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 4 Mar 2019 09:26:23 +0100 Subject: [PATCH 15/16] wireguard: add "peer-routes" setting for WireGuard profiles This setting is not yet implemented. This adds new API for 1.16.0 and is an ABI break since 1.16-rc1. --- clients/common/nm-meta-setting-desc.c | 3 ++ clients/common/settings-docs.h.in | 1 + libnm-core/nm-setting-wireguard.c | 45 +++++++++++++++++++++++++++ libnm-core/nm-setting-wireguard.h | 4 +++ libnm/libnm.ver | 1 + 5 files changed, 54 insertions(+) diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 1857602133..1203e008fd 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -7536,6 +7536,9 @@ static const NMMetaPropertyInfo *const property_infos_WIREGUARD[] = { .base = 16, ), ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_PEER_ROUTES, + .property_type = &_pt_gobject_bool, + ), PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_MTU, .property_type = &_pt_gobject_mtu, ), diff --git a/clients/common/settings-docs.h.in b/clients/common/settings-docs.h.in index 2bdff62d10..7b958faae9 100644 --- a/clients/common/settings-docs.h.in +++ b/clients/common/settings-docs.h.in @@ -365,6 +365,7 @@ #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_FWMARK N_("The use of fwmark is optional and is by default off. Setting it to 0 disables it. Otherwise it is a 32-bit fwmark for outgoing packets.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_LISTEN_PORT N_("The listen-port. If listen-port is not specified, the port will be chosen randomly when the interface comes up.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_MTU N_("If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple fragments. If zero a default MTU is used. Note that contrary to wg-quick's MTU setting, this does not take into account the current routes at the time of activation.") +#define DESCRIBE_DOC_NM_SETTING_WIREGUARD_PEER_ROUTES N_("Whether to automatically add routes for the AllowedIPs ranges of the peers. If TRUE (the default), NetworkManager will automatically add routes in the routing tables according to ipv4.route-table and ipv6.route-table. If FALSE, no such routes are added automatically. In this case, the user may want to configure static routes in ipv4.routes and ipv6.routes, respectively.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_PRIVATE_KEY N_("The 256 bit private-key in base64 encoding.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS N_("Flags indicating how to handle the \"private-key\" property.") #define DESCRIBE_DOC_NM_SETTING_WPAN_CHANNEL N_("IEEE 802.15.4 channel. A positive integer or -1, meaning \"do not set, use whatever the device is already set to\".") diff --git a/libnm-core/nm-setting-wireguard.c b/libnm-core/nm-setting-wireguard.c index 317f30f845..1b158a3215 100644 --- a/libnm-core/nm-setting-wireguard.c +++ b/libnm-core/nm-setting-wireguard.c @@ -853,6 +853,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_FWMARK, PROP_LISTEN_PORT, PROP_MTU, + PROP_PEER_ROUTES, PROP_PRIVATE_KEY, PROP_PRIVATE_KEY_FLAGS, ); @@ -866,6 +867,7 @@ typedef struct { guint32 mtu; guint16 listen_port; bool private_key_valid:1; + bool peer_routes:1; } NMSettingWireGuardPrivate; /** @@ -980,6 +982,22 @@ nm_setting_wireguard_get_listen_port (NMSettingWireGuard *self) return NM_SETTING_WIREGUARD_GET_PRIVATE (self)->listen_port; } +/** + * nm_setting_wireguard_get_peer_routes: + * @self: the #NMSettingWireGuard instance + * + * Returns: whether automatically add peer routes. + * + * Since: 1.16 + */ +gboolean +nm_setting_wireguard_get_peer_routes (NMSettingWireGuard *self) +{ + g_return_val_if_fail (NM_IS_SETTING_WIREGUARD (self), TRUE); + + return NM_SETTING_WIREGUARD_GET_PRIVATE (self)->peer_routes; +} + /** * nm_setting_wireguard_get_mtu: * @self: the #NMSettingWireGuard instance @@ -2187,6 +2205,9 @@ get_property (GObject *object, guint prop_id, case PROP_MTU: g_value_set_uint (value, priv->mtu); break; + case PROP_PEER_ROUTES: + g_value_set_boolean (value, priv->peer_routes); + break; case PROP_PRIVATE_KEY: g_value_set_string (value, priv->private_key); break; @@ -2216,6 +2237,9 @@ set_property (GObject *object, guint prop_id, case PROP_MTU: priv->mtu = g_value_get_uint (value); break; + case PROP_PEER_ROUTES: + priv->peer_routes = g_value_get_boolean (value); + break; case PROP_PRIVATE_KEY: nm_clear_pointer (&priv->private_key, nm_free_secret); str = g_value_get_string (value); @@ -2248,6 +2272,7 @@ nm_setting_wireguard_init (NMSettingWireGuard *setting) priv->peers_arr = g_ptr_array_new (); priv->peers_hash = g_hash_table_new (nm_pstr_hash, nm_pstr_equal); + priv->peer_routes = TRUE; } /** @@ -2362,6 +2387,26 @@ nm_setting_wireguard_class_init (NMSettingWireGuardClass *klass) | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + /** + * NMSettingWireGuard:peer-routes: + * + * Whether to automatically add routes for the AllowedIPs ranges + * of the peers. If %TRUE (the default), NetworkManager will automatically + * add routes in the routing tables according to ipv4.route-table and + * ipv6.route-table. + * If %FALSE, no such routes are added automatically. In this case, the + * user may want to configure static routes in ipv4.routes and ipv6.routes, + * respectively. + * + * Since: 1.16 + **/ + obj_properties[PROP_PEER_ROUTES] = + g_param_spec_boolean (NM_SETTING_WIREGUARD_PEER_ROUTES, "", "", + TRUE, + G_PARAM_READWRITE + | NM_SETTING_PARAM_INFERRABLE + | G_PARAM_STATIC_STRINGS); + /** * NMSettingWireGuard:mtu: * diff --git a/libnm-core/nm-setting-wireguard.h b/libnm-core/nm-setting-wireguard.h index 257439267c..17fb4664c3 100644 --- a/libnm-core/nm-setting-wireguard.h +++ b/libnm-core/nm-setting-wireguard.h @@ -134,6 +134,7 @@ int nm_wireguard_peer_cmp (const NMWireGuardPeer *a, #define NM_SETTING_WIREGUARD_PEERS "peers" #define NM_SETTING_WIREGUARD_MTU "mtu" +#define NM_SETTING_WIREGUARD_PEER_ROUTES "peer-routes" #define NM_WIREGUARD_PEER_ATTR_ALLOWED_IPS "allowed-ips" #define NM_WIREGUARD_PEER_ATTR_ENDPOINT "endpoint" @@ -196,6 +197,9 @@ gboolean nm_setting_wireguard_remove_peer (NMSettingWireGuard *self, NM_AVAILABLE_IN_1_16 guint nm_setting_wireguard_clear_peers (NMSettingWireGuard *self); +NM_AVAILABLE_IN_1_16 +gboolean nm_setting_wireguard_get_peer_routes (NMSettingWireGuard *self); + NM_AVAILABLE_IN_1_16 guint32 nm_setting_wireguard_get_mtu (NMSettingWireGuard *self); diff --git a/libnm/libnm.ver b/libnm/libnm.ver index cd523dae04..3af360667e 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1469,6 +1469,7 @@ global: nm_setting_wireguard_get_mtu; nm_setting_wireguard_get_peer; nm_setting_wireguard_get_peer_by_public_key; + nm_setting_wireguard_get_peer_routes; nm_setting_wireguard_get_peers_len; nm_setting_wireguard_get_private_key; nm_setting_wireguard_get_private_key_flags; From 626beaf83e142fcaff32dbf1662d75af1d826b2d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 4 Mar 2019 09:31:28 +0100 Subject: [PATCH 16/16] wireguard: implement direct "peer-routes" for WireGuard allowed-ips ranges --- src/devices/nm-device-wireguard.c | 137 ++++++++++++++++++++++++++++++ src/devices/nm-device.c | 1 - 2 files changed, 137 insertions(+), 1 deletion(-) diff --git a/src/devices/nm-device-wireguard.c b/src/devices/nm-device-wireguard.c index 4e8d630e48..34fe1e1fff 100644 --- a/src/devices/nm-device-wireguard.c +++ b/src/devices/nm-device-wireguard.c @@ -1247,6 +1247,131 @@ act_stage2_config (NMDevice *device, return NM_ACT_STAGE_RETURN_FAILURE; } +static NMIPConfig * +_get_dev2_ip_config (NMDeviceWireGuard *self, + int addr_family) +{ + gs_unref_object NMIPConfig *ip_config = NULL; + NMConnection *connection; + NMSettingWireGuard *s_wg; + guint n_peers; + guint i; + int ip_ifindex; + guint32 route_metric; + guint32 route_table_coerced; + + connection = nm_device_get_applied_connection (NM_DEVICE (self)); + + s_wg = NM_SETTING_WIREGUARD (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIREGUARD)); + + /* Differences to `wg-quick`. + * + * `wg-quick` supports the "Table" setting with 3 modes: + * + * a1) "off": this is what we do with "peer-routes" disabled. + * + * a2) an explicit routing table. This is our behavior with "peer-routes" on. In this case + * we honor the "ipv4.route-table" and "ipv6.route-table" settings. One difference is that + * `wg-quick` would resolve table names from /etc/iproute2/rt_tables. Our connection profiles + * only contain table numbers, so that conversion from name to table must have happend + * before already. + * + * a3) "auto" (the default). In this case, `wg-quick` would only add the route to the + * main table, if the AllowedIP range is not yet reachable on the link. With "peer-routes" + * enabled, we don't check for that and always add the routes to the main-table + * (with 'ipv4.route-table' and 'ipv6.route-table' set to zero or RT_TABLE_MAIN (254)). + * + * Also, in "auto" mode, `wg-quick` would add special handling for /0 routes and pick + * an empty table to configure policy routing to avoid routing loops. This handling + * of routing-loops via policy routing is not yet done, and requires a separate solution + * from constructing the peer-routes here. + */ + if (!nm_setting_wireguard_get_peer_routes (s_wg)) + return NULL; + + ip_ifindex = nm_device_get_ip_ifindex (NM_DEVICE (self)); + + if (ip_ifindex <= 0) + return NULL; + + route_metric = nm_device_get_route_metric (NM_DEVICE (self), addr_family); + + route_table_coerced = nm_platform_route_table_coerce (nm_device_get_route_table (NM_DEVICE (self), addr_family, TRUE)); + + n_peers = nm_setting_wireguard_get_peers_len (s_wg); + for (i = 0; i < n_peers; i++) { + NMWireGuardPeer *peer = nm_setting_wireguard_get_peer (s_wg, i); + guint n_aips; + guint j; + + n_aips = nm_wireguard_peer_get_allowed_ips_len (peer); + for (j = 0; j < n_aips; j++) { + NMPlatformIPXRoute rt; + NMIPAddr addrbin; + const char *aip; + gboolean valid; + int prefix; + + aip = nm_wireguard_peer_get_allowed_ip (peer, j, &valid); + + if ( !valid + || !nm_utils_parse_inaddr_prefix_bin (addr_family, + aip, + NULL, + &addrbin, + &prefix)) + continue; + + if (prefix < 0) + prefix = (addr_family == AF_INET) ? 32 : 128; + + if (!ip_config) + ip_config = nm_device_ip_config_new (NM_DEVICE (self), addr_family); + + nm_utils_ipx_address_clear_host_address (addr_family, &addrbin, NULL, prefix); + + if (addr_family == AF_INET) { + rt.r4 = (NMPlatformIP4Route) { + .network = addrbin.addr4, + .plen = prefix, + .ifindex = ip_ifindex, + .rt_source = NM_IP_CONFIG_SOURCE_USER, + .table_coerced = route_table_coerced, + .metric = route_metric, + }; + } else { + rt.r6 = (NMPlatformIP6Route) { + .network = addrbin.addr6, + .plen = prefix, + .ifindex = ip_ifindex, + .rt_source = NM_IP_CONFIG_SOURCE_USER, + .table_coerced = route_table_coerced, + .metric = route_metric, + }; + } + + nm_ip_config_add_route (ip_config, &rt.rx, NULL); + } + } + + return g_steal_pointer (&ip_config); +} + +static NMActStageReturn +act_stage3_ip_config_start (NMDevice *device, + int addr_family, + gpointer *out_config, + NMDeviceStateReason *out_failure_reason) +{ + gs_unref_object NMIPConfig *ip_config = NULL; + + ip_config = _get_dev2_ip_config (NM_DEVICE_WIREGUARD (device), addr_family); + + nm_device_set_dev2_ip_config (device, addr_family, ip_config); + + return NM_DEVICE_CLASS (nm_device_wireguard_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); +} + static guint32 get_configured_mtu (NMDevice *device, NMDeviceMtuSource *out_source) { @@ -1312,6 +1437,7 @@ can_reapply_change (NMDevice *device, NM_SETTING_WIREGUARD_FWMARK, NM_SETTING_WIREGUARD_LISTEN_PORT, NM_SETTING_WIREGUARD_PEERS, + NM_SETTING_WIREGUARD_PEER_ROUTES, NM_SETTING_WIREGUARD_PRIVATE_KEY, NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS); } @@ -1329,6 +1455,16 @@ reapply_connection (NMDevice *device, NMConnection *con_old, NMConnection *con_new) { + NMDeviceWireGuard *self = NM_DEVICE_WIREGUARD (device); + gs_unref_object NMIPConfig *ip4_config = NULL; + gs_unref_object NMIPConfig *ip6_config = NULL; + + ip4_config = _get_dev2_ip_config (self, AF_INET); + ip6_config = _get_dev2_ip_config (self, AF_INET6); + + nm_device_set_dev2_ip_config (device, AF_INET, ip4_config); + nm_device_set_dev2_ip_config (device, AF_INET6, ip6_config); + NM_DEVICE_CLASS (nm_device_wireguard_parent_class)->reapply_connection (device, con_old, con_new); @@ -1483,6 +1619,7 @@ nm_device_wireguard_class_init (NMDeviceWireGuardClass *klass) device_class->create_and_realize = create_and_realize; device_class->act_stage2_config = act_stage2_config; device_class->act_stage2_config_also_for_external_or_assume = TRUE; + device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; device_class->get_generic_capabilities = get_generic_capabilities; device_class->link_changed = link_changed; device_class->update_connection = update_connection; diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index b24c9a7731..d5f7847f92 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -11077,7 +11077,6 @@ can_reapply_change (NMDevice *self, const char *setting_name, static void reapply_connection (NMDevice *self, NMConnection *con_old, NMConnection *con_new) { - } /* check_and_reapply_connection: