Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by Stephen Hemminger
Fri, 20 Nov 2026 20:01
[RFC next-net 2/3] ipv4: accept the reported route type when deleting a blackhole nexthop route
Author: Stephen Hemminger
Date: Fri, 20 Nov 2026 20:01
Date: Fri, 20 Nov 2026 20:01
100 lines
15183 bytes
15183 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads