Article View: linux.kernel.netdev
Article #19582[PATCH net-next v4] ipv6: check mc_forwarding before calling ip6mr_get_route()
From: Wenbo Sun
Date: Fri, 20 Nov 2026 03:23
Date: Fri, 20 Nov 2026 03:23
90 lines
12551 bytes
12551 bytes
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@cmss.chinamobile.com>
---
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/20261116014744.18223-1-sunwenbo@cmss.chinamobile.com/
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/20261112094630.197244-1-sunwenbo@cmss.chinamobile.com/
Changes in v2:
- Reword commit message for clearer tone.
- Link to v1: https://lore.kernel.org/netdev/20261111094528.425826-1-sunwenbo@cmss.chinamobile.com/
net/ipv6/route.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 1b2dcc066e19..419161269701 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -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)
--
2.33.0
Technical Details
Message-ID:
<20261120032327.18375-1-sunwenbo@cmss.chinamobile.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367599-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367599-linux-kernel-netdev=dewy.ru From: sunwenbo@cmss.chinamobile.com (Wenbo Sun) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v4] ipv6: check mc_forwarding before calling ip6mr_get_route() Date: Fri, 20 Nov 2026 11:23:27 +0800 Organization: Usenet Network Message-ID: <20261120032327.18375-1-sunwenbo@cmss.chinamobile.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3049122"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:Qik8YX/93/eSuVfFcCf5sP88zuk= sha256:x3eCkB1/ZPsETJhadKWmy1dcdwm6iBku7A6tUfUxfsY= sha1:mRd36Tg7XSAMsvVCtX3d+MfwHuA= sha256:OyLu3nIBlgnoIMlP+Ifji4/D4V9slew34rGmWhBxXv8= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id C2DB111587F; Fri, 20 Nov 2026 06:24:04 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.85 X-Spam-Status: No, score=-2.85 tagged_above=-9999 required=6.31 tests=[DKIM_INVALID=0.1, DKIM_SIGNED=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=fail (1024-bit key) reason="fail (body has been altered)" header.d=cmss.chinamobile.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DKA7klKpU4pH; Fri, 20 Nov 2026 06:24:01 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-367599-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=cmss.chinamobile.com X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id F320011587B; Fri, 20 Nov 2026 06:23:52 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id B52B6641C0A; Fri, 20 Nov 2026 03:23:51 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1795145028; b=vtM4PQTYkKRla57/QqCRUT+QxEaKEgqULoiPShAk7dzKg7oGIQjsh246ywcDEgHjJTaI 46x/IHoYktMrvb8a8crT+ilmh67yILQQp0wJLyjr5Lk9x25wdIEs7BL6o/aPzjROWLego E4XfeXxf6TWYGbftxfMyRsLeF2WUr5JFXonA7AdpWc2GGX9VHw5asGUY+puw9YpWbr573 OE26ni3ls9rzhg8ddhQ2DYag6Bo2qv/cFUNiHhQB4fkr65dGTcKY3cmUPrf7C+Hq/ZOM6 /wokpNV70UNM5X5muaHHXpV25/m+EgfSksR6uugm/H5Pd7fI/wV4N0TaBzq2Yk3LHmg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795145028; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:X-RM-TagInfo: X-RM-SPAM-FLAG:Received:X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG: Received:X-RM-TRANSID:From:To:Cc:Subject:Date:Message-Id:X-Mailer: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding; bh=7nYL4hSIO74kr4TiC7Rkam1cn1cFWaksrMGkbt493mw=; b=V3P2N7PFLAkn42kKBtsS/iEgTgOSRUebAf6KfpSNHBZMBlRisdQrlh4/yiyUuFKWlNe2 vxQ1b20DfcK3OI+ImhV/gkqLRIU4cVw0R8UoUhgAFUslLJcT71feh6R4gKbv5/bkm5Z4c jhqgJvaSZ5iwQejvSBWj8hwUOSAGD8vczsr/qUBjUcMLU2w6QRWk1pzMaTKhe59xbtHe/ 6BJStdJB7AP/TGEHwFHnBkigfIylos5rPUro6/TMVHJEXxU6Xr1J1ngpjmqzcpyLMiRvW 8zI4S5kI+YCOK3Kgu3KmrNGXTfyGcQJ/JN7kTkrgXtGykoD6iP0EDkwiqxhpzsZeVwg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=HjZEkKyl; dmarc=pass header.from=cmss.chinamobile.com; spf=pass smtp.mailfrom=cmss.chinamobile.com; arc=fail smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E09C660A260C; Fri, 20 Nov 2026 03:23:47 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=HjZEkKyl X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.151 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795145027; b=RYBg6QrWGGFqeF/Cvhu3AMeN8hsUxFcAv7OyrJL0J1NAYM/F5WP/CeTHe8Yqz/S4drtH OryRTapIh5NxXm2keVms3DfCVKvzRritQeUsXQz4uvNEBIx3nBpNgcaoMzhRdRq++v5k3 Bl5TUzTbxs33IY9hcuG9hrP4l6F6NCXUnfm6dqmQyovpVJhG8X/lRAJGkIiTbvovtjHOo PtKLbIZmE0xE5Cg8i1RfEcnmK7gyYIVIJ6TpO4o1bdG2ttMCVosTzN5ZlH65O6PusPXlV ydcDBYLL+kSRkPIouLJ5tSS6I9FsyTK0zPkSQt2mnYFjAoZKb5OzLJcCPIy5ZnYm4Hw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795145027; h=DMARC-Filter:DKIM-Signature:X-RM-TagInfo:X-RM-SPAM-FLAG:Received: X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:X-RM-TRANSID:From: To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=7nYL4hSIO74kr4TiC7Rkam1cn1cFWaksrMGkbt493mw=; b=aRqSvREW24DbxDvacLu2O+/xE4npCL0jU0jHA1jiru/EEXFjFCP4GZF/oU9/MAfl7lcn hHMrrYKehNwj0V5IssmgMewMrWSmakwqixM1g1IbPsW2OWYEoRU4Aj1COqmbzbxtYNJY6 rIWZVdKLy5GX/sEbV0EiiCtKXd5GvLrs7vmBCFvHmeBL8LYBpA2Iz7x1sruUnSyAB5nC9 pp+iSNHsrUYIADvbyto70MiUlsEihP18fLUKPORrEnJZtKvnr7bNEKcyaGVYCmMgWvQnw WBYIGwFN8Ju4vQaLNbJBv9y+CeniVx6rGcYGskE+rZfVXn3zao4bu3KPt9neVk/XohQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=cmss.chinamobile.com; spf=pass smtp.mailfrom=cmss.chinamobile.com; dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=HjZEkKyl; arc=none smtp.remote-ip=111.22.67.151 X-Received: from cmccmta8.chinamobile.com (cmccmta8.chinamobile.com [111.22.67.151]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F0BF606A33E; Fri, 20 Nov 2026 03:23:44 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3F0BF606A33E X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmss.chinamobile.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmss.chinamobile.com; s=default; l=0; h=from:subject:message-id:to:cc:mime-version; bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=; b=HjZEkKylCWcx68Qdtre67jYjfWUPljANgz4ETSqsZhu6j2NPfwc+i/e7OJdexYS9iSwcFm3X+MZX3 a2IyHw6Tiwq/HwM9h2d0DWmS8/JGMN9tsoR7lpmAzsy68hB9SMh/cYm/BDMs6poh1ElRQzrbMlLLGP 1QNmL2WuWxcfeoaw= X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 X-Received: from spf.mail.chinamobile.com (unknown[10.188.0.87]) by rmmx-syy-dmz-app02-12002 (RichMail) with SMTP id 2ee26affbd3b3f1-5fa05; Fri, 20 Nov 2026 11:23:43 +0800 (CST) X-RM-TRANSID: 2ee26affbd3b3f1-5fa05 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 X-Received: from localhost.net (unknown[223.64.113.192]) by rmsmtp-syy-appsvr04-12004 (RichMail) with SMTP id 2ee46affbd3dd45-13b11; Fri, 20 Nov 2026 11:23:43 +0800 (CST) X-RM-TRANSID: 2ee46affbd3dd45-13b11 X-Cc: Simon Horman <horms@kernel.org>, Hangbin Liu <hangbin.liu@linux.dev>, Hangbin Liu <liuhangbin@kylinos.cn>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, sunwenbo@cmss.chinamobile.com, 1342116488@qq.com X-Mailer: git-send-email 2.33.0 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-Received-Bytes: 12265