From 5f25baaba435aaa71e63350eac72afbf4d4513fd Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 17 Sep 2021 13:53:18 +0200 Subject: [PATCH] platform: preserve IPv6 multicast route added by kernel Kernels < 5.11 add a route like: unicast ff00::/8 dev $IFACE proto boot scope global metric 256 pref medium to allow sending and receiving IPv6 multicast traffic. Ensure it's not removed it when we do a route sync in mode ALL. In kernel 5.11 there were commits: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ceed9038b2783d14e0422bdc6fd04f70580efb4c https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a826b04303a40d52439aa141035fca5654ccaccd After those the route looks like multicast ff00::/8 dev $IFACE proto kernel metric 256 pref medium As NM ignores routes with rtm_type multicast, the code in this commit is not needed on newer kernels. https://bugzilla.redhat.com/show_bug.cgi?id=2004212 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/984 (cherry picked from commit 8003ca68f770c69e109c16f638abbcce44af9439) (cherry picked from commit ce8eb446b4d9465a906bf8952c1b454dab8d0c7c) --- src/libnm-platform/nm-platform.c | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c index 6c0d0015d6..b7a65df597 100644 --- a/src/libnm-platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -4304,6 +4304,7 @@ nm_platform_ip_route_get_prune_list(NMPlatform * self, CList * iter; NMPlatformIP4Route rt_local4; NMPlatformIP6Route rt_local6; + NMPlatformIP6Route rt_mcast6; const NMPlatformLink * pllink; const NMPlatformLnkVrf * lnk_vrf; guint32 local_table; @@ -4328,6 +4329,7 @@ nm_platform_ip_route_get_prune_list(NMPlatform * self, rt_local4.plen = 0; rt_local6.plen = 0; + rt_mcast6.plen = 0; routes_prune = g_ptr_array_new_full(head_entry->len, (GDestroyNotify) nm_dedup_multi_obj_unref); @@ -4420,6 +4422,43 @@ nm_platform_ip_route_get_prune_list(NMPlatform * self, == 0) continue; } + + /* Kernels < 5.11 add a route like: + * + * unicast ff00::/8 dev $IFACE proto boot scope global metric 256 pref medium + * + * to allow sending and receiving IPv6 multicast traffic. Don't remove it. + * Since kernel 5.11 the route looks like: + * + * multicast ff00::/8 dev $IFACE proto kernel metric 256 pref medium + * + * As NM ignores routes with rtm_type multicast, there is no need for the code + * below on newer kernels. + */ + if (nm_platform_ip_route_get_effective_table(&rt->rx) == local_table + && rt->rx.plen == 8 && rt->rx.rt_source == NM_IP_CONFIG_SOURCE_RTPROT_BOOT + && rt->rx.metric == 256 && rt->r6.rt_pref == NM_ICMPV6_ROUTER_PREF_MEDIUM + && IN6_IS_ADDR_UNSPECIFIED(&rt->r6.gateway)) { + if (rt_mcast6.plen == 0) { + rt_mcast6 = (NMPlatformIP6Route){ + .ifindex = ifindex, + .type_coerced = nm_platform_route_type_coerce(RTN_UNICAST), + .plen = 8, + .rt_source = NM_IP_CONFIG_SOURCE_RTPROT_BOOT, + .metric = 256, + .table_coerced = nm_platform_route_table_coerce(local_table), + .rt_pref = NM_ICMPV6_ROUTER_PREF_MEDIUM, + .gateway = IN6ADDR_ANY_INIT, + .network = {{{0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}}, + }; + } + + if (nm_platform_ip6_route_cmp(&rt->r6, + &rt_mcast6, + NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) + == 0) + continue; + } } break; -- 2.31.1