From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: dsahern@kernel.org,
Stephen Hemminger <stephen@networkplumber.org>,
Yuen Su <zypulsecore@gmail.com>, Ido Schimmel <idosch@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [RFC next-net 1/3] net: accept legacy nexthop attributes when deleting by nexthop id
Date: Fri, 20 Nov 2026 12:01:28 -0800 [thread overview]
Message-ID: <20261120200635.95798-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20261120200635.95798-1-stephen@networkplumber.org>
A route dump expands a nexthop object into the legacy attributes as well
when nexthop_compat_mode is on, which is the default. Both delete paths
then reject the result as "Nexthop specification and nexthop id are
mutually exclusive", so the kernel refuses its own dump output.
That breaks "ip route flush", which dumps routes and sends them back as
RTM_DELROUTE:
# ip nexthop add id 101 via 192.0.2.1 dev dummy0
# ip route add 203.0.113.0/24 nhid 101
# ip route show 203.0.113.0/24
203.0.113.0/24 nhid 101 via 192.0.2.1 dev dummy0
# ip route flush to 203.0.113.0/24
Failed to send flush request: Invalid argument
Setting nexthop_compat_mode to 0 drops the legacy attributes and the same
flush works, so the round trip is all that's wrong here. Any client that
deletes a route by echoing a dump hits this, so fix it once in the kernel.
Ignore the legacy attributes on RTM_DELROUTE when RTA_NH_ID is present.
The id is already authoritative in the matching code: fib_nh_match()
decides on cfg->fc_nh_id alone, and ip6_route_del() compares rt->nh->id
and skips the device and gateway tests for nexthop-backed routes.
RTM_NEWROUTE still rejects the combination.
Clear the parsed fields next to the existing exclusivity check rather
than filtering inside the attribute loop. The lwtunnel validation done
there cannot reject a dumped route, because an encap route holds a
reference on its encap module for as long as it exists. IPv6 drops the
attributes in rtm_to_fib6_config() the same way.
A delete passing both an id and a nexthop spec now ignores the spec. The
request can't tell a hand-written gateway from a dump-expanded one, and
the combination is -EINVAL today, so nothing depends on it.
Reported-by: Yuen Su <zypulsecore@gmail.com>
Link: https://lore.kernel.org/netdev/CAC9WPdwmM4=64DH5nY85srnLhRBS7PkjR9vrsALpob-GutbmZw@mail.gmail.com/
Fixes: 493ced1ac47c ("ipv4: Allow routes to use nexthop objects")
Fixes: 5b98324ebe29 ("ipv6: Allow routes to use nexthop objects")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
net/ipv4/fib_frontend.c | 17 +++++++++++++++--
net/ipv6/route.c | 14 ++++++++++++--
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 8c123b111b3d..1d5a42dd35b5 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -869,8 +869,21 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
}
if (cfg->fc_nh_id) {
- if (cfg->fc_oif || cfg->fc_gw_family ||
- cfg->fc_encap || cfg->fc_mp) {
+ if (nlh->nlmsg_type == RTM_DELROUTE) {
+ /* A dump of a route using a nexthop object expands
+ * that nexthop into the legacy attributes too. Ignore
+ * those here so the dump can be fed back as-is; the id
+ * identifies the nexthop on its own.
+ */
+ cfg->fc_oif = 0;
+ cfg->fc_gw_family = 0;
+ memset(&cfg->fc_gw6, 0, sizeof(cfg->fc_gw6));
+ cfg->fc_encap = NULL;
+ cfg->fc_encap_type = LWTUNNEL_ENCAP_NONE;
+ cfg->fc_mp = NULL;
+ cfg->fc_mp_len = 0;
+ } else if (cfg->fc_oif || cfg->fc_gw_family ||
+ cfg->fc_encap || cfg->fc_mp) {
NL_SET_ERR_MSG(extack,
"Nexthop specification and nexthop id are mutually exclusive");
err = -EINVAL;
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 4a4c5ace63c5..7467ef5d5f1d 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -5258,8 +5258,18 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
cfg->fc_flags |= (rtm->rtm_flags & RTNH_F_ONLINK);
if (tb[RTA_NH_ID]) {
- if (tb[RTA_GATEWAY] || tb[RTA_OIF] ||
- tb[RTA_MULTIPATH] || tb[RTA_ENCAP]) {
+ /* A dump expands the nexthop object into the legacy
+ * attributes too. Ignore those on delete so the dump can be
+ * fed back as-is; the id identifies the nexthop on its own.
+ */
+ if (!newroute) {
+ tb[RTA_GATEWAY] = NULL;
+ tb[RTA_OIF] = NULL;
+ tb[RTA_MULTIPATH] = NULL;
+ tb[RTA_ENCAP] = NULL;
+ tb[RTA_ENCAP_TYPE] = NULL;
+ } else if (tb[RTA_GATEWAY] || tb[RTA_OIF] ||
+ tb[RTA_MULTIPATH] || tb[RTA_ENCAP]) {
NL_SET_ERR_MSG(extack,
"Nexthop specification and nexthop id are mutually exclusive");
goto errout;
--
2.53.0
next prev parent reply other threads:[~2026-11-20 20:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 20:01 [RFC net-next 0/3] net: fix route flush for routes using nexthop objects Stephen Hemminger
2026-11-20 20:01 ` Stephen Hemminger [this message]
2026-11-20 20:01 ` [RFC next-net 2/3] ipv4: accept the reported route type when deleting a blackhole nexthop route Stephen Hemminger
2026-11-20 20:01 ` [RFC next-net 3/3] selftests: fib_nexthops: test route flush with nexthop objects Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120200635.95798-2-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=zypulsecore@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox