Netdev List
 help / color / mirror / Atom feed
From: Andrii Tereshchenko <opensource@andrii.net>
To: David Ahern <dsahern@kernel.org>
Cc: Stephen Hemminger <stephen@networkplumber.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: [PATCH iproute2-next v2] ip: xfrm: add IP-TFS mode and iptfs-opts
Date: Fri,  4 Dec 2026 07:44:27 -0800	[thread overview]
Message-ID: <b5e4c6c6-66cf-40d2-b62f-08806661ba0b@mid.andrii.net> (raw)

The kernel has IP Traffic Flow Security (RFC 9347) since v6.14, but
ip xfrm cannot create an SA or policy template that uses the mode.

Add "iptfs" to MODE 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 ones. Keywords follow the
LabN tree, so scripts written for it keep working. The list ends at
the first word that is not an option, as FLAG-LIST does. Times go
through get_time(), as in tc; a bare number is microseconds.
packet-size is an alias of pkt-size. Only given options are sent,
0 included, so the rest keep kernel defaults. Direction checks are
left to the kernel, whose extack names the offending option. The
mode word is matched exactly, so "mode i" still means in_trigger.

ip xfrm state prints the returned attributes as one iptfs-opts
line that "ip xfrm state add" accepts back.

A kernel without IP-TFS support may accept such an SA, drop its
options and then fail its traffic. One with it reports the
attributes back, so after an add or update ip reads the SA back:
without IP-TFS attributes it reports the missing support and
exits 2, leaving the SA installed. An update that meets an SA in
another mode reports that instead. An SA the read-back does not
find is left alone, with a warning.

Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Andrii Tereshchenko <opensource@andrii.net>
---
An AI coding assistant was used to write this patch; I reviewed and
tested the result.

v2:
- Parse drop-time and init-delay with get_time() instead of a private
  copy of it (Stephen Hemminger). They now take what tc takes; the
  commit message and man page no longer promise decimal only.
- On a kernel without IP-TFS support, report it and exit 2, but leave
  the SA alone instead of deleting it (Stephen Hemminger). The
  read-back GETSA stays; it is the only call after the add.
- Move the AI note out of the commit message.
- Exit if an IP-TFS attribute does not fit the request, as for
  XFRMA_MARK and XFRMA_SA_DIR, instead of sending the request
  without it.
- If an update meets an SA in another mode, say so instead of
  reporting missing kernel support; an update does not change the
  mode of an installed SA.
- When the kernel does not find the SA for the read-back, print a
  warning instead of the kernel error (an SA without an SPI).
- Man page: list the units TIME takes (the usage text too), say what
  update does to an SA that allocspi reserved, add dir to the
  allocspi synopsis, and name iptfs in the policy MODE paragraph.
- Rebase on current iproute2-next (06b62d17): mechanical, for the
  upstream rth -> xrth and dir -> sa_dir renames. No other code
  change; the build is -Wshadow clean, times go through get_time(),
  a short request exits instead of being sent partial, and an
  update that meets another mode says so.

v1: https://lore.kernel.org/netdev/310fdfc1-7a77-48eb-bcc7-2437ff3a653e@mid.andrii.net/

Stephen, thanks for the careful review, and for checking the wire
format byte for byte.

On Mon, 30 Nov 2026 09:07:49 -0800, Stephen Hemminger wrote:
> 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.

Fair. I should have caught the private time parser by reading
lib/utils.c. It is gone.

> 1. The readback and rollback drop pcpu-num

Adding XFRMA_SA_PCPU would break the read-back rather than key it.
The kernel refuses that attribute on GETSA and DELSA: since
83dfce38c49f, xfrm_reject_unused_attr() in net/xfrm/xfrm_user.c
accepts it only on NEWSA, UPDSA, ALLOCSPI and ACQUIRE. pcpu_num is
not part of the lookup either: xfrm_user_state_lookup() matches
daddr, spi, proto, family and mark, and xfrm_state_add() refuses a
second SA with the same tuple and mark whatever its pcpu_num. That
is likely also why "ip xfrm state get" and "delete" never took
pcpu-num. With point 3 there is no DELSA, so a wrong-SA delete
cannot happen; a comment at the GETSA says why pcpu-num is not sent.

> 2. Don't reimplement get_time()

Done, and the range check is posted as its own iproute2-next
series [1]; it refuses values such as 4295s instead of wrapping,
in get_time() and the other parsers, for tc as well [2].

> 3. Design question: should ip delete an SA behind the user's back?

Agreed, and dropped. ip still reads the SA back, reports the missing
support and exits 2; the SA stays installed. I agree the kernel
should refuse such an SA, and will send that fix to ipsec separately.

> 4. The attribution line

Since the kernel dropped Assisted-by in October (1e035297ffda) and
asks for that note outside the changelog, v2 keeps one plain line
below the ---.

On the smaller notes: repeated options stay last-wins, like mode,
reqid and dir; add and update call duparg() only for coa, ctx and
the algorithms.

Tested in QEMU guests on kernels based on ipsec master with
CONFIG_XFRM_IPTFS=y, two of them debug builds with KASAN and lockdep:
every option in both directions, add, update, get, delete and flush,
policy templates with mode iptfs, the printed iptfs-opts line fed back
to "ip xfrm state add", the time units, the kernel's refusals, and
traffic between two namespaces through IP-TFS SAs set up with ip alone.
On a kernel built without IP-TFS support, ip reports it, keeps the SA
and exits 2, with and without pcpu-num. Builds with gcc and clang add
no warnings, nor does a gcc -m32 build of lib and ip on iproute2 main.

Not done: no JSON output, as for the rest of ip xfrm.

Andrii Tereshchenko

[1] series cover: https://lore.kernel.org/netdev/3c88d843-f74b-4982-88c6-2bcf648348e6@mid.andrii.net/
[2] the lib fix: https://lore.kernel.org/netdev/b20b5c19-0152-411e-850a-d96d7b3393a3@mid.andrii.net/

 ip/ipxfrm.c        | 133 +++++++++++++++++++++++++++++++++++++++++++++
 ip/xfrm.h          |  22 ++++++++
 ip/xfrm_policy.c   |   2 +-
 ip/xfrm_state.c    | 112 +++++++++++++++++++++++++++++++++++++-
 man/man8/ip-xfrm.8 | 133 ++++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 397 insertions(+), 5 deletions(-)

diff --git a/ip/ipxfrm.c b/ip/ipxfrm.c
index 4a63dc16..02656d58 100644
--- a/ip/ipxfrm.c
+++ b/ip/ipxfrm.c
@@ -303,6 +303,9 @@ static void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
 	case XFRM_MODE_BEET:
 		fprintf(fp, "beet");
 		break;
+	case XFRM_MODE_IPTFS:
+		fprintf(fp, "iptfs");
+		break;
 	default:
 		fprintf(fp, "%u", mode);
 		break;
@@ -907,6 +910,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family, FILE *fp,
 		fprintf(fp, "tfcpad %u", tfcpad);
 		fprintf(fp, "%s", _SL_);
 	}
+	xfrm_iptfs_opts_print(tb, fp, prefix);
 	if (tb[XFRMA_SA_DIR]) {
 		__u8 sa_dir = rta_getattr_u8(tb[XFRMA_SA_DIR]);
 
@@ -1214,6 +1218,8 @@ int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp)
 		*mode = XFRM_MODE_IN_TRIGGER;
 	else if (matches(*argv, "beet") == 0)
 		*mode = XFRM_MODE_BEET;
+	else if (strcmp(*argv, "iptfs") == 0)
+		*mode = XFRM_MODE_IPTFS;
 	else
 		invarg("MODE value is invalid", *argv);
 
@@ -1243,6 +1249,133 @@ int xfrm_encap_type_parse(__u16 *type, int *argcp, char ***argvp)
 	return 0;
 }
 
+/* IP-TFS times are microseconds, as get_time() returns them. */
+static int xfrm_iptfs_opt_parse(struct xfrm_iptfs_opts *o, int *argcp,
+				char ***argvp)
+{
+	char **argv = *argvp;
+	int argc = *argcp;
+
+	if (strcmp(*argv, "drop-time") == 0) {
+		NEXT_ARG();
+		if (get_time(&o->drop_time, *argv))
+			invarg("value after \"drop-time\" is invalid", *argv);
+		o->set |= XFRM_IPTFS_OPT_DROP_TIME;
+	} else if (strcmp(*argv, "reorder-window") == 0) {
+		NEXT_ARG();
+		if (get_u16(&o->reorder_window, *argv, 0))
+			invarg("value after \"reorder-window\" is invalid", *argv);
+		o->set |= XFRM_IPTFS_OPT_REORDER_WINDOW;
+	} else if (strcmp(*argv, "dont-frag") == 0) {
+		o->set |= XFRM_IPTFS_OPT_DONT_FRAG;
+	} else if (strcmp(*argv, "init-delay") == 0) {
+		NEXT_ARG();
+		if (get_time(&o->init_delay, *argv))
+			invarg("value after \"init-delay\" is invalid", *argv);
+		o->set |= XFRM_IPTFS_OPT_INIT_DELAY;
+	} else if (strcmp(*argv, "max-queue-size") == 0) {
+		NEXT_ARG();
+		if (get_u32(&o->max_qsize, *argv, 0))
+			invarg("value after \"max-queue-size\" is invalid", *argv);
+		o->set |= XFRM_IPTFS_OPT_MAX_QSIZE;
+	} else if (strcmp(*argv, "pkt-size") == 0 ||
+		   strcmp(*argv, "packet-size") == 0) {
+		NEXT_ARG();
+		if (get_u32(&o->pkt_size, *argv, 0))
+			invarg("value after \"pkt-size\"/\"packet-size\" is invalid", *argv);
+		o->set |= XFRM_IPTFS_OPT_PKT_SIZE;
+	} else {
+		return -1;
+	}
+
+	*argcp = argc;
+	*argvp = argv;
+
+	return 0;
+}
+
+/* IPTFS-OPT-LIST: one or more options, ended by the first other word */
+int xfrm_iptfs_opts_parse(struct xfrm_iptfs_opts *o, int *argcp,
+			  char ***argvp)
+{
+	char **argv = *argvp;
+	int argc = *argcp;
+
+	if (xfrm_iptfs_opt_parse(o, &argc, &argv))
+		invarg("IPTFS-OPT value is invalid", *argv);
+
+	while (NEXT_ARG_OK()) {
+		NEXT_ARG();
+		if (xfrm_iptfs_opt_parse(o, &argc, &argv)) {
+			PREV_ARG(); /* back track */
+			break;
+		}
+	}
+
+	*argcp = argc;
+	*argvp = argv;
+
+	return 0;
+}
+
+/* -1 if an attribute does not fit; the message is then partial. */
+int xfrm_iptfs_opts_addattr(struct nlmsghdr *n, int maxlen,
+			    const struct xfrm_iptfs_opts *o)
+{
+	if ((o->set & XFRM_IPTFS_OPT_DROP_TIME) &&
+	    addattr32(n, maxlen, XFRMA_IPTFS_DROP_TIME, o->drop_time))
+		return -1;
+	if ((o->set & XFRM_IPTFS_OPT_REORDER_WINDOW) &&
+	    addattr16(n, maxlen, XFRMA_IPTFS_REORDER_WINDOW,
+		      o->reorder_window))
+		return -1;
+	if ((o->set & XFRM_IPTFS_OPT_DONT_FRAG) &&
+	    addattr(n, maxlen, XFRMA_IPTFS_DONT_FRAG))
+		return -1;
+	if ((o->set & XFRM_IPTFS_OPT_INIT_DELAY) &&
+	    addattr32(n, maxlen, XFRMA_IPTFS_INIT_DELAY, o->init_delay))
+		return -1;
+	if ((o->set & XFRM_IPTFS_OPT_MAX_QSIZE) &&
+	    addattr32(n, maxlen, XFRMA_IPTFS_MAX_QSIZE, o->max_qsize))
+		return -1;
+	if ((o->set & XFRM_IPTFS_OPT_PKT_SIZE) &&
+	    addattr32(n, maxlen, XFRMA_IPTFS_PKT_SIZE, o->pkt_size))
+		return -1;
+
+	return 0;
+}
+
+/* One line that "ip xfrm state add ... iptfs-opts" accepts back. */
+void xfrm_iptfs_opts_print(struct rtattr *tb[], FILE *fp, const char *prefix)
+{
+	if (!tb[XFRMA_IPTFS_DROP_TIME] && !tb[XFRMA_IPTFS_REORDER_WINDOW] &&
+	    !tb[XFRMA_IPTFS_DONT_FRAG] && !tb[XFRMA_IPTFS_INIT_DELAY] &&
+	    !tb[XFRMA_IPTFS_MAX_QSIZE] && !tb[XFRMA_IPTFS_PKT_SIZE])
+		return;
+
+	if (prefix)
+		fputs(prefix, fp);
+	fprintf(fp, "iptfs-opts");
+	if (tb[XFRMA_IPTFS_DROP_TIME])
+		fprintf(fp, " drop-time %u",
+			rta_getattr_u32(tb[XFRMA_IPTFS_DROP_TIME]));
+	if (tb[XFRMA_IPTFS_REORDER_WINDOW])
+		fprintf(fp, " reorder-window %u",
+			rta_getattr_u16(tb[XFRMA_IPTFS_REORDER_WINDOW]));
+	if (tb[XFRMA_IPTFS_DONT_FRAG])
+		fprintf(fp, " dont-frag");
+	if (tb[XFRMA_IPTFS_INIT_DELAY])
+		fprintf(fp, " init-delay %u",
+			rta_getattr_u32(tb[XFRMA_IPTFS_INIT_DELAY]));
+	if (tb[XFRMA_IPTFS_MAX_QSIZE])
+		fprintf(fp, " max-queue-size %u",
+			rta_getattr_u32(tb[XFRMA_IPTFS_MAX_QSIZE]));
+	if (tb[XFRMA_IPTFS_PKT_SIZE])
+		fprintf(fp, " pkt-size %u",
+			rta_getattr_u32(tb[XFRMA_IPTFS_PKT_SIZE]));
+	fprintf(fp, "%s", _SL_);
+}
+
 /* NOTE: reqid is used by host-byte order */
 int xfrm_reqid_parse(__u32 *reqid, int *argcp, char ***argvp)
 {
diff --git a/ip/xfrm.h b/ip/xfrm.h
index 5238fc8b..c7ca5846 100644
--- a/ip/xfrm.h
+++ b/ip/xfrm.h
@@ -120,6 +120,28 @@ int xfrm_policy_default_print(struct nlmsghdr *n, FILE *fp);
 int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
 		  int loose, int *argcp, char ***argvp);
 int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp);
+
+#define XFRM_IPTFS_OPT_DROP_TIME	BIT(0)
+#define XFRM_IPTFS_OPT_REORDER_WINDOW	BIT(1)
+#define XFRM_IPTFS_OPT_DONT_FRAG	BIT(2)
+#define XFRM_IPTFS_OPT_INIT_DELAY	BIT(3)
+#define XFRM_IPTFS_OPT_MAX_QSIZE	BIT(4)
+#define XFRM_IPTFS_OPT_PKT_SIZE		BIT(5)
+
+struct xfrm_iptfs_opts {
+	__u32 set;		/* XFRM_IPTFS_OPT_* given on the command line */
+	__u32 drop_time;	/* usec */
+	__u32 init_delay;	/* usec */
+	__u32 max_qsize;	/* octets */
+	__u32 pkt_size;		/* octets, 0: path MTU */
+	__u16 reorder_window;	/* packets */
+};
+
+int xfrm_iptfs_opts_parse(struct xfrm_iptfs_opts *o, int *argcp,
+			  char ***argvp);
+int xfrm_iptfs_opts_addattr(struct nlmsghdr *n, int maxlen,
+			    const struct xfrm_iptfs_opts *o);
+void xfrm_iptfs_opts_print(struct rtattr *tb[], FILE *fp, const char *prefix);
 int xfrm_encap_type_parse(__u16 *type, int *argcp, char ***argvp);
 int xfrm_reqid_parse(__u32 *reqid, int *argcp, char ***argvp);
 int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp);
diff --git a/ip/xfrm_policy.c b/ip/xfrm_policy.c
index ea7e8c0c..fe486439 100644
--- a/ip/xfrm_policy.c
+++ b/ip/xfrm_policy.c
@@ -77,7 +77,7 @@ static void usage(void)
 		strxf_xfrmproto(IPPROTO_ROUTING),
 		strxf_xfrmproto(IPPROTO_DSTOPTS));
 	fprintf(stderr,
-		"MODE := transport | tunnel | beet | ro | in_trigger\n"
+		"MODE := transport | tunnel | beet | ro | in_trigger | iptfs\n"
 		"LEVEL := required | use\n");
 
 	exit(-1);
diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c
index db80a0e0..e249c323 100644
--- a/ip/xfrm_state.c
+++ b/ip/xfrm_state.c
@@ -48,6 +48,7 @@ static void usage(void)
 		"        [ offload [ crypto | packet ] dev DEV dir DIR ]\n"
 		"        [ output-mark OUTPUT-MARK [ mask MASK ] ]\n"
 		"        [ if_id IF_ID ] [ tfcpad LENGTH ] [ pcpu-num CPUNUM ]\n"
+		"        [ iptfs-opts IPTFS-OPT-LIST ]\n"
 		"Usage: ip xfrm state allocspi ID [ mode MODE ] [ mark MARK [ mask MASK ] ]\n"
 		"        [ reqid REQID ] [ dir DIR ] [ seq SEQ ] [ min SPI max SPI ] [ pcpu-num CPUNUM ]\n"
 		"Usage: ip xfrm state { delete | get } ID [ mark MARK [ mask MASK ] ]\n"
@@ -84,7 +85,7 @@ static void usage(void)
 		"        %s", strxf_algotype(XFRMA_ALG_COMP));
 	fprintf(stderr,
 		" ALGO-NAME\n"
-		"MODE := transport | tunnel | beet | ro | in_trigger\n"
+		"MODE := transport | tunnel | beet | ro | in_trigger | iptfs\n"
 		"FLAG-LIST := [ FLAG-LIST ] FLAG\n"
 		"FLAG := noecn | decap-dscp | nopmtudisc | wildrecv | icmp | af-unspec | align4 | esn\n"
 		"EXTRA-FLAG-LIST := [ EXTRA-FLAG-LIST ] EXTRA-FLAG\n"
@@ -97,7 +98,12 @@ static void usage(void)
 		"LIMIT := { time-soft | time-hard | time-use-soft | time-use-hard } SECONDS |\n"
 		"         { byte-soft | byte-hard } SIZE | { packet-soft | packet-hard } COUNT\n"
 		"ENCAP := { espinudp | espinudp-nonike | espintcp } SPORT DPORT OADDR\n"
-		"DIR := in | out\n");
+		"DIR := in | out\n"
+		"IPTFS-OPT-LIST := IPTFS-OPT [ IPTFS-OPT-LIST ]\n"
+		"IPTFS-OPT := drop-time TIME | reorder-window COUNT |\n"
+		"             dont-frag | init-delay TIME |\n"
+		"             max-queue-size SIZE | { pkt-size | packet-size } SIZE\n"
+		"TIME := NUMBER[us|usec|usecs|ms|msec|msecs|s|sec|secs] (default unit: us)\n");
 
 	exit(-1);
 }
@@ -267,6 +273,78 @@ static void xfrm_dir_parse(__u8 *dir, int *argcp, char ***argvp)
 	*argvp = argv;
 }
 
+enum {
+	IPTFS_SA_OK,		/* or the kernel cannot tell us: trust it */
+	IPTFS_SA_OTHER_MODE,
+	IPTFS_SA_NO_SUPPORT,
+};
+
+/*
+ * A kernel without IP-TFS support (CONFIG_XFRM_IPTFS off, or the
+ * xfrm_iptfs module not loadable) may accept an IP-TFS SA, drop its
+ * IP-TFS options and then fail its traffic. A kernel with it reports
+ * the SA's IP-TFS attributes back, defaults included, so ask. An
+ * update keeps the mode of an SA added before, so look at the mode
+ * first. The kernel looks an SA up by daddr, spi, proto, family and
+ * mark, and refuses XFRMA_SA_PCPU on GETSA, so pcpu-num is not sent
+ * here. The answer is only as good as that lookup: an SA without an
+ * SPI is not found, and an update finds its SA through the mask of
+ * the mark where GETSA may want mark and mask as the SA has them, so
+ * after an update GETSA may find no SA or another one. An SA that is
+ * not found is left alone, with a warning.
+ */
+static int xfrm_state_iptfs_check(struct rtnl_handle *rtnl,
+				  const struct xfrm_usersa_info *xsinfo,
+				  const struct xfrm_mark *mark)
+{
+	struct {
+		struct nlmsghdr	n;
+		struct xfrm_usersa_id	xsid;
+		char			buf[RTA_BUF_SIZE];
+	} req = {
+		.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsid)),
+		.n.nlmsg_flags = NLM_F_REQUEST,
+		.n.nlmsg_type = XFRM_MSG_GETSA,
+		.xsid.daddr = xsinfo->id.daddr,
+		.xsid.spi = xsinfo->id.spi,
+		.xsid.family = xsinfo->family,
+		.xsid.proto = xsinfo->id.proto,
+	};
+	struct rtattr *tb[XFRMA_MAX + 1];
+	struct xfrm_usersa_info *info;
+	struct nlmsghdr *answer;
+	int ret = IPTFS_SA_OK;
+	int len, i;
+
+	if (mark->m)
+		addattr_l(&req.n, sizeof(req.buf), XFRMA_MARK, mark,
+			  sizeof(*mark));
+
+	if (rtnl_talk_suppress_rtnl_errmsg(rtnl, &req.n, &answer) < 0) {
+		fprintf(stderr, "the SA could not be read back; IP-TFS support was not checked.\n");
+		return IPTFS_SA_OK;
+	}
+
+	info = NLMSG_DATA(answer);
+	len = answer->nlmsg_len - NLMSG_SPACE(sizeof(*info));
+	if (answer->nlmsg_type == XFRM_MSG_NEWSA && len >= 0) {
+		if (info->mode != XFRM_MODE_IPTFS) {
+			ret = IPTFS_SA_OTHER_MODE;
+		} else {
+			parse_rtattr(tb, XFRMA_MAX, XFRMS_RTA(info), len);
+			ret = IPTFS_SA_NO_SUPPORT;
+			for (i = XFRMA_IPTFS_DROP_TIME;
+			     i <= XFRMA_IPTFS_PKT_SIZE; i++) {
+				if (tb[i])
+					ret = IPTFS_SA_OK;
+			}
+		}
+	}
+	free(answer);
+
+	return ret;
+}
+
 static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
 {
 	struct rtnl_handle xrth;
@@ -310,6 +388,7 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
 	__u32 pcpu_num = -1;
 	__u32 if_id = 0;
 	__u32 tfcpad = 0;
+	struct xfrm_iptfs_opts iptfs = {};
 
 	while (argc > 0) {
 		if (strcmp(*argv, "mode") == 0) {
@@ -463,6 +542,9 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
 			NEXT_ARG();
 			if (get_u32(&pcpu_num, *argv, 0))
 				invarg("value after \"pcpu-num\" is invalid", *argv);
+		} else if (strcmp(*argv, "iptfs-opts") == 0) {
+			NEXT_ARG();
+			xfrm_iptfs_opts_parse(&iptfs, &argc, &argv);
 		} else {
 			/* try to assume ALGO */
 			int type = xfrm_algotype_getbyname(*argv);
@@ -653,12 +735,25 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
 	if (tfcpad)
 		addattr32(&req.n, sizeof(req.buf), XFRMA_TFCPAD, tfcpad);
 
+	if (iptfs.set) {
+		if (req.xsinfo.mode != XFRM_MODE_IPTFS) {
+			fprintf(stderr, "\"iptfs-opts\" requires \"mode iptfs\"\n");
+			exit(1);
+		}
+		if (xfrm_iptfs_opts_addattr(&req.n, sizeof(req.buf),
+					    &iptfs) < 0) {
+			fprintf(stderr, "XFRMA_IPTFS_* failed\n");
+			exit(1);
+		}
+	}
+
 	if (xfrm_xfrmproto_is_ipsec(req.xsinfo.id.proto)) {
 		switch (req.xsinfo.mode) {
 		case XFRM_MODE_TRANSPORT:
 		case XFRM_MODE_TUNNEL:
 			break;
 		case XFRM_MODE_BEET:
+		case XFRM_MODE_IPTFS:
 			if (req.xsinfo.id.proto == IPPROTO_ESP)
 				break;
 			/* fallthrough */
@@ -781,6 +876,19 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
 	if (rtnl_talk(&xrth, &req.n, NULL) < 0)
 		exit(2);
 
+	if (req.xsinfo.mode == XFRM_MODE_IPTFS) {
+		switch (xfrm_state_iptfs_check(&xrth, &req.xsinfo, &mark)) {
+		case IPTFS_SA_OTHER_MODE:
+			fprintf(stderr,
+				"Error: the SA is not in iptfs mode; \"update\" does not change the mode of an existing SA.\n");
+			exit(2);
+		case IPTFS_SA_NO_SUPPORT:
+			fprintf(stderr,
+				"Error: the kernel has no IP-TFS support (CONFIG_XFRM_IPTFS, module xfrm_iptfs); the SA is installed but cannot pass traffic.\n");
+			exit(2);
+		}
+	}
+
 	rtnl_close(&xrth);
 
 	return 0;
diff --git a/man/man8/ip-xfrm.8 b/man/man8/ip-xfrm.8
index 50fbb1a7..ece57160 100644
--- a/man/man8/ip-xfrm.8
+++ b/man/man8/ip-xfrm.8
@@ -78,6 +78,8 @@ ip-xfrm \- transform configuration
 .IR LENGTH " ]"
 .RB "[ " pcpu-num
 .IR CPUNUM " ]"
+.RB "[ " iptfs-opts
+.IR IPTFS-OPT-LIST " ]"
 
 .ti -8
 .B "ip xfrm state allocspi"
@@ -90,6 +92,8 @@ ip-xfrm \- transform configuration
 .IR MASK " ] ]"
 .RB "[ " reqid
 .IR REQID " ]"
+.RB "[ " dir
+.IR SA-DIR " ]"
 .RB "[ " seq
 .IR SEQ " ]"
 .RB "[ " min
@@ -169,12 +173,30 @@ ip-xfrm \- transform configuration
 
 .ti -8
 .IR MODE " := "
-.BR transport " | " tunnel " | " beet " | " ro " | " in_trigger
+.BR transport " | " tunnel " | " beet " | " ro " | " in_trigger " | " iptfs
 
 .ti -8
 .IR SA-DIR " := "
 .BR in " | " out
 
+.ti -8
+.IR IPTFS-OPT-LIST " := " IPTFS-OPT " [ " IPTFS-OPT-LIST " ]"
+
+.ti -8
+.IR IPTFS-OPT " := "
+.B drop-time
+.IR TIME " | "
+.B reorder-window
+.IR COUNT " | "
+.BR dont-frag " | "
+.B init-delay
+.IR TIME " |"
+.br
+.B max-queue-size
+.IR SIZE " | { "
+.BR pkt-size " | " packet-size " } "
+.I SIZE
+
 .ti -8
 .IR FLAG-LIST " := [ " FLAG-LIST " ] " FLAG
 
@@ -425,7 +447,7 @@ ip-xfrm \- transform configuration
 
 .ti -8
 .IR MODE " := "
-.BR transport " | " tunnel " | " beet " | " ro " | " in_trigger
+.BR transport " | " tunnel " | " beet " | " ro " | " in_trigger " | " iptfs
 
 .ti -8
 .IR LEVEL " :="
@@ -558,6 +580,109 @@ Mobile IPv6 modes are route optimization
 and inbound trigger
 .RB "(" in_trigger ")."
 
+IPsec ESP also has IP Traffic Flow Security
+.RB "(" iptfs ","
+RFC 9347), which needs
+.BR dir " " in " or " out
+and takes
+.IR IPTFS-OPT-LIST "."
+
+.TP
+.I IPTFS-OPT-LIST
+sets IP-TFS parameters of an
+.B iptfs
+mode SA. Options not given keep the kernel defaults. Each option applies to
+one SA direction; the kernel refuses an option given for the other one.
+The list ends at the first word that is not an IP-TFS option.
+.I TIME
+is a number with an optional unit
+.BR us ", " usec ", " usecs ", " ms ", " msec ", " msecs ","
+.BR s ", " sec ", or " secs
+(in any case), as for times in
+.BR tc (8).
+Without a unit it is microseconds, unlike
+.B limit time-*
+(seconds).
+.I SIZE
+and
+.I COUNT
+are numbers without a unit (octets, packets).
+The mode and these settings are fixed when the SA is installed.
+.B ip xfrm state update
+installs an SA that
+.B ip xfrm state allocspi
+reserved with the same
+.BR dir ","
+with the mode and the settings given; on an SA that is installed
+already it changes neither (delete and add it again).
+The kernel needs
+.B CONFIG_XFRM_IPTFS
+(module
+.BR xfrm_iptfs ")."
+Some kernels without it accept an IP-TFS SA and then cannot pass its
+traffic;
+.B ip
+reads the SA back after
+.B add
+or
+.BR update ","
+reports an error and exits with status 2; the SA stays installed.
+It does the same when
+.B update
+leaves an installed SA in another mode.
+Both need the kernel to find the SA again. It may not find an SA added
+without
+.BR spi ","
+or one that
+.B update
+matched only through the mask of its mark;
+.B ip
+then prints a warning and exits with status 0.
+.RS
+.TP
+.BI drop-time " TIME"
+(in) how long to wait for a missing outer packet before treating it as lost
+(kernel default 1s).
+.TP
+.BI reorder-window " COUNT"
+(in) how many outer packets may be held to put them back in order; 0 turns
+reordering off (kernel default 3).
+.TP
+.B dont-frag
+(out) do not fragment inner packets across outer packets; an inner packet
+too large for one outer packet is dropped. This is not the DF bit of the
+outer IP header, nor
+.BR nopmtudisc .
+.TP
+.BI init-delay " TIME"
+(out) how long to wait for more inner packets before sending the first
+outer packet (kernel default 0).
+.TP
+.BI max-queue-size " SIZE"
+(out) the most octets of inner packets queued for sending (kernel default
+10485760, 10 MiB).
+.TP
+.BI pkt-size " SIZE"
+(out) the size of the outer packets in octets; 0 uses the path MTU (kernel
+default 0).
+.B packet-size
+is the same option.
+.RE
+.IP
+The RFC 9348 (YANG) names of these parameters are
+.B lost-packet-timer-interval
+.RB "(" drop-time "),"
+.B window-size
+.RB "(" reorder-window "),"
+.B dont-fragment
+.RB "(" dont-frag "),"
+.B max-aggregation-time
+.RB "(" init-delay "),"
+and
+.B outer-packet-size
+.RB "(" pkt-size ");"
+RFC 9348 counts times in milliseconds.
+
 .TP
 .I FLAG-LIST
 contains one or more of the following optional flags:
@@ -720,6 +845,10 @@ Mobile IPv6 modes are route optimization
 and inbound trigger
 .RB "(" in_trigger ")."
 
+IPsec ESP also has IP Traffic Flow Security
+.RB "(" iptfs ","
+RFC 9347).
+
 .TP
 .I LEVEL
 can be

base-commit: 06b62d179bbb5b62cba965dcda48a613dbc59416
-- 
2.53.0


                 reply	other threads:[~2026-12-04 15:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=b5e4c6c6-66cf-40d2-b62f-08806661ba0b@mid.andrii.net \
    --to=opensource@andrii.net \
    --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=sd@queasysnail.net \
    --cc=steffen.klassert@secunet.com \
    --cc=stephen@networkplumber.org \
    /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