* [PATCH iproute2-next] ip: xfrm: add IP-TFS mode and iptfs-opts
@ 2026-11-30 1:36 Andrii Tereshchenko
2026-11-30 17:07 ` Stephen Hemminger
0 siblings, 1 reply; 2+ messages in thread
From: Andrii Tereshchenko @ 2026-11-30 1:36 UTC (permalink / raw)
To: David Ahern
Cc: Stephen Hemminger, Steffen Klassert, Herbert Xu, Christian Hopps,
Sabrina Dubroca, netdev, ipsec
The kernel 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>
---
Tested in QEMU guests on ipsec master kernels 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 and limits, 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, removes the SA and exits 2.
Builds with gcc, clang and gcc -m32 add no warnings.
Not done: no JSON output, as for the rest of ip xfrm.
ip/ipxfrm.c | 162 +++++++++++++++++++++++++++++++++++++++++++++
ip/xfrm.h | 22 ++++++
ip/xfrm_policy.c | 2 +-
ip/xfrm_state.c | 96 ++++++++++++++++++++++++++-
man/man8/ip-xfrm.8 | 110 +++++++++++++++++++++++++++++-
5 files changed, 387 insertions(+), 5 deletions(-)
diff --git a/ip/ipxfrm.c b/ip/ipxfrm.c
index 78d9e192..24d6dd9d 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 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,162 @@ int xfrm_encap_type_parse(__u16 *type, int *argcp, char ***argvp)
return 0;
}
+/*
+ * 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 },
+ };
+ unsigned int i;
+ double t;
+ char *p;
+
+ if (get_u32(val, arg, 10) == 0)
+ return 0;
+
+ t = strtod(arg, &p);
+ if (p == arg || t < 0 || !*p)
+ return -1;
+ for (i = 0; i < ARRAY_SIZE(units); i++)
+ if (strcasecmp(p, units[i].name) == 0)
+ break;
+ if (i == ARRAY_SIZE(units))
+ return -1;
+ t *= units[i].mult;
+ if (t > UINT32_MAX || (double)(__u32)t != t)
+ return -1; /* out of range or not whole microseconds */
+
+ *val = t;
+ return 0;
+}
+
+static int xfrm_iptfs_opt_parse(struct xfrm_iptfs_opts *o, int *argcp,
+ char ***argvp)
+{
+ int argc = *argcp;
+ char **argv = *argvp;
+
+ if (strcmp(*argv, "drop-time") == 0) {
+ NEXT_ARG();
+ if (xfrm_iptfs_get_usec(&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 (xfrm_iptfs_get_usec(&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\" 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)
+{
+ int argc = *argcp;
+ char **argv = *argvp;
+
+ 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;
+}
+
+void 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);
+ if (o->set & XFRM_IPTFS_OPT_REORDER_WINDOW)
+ addattr16(n, maxlen, XFRMA_IPTFS_REORDER_WINDOW,
+ o->reorder_window);
+ if (o->set & XFRM_IPTFS_OPT_DONT_FRAG)
+ addattr(n, maxlen, XFRMA_IPTFS_DONT_FRAG);
+ if (o->set & XFRM_IPTFS_OPT_INIT_DELAY)
+ addattr32(n, maxlen, XFRMA_IPTFS_INIT_DELAY, o->init_delay);
+ if (o->set & XFRM_IPTFS_OPT_MAX_QSIZE)
+ addattr32(n, maxlen, XFRMA_IPTFS_MAX_QSIZE, o->max_qsize);
+ if (o->set & XFRM_IPTFS_OPT_PKT_SIZE)
+ addattr32(n, maxlen, XFRMA_IPTFS_PKT_SIZE, o->pkt_size);
+}
+
+/* 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..ca1b6497 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);
+void 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 5261a292..6b119b21 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 dcd08d59..8f22cea5 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|ms|msec|s|sec] (default unit: us)\n");
exit(-1);
}
@@ -267,6 +273,66 @@ static void xfrm_dir_parse(__u8 *dir, int *argcp, char ***argvp)
*argvp = argv;
}
+/* Send GETSA or DELSA for the SA that xsinfo and mark identify. */
+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)
+{
+ 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 = type,
+ .xsid.daddr = xsinfo->id.daddr,
+ .xsid.spi = xsinfo->id.spi,
+ .xsid.family = xsinfo->family,
+ .xsid.proto = xsinfo->id.proto,
+ };
+
+ if (mark->m)
+ addattr_l(&req.n, sizeof(req.buf), XFRMA_MARK, mark,
+ sizeof(*mark));
+
+ return rtnl_talk(rth, &req.n, answer);
+}
+
+/*
+ * 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.
+ */
+static bool xfrm_state_has_iptfs(struct rtnl_handle *rth,
+ const struct xfrm_usersa_info *xsinfo,
+ const struct xfrm_mark *mark)
+{
+ struct rtattr *tb[XFRMA_MAX + 1];
+ struct xfrm_usersa_info *info;
+ struct nlmsghdr *answer;
+ bool has = true; /* if the kernel cannot tell us, trust it */
+ int len, i;
+
+ if (xfrm_state_id_talk(rth, XFRM_MSG_GETSA, xsinfo, mark, &answer) < 0)
+ return true;
+
+ info = NLMSG_DATA(answer);
+ len = answer->nlmsg_len - NLMSG_SPACE(sizeof(*info));
+ if (answer->nlmsg_type == XFRM_MSG_NEWSA && len >= 0) {
+ parse_rtattr(tb, XFRMA_MAX, XFRMS_RTA(info), len);
+ has = false;
+ for (i = XFRMA_IPTFS_DROP_TIME; i <= XFRMA_IPTFS_PKT_SIZE; i++)
+ if (tb[i])
+ has = true;
+ }
+ free(answer);
+
+ return has;
+}
+
static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
{
struct rtnl_handle rth;
@@ -310,6 +376,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 +530,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 +723,21 @@ 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);
+ }
+ xfrm_iptfs_opts_addattr(&req.n, sizeof(req.buf), &iptfs);
+ }
+
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 +860,19 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
if (rtnl_talk(&rth, &req.n, NULL) < 0)
exit(2);
+ if (req.xsinfo.mode == XFRM_MODE_IPTFS &&
+ !xfrm_state_has_iptfs(&rth, &req.xsinfo, &mark)) {
+ fprintf(stderr,
+ "Error: the kernel has no IP-TFS support (CONFIG_XFRM_IPTFS, module xfrm_iptfs)");
+ 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");
+ else
+ fprintf(stderr, "; the SA cannot pass traffic.\n");
+ exit(2);
+ }
+
rtnl_close(&rth);
return 0;
diff --git a/man/man8/ip-xfrm.8 b/man/man8/ip-xfrm.8
index 50fbb1a7..895a232a 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"
@@ -169,12 +171,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 +445,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 +578,92 @@ 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 decimal number with an optional unit
+.BR us ", " usec ", " ms ", " msec ", " s ", or " sec
+(also with a trailing
+.BR s ","
+in any case). Without a unit it is microseconds, unlike
+.B limit time-*
+(seconds). It must come to whole microseconds.
+.I SIZE
+and
+.I COUNT
+are plain numbers (octets, packets).
+The settings are fixed when the SA is created:
+.B ip xfrm state update
+does not change them on an existing SA (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 does not keep an SA it just added.
+.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:
base-commit: 8055701cb470fdc9e5e9909369bff3f7e24c872e
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH iproute2-next] ip: xfrm: add IP-TFS mode and iptfs-opts
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
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2026-11-30 17:07 UTC (permalink / raw)
To: Andrii Tereshchenko
Cc: David Ahern, Steffen Klassert, Herbert Xu, Christian Hopps,
Sabrina Dubroca, netdev, ipsec
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 17:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox