From: Stephen Hemminger <stephen@networkplumber.org>
To: Andrii Tereshchenko <opensource@andrii.net>
Cc: David Ahern <dsahern@kernel.org>,
Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Christian Hopps <chopps@labn.net>,
Sabrina Dubroca <sd@queasysnail.net>,
netdev@vger.kernel.org, ipsec@lists.linux.dev
Subject: Re: [PATCH iproute2-next] ip: xfrm: add IP-TFS mode and iptfs-opts
Date: Mon, 30 Nov 2026 09:07:49 -0800 [thread overview]
Message-ID: <20261130090749.593496fd@phoenix.local> (raw)
In-Reply-To: <310fdfc1-7a77-48eb-bcc7-2437ff3a653e@mid.andrii.net>
On Sun, 29 Nov 2026 18:36:02 -0700
Andrii Tereshchenko <opensource@andrii.net> wrote:
> has IP Traffic Flow Security (RFC 9347) since v6.14, as
> XFRM_MODE_IPTFS with six XFRMA_IPTFS_* attributes, but ip xfrm cannot
> create such an SA or a policy template that uses the mode.
>
> Add "iptfs" to MODE for states and policy templates, and an
> "iptfs-opts" list for states: drop-time and reorder-window for inbound
> SAs; dont-frag, init-delay, max-queue-size and pkt-size for outbound
> SAs. The keywords follow the out-of-tree LabN iproute2 tree, so scripts
> written for it keep working. The list ends at the first word that is
> not an IP-TFS option, as FLAG-LIST does. Times take the get_time()
> units (us, ms, s and their long forms, in any case); a bare number is
> decimal microseconds, as in the kernel attributes. packet-size is an
> alias of pkt-size, the name other IPsec implementations use.
> Only the options given are sent, 0 included, so the kernel defaults
> apply to the others. Direction rules are left to the kernel, which
> names the offending option in its extack. The new mode word is matched
> exactly, so "mode i" still means in_trigger.
>
> ip xfrm state prints the attributes the kernel returns as one
> iptfs-opts line that "ip xfrm state add" accepts back.
>
> A kernel without IP-TFS support (CONFIG_XFRM_IPTFS off, or xfrm_iptfs
> not loadable) can accept an IP-TFS SA, drop its options and then fail
> its traffic. A kernel with it reports the SA's IP-TFS attributes back,
> defaults included, so after an IP-TFS add or update ip reads the SA
> back; without IP-TFS attributes it reports the missing support, does
> not keep an SA it just added, and exits with an error.
>
> Made with an AI coding assistant, reviewed by the submitter.
>
> Signed-off-by: Andrii Tereshchenko <opensource@andrii.net>
I don't mind use of AI, but you need to review, reword and look at what
gets produced. This is sloppy and reimplements needlessly.
Wordier AI review (with coaching)...
On Sun, 29 Nov 2026 18:36:02 -0700
Andrii Tereshchenko <opensource@andrii.net> wrote:
> Add "iptfs" to MODE for states and policy templates, and an
> "iptfs-opts" list for states: drop-time and reorder-window for inbound
> SAs; dont-frag, init-delay, max-queue-size and pkt-size for outbound
> SAs.
The parsing and the netlink encoding look right. I applied this and
checked the wire format under strace: drop-time 1s gives
XFRMA_IPTFS_DROP_TIME = 1000000, reorder-window is a u16,
dont-frag is a zero-length flag, pkt-size 1400 is 0x578. The
IPTFS-OPT-LIST terminates correctly in every position I tried --
followed by another keyword, at the end of the command line, and with
dont-frag (which takes no value) last. New keywords all use strcmp(),
not matches(), and the exact match on "iptfs" keeps "mode i" meaning
in_trigger. Builds clean.
Three things I want changed, plus a design question.
1. The readback and rollback drop pcpu-num
----------------------------------------------------------------
> +static int xfrm_state_id_talk(struct rtnl_handle *rth, __u16 type,
> + const struct xfrm_usersa_info *xsinfo,
> + const struct xfrm_mark *mark,
> + struct nlmsghdr **answer)
> +{
[...]
> + if (mark->m)
> + addattr_l(&req.n, sizeof(req.buf), XFRMA_MARK, mark,
> + sizeof(*mark));
The add path a few lines above the new call site sets XFRMA_SA_PCPU:
if (pcpu_num != -1)
addattr32(&req.n, sizeof(req.buf), XFRMA_SA_PCPU, pcpu_num);
but xfrm_state_id_talk() sends only daddr/spi/family/proto plus the
mark. So for
ip xfrm state add ... mode iptfs pcpu-num 3 iptfs-opts ...
the verification GETSA and, worse, the rollback DELSA are not keyed on
the same SA that was just added. The DELSA is the half that bothers me:
it can remove a state the command did not create. Please thread
pcpu_num through and add XFRMA_SA_PCPU when it is set.
Note that "ip xfrm state get" and "delete" don't take pcpu-num today
either, so the lookup gap isn't yours alone, but new code shouldn't
widen it -- especially not new code whose failure mode is deleting
something.
2. Don't reimplement get_time()
----------------------------------------------------------------
> +/*
> + * IP-TFS times are microseconds, as in the kernel attributes. A bare
> + * number is decimal microseconds; a unit is one of the get_time() units,
> + * in any case. Unlike get_time(), refuse values that overflow or are not
> + * whole microseconds instead of truncating them.
> + */
> +static int xfrm_iptfs_get_usec(__u32 *val, const char *arg)
> +{
> + static const struct {
> + const char *name;
> + double mult;
> + } units[] = {
> + { "s", 1e6 }, { "sec", 1e6 }, { "secs", 1e6 },
> + { "ms", 1e3 }, { "msec", 1e3 }, { "msecs", 1e3 },
> + { "us", 1 }, { "usec", 1 }, { "usecs", 1 },
> + };
This is get_time() from lib/utils.c, copied. Same strtod(), same unit
spellings, same case-insensitive compare, same unit table, and the same
microsecond base -- get_time() already returns microseconds, which is
what TIME_UNITS_PER_SEC being 1000000 means. The comment names the
function it is reimplementing.
The kernel attributes are in microseconds and get_time() hands you
microseconds, so there is nothing to convert and the whole helper
reduces to:
if (get_time(&t, arg))
invarg("value after \"drop-time\" is invalid", *argv);
I built that against the real get_time() and ran your documented cases
through it -- 1s, 1, 100us, 1ms, 0, 4294967295, 1.0s, 2secs, 1S, 0.5ms,
1.999999s, 1sec, 1usecs, 1MS, 1Sec all come out identical to your
version, and abc, "" and -1 are all rejected. Every behaviour the man
page promises is already in the library.
If some future attribute is in different units, convert after getting
microseconds; don't fork the parser to change its base. That keeps one
copy of the unit table and one set of accepted spellings.
That leaves the two edge cases your comment cites as the reason for the
fork:
1.5us get_time gives 1 (truncates; you reject)
4295s get_time gives 32704 (wraps; you reject)
The wrap is a genuine get_time() bug -- it assigns a double to unsigned
int with no range check. Fix it there, where every caller benefits, and
send it as its own patch; tc has been living with it for years. The
truncation is arguably correct behaviour for a microsecond-resolution
field. Neither justifies a private copy in ip/ipxfrm.c that will drift
the first time someone adds a unit to get_time().
Yes, get_time_rtt() is also a fork of get_time(). It carries a comment
explaining that its callers want milliseconds and a different
raw-number rule. That's a real semantic difference; yours isn't, and one
old wart isn't a licence for another.
One more thing the fork gets wrong on its own. strtod() is C99 and
accepts hex floats, so the fallback takes what your get_u32(..., 10)
first pass just rejected:
drop-time 0x10 -> rejected
drop-time 0x10us -> accepted, 16 us
drop-time 0x1p4us -> accepted, 16 us
contradicting both the commit message and the man page, which say
decimal. Plain get_time() is at least consistent: it takes hex in both
cases. (I tried writing a decimal-only guard for you and got it wrong
twice -- rejecting 'e' kills "sec" and "usecs", and a digit-prefix check
still lets "0x10" through. Which is itself an argument for not hand
rolling number parsing here.)
Smaller, same area: drop-time and init-delay are base 10 while
reorder-window, max-queue-size and pkt-size go through get_u32() with
base 0 and so take hex. Reads oddly in one option list.
3. Design question: should ip delete an SA behind the user's back?
----------------------------------------------------------------
> + if (req.xsinfo.mode == XFRM_MODE_IPTFS &&
> + !xfrm_state_has_iptfs(&rth, &req.xsinfo, &mark)) {
[...]
> + if (cmd == XFRM_MSG_NEWSA &&
> + xfrm_state_id_talk(&rth, XFRM_MSG_DELSA, &req.xsinfo,
> + &mark, NULL) == 0)
> + fprintf(stderr, "; the SA was not kept.\n");
This is new behavior for ip xfrm. No other "state add" path does a
verify round trip after a successful rtnl_talk(), and none of them
undoes work the kernel accepted. I understand the motivation -- a
kernel without CONFIG_XFRM_IPTFS silently dropping the options is a
nasty failure -- but I'm not sure ip is the right place to paper over
it.
Reporting the problem is clearly useful. Deleting is the part I'd drop:
between the add and the DELSA, a keying daemon can already have the SA
in hand, and ip has no way to know. Diagnose it, exit non-zero, and
leave the state alone. If the kernel is going to accept an SA it cannot
run, that's a kernel bug worth fixing there.
Your call if you want to keep it, but then at minimum fix (1) first,
because an unkeyed DELSA plus automatic rollback is how you delete the
wrong SA.
4. The attribution line
----------------------------------------------------------------
> Made with an AI coding assistant, reviewed by the submitter.
AI assistance is fine here; just don't let it be sloppy. If you want to
record it, use the kernel trailer form, which this tree has started
following:
Assisted-by: Claude:claude-opus-5
as a trailer next to your Signed-off-by, not free prose in the body.
Don't spend effort on it either way -- I drop Assisted-by when I merge.
The Signed-off-by is the line that matters, and the DCO is your
certification regardless of what wrote the first draft.
What I do care about is item 2, which is the sloppy part. A private copy
of a library function, with a comment naming the function it copies, is
the characteristic failure here: the helper gets written instead of
found. Same for item 1 -- the add path sets XFRMA_SA_PCPU nine lines
above the new readback call that omits it. Both are things a read of the
surrounding file catches, and both are the submitter's job to catch
before posting, whatever produced the code.
So: keep using the assistant, and please give the result the same read
you'd give a patch someone else sent you. The parsing and the wire
format here are genuinely correct -- I checked them byte for byte, and
that part of the work is good.
Smaller notes, no action needed unless you want to:
- Repeated options silently overwrite (iptfs-opts pkt-size 1 pkt-size 2
takes 2) rather than calling duparg(). FLAG-LIST behaves the same way,
so this is consistent with what's there.
- No JSON, as you noted. Correct -- ip xfrm has none anywhere, so
fprintf() here is the right call, not print_*().
- The man page addition is good, and citing the RFC 9348 YANG names is
a nice touch for anyone cross-referencing another implementation.
Thanks,
Stephen
prev parent reply other threads:[~2026-11-30 17:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 1:36 [PATCH iproute2-next] ip: xfrm: add IP-TFS mode and iptfs-opts Andrii Tereshchenko
2026-11-30 17:07 ` 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=20261130090749.593496fd@phoenix.local \
--to=stephen@networkplumber.org \
--cc=chopps@labn.net \
--cc=dsahern@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=ipsec@lists.linux.dev \
--cc=netdev@vger.kernel.org \
--cc=opensource@andrii.net \
--cc=sd@queasysnail.net \
--cc=steffen.klassert@secunet.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