From 74f2c591ec7896c3ccb592ab746b41e87ca64054 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Tue, 5 Mar 2024 13:26:57 -0500 Subject: [PATCH] device: use subnet when the applied connection has IPv6 method shared We should use the IPv6 subnet when we have an applied connection stored on the downlink device, and the IPv6 method should be "shared" for that applied connection. It does not make sense to register l3cd and set router config for ndisc instance when the downlink device is already deactivated. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1880 Resolves: https://issues.redhat.com/browse/RHEL-17350 Signed-off-by: Wen Liang (cherry picked from commit 15901a74892e460721604ddfa5a70e7826bbff8d) (cherry picked from commit 86fbfb3806857335da35851563f0b174ea556a8c) (cherry picked from commit 546dd7017857611e93531c1f67ed6dfedcf126f2) --- src/core/devices/nm-device.c | 49 +++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 7f287e37e1..6a7606456a 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -10766,25 +10766,32 @@ nm_device_needs_ip6_subnet(NMDevice *self) void nm_device_use_ip6_subnet(NMDevice *self, const NMPlatformIP6Address *subnet) { - nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; - char sbuf[NM_UTILS_TO_STRING_BUFFER_SIZE]; - NMPlatformIP6Address address; + NMConnection *connection = nm_device_get_applied_connection(self); - l3cd = nm_device_create_l3_config_data(self, NM_IP_CONFIG_SOURCE_SHARED); + if (connection) { + NMSettingIPConfig *s_ip6 = nm_connection_get_setting_ip6_config(connection); - /* Assign a ::1 address in the subnet for us. */ - address = *subnet; - address.address.s6_addr32[3] |= htonl(1); + if (nm_streq(nm_setting_ip_config_get_method(s_ip6), NM_SETTING_IP6_CONFIG_METHOD_SHARED)) { + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + char sbuf[NM_UTILS_TO_STRING_BUFFER_SIZE]; + NMPlatformIP6Address address; + l3cd = nm_device_create_l3_config_data(self, NM_IP_CONFIG_SOURCE_SHARED); - nm_l3_config_data_add_address_6(l3cd, &address); + /* Assign a ::1 address in the subnet for us. */ + address = *subnet; + address.address.s6_addr32[3] |= htonl(1); - _LOGD(LOGD_IP6, - "ipv6-pd: using %s", - nm_platform_ip6_address_to_string(&address, sbuf, sizeof(sbuf))); + nm_l3_config_data_add_address_6(l3cd, &address); - _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_PD_6, l3cd, FALSE); - _dev_l3_cfg_commit(self, TRUE); - _dev_ipac6_ndisc_set_router_config(self); + _LOGD(LOGD_IP6, + "ipv6-pd: using %s", + nm_platform_ip6_address_to_string(&address, sbuf, sizeof(sbuf))); + + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_PD_6, l3cd, FALSE); + _dev_l3_cfg_commit(self, TRUE); + _dev_ipac6_ndisc_set_router_config(self); + } + } } /* @@ -12183,13 +12190,15 @@ activate_stage3_ip_config(NMDevice *self) ipv6_method = nm_device_get_effective_ip_config_method(self, AF_INET6); if (!g_file_test("/proc/sys/net/ipv6", G_FILE_TEST_IS_DIR)) { - _NMLOG_ip((nm_device_sys_iface_state_is_external(self) || - NM_IN_STRSET(ipv6_method, - NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NM_SETTING_IP6_CONFIG_METHOD_DISABLED, - NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) ? LOGL_DEBUG : LOGL_WARN, + _NMLOG_ip((nm_device_sys_iface_state_is_external(self) + || NM_IN_STRSET(ipv6_method, + NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NM_SETTING_IP6_CONFIG_METHOD_DISABLED, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) + ? LOGL_DEBUG + : LOGL_WARN, AF_INET6, - "IPv6 not supported by kernel resulting in \"ipv6.method=disabled\""); + "IPv6 not supported by kernel resulting in \"ipv6.method=disabled\""); ipv6_method = NM_SETTING_IP6_CONFIG_METHOD_DISABLED; } else if (nm_streq(ipv6_method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { ipv6_method = klass->get_ip_method_auto(self, AF_INET6);