From: Stephen Hemminger <stephen@networkplumber.org>
To: Yuen Su <zypulsecore@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH iproute2 v3] ip: flush nexthop-object routes without compatibility attributes
Date: Tue, 17 Nov 2026 13:25:41 -0800 [thread overview]
Message-ID: <20261117132541.03df0f80@phoenix.local> (raw)
In-Reply-To: <CAC9WPdy-t24XJXdPjDLP5ZZWqTJpkqy3OmvZsrOpr3qB9S_y0g@mail.gmail.com>
On Mon, 16 Nov 2026 21:25:37 -0800
Yuen Su <zypulsecore@gmail.com> wrote:
> Route dumps can contain RTA_NH_ID plus expanded nexthop attributes.
> The kernel rejects that combination on deletion. Strip the expansion
> from the flush copy, preserving the ID and other route selectors. Use
> the compacted length for batching and retain the original for display.
>
> Blackhole nexthops also hide the IPv4 alias type. Track explicit type
> selectors separately from the VRF default. Without an explicit type,
> clear the synthetic type for unfiltered requests and for VRF requests
> with scope below LINK. Local and broadcast aliases cannot have that
> scope, and deletion still matches it. Ambiguous link/host-scope aliases
> retain the existing failure.
>
> Leave IPv6 blackhole dumps unchanged: they can hide a local type, and
> deletion does not check the type. Stripping their expansion would allow
> a VRF flush to delete a local route that previously survived an error.
>
> Extend the namespace tests with the VRF case, explicit types in either
> argument order, excluded local/broadcast aliases and IPv6 retention.
>
> Signed-off-by: Yuen Su <zypulsecore@gmail.com>
> ---
The version you sent is corrupted by mail system but there is a bigger issue.
After looking at this in more detail and at a higher level, the root cause
of the problem is that kernel is buggy here, and working around it in ip
command is the wrong way to handle it.
Pre-nexthop the ip command could just do flush by getting all the routes
with show and then turning around and feeding those back as delete operations.
Somewhere along the way, this property was lost. That is the root cause here.
I am not taking this kind of workaround in ip, fix the kernel.
Yes it maybe really hard to unwind broken route API.
Long winded AI prompted analysis below:
On Mon, 16 Nov 2026 21:25:37 -0800, Yuen Su wrote:
> Subject: [PATCH iproute2 v3] ip: flush nexthop-object routes without
> compatibility attributes
>
> Route dumps can contain RTA_NH_ID plus expanded nexthop attributes.
> The kernel rejects that combination on deletion.
Right, and that is the bug -- in the kernel, not in ip. Flush has always
worked by taking the dump message, flipping nlmsg_type to RTM_DELROUTE
and sending it back. That round-trip is the design, which is why
print_route() does a bare memcpy and nothing else. A dump the kernel
will not accept back is a kernel bug, and I would rather see it fixed
there than worked around here.
Both halves of this are in fib_dump_info():
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;
if (!READ_ONCE(...sysctl_nexthop_compat_mode))
goto offload;
}
1) The compat expansion is emitted alongside RTA_NH_ID, and
rtm_to_fib_config() rejects exactly that pair:
if (cfg->fc_nh_id) {
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");
So the dump violates the kernel's own input validation, and
nexthop_compat_mode defaults to 1, so this is the default path.
2) rtm_type is overwritten with a synthetic RTN_BLACKHOLE. The route's
real type is destroyed on the way out.
The second one is why I do not think the type-guessing half of this
patch can be made to work. It is trying to recover a field that is not
on the wire. That is also what the changelog is admitting to:
> Ambiguous link/host-scope aliases retain the existing failure.
and the IPv4-only/IPv6-excluded asymmetry falls out of the same thing --
the clobber is in the IPv4 path only, which is why ip6_route_del() never
needing fc_type is not a coincidence.
The clobber came in with
4c7e8084fd46 ("ipv4: Plumb support for nexthop object in a fib_info")
David Ahern, Jun 2019, v5.3
which added RTA_NH_ID and the rtm_type assignment together. The sysctl
arrived later in
4f80116d3df3 ("net: ipv4: add sysctl for nexthop api compatibility mode")
Roopa Prabhu, Apr 2020, v5.12
defaulting to 1, so the unacceptable-dump combination became the normal
case rather than an opt-in.
Either kernel fix makes this patch unnecessary. Having
rtm_to_fib_config() ignore the expansion when fc_nh_id is set looks
safest to me: RTA_NH_ID is the authoritative specification anyway, it
keeps whatever display value compat mode has, and it makes every dump
already in the field round-trippable -- including from older ip
binaries, which this patch cannot help. Dropping or relocating the
rtm_type assignment handles the second half. dsahern is on Cc.
On the iproute2 side, if you want to carry something for kernels already
deployed, please split it and send only the stripping:
case RTA_OIF:
case RTA_GATEWAY:
case RTA_MULTIPATH:
case RTA_VIA:
case RTA_ENCAP_TYPE:
case RTA_ENCAP:
That set matches the fc_oif/fc_gw_family/fc_encap/fc_mp check exactly,
drops nothing else, and needs no argument about types. It is a
self-contained fix for the subject line. I checked the mechanics and
they are sound: flush_nexthop_compat() reads the original n and writes
the already-copied fn so there is no overlap, and the buffer bound still
tests the original n->nlmsg_len, which is >= the compacted length.
Drop type_explicit, the RTN_UNSPEC relaxation and the scope threshold.
That machinery only exists to paper over the rtm_type clobber, it is the
only part of the patch that is hard to review, it needs fib_props[] and
fib_table_delete() to justify itself, and it still leaves documented
failures. Most of the 176-line test is testing that logic rather than
the fix.
Separately: this v3 does not apply. The mail body was reflowed, hunk
headers included --
> @@ -766,6 +767,39 @@ static void print_rta_multipath(FILE *fp, const
> struct rtmsg *r,
and the last 27 lines of the new test are missing from the diff; they
appear earlier in the message, between the diffstat and base-commit.
The hunk claims 176 added lines and only 149 are where the diff expects
them, so un-wrapping alone will not recover it. The Received header
shows gmailapi.google.com with HTTPREST, which is the usual cause.
git send-email avoids it. I repaired the reflow locally to review the
code; the C hunks apply cleanly once unwrapped and build warning-free.
prev parent reply other threads:[~2026-11-17 21:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 10:24 [PATCH iproute2 v2] ip: flush nexthop-object routes without compatibility attributes Yuen Su
2026-11-16 23:16 ` Stephen Hemminger
2026-11-17 5:25 ` [PATCH iproute2 v3] " Yuen Su
2026-11-17 21:25 ` Stephen Hemminger [this message]
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=20261117132541.03df0f80@phoenix.local \
--to=stephen@networkplumber.org \
--cc=netdev@vger.kernel.org \
--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