ipv6: check mc_forwarding before calling ip6mr_get_route()
Subsystems (3)
PATCH v4 1/1 ipv6: check mc_forwarding before calling ip6mr_get_route()
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.
---
Changes in v4:
- Converge the series back into a focused single patch and drop patch
2/2 ("ipv6: preserve ip6mr_get_route() error in rt6_fill_node()") so
we do not alter the -EMSGSIZE errno to a misleading -ENODEV while ip6mr_get_route() still lacks skb->dev and (S,G) parameters.
- Check dest != NULL (so RTM_F_FIB_MATCH queries bypass
ip6mr_get_route() and return the matched FIB6 entry with RTA_IIF) and
keep ipv6_addr_is_multicast(&rt6_dst->addr) (avoiding regression on non-multicast matched routes such as ::/0), while testing
ipv6_addr_type(dest) against `IPV6_ADDR_LOOPBACK |
IPV6_ADDR_LINKLOCAL`, per Sashiko review.
- Add UML tests for RTM_F_FIB_MATCH and non-multicast matched routes
(::/0) with MRT6_INIT enabled.
- Link to v3: https://lore.kernel.org/netdev/[email protected]/
Changes in v3:
- Also exclude interface-local (IPV6_ADDR_LOOPBACK) and link-local (IPV6_ADDR_LINKLOCAL) multicast and drop Hangbin Liu's Reviewed-by tag
due to the code change.
- Link to v2: https://lore.kernel.org/netdev/[email protected]/
Changes in v2:
- Reword commit message for clearer tone.
- Link to v1: https://lore.kernel.org/netdev/[email protected]/
net/ipv6/route.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv6/route.c +4 -1
@@ -5868,7 +5868,10 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb,#endif if (iif) {#ifdef CONFIG_IPV6_MROUTE -if (ipv6_addr_is_multicast (&rt6_dst->addr)) { +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)) {int err =ip6mr_get_route (net, skb, rtm, portid);if (err ==0 )
Signature · 1 line
2.33.0
Quoted 38 lines · Wenbo Sun
When
CONFIG_IPV6_MROUTEis enabled,rt6_fill_node()currently callsip6mr_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_forwardingis 0);
2. The queried destination address (dest) has interface-local (IPV6_ADDR_LOOPBACK) or link-local (IPV6_ADDR_LINKLOCAL) scope, whichip6_mc_input()never forwards;
3. The query requests a raw FIB entry viaRTM_F_FIB_MATCH(whereinet6_rtm_getroute()passes dest as NULL), for which IPv4 usesfib_dump_info()rather thanipmr_get_route().In those cases, calling
ip6mr_get_route()falls into the cache-miss path (whereskb->devis not set byinet6_rtm_getroute()) and fails, causingrt6_fill_node()to jump tonla_put_failureand return-EMSGSIZEinstead of emittingRTA_IIFand the matched route attributes. Note that supporting MFC cache lookups whenmc_forwardingis enabled for routable multicast groups would also require passing the queried (S,G) and input device intoip6mr_get_route(), which is left out of scope for this change.Align
rt6_fill_node()with IPv4rt_fill_info()andip6_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, andmc_forwardingis enabled before callingip6mr_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_forwardingdisabled, link-local (ff02::1) and interface-local (ff01::1) queries withmc_forwardingenabled,RTM_F_FIB_MATCHqueries, and queries matching a non-multicast route (::/0) all succeed and reportRTA_IIF.
Quoted 4 lines
Built with W=1 on UML,
x86_64allmodconfig, andx86_64allyesconfig with zero new warnings or errors.Signed-off-by Wenbo Sun <[email protected]>
This patch was applied to netdev/net-next.git (main) by Willem de Bruijn <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Willem de Bruijn <[email protected]>:
Quoted 15 lines · On Fri, 20 Nov 2026 11:23:27 +0800 you wrote:
When
CONFIG_IPV6_MROUTEis enabled,rt6_fill_node()currently callsip6mr_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_forwardingis 0);
2. The queried destination address (dest) has interface-local (IPV6_ADDR_LOOPBACK) or link-local (IPV6_ADDR_LINKLOCAL) scope, whichip6_mc_input()never forwards;
3. The query requests a raw FIB entry viaRTM_F_FIB_MATCH(whereinet6_rtm_getroute()passes dest as NULL), for which IPv4 usesfib_dump_info()rather thanipmr_get_route().
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v4] ipv6: check mc_forwarding before calling ip6mr_get_route()
https://git.kernel.org/netdev/net-next/c/dddb95f652f3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html