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 2/3] ipv4: accept the reported route type when deleting a blackhole nexthop route
Date: Fri, 20 Nov 2026 12:01:29 -0800 [thread overview]
Message-ID: <20261120200635.95798-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20261120200635.95798-1-stephen@networkplumber.org>
fib_dump_info() rewrites rtm_type to RTN_BLACKHOLE for a blackhole nexthop
object, before the nexthop_compat_mode bail-out:
if (fi->nh) {
if (nla_put_u32(skb, RTA_NH_ID, fi->nh->id))
goto nla_put_failure;
if (nexthop_is_blackhole(fi->nh))
rtm->rtm_type = RTN_BLACKHOLE;
So rtm_type describes the nexthop object, not the alias, which keeps the
type it was created with. fib_table_delete() matches the stored type, so
the kernel won't delete a route using the type it just reported:
# ip nexthop add id 301 blackhole
# ip route add 192.0.2.0/24 nhid 301
# ip route show 192.0.2.0/24
blackhole 192.0.2.0/24 nhid 301 dev lo
# ip route del blackhole 192.0.2.0/24 nhid 301
RTNETLINK answers: No such process
# ip route del unicast 192.0.2.0/24 nhid 301
#
"ip route flush" echoes the dumped message back, rtmsg header included, so
it carries the rewritten type and fails with ESRCH. Because the rewrite
happens before the compat-mode check, this breaks flush even with
nexthop_compat_mode off, where there are no legacy attributes at all.
Accept RTN_BLACKHOLE on delete when the alias uses a blackhole nexthop
object, so a route can be removed using the type that was advertised.
"ip route flush type blackhole" works too: the type filter is applied to
the dump in userspace, so the kernel only ever sees the type it reported.
Dropping the rewrite in fib_dump_info() instead would change what every
existing dump reader sees.
IPv6 is unaffected, ip6_route_del() doesn't compare rtm_type.
Reported-by: Yuen Su <zypulsecore@gmail.com>
Link: https://lore.kernel.org/netdev/CAC9WPdwmM4=64DH5nY85srnLhRBS7PkjR9vrsALpob-GutbmZw@mail.gmail.com/
Fixes: 4c7e8084fd46 ("ipv4: Plumb support for nexthop object in a fib_info")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
net/ipv4/fib_lookup.h | 1 +
net/ipv4/fib_semantics.c | 14 ++++++++++++++
net/ipv4/fib_trie.c | 2 +-
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/fib_lookup.h b/net/ipv4/fib_lookup.h
index 0b72796dd1ad..5109cc197de2 100644
--- a/net/ipv4/fib_lookup.h
+++ b/net/ipv4/fib_lookup.h
@@ -40,6 +40,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
struct netlink_ext_ack *extack);
int fib_nh_match(struct net *net, struct fib_config *cfg, struct fib_info *fi,
struct netlink_ext_ack *extack);
+bool fib_type_match(u8 fc_type, const struct fib_alias *fa);
bool fib_metrics_match(struct fib_config *cfg, struct fib_info *fi);
int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
const struct fib_rt_info *fri, unsigned int flags);
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index db030bc26b6d..a089761e2104 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -1061,6 +1061,20 @@ int fib_nh_match(struct net *net, struct fib_config *cfg, struct fib_info *fi,
return 0;
}
+/* fib_dump_info() reports a blackhole nexthop object as RTN_BLACKHOLE
+ * whatever type the alias has, so accept that type back on delete.
+ */
+bool fib_type_match(u8 fc_type, const struct fib_alias *fa)
+{
+ const struct fib_info *fi = fa->fa_info;
+
+ if (!fc_type || fa->fa_type == fc_type)
+ return true;
+
+ return fc_type == RTN_BLACKHOLE && fi->nh &&
+ nexthop_is_blackhole(fi->nh);
+}
+
bool fib_metrics_match(struct fib_config *cfg, struct fib_info *fi)
{
struct nlattr *nla;
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 523a5a4228d0..c67df5aa1b96 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1726,7 +1726,7 @@ int fib_table_delete(struct net *net, struct fib_table *tb,
(fa->fa_dscp != dscp))
break;
- if ((!cfg->fc_type || fa->fa_type == cfg->fc_type) &&
+ if (fib_type_match(cfg->fc_type, fa) &&
(cfg->fc_scope == RT_SCOPE_NOWHERE ||
fa->fa_info->fib_scope == cfg->fc_scope) &&
(!cfg->fc_prefsrc ||
--
2.53.0
next prev parent reply other threads:[~2026-11-20 20:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261120200635.95798-1-stephen@networkplumber.org>
2026-11-20 20:01 ` [RFC next-net 1/3] net: accept legacy nexthop attributes when deleting by nexthop id Stephen Hemminger
2026-11-20 20:01 ` Stephen Hemminger [this message]
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-3-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
all inboxes | Powered by JetHome®