From 3d9e213e2a4246889bd1d99b645e170765d8171e Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 17 May 2022 14:10:45 +0200 Subject: [PATCH] device: allow override of IPv6 link-local method Some device types might want to use a custom method to set an IPv6 link-local address. For example, with PPP the interface identifier is announced by the server via IPV6CP. --- src/core/devices/nm-device-private.h | 3 ++ src/core/devices/nm-device.c | 43 +++++++++++++++++++++++++++- src/core/devices/nm-device.h | 2 ++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/core/devices/nm-device-private.h b/src/core/devices/nm-device-private.h index b54aed6a75..1b18a03aa8 100644 --- a/src/core/devices/nm-device-private.h +++ b/src/core/devices/nm-device-private.h @@ -104,6 +104,9 @@ nm_device_devip_set_failed(NMDevice *self, int addr_family, NMDeviceStateReason nm_device_devip_set_state_full(self, addr_family, NM_DEVICE_IP_STATE_FAILED, NULL, reason); } +void +nm_device_ipll6_set_state(NMDevice *self, NMDeviceIPState ip_state, const NML3ConfigData *l3cd); + gboolean nm_device_sysctl_ip_conf_set(NMDevice *self, int addr_family, const char *property, diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index cc83c046fd..5833aaab8b 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -10619,7 +10619,8 @@ _dev_ipll6_set_llstate(NMDevice *self, NML3IPv6LLState llstate, const struct in6 || (!priv->ipll_data_6.v6.ipv6ll && NM_IN_SET(priv->ipll_data_6.v6.llstate, NM_L3_IPV6LL_STATE_NONE, - NM_L3_IPV6LL_STATE_DEFUNCT))); + NM_L3_IPV6LL_STATE_DEFUNCT)) + || (!priv->ipll_data_6.v6.ipv6ll && NM_DEVICE_GET_CLASS(self)->ipll6_start)); switch (priv->ipll_data_6.v6.llstate) { case NM_L3_IPV6LL_STATE_NONE: @@ -10680,6 +10681,39 @@ _dev_ipll6_set_llstate(NMDevice *self, NML3IPv6LLState llstate, const struct in6 } } +void +nm_device_ipll6_set_state(NMDevice *self, NMDeviceIPState ip_state, const NML3ConfigData *l3cd) +{ + NMDedupMultiIter iter; + const NMPlatformIP6Address *pladdr = NULL; + NML3IPv6LLState llstate; + + switch (ip_state) { + case NM_DEVICE_IP_STATE_PENDING: + llstate = NM_L3_IPV6LL_STATE_STARTING; + break; + case NM_DEVICE_IP_STATE_READY: + nm_assert(l3cd); + llstate = NM_L3_IPV6LL_STATE_READY; + break; + case NM_DEVICE_IP_STATE_FAILED: + llstate = NM_L3_IPV6LL_STATE_DEFUNCT; + break; + default: + nm_assert_not_reached(); + } + + if (l3cd) { + nm_l3_config_data_iter_ip6_address_for_each (&iter, l3cd, &pladdr) + break; + } + + if (ip_state == NM_DEVICE_IP_STATE_READY) + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_LL_6, l3cd, FALSE); + + _dev_ipll6_set_llstate(self, llstate, pladdr ? &pladdr->address : NULL); +} + static void _dev_ipll6_state_change_cb(NML3IPv6LL *ipv6ll, NML3IPv6LLState llstate, @@ -10691,6 +10725,12 @@ _dev_ipll6_state_change_cb(NML3IPv6LL *ipv6ll, static void _dev_ipll6_start(NMDevice *self) +{ + NM_DEVICE_GET_CLASS(self)->ipll6_start(self); +} + +static void +ipll6_start(NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMConnection *connection; @@ -17742,6 +17782,7 @@ nm_device_class_init(NMDeviceClass *klass) klass->can_reapply_change = can_reapply_change; klass->reapply_connection = reapply_connection; klass->set_platform_mtu = set_platform_mtu; + klass->ipll6_start = ipll6_start; klass->rfkill_type = NM_RFKILL_TYPE_UNKNOWN; diff --git a/src/core/devices/nm-device.h b/src/core/devices/nm-device.h index 377c2fb6b8..734ccbd9bf 100644 --- a/src/core/devices/nm-device.h +++ b/src/core/devices/nm-device.h @@ -417,6 +417,8 @@ typedef struct _NMDeviceClass { gboolean (*set_platform_mtu)(NMDevice *self, guint32 mtu); const char *(*get_dhcp_anycast_address)(NMDevice *self); + + void (*ipll6_start)(NMDevice *self); } NMDeviceClass; GType nm_device_get_type(void);