Re: [PATCH net-next v4] ipv6: check mc_forwarding before calling ip6mr_get_route()
From: Ido Schimmel
Date: Tue Nov 24 2026 - 09:43:23 EST
On Fri, Nov 20, 2026 at 11:23:27AM +0800, Wenbo Sun wrote:
> When CONFIG_IPV6_MROUTE is enabled, rt6_fill_node() currently calls
> ip6mr_get_route() whenever an input interface (RTA_IIF) is specified and
> the matched route prefix (rt6_dst->addr) is multicast.
>
> However, ip6mr_get_route() should not be invoked in three cases where
> the kernel does not perform multicast forwarding lookup:
> 1. Multicast forwarding is disabled in the network namespace
> (mc_forwarding is 0);
> 2. The queried destination address (dest) has interface-local
> (IPV6_ADDR_LOOPBACK) or link-local (IPV6_ADDR_LINKLOCAL) scope, which
> ip6_mc_input() never forwards;
> 3. The query requests a raw FIB entry via RTM_F_FIB_MATCH (where
> inet6_rtm_getroute() passes dest as NULL), for which IPv4 uses
> fib_dump_info() rather than ipmr_get_route().
>
> In those cases, calling ip6mr_get_route() falls into the cache-miss path
> (where skb->dev is not set by inet6_rtm_getroute()) and fails, causing
> rt6_fill_node() to jump to nla_put_failure and return -EMSGSIZE instead
> of emitting RTA_IIF and the matched route attributes. Note that
> supporting MFC cache lookups when mc_forwarding is enabled for routable
> multicast groups would also require passing the queried (S,G) and input
> device into ip6mr_get_route(), which is left out of scope for this
> change.
>
> Align rt6_fill_node() with IPv4 rt_fill_info() and ip6_mc_input() by
> requiring that dest is non-NULL, the matched route prefix
> (rt6_dst->addr) is multicast, dest is neither interface-local nor
> link-local multicast, and mc_forwarding is enabled before calling
> ip6mr_get_route().
>
> This alignment was identified with the assistance of an LLM-based code
> review comparing IPv4 and IPv6 multicast route get handling, confirmed
> in a User-Mode Linux (UML) environment, and verified in UML that
> routable multicast queries with mc_forwarding disabled, link-local
> (ff02::1) and interface-local (ff01::1) queries with mc_forwarding
> enabled, RTM_F_FIB_MATCH queries, and queries matching a non-multicast
> route (::/0) all succeed and report RTA_IIF.
>
> Built with W=1 on UML, x86_64 allmodconfig, and x86_64 allyesconfig with
> zero new warnings or errors.
>
> Signed-off-by: Wenbo Sun <sunwenbo@xxxxxxxxxxxxxxxxxxxx>
Reviewed-by: Ido Schimmel <idosch@xxxxxxxxxx>