Re: [PATCH net-next] ipv6: check mc_forwarding before calling ip6mr_get_route()
From: Wenbo Sun
Date: Thu Nov 12 2026 - 02:17:15 EST
Hi Hangbin,
Thanks for the review and the Reviewed-by tag!
On Thu, Nov 12, 2026 at 02:14:50AM +0000, Hangbin Liu wrote:
> In commit fd61c6ba313d ("net: ipv6: remove nowait arg to rt6_fill_node"),
> David Ahern removed the nowait arg. Should we still return immediately
> after err == 0? Also later if (err < 0), it still goto nla_put_failure
> and return -EMSGSIZE. Maybe we can carry the err to the end and return
> a more meaningful reason?
>
> Anyway the added checking makes sense to me.
>
> Reviewed-by: Hangbin Liu <liuhangbin@xxxxxxxxxx>
Both are very good observations on the existing ip6mr_get_route() error
handling in rt6_fill_node():
1) Regarding `if (err == 0) return 0;`:
Commit fd61c6ba313d only removed the unused `nowait` parameter (whose
value was always 0) and kept the pre-existing `!nowait && err == 0`
early return, mirroring IPv4 rt_fill_info(). Returning 0 from
ip6mr_get_route() means a cache miss was queued via
ip6mr_cache_unresolved() on nl_queries for asynchronous resolution;
falling through in rt6_fill_node() would append normal FIB attributes
without RTA_IIF.
That said, looking closely at inet6_rtm_getroute(), `skb->dev` is
currently never assigned there (unlike inet_rtm_getroute() in IPv4),
so on a cache miss ip6mr_get_route() takes `if (!dev || ...)` and
returns -ENODEV before ever reaching ip6mr_cache_unresolved(). Even
if `err == 0` were reached, returning 0 early skips nlmsg_end() while
inet6_rtm_getroute() still calls rtnl_unicast() when `err >= 0`.
Reworking that path would require changes in ip6mr.c and
inet6_rtm_getroute(), which goes beyond this patch's scope.
2) Regarding returning the real negative `err` instead of -EMSGSIZE:
Agreed -- ip6mr_get_route() can return -ENOENT, -ENODEV, -ENOMEM, or
-ENOBUFS, and jumping to nla_put_failure masks all of them as
-EMSGSIZE ("Message too long") even when mc_forwarding is enabled.
Among all callers of rt6_fill_node(), only inet6_rtm_getroute() passes
a non-zero iif and propagates negative errors back to userspace, so
initializing `int err = -EMSGSIZE;` and returning `err` at the failure
label looks safe and much cleaner.
To make it easy to review both together while keeping each change clear,
I plan to split this into a 2-patch [PATCH net-next v2 1/2] + [2/2]
series after the 24-hour resend window:
- Patch 1/2: check mc_forwarding before calling ip6mr_get_route()
(carrying your Reviewed-by: Hangbin Liu <liuhangbin@xxxxxxxxxx>).
- Patch 2/2: preserve and return the negative error from
ip6mr_get_route() in rt6_fill_node() instead of -EMSGSIZE.
Thanks,
Wenbo