Re: [PATCH net-next v3 1/2] ipv6: check mc_forwarding before calling ip6mr_get_route()
From: Hangbin Liu
Date: Mon Nov 23 2026 - 01:17:18 EST
On Fri, Nov 20, 2026 at 11:22:19AM +0800, Wenbo Sun wrote:
> Thank you for the detailed review on v3 1/2. We reproduced and verified each
> of the findings in a User-Mode Linux (UML) environment (`CONFIG_IPV6_MROUTE=y`)
> and prepared a focused single-patch v4 to address them:
>
> 1. Root-Cause Analysis & Local UML Reproduction of v3 1/2 Findings:
>
> Base UML topology:
> ip link add d0 type veth peer name d1
> ip link set d0 up && ip link set d1 up
> ip -6 addr add 2001:db8::2/64 dev d0
> ip -6 addr add ff0e::1 dev d0 autojoin
>
> (a) [High] Routable multicast query when mc_forwarding=1:
> In `inet6_rtm_getroute()`, `skb->dev` is never set on the newly
> allocated reply skb, and `ip6mr_get_route()` looks up
> `ip6mr_cache_find(mrt, &rt->rt6i_src.addr, &rt->rt6i_dst.addr)`, where
> `rt` is the per-CPU route copied from `f6i->fib6_dst` (`ff00::/8`).
> We reproduced this in UML by opening an `AF_INET6` `SOCK_RAW`
> (`IPPROTO_ICMPV6`) socket, enabling `MRT6_INIT`, registering `d0` via
> `MRT6_ADD_MIF`, and adding `(S=2001:db8::3, G=ff0e::1)` via
> `MRT6_ADD_MFC`:
> MRT6_ADD_MIF(mifi=0, pifi=3) OK
> MRT6_ADD_MFC(S=2001:db8::3, G=ff0e::1) OK
> mc_forwarding=1
> $ ip -6 route get ff0e::1 from 2001:db8::3 iif d0
> RTNETLINK answers: No such device
> ip_exit=512
> Because `ip6mr_get_route()` checks `(::, ff00::)` instead of the
> queried `(S,G)` and `skb->dev` is NULL, it misses even when the MFC
> entry exists. Making `mc_forwarding=1` MFC queries work requires
> passing `(src, dest)` and handling `skb->dev` / `skb_realloc_headroom()`
> across `inet6_rtm_getroute()` and `ip6mr_get_route()`, which we now
> explicitly state as out of scope in the commit message and drop patch
> 2/2 in v4 so we do not alter the uAPI errno to -ENODEV prematurely.
>
> (b) [Medium 1] Regression when a multicast query matches a non-multicast
> route (e.g. `::/0`):
> In v3, replacing `ipv6_addr_is_multicast(&rt6_dst->addr)` with
> `ipv6_addr_is_multicast(mc_dst)` caused queries matching a non-multicast
> FIB route (when `ff00::/8` is absent, such as on `lo`, an l3mdev
> master, or after deleting `ff00::/8`) to enter `ip6mr_get_route()` when
> `mc_forwarding=1`.
> Reproduced on v3 in UML:
> # ip -6 route del multicast ff00::/8 dev d0 table local
> # ip -6 route add ::/0 dev d0
> # (with MRT6_INIT / mc_forwarding=1):
> $ ip -6 route get ff0e::1 from 2001:db8::3 iif d0
> RTNETLINK answers: No such device
> ip_exit=512
>
> (c) [Medium 2] `RTM_F_FIB_MATCH` (`fibmatch`) missing link-local exclusion:
> In `inet6_rtm_getroute()`, the `fibmatch` branch calls `rt6_fill_node()`
> with `dst = NULL, dest = NULL`. In v3, `mc_dst` fell back to
> `&rt6_dst->addr` (`ff00::`, scope 0), so link-local `fibmatch` queries
> still entered `ip6mr_get_route()` when `mc_forwarding=1` (whereas IPv4
> `fibmatch` uses `fib_dump_info()` and never calls `ipmr_get_route()`).
> Reproduced on v3 in UML (with `MRT6_INIT` / `mc_forwarding=1`):
> $ ip -6 route get fibmatch ff02::1 from 2001:db8::3 iif d0
> RTNETLINK answers: No such device
> ip_exit=512
>
> (d) [Low] Fixes tag / net vs net-next:
> Because this patch aligns long-standing non-crash route-get reporting
> semantics with IPv4 (while full `mc_forwarding=1` MFC lookup in
> `ip6mr_get_route()` remains a separate effort), we keep targeting
> net-next without a Fixes tag, and have softened the commit message
> accordingly.
>
> 2. Concrete Fix in v4 & UML Verification Results:
>
> In v4, we converge the series into a single patch that checks `dest != NULL`
> (so `fibmatch` queries always emit the matched FIB6 entry and `RTA_IIF`),
> keeps `ipv6_addr_is_multicast(&rt6_dst->addr)` (avoiding the non-multicast
> route regression), and tests `ipv6_addr_type(dest)` against
> `(IPV6_ADDR_LOOPBACK | IPV6_ADDR_LINKLOCAL)`:
>
> if (dest && ipv6_addr_is_multicast(&rt6_dst->addr) &&
> !(ipv6_addr_type(dest) &
> (IPV6_ADDR_LOOPBACK | IPV6_ADDR_LINKLOCAL)) &&
> atomic_read(&net->ipv6.devconf_all->mc_forwarding))
>
> Verified on v4 in UML (`FAILURES=0, TEST_EXIT_CODE=0`):
> - Test 1 (`mc_forwarding=0`, `ff0e::1` with `iif d0`):
> `ff0e::1 dev d0 proto kernel metric 256 iif d0 pref medium` (PASS)
> - Test 2 (`mc_forwarding=1`, link-local `ff02::1` with `iif d0`):
> `multicast ff02::1 dev d0 proto kernel metric 256 iif d0 pref medium` (PASS)
> - Test 3 (`mc_forwarding=1`, interface-local `ff01::1` with `iif d0`):
> `multicast ff01::1 dev d0 proto kernel metric 256 iif d0 pref medium` (PASS)
> - Test 4 (`mc_forwarding=1`, `fibmatch` for `ff02::1` and `ff0e::1` with
> `iif d0`):
> `multicast ff00::/8 dev d0 table local proto kernel metric 256 iif d0 pref medium`
> (`ip_exit=0`, PASS)
> - Test 5 (`mc_forwarding=1`, `ff0e::1` matching `::/0` after removing
> `ff00::/8`):
> `ff0e::1 from 2001:db8::3 dev d0 proto boot src 2001:db8::2 metric 1024 iif d0 pref medium`
> (`ip_exit=0`, PASS)
> - Test 6 (IPv6 unicast with `iif`, IPv6 multicast without `iif`, IPv4
> multicast with `iif` regressions): all PASS.
>
> Thanks,
> Wenbo
>
I think it worth to add a selftest to cover these testings.
Thanks
Hangbin