device: merge activate_stage5_ip_config_result_[46]()

This commit is contained in:
Thomas Haller
2020-10-29 22:51:37 +01:00
parent 399684538b
commit f20d0d6984

View File

@@ -695,6 +695,8 @@ static guint32 default_route_metric_penalty_get(NMDevice *self, int addr_family)
static guint _prop_get_ipv4_dad_timeout(NMDevice *self); static guint _prop_get_ipv4_dad_timeout(NMDevice *self);
static NMIP6Config *dad6_get_pending_addresses(NMDevice *self);
static void _carrier_wait_check_queued_act_request(NMDevice *self); static void _carrier_wait_check_queued_act_request(NMDevice *self);
static gint64 _get_carrier_wait_ms(NMDevice *self); static gint64 _get_carrier_wait_ms(NMDevice *self);
@@ -728,14 +730,6 @@ static void concheck_update_state(NMDevice * self,
static void sriov_op_cb(GError *error, gpointer user_data); static void sriov_op_cb(GError *error, gpointer user_data);
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,
};
/*****************************************************************************/ /*****************************************************************************/
static NM_UTILS_LOOKUP_STR_DEFINE( static NM_UTILS_LOOKUP_STR_DEFINE(
@@ -11676,12 +11670,14 @@ nm_device_arp_announce(NMDevice *self)
} }
static void static void
activate_stage5_ip_config_result_4(NMDevice *self) activate_stage5_ip_config_result_x(NMDevice *self, int addr_family)
{ {
const int IS_IPv4 = NM_IS_IPv4(addr_family);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
NMActRequest * req; NMActRequest * req;
const char * method; const char * method;
int ip_ifindex; int ip_ifindex;
int errsv;
gboolean do_announce = FALSE; gboolean do_announce = FALSE;
req = nm_device_get_act_request(self); req = nm_device_get_act_request(self);
@@ -11689,6 +11685,8 @@ activate_stage5_ip_config_result_4(NMDevice *self)
/* Interface must be IFF_UP before IP config can be applied */ /* Interface must be IFF_UP before IP config can be applied */
ip_ifindex = nm_device_get_ip_ifindex(self); ip_ifindex = nm_device_get_ip_ifindex(self);
g_return_if_fail(ip_ifindex);
if (!nm_platform_link_is_up(nm_device_get_platform(self), ip_ifindex) if (!nm_platform_link_is_up(nm_device_get_platform(self), ip_ifindex)
&& !nm_device_sys_iface_state_is_external_or_assume(self)) { && !nm_device_sys_iface_state_is_external_or_assume(self)) {
nm_platform_link_set_up(nm_device_get_platform(self), ip_ifindex, NULL); nm_platform_link_set_up(nm_device_get_platform(self), ip_ifindex, NULL);
@@ -11698,14 +11696,37 @@ activate_stage5_ip_config_result_4(NMDevice *self)
nm_device_get_ip_iface(self)); nm_device_get_ip_iface(self));
} }
if (!ip_config_merge_and_apply(self, AF_INET, TRUE)) { if (!ip_config_merge_and_apply(self, addr_family, TRUE)) {
_LOGD(LOGD_DEVICE | LOGD_IP4, "Activation: Stage 5 of 5 (IPv4 Commit) failed"); _LOGD(LOGD_DEVICE | LOGD_IPX(IS_IPv4),
nm_device_ip_method_failed(self, AF_INET, NM_DEVICE_STATE_REASON_CONFIG_FAILED); "Activation: Stage 5 of 5 (IPv%c Commit) failed",
nm_utils_addr_family_to_char(addr_family));
nm_device_ip_method_failed(self, addr_family, NM_DEVICE_STATE_REASON_CONFIG_FAILED);
return; return;
} }
/* Start IPv4 sharing if we need it */ if (!IS_IPv4) {
method = nm_device_get_effective_ip_config_method(self, AF_INET); if (priv->dhcp6.mode != NM_NDISC_DHCP_LEVEL_NONE
&& 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.
*/
nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP6_CHANGE,
self,
NULL,
NULL,
NULL,
NULL);
} else {
/* still waiting for first dhcp6 lease. */
return;
}
}
}
/* Start IPv4 sharing/IPv6 forwarding if we need it */
method = nm_device_get_effective_ip_config_method(self, addr_family);
if (IS_IPv4) {
if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) { if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) {
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
@@ -11713,11 +11734,32 @@ activate_stage5_ip_config_result_4(NMDevice *self)
_LOGW(LOGD_SHARING, _LOGW(LOGD_SHARING,
"Activation: Stage 5 of 5 (IPv4 Commit) start sharing failed: %s", "Activation: Stage 5 of 5 (IPv4 Commit) start sharing failed: %s",
error->message); error->message);
nm_device_ip_method_failed(self, AF_INET, NM_DEVICE_STATE_REASON_SHARED_START_FAILED); nm_device_ip_method_failed(self,
AF_INET,
NM_DEVICE_STATE_REASON_SHARED_START_FAILED);
return; return;
} }
} }
} else {
if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) {
if (!nm_platform_sysctl_set(
nm_device_get_platform(self),
NMP_SYSCTL_PATHID_ABSOLUTE("/proc/sys/net/ipv6/conf/all/forwarding"),
"1")) {
errsv = errno;
_LOGE(LOGD_SHARING,
"share: error enabling IPv6 forwarding: (%d) %s",
errsv,
nm_strerror_native(errsv));
nm_device_ip_method_failed(self,
AF_INET6,
NM_DEVICE_STATE_REASON_SHARED_START_FAILED);
return;
}
}
}
if (IS_IPv4) {
if (priv->dhcp_data_4.client) { if (priv->dhcp_data_4.client) {
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
@@ -11735,9 +11777,34 @@ activate_stage5_ip_config_result_4(NMDevice *self)
*/ */
if (priv->dhcp_data_4.client && nm_device_activate_ip4_state_in_conf(self) if (priv->dhcp_data_4.client && nm_device_activate_ip4_state_in_conf(self)
&& (nm_device_get_state(self) > NM_DEVICE_STATE_IP_CONFIG)) { && (nm_device_get_state(self) > NM_DEVICE_STATE_IP_CONFIG)) {
nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP4_CHANGE, self, NULL, NULL, NULL, NULL); nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP4_CHANGE,
self,
NULL,
NULL,
NULL,
NULL);
}
} }
if (!IS_IPv4) {
/* Check if we have to wait for DAD */
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
priv->dad6_ip6_config = dad6_get_pending_addresses(self);
if (priv->dad6_ip6_config) {
_LOGD(LOGD_DEVICE | LOGD_IP6, "IPv6 DAD: awaiting termination");
} else {
_set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_DONE);
check_ip_state(self, FALSE, TRUE);
}
}
}
if (IS_IPv4) {
/* Send ARP announcements */ /* Send ARP announcements */
if (nm_device_is_master(self)) { if (nm_device_is_master(self)) {
@@ -11762,12 +11829,31 @@ activate_stage5_ip_config_result_4(NMDevice *self)
if (do_announce) if (do_announce)
nm_device_arp_announce(self); nm_device_arp_announce(self);
}
if (IS_IPv4) {
/* Enter the IP_CHECK state if this is the first method to complete */ /* Enter the IP_CHECK state if this is the first method to complete */
_set_ip_state(self, AF_INET, NM_DEVICE_IP_STATE_DONE); _set_ip_state(self, AF_INET, NM_DEVICE_IP_STATE_DONE);
check_ip_state(self, FALSE, TRUE); check_ip_state(self, FALSE, TRUE);
}
} }
static void
activate_stage5_ip_config_result_4(NMDevice *self)
{
activate_stage5_ip_config_result_x(self, AF_INET);
}
static void
activate_stage5_ip_config_result_6(NMDevice *self)
{
activate_stage5_ip_config_result_x(self, AF_INET6);
}
#define activate_stage5_ip_config_result_x_fcn(addr_family) \
(NM_IS_IPv4(addr_family) ? activate_stage5_ip_config_result_4 \
: activate_stage5_ip_config_result_6)
void void
nm_device_activate_schedule_ip_config_result(NMDevice *self, int addr_family, NMIPConfig *config) nm_device_activate_schedule_ip_config_result(NMDevice *self, int addr_family, NMIPConfig *config)
{ {
@@ -11791,7 +11877,9 @@ nm_device_activate_schedule_ip_config_result(NMDevice *self, int addr_family, NM
_set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_CONF); _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); activation_source_schedule(self,
activate_stage5_ip_config_result_x_fcn(addr_family),
addr_family);
} }
NMDeviceIPState NMDeviceIPState
@@ -11872,90 +11960,6 @@ dad6_get_pending_addresses(NMDevice *self)
return dad6_config; return dad6_config;
} }
static void
activate_stage5_ip_config_result_6(NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
NMActRequest * req;
const char * method;
int ip_ifindex;
int errsv;
req = nm_device_get_act_request(self);
g_assert(req);
/* Interface must be IFF_UP before IP config can be applied */
ip_ifindex = nm_device_get_ip_ifindex(self);
g_return_if_fail(ip_ifindex);
if (!nm_platform_link_is_up(nm_device_get_platform(self), ip_ifindex)
&& !nm_device_sys_iface_state_is_external_or_assume(self)) {
nm_platform_link_set_up(nm_device_get_platform(self), ip_ifindex, NULL);
if (!nm_platform_link_is_up(nm_device_get_platform(self), ip_ifindex))
_LOGW(LOGD_DEVICE,
"interface %s not up for IP configuration",
nm_device_get_ip_iface(self));
}
if (ip_config_merge_and_apply(self, AF_INET6, TRUE)) {
if (priv->dhcp6.mode != NM_NDISC_DHCP_LEVEL_NONE
&& 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.
*/
nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP6_CHANGE,
self,
NULL,
NULL,
NULL,
NULL);
} else {
/* still waiting for first dhcp6 lease. */
return;
}
}
/* Start IPv6 forwarding if we need it */
method = nm_device_get_effective_ip_config_method(self, AF_INET6);
if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) {
if (!nm_platform_sysctl_set(
nm_device_get_platform(self),
NMP_SYSCTL_PATHID_ABSOLUTE("/proc/sys/net/ipv6/conf/all/forwarding"),
"1")) {
errsv = errno;
_LOGE(LOGD_SHARING,
"share: error enabling IPv6 forwarding: (%d) %s",
errsv,
nm_strerror_native(errsv));
nm_device_ip_method_failed(self,
AF_INET6,
NM_DEVICE_STATE_REASON_SHARED_START_FAILED);
return;
}
}
/* Check if we have to wait for DAD */
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
priv->dad6_ip6_config = dad6_get_pending_addresses(self);
if (priv->dad6_ip6_config) {
_LOGD(LOGD_DEVICE | LOGD_IP6, "IPv6 DAD: awaiting termination");
} else {
_set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_DONE);
check_ip_state(self, FALSE, TRUE);
}
}
} else {
_LOGW(LOGD_DEVICE | LOGD_IP6, "Activation: Stage 5 of 5 (IPv6 Commit) failed");
nm_device_ip_method_failed(self, AF_INET6, NM_DEVICE_STATE_REASON_CONFIG_FAILED);
}
}
/*****************************************************************************/ /*****************************************************************************/
static void static void
@@ -14251,7 +14255,8 @@ queued_ip_config_change(NMDevice *self, int addr_family)
* update in such case. * update in such case.
*/ */
if (priv->activation_source_id_x[IS_IPv4] != 0 if (priv->activation_source_id_x[IS_IPv4] != 0
&& priv->activation_source_func_x[IS_IPv4] == activate_stage5_ip_config_result_x[IS_IPv4]) && priv->activation_source_func_x[IS_IPv4]
== activate_stage5_ip_config_result_x_fcn(addr_family))
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
priv->queued_ip_config_id_x[IS_IPv4] = 0; priv->queued_ip_config_id_x[IS_IPv4] = 0;