From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796058478; b=X3iO/lAalpK3tDP9ypr64KxyT7N3k1toXuuojQZEGkuB8DIWPddvV8GUiZEwT1bDhCAT 4UQ+wvdyDnitfh5zQ+P32+toPaS2NATwuJTHigzyx0ZiFsqFezOyfKSrWO+itpDP+px28 351FoIwm8m5kwnhNF6W276LZ24PPc+T+Ua6tIuLKlWsWob1v2KgwXHcYOAN8uFVrV/C84 EKcF2cQXvB9kHV2WqdPEpDrLkQ+qi9VSo40ITi1luMwD/Fw29t9GfQZs5/adynpnhV7a8 CAn34oOlxaQdysuuQm/Gn8YPQAyORmfbGPPOPdIGpUBXOrl5GhV7G2E8TDGBeHlqKLg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796058478; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=EaXgy/rmcdCNSc/Tq51oYbwFygIjfnd76dbxsHjwnno=; b=jeJOMb0+71GPhqoz9a0HIoQbk12jHTjWXgt7o8HvDH2AsyBYoWbzF5T/lnFM0suIqiPR EDDSwTsluWUDzPg6OG1AXAfZpeezGZy81HGpS8mJKfow6EiwpNiNooNInYnRj1WJVhJyM UpMR6LqcpiO/2zMc/Sfpll41CekFMstR8n1FcEYTX9MrNjGVMnRcwrV5i7k2yOk0tnNeo /72rd2HoL7sUhQUJv1TUGiqNAOwEYHzNdAT6cUrlOHC/RnIOjmgu0ujfcD/6k6U1WOr+i XYFZi1wCUarpfN+/NHx3yfx/HleLZSlpcVSeKxZpzWEJzhHxh2xsnHQ47aHut1d04gA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=networkplumber.org; spf=pass smtp.mailfrom=networkplumber.org; dkim=pass header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=N+wSzXbm; arc=none smtp.remote-ip=209.85.216.43 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4E09606A320 for ; Mon, 30 Nov 2026 17:07:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E4E09606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=networkplumber.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=N+wSzXbm Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3b520f1604fso1815203a91.2 for ; Mon, 30 Nov 2026 09:07:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1796058472; x=1796663272; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=EaXgy/rmcdCNSc/Tq51oYbwFygIjfnd76dbxsHjwnno=; b=N+wSzXbmXj3iYCRit9RXxK7bfgLlZJORXm4Ei7D8seWDvBWW6I+Y/h5c/dyGP8ExWB 0tdM1LEOG8canuxlD01cLW0Hsc5nRiEcTNLBftOvaVEjhSJd63U9EnWjiVPMVPoAUD8n m3b3X8Y4BwcXILsII63AUHuKkmcCRx4vzqznpf5vkw75DfPFYTSkTjW7fK1nRSInlrvc PieD0bVft8Qg/LAJTXAfRYcuJzCRzlPvD+6hYqZkM6tNloer8uFLFXwP8Y7Kk1HyyjgZ ApssMVIqxz1pnU32R8xoz5uPpTh/uId9nzStB9VZZs5vAQQl5E4SdJkQtBU7gxngDXz2 X2FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796058472; x=1796663272; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=EaXgy/rmcdCNSc/Tq51oYbwFygIjfnd76dbxsHjwnno=; b=yNRhUerDXK8WZOO2/Oo/ZtCfO0gNZOMnNnrMDXb/C7mTC+HCAe1XR1qI9YUnqAsA1C YFudcAmm4tghrOxGxh+obRliiGMaC7DXnhUYTGzvbmaU0ywgoWbi8Q/rBraQTyJR11SN ZbqCLxIXyRwrWq4A0m8XgvTdZG9kQpuQqG25soHsWV5ZvyCBQfSEEyOrmb+8oXJEmmAj RyJzzV8RqHzUo/weRXaTjLZdED6OPVSTom+4HN+g0z6xre8/kU3mMKSFz6GXO6qBT9iY i5WvqSlpRGaYvYMmKrAWlcDGMCj/2aHRzDQixAoVMAP0J1keXBwE+J5S0lu/xQW8CZnV qP7g== X-Forwarded-Encrypted: i=1; AL+hErFV7mGKRtxuOIkAWFukkhGpeO1m4G7OD4jQHZp3OV6cZ5vsfDjmZ0F62eCZefWRW4pzlhQEGaE=@vger.kernel.org X-Gm-Message-State: APuU4Z+czx04LZKmV2ueXH9yrUaYFJufM7wizsDYfn9l/plT2Kuy3O7e DfvZYpp9pQ7uF7rjhsBTSllJtW04ydPngWCn9oiFZpK3M1+382MjHnDdS4qOl7JTy8U= X-Gm-Gg: AZFdTZecNjwVml3nLA2ZEsfGMdZLtSwoW44SjzaYjjuTA3Sv1eNmE2RWLRGssdq0zwc 8N6zZF4SiVgbM9AGAc2VDloebpAYNWddvmlwGcrSeOf3aMyz9lyRj27xFY7jqMEbTJxGclI3W2H 02zOK3AHF/r5KP2zkkLDWcWuprxdQv9JzfGxprn9WZPt79OxWvkmz7bI/mQdYWWufW2mOITnSj5 90hIzKUwLzxk5JLCA06dK1nRPg2n8Xv8/3OHh85uboHpdoCdhaZNKHsR9wchLdiCSsIes3pJ7yN NigdtKYaOjCFk818a1urnumnDVYKCU31WecIFkCkH023fMulaEqOklaGUNtQAhjVBMsipGqo3lP tQ0aKIBV9RBeHT6wzfZcPzTGQF4f5KkU6b6PWnOEjM3ieCZC/BsUVQTq5hmxLudnq1uKMYE7wLB HHYzB/SQNoXTi/Fkl61J9Fk8TIHfahB4kPG4gWRxbUgT56mon30tsfZq0j/jb2g+6KzbcmLYi2S lxBD574uWi1dYSmX7gr3ot0BjKebMg45BY3p+h/uPvpPSJJDsXwoflrVk40Z3jL9r7k+nnsjxS4 79O17yYwfztNJR2ELE9Zi3BXIJ92YH3Pllexo2MUu1NDWj+QFlBOuZBF00moW8McSn3Xek4= X-Received: by 2002:a17:90a:e184:b0:3b5:6bbc:43c3 with SMTP id 98e67ed59e1d1-3b56bbc4859mr6731546a91.45.1796058471978; Mon, 30 Nov 2026 09:07:51 -0800 (PST) Received: from phoenix.local (204-195-112-43.wavecable.com. [204.195.112.43]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b44b792474sm26042348a91.3.2026.11.30.09.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 09:07:51 -0800 (PST) Date: Mon, 30 Nov 2026 09:07:49 -0800 From: Stephen Hemminger To: Andrii Tereshchenko Cc: David Ahern , Steffen Klassert , Herbert Xu , Christian Hopps , Sabrina Dubroca , netdev@vger.kernel.org, ipsec@lists.linux.dev Subject: Re: [PATCH iproute2-next] ip: xfrm: add IP-TFS mode and iptfs-opts Message-ID: <20261130090749.593496fd@phoenix.local> In-Reply-To: <310fdfc1-7a77-48eb-bcc7-2437ff3a653e@mid.andrii.net> References: <310fdfc1-7a77-48eb-bcc7-2437ff3a653e@mid.andrii.net> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 29 Nov 2026 18:36:02 -0700 Andrii Tereshchenko 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 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 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