When CONFIG_IPV6_MROUTE is enabled, rt6_fill_node() currently calls ip6mr_get_route() whenever an input interface (RTA_IIF) is specified and the route destination is multicast. However, inet6_rtm_getroute() does not set skb->dev on the newly allocated reply skb, and the looked-up rt6_info carries the matched FIB6 prefix (such as ff00::/8 from addrconf_add_mroute()) rather than the queried (S,G) addresses. As a result, when multicast forwarding is disabled (mc_forwarding is 0), ip6mr_get_route() falls into the cache-miss check and returns -ENODEV, causing rt6_fill_node() to jump to nla_put_failure and report -EMSGSIZE ("RTNETLINK answers: Message too long") to userspace. Similarly, interface-local and link-local multicast groups are never forwarded by ip6_mc_input(), so querying them with mc_forwarding enabled also enters ip6mr_get_route() and fails instead of reporting the local route. In contrast, the IPv4 counterpart rt_fill_info() guards ipmr_get_route() with !ipv4_is_local_multicast(dst) and IPV4_DEVCONF_ALL_RO(net, MC_FORWARDING), falling back to emitting RTA_IIF and normal route attributes. To align IPv6 behavior with IPv4 and ip6_mc_input(), check that mc_forwarding is non-zero and that the destination (dest when available, otherwise rt6_dst->addr) is neither interface-local (IPV6_ADDR_LOOPBACK) nor link-local (IPV6_ADDR_LINKLOCAL) multicast before calling ip6mr_get_route(). This discrepancy was identified with the assistance of an LLM-based code review comparing IPv4 and IPv6 multicast route get handling, confirmed on a UML kernel where multicast route queries with an input interface failed on an unpatched kernel, and verified in UML that routable multicast queries with mc_forwarding disabled as well as link-local (ff02::1) and interface-local (ff01::1) queries with mc_forwarding enabled now 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 --- net/ipv6/route.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 1b2dcc066e19..27597d149672 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -5868,7 +5868,12 @@ 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)) { + const struct in6_addr *mc_dst = dest ? : &rt6_dst->addr; + + if (ipv6_addr_is_multicast(mc_dst) && + !(ipv6_addr_type(mc_dst) & + (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) -- 2.33.0 In rt6_fill_node(), when ip6mr_get_route() fails with a negative error (for example -ENODEV, -ENOENT, -ENOMEM, or -ENOBUFS), the error path currently jumps to nla_put_failure and unconditionally returns -EMSGSIZE ("RTNETLINK answers: Message too long"). Among all callers of rt6_fill_node(), only inet6_rtm_getroute() passes a non-zero input interface (RTA_IIF) and propagates negative errors back to userspace. Keeping -EMSGSIZE as the default return value for attribute put failures while preserving the negative error returned by ip6mr_get_route() lets userspace see the actual failure reason when multicast forwarding is enabled. This issue was pointed out during code review of rt6_fill_node() by Hangbin Liu, confirmed on a UML kernel with MRT6_INIT enabled (where querying a routable multicast route with an input interface reported "Message too long" despite the failure in ip6mr_get_route() being -ENODEV), and verified after the patch that it returns -ENODEV ("No such device") instead while other rt6_fill_node() paths behave unchanged. Built with W=1 on UML, x86_64 allmodconfig, and x86_64 allyesconfig with zero new warnings or errors. Suggested-by: Hangbin Liu Reviewed-by: Hangbin Liu Signed-off-by: Wenbo Sun --- net/ipv6/route.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 27597d149672..d59aa9272a44 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -5814,6 +5814,7 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb, struct nlmsghdr *nlh; struct rtmsg *rtm; long expires = 0; + int err = -EMSGSIZE; nlh = nlmsg_put(skb, portid, seq, type, sizeof(*rtm), flags); if (!nlh) @@ -5874,12 +5875,14 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb, !(ipv6_addr_type(mc_dst) & (IPV6_ADDR_LOOPBACK | IPV6_ADDR_LINKLOCAL)) && atomic_read(&net->ipv6.devconf_all->mc_forwarding)) { - int err = ip6mr_get_route(net, skb, rtm, portid); + int ret = ip6mr_get_route(net, skb, rtm, portid); - if (err == 0) + if (ret == 0) return 0; - if (err < 0) + if (ret < 0) { + err = ret; goto nla_put_failure; + } } else #endif if (nla_put_u32(skb, RTA_IIF, iif)) @@ -6002,7 +6005,7 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb, nla_put_failure: nlmsg_cancel(skb, nlh); - return -EMSGSIZE; + return err; } static int fib6_info_nh_uses_dev(struct fib6_nh *nh, void *arg) -- 2.33.0