diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2020-05-28 18:38:59 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2020-05-28 18:38:59 +0200 |
commit | da3b534d456c00f226fb0c89ff805d4ca90ef35b (patch) | |
tree | 457aaa9f5cd0d2b5a4150784646f97bc74b0c113 | |
parent | b74c333413dfeaff5fb6007981c41c5fcfe8cb4c (diff) | |
parent | 49305559dc2a1244a3c9c80e9cec2a0d0c25960d (diff) | |
download | NetworkManager-da3b534d456c00f226fb0c89ff805d4ca90ef35b.tar.gz |
merge: branch 'bg/ipv6-kernel-token-rh1819680'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/519
https://bugzilla.redhat.com/show_bug.cgi?id=1819680
-rw-r--r-- | src/devices/nm-device.c | 58 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 1 |
2 files changed, 47 insertions, 12 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index dc46d3f7cc..9b018ccc8c 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1509,6 +1509,50 @@ nm_device_sysctl_ip_conf_get_int_checked (NMDevice *self, fallback); } +static void +set_ipv6_token (NMDevice *self, NMUtilsIPv6IfaceId iid, const char *token_str) +{ + NMPlatform *platform; + int ifindex; + const NMPlatformLink *link; + char buf[32]; + gint64 val; + + /* Setting the kernel token is not strictly necessary as the + * IPv6 address is generated in userspace. However it is + * convenient so that users can see the token with iproute + * ('ip token'). */ + platform = nm_device_get_platform (self); + ifindex = nm_device_get_ip_ifindex (self); + link = nm_platform_link_get (platform, ifindex); + + if (link && link->inet6_token.id == iid.id) { + _LOGT (LOGD_DEVICE | LOGD_IP6, "token %s already set", token_str); + return; + } + + /* The kernel allows setting a token only when 'accept_ra' + * is 1: temporarily flip it if necessary; unfortunately + * this will also generate an additional Router Solicitation + * from kernel. */ + val = nm_device_sysctl_ip_conf_get_int_checked (self, + AF_INET6, + "accept_ra", + 10, + G_MININT32, + G_MAXINT32, + 1); + if (val != 1) + nm_device_sysctl_ip_conf_set (self, AF_INET6, "accept_ra", "1"); + + nm_platform_link_set_ipv6_token (platform, ifindex, iid); + + if (val != 1) { + nm_sprintf_buf (buf, "%d", (int) val); + nm_device_sysctl_ip_conf_set (self, AF_INET6, "accept_ra", buf); + } +} + gboolean nm_device_sysctl_ip_conf_set (NMDevice *self, int addr_family, @@ -8178,23 +8222,13 @@ ip_config_merge_and_apply (NMDevice *self, } if (!IS_IPv4) { - const NMPlatformLink *link; NMUtilsIPv6IfaceId iid; - NMPlatform *platform; - int ifindex; if ( commit && priv->ndisc_started && ip6_addr_gen_token && nm_utils_ipv6_interface_identifier_get_from_token (&iid, ip6_addr_gen_token)) { - platform = nm_device_get_platform (self); - ifindex = nm_device_get_ip_ifindex (self); - link = nm_platform_link_get (platform, ifindex); - - if (link && link->inet6_token.id == iid.id) - _LOGT (LOGD_DEVICE | LOGD_IP6, "token %s already set", ip6_addr_gen_token); - else - nm_platform_link_set_ipv6_token (platform, ifindex, iid); + set_ipv6_token (self, iid, ip6_addr_gen_token); } } @@ -15696,11 +15730,13 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean /* Take out any entries in the routing table and any IP address the device had. */ if (ifindex > 0) { NMPlatform *platform = nm_device_get_platform (self); + NMUtilsIPv6IfaceId iid = { }; nm_platform_ip_route_flush (platform, AF_UNSPEC, ifindex); nm_platform_ip_address_flush (platform, AF_UNSPEC, ifindex); nm_platform_tfilter_sync (platform, ifindex, NULL); nm_platform_qdisc_sync (platform, ifindex, NULL); + set_ipv6_token (self, iid, "::"); } } diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 5ac788f73f..b7a43a0ea1 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1572,7 +1572,6 @@ nm_platform_link_set_ipv6_token (NMPlatform *self, int ifindex, NMUtilsIPv6Iface _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex >= 0, FALSE); - g_return_val_if_fail (iid.id, FALSE); if (klass->link_set_token) return klass->link_set_token (self, ifindex, iid); |