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");