Netdev List
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Yuen Su <zypulsecore@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH iproute2 v2] ip: flush nexthop-object routes without compatibility attributes
Date: Mon, 16 Nov 2026 15:16:18 -0800	[thread overview]
Message-ID: <20261116151618.2ee4bf9d@phoenix.local> (raw)
In-Reply-To: <20261026102420.612573-1-zypulsecore@gmail.com>

On Mon, 26 Oct 2026 18:24:20 +0800
Yuen Su <zypulsecore@gmail.com> wrote:

> Route dumps can contain RTA_NH_ID plus expanded nexthop attributes.
> The kernel rejects that combination on route deletion. Strip the
> expansion from the flush copy, keeping the ID and route selectors.
> Use the compacted length for batching and retain the dump for display.
> 
> IPv4 fib_dump_info() also reports blackhole nexthop objects as
> RTN_BLACKHOLE instead of the alias type, independently of
> nexthop_compat_mode. Work around this with RTN_UNSPEC only when no
> type filter was requested. The kernel then deletes the first alias
> matching the remaining selectors; alias order and changes between
> dump and deletion can affect that choice. Preserve explicit types.
> 
> Add namespace regressions covering ID-based flushes, ordinary routes,
> batching and type selection, with a nexthop capability probe.
> 
> Signed-off-by: Yuen Su <zypulsecore@gmail.com>
> ---

In general looked OK, but AI review with review-prompts showed
some issues.

On Mon, 26 Oct 2026 18:24:20 +0800, Yuen Su wrote:

The mechanism here is right, and I checked the premise against the
kernel: fib_frontend.c rtm_to_fib_config() rejects fc_nh_id combined
with fc_oif/fc_gw_family/fc_encap/fc_mp, and your strip list covers
exactly those four (RTA_OIF, RTA_GATEWAY/RTA_VIA, RTA_ENCAP/
RTA_ENCAP_TYPE, RTA_MULTIPATH). fib_nh_match() returns 0 on an
ID-only request, so the compacted message matches. The AF_INET-only
restriction on the type workaround is also correct: ip6_route_del()
never compares fc_type against rt->fib6_type, so IPv6 needs no
equivalent even though rt6_fill_node() synthesizes RTN_BLACKHOLE the
same way.

One case the workaround does not cover.

> +	/* Work around fib_dump_info() replacing the IPv4 alias type with
> +	 * RTN_BLACKHOLE for blackhole nexthop objects, independently of
> +	 * nexthop_compat_mode. Keep explicit type constraints.
> +	 */
> +	if (!filter.typemask &&
> +	    r->rtm_family == AF_INET && r->rtm_type == RTN_BLACKHOLE)
> +		dr->rtm_type = RTN_UNSPEC;

filter.typemask is not only set by an explicit "type" argument. The
vrf keyword sets it too, in iproute_list_flush_or_save():

	} else if (matches(*argv, "vrf") == 0) {
		...
		filter.tb = tid;
		filter.typemask = ~(1 << RTN_LOCAL | 1<<RTN_BROADCAST);

That parser is shared between list, flush and save, so

	ip route flush vrf blue

leaves typemask nonzero with no type requested by the user, the
workaround is skipped, and the delete request carries the synthesized
RTN_BLACKHOLE. For an IPv4 unicast route using a blackhole nexthop
object in that VRF table, fib_table_delete() requires an exact match:

	if ((!cfg->fc_type || fa->fa_type == cfg->fc_type) &&

fa_type is RTN_UNICAST, fc_type is RTN_BLACKHOLE, no alias matches,
and the delete returns ESRCH. iproute_flush() keeps redumping and
resending until the 30 second timeout, then reports entries remaining.

To be clear about severity: this is not a regression. Those routes
fail to flush before your patch as well, for the same reason the
patch exists. It is a gap in the fix, and worth deciding on rather
than leaving implicit, because flush vrf is a common way to tear
down a VRF.

The awkward part is that typemask cannot distinguish the two cases by
inspection - the vrf mask has the RTN_BLACKHOLE bit set, so you
cannot test for it. How would you prefer to handle it? A separate
flag recording that the user actually passed "type" would make the
guard say what the comment says, and would leave the vrf mask alone:

	} else if (matches(*argv, "type") == 0) {
		...
		filter.typemask = (1<<type);
		filter.type_explicit = 1;

then test !filter.type_explicit in flush_nexthop_compat(). I have no
strong preference on the spelling; the point is that the current
guard is testing a proxy that has a second writer.

Worth extending the new test to cover it, since it is the one flush
form where the workaround silently does not apply.

Everything else I looked at checked out. The buffer arithmetic is
sound: the space check against the uncompacted n->nlmsg_len is
conservative because compaction only shrinks, and nlmsg_len stays
NLMSG-aligned since it starts at NLMSG_LENGTH(sizeof(*r)) and
advances by RTA_ALIGN, so the NLMSG_ALIGN(filter.flushp) arithmetic
for the next message in the batch still holds. Display still uses the
untouched dump. The testsuite helpers all exist in lib/generic.sh and
the build is clean.

      reply	other threads:[~2026-11-16 23:16 UTC|newest]

Thread overview: 2+ 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 [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=20261116151618.2ee4bf9d@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