From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.227 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796002566; b=py+aFA6Tf573ayiPjfZlh75bW1jOvkd4c6NF5YLrEnY1cFEge1o4ctWd3U5ycYqkcNNi OW+Ot7uaFiD8N0XWYtip56SJAuqrjNAlwPDgvZ5cnN2tVl2htpYm4kSaB5Gk5KJsbedoA cVFZayndcDmVRBsHej1ifWzW8042woTJ0j04eVslzvBH4g2j2i1OHlNUE7ZHrvGjqS5gb 3tvUGME3UabbJ8eGZOPxYPWOjrC2LM2xYEIu+5tbF38paSAb0VmiXGKJ38JvjvIiVXyNW qcYLAVVVObYpqRYa+yUj2JsFsR8r4Fyk5NEJZVn2y249+WZC/M1C311h7CFBFFljJwQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796002566; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: X-Relaying-Domain:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=oHHGRErwpSIoeeWvqa6u+QTxj+U4CV0s/CGVl+ko8HU=; b=2OMYPk7r6nVa8mLqolytveyo03Ha72mTnJHmMvfbcEZyTjZztD2UolWO2wNdchVES9Pn TAdH2TuvtK/9N+ODBVdV2qGMN0I8NqPab2I3/EaFN+3tj1GEelYLWBMH21+89ykQk6ATt hD15oCSBOsZc9OG6wu+UOpOdHgwgc+A9OJvtWa8awuHJF+lL/F0N0BP1ukdq6ybv4RF8j JPIx8qtYtp/QyseOfwey7DS9drUV6Y5t7uUpUNwKEKAKpXlRfakwKnHcy9JzCxmVIBbzU hq677sWzweKVo8oeI2B0uMDpmCbY4TN3k0mT9nwtcuEsvEPRNVfSVWZUVLqUi8b9mvg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=andrii.net; spf=pass smtp.mailfrom=andrii.net; dkim=pass header.d=andrii.net header.i=@andrii.net header.a=rsa-sha256 header.s=gmail-2025 header.b=fTkFwy41; arc=none smtp.remote-ip=209.85.222.227 Received: from mail-qk1-f227.google.com (mail-qk1-f227.google.com [209.85.222.227]) (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 EF6FD606A31C for ; Mon, 30 Nov 2026 01:36:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EF6FD606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=andrii.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=andrii.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=andrii.net header.i=@andrii.net header.a=rsa-sha256 header.s=gmail-2025 header.b=fTkFwy41 Received: by mail-qk1-f227.google.com with SMTP id af79cd13be357-9495c633eb5so554260085a.1 for ; Sun, 29 Nov 2026 17:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=andrii.net; s=gmail-2025; t=1796002565; x=1796607365; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=oHHGRErwpSIoeeWvqa6u+QTxj+U4CV0s/CGVl+ko8HU=; b=fTkFwy41E/I+FvedrLqHUDWf6KQjVLwdPWhei19lZ0caZ3Wr3aIodAcYaMzZbpniKB N0ZXhNp9dhwhUADUden/oFW7Fl+Gpjx3iKxZhJKAP1IKG2kzl41kVNbQ654rKxNQtrQi ID65MMGDO55RJEPJgCsvVLXga2zO1KMHrI54tZ9Nz54ID/P+DpFNDb2CDNaZrOTmNmPW rSsliEjC1qPa1RUJEzmPz86IhbL8XV3dVoAUnybpcG2dk0SAAHbgjlSyr/FCqmuxNtm3 dFeAhRzlJyR3SJXr3I3W3xBrRYYNKU/EtkJGhYVYjNuiEe5xANnwvVYtb+IsdFyJ7xH7 eLSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796002565; x=1796607365; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=oHHGRErwpSIoeeWvqa6u+QTxj+U4CV0s/CGVl+ko8HU=; b=Q8uxYRGBUtQMN0HaflsESbuLqs6iDM+YKfktUvOENegInewZ9uV1shXZWhO8SCnxr1 Af9lu8MujXUKxXiVos0EFeWYMND9OS67fSaTDM9JcoqOK6ZUUBGfp5zKeJTsaCSHSsQ5 fQ73l/ey+XyRw60kgNtEXtkG/5xLYg6qsoVB8sDO2u00oYulejgrWNFG1QWC4dsSKw4/ PbILWrl+4nanDuBWUAoPt7vuulqyqhOlWWcYO7dyGoIgBBC+oyUULJrzvoiEneAp+Nm2 BYbJ+ei6yoON1lHintLWbdPMnJIrr4m0tVJRulGKN7f8tPA0RdXtOnN5NVphLODC6IcS 9uVA== X-Forwarded-Encrypted: i=1; AL+hErGbZpW6/DputbpE5oZSk2xd87a4UgAOkfb7Hr9c0nryJHlIs0la/Ninh8Z+/fjANhN2X6c3Eok=@vger.kernel.org X-Gm-Message-State: APuU4Z9pqnPj4NZOK8wk/7dP185jZn1JiN0fVCXgk81Tx9Wb34t4yD90 uzBbYjWfkrk4FBSeonPKX8SO+gnMF4fATQpRe6W3BLcRXUbAhahC4nvFgYzuCoO0Ebq8hOMBXLZ Jg2FAkGkCq657TRWHpdt33Wh2dMH5NnWIc3kmQsQfHJ0EoL206Gpw X-Gm-Gg: AZFdTZcdL8JprC8WXE8PvbnnofdEJqcqKgOMhJcNuzvD4ojpsxoDvWLd4mE3sljMdtz MNS0KLIkFk5g5vZLX3h/vV2pNinHNmvgIh/e7Wffy29BzBY0To//jfT90chGOl9NX4l/eZAZsVF EXriZwAuSVdyHCYSU5iFE5rFYAVBpDcNMWnUTxVtyDn0EwcbB462Q+GfsVzK21lIP+/xHx3qrNW sFrh5FqY89ugWycULFGv3Svrs8wlmEs9Sltaciwx7HPrXWqflgQxtiEo6NVrxDdTEn36aDepyNy mgqumcekVTiAcQvW4YjkrOm89Ae9oAa11RJk8HytU498XepRC38TfzGvFAsttBxxmPcp9RzNAZV nZL9RKk1fYnb5gCm0xQ0nvCAJxUU= X-Received: by 2002:a05:620a:838a:b0:949:6f9f:34fe with SMTP id af79cd13be357-949ba9fe0acmr5479219185a.36.1796002564798; Sun, 29 Nov 2026 17:36:04 -0800 (PST) Received: from andrii.ai (mac.hestia.andrii.net. [2602:f337:ed:4865:7374:6961:204d:6163]) by smtp-relay.gmail.com with ESMTPS id af79cd13be357-949bb369035sm260192085a.10.2026.11.29.17.36.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 29 Nov 2026 17:36:04 -0800 (PST) X-Relaying-Domain: andrii.net From: Andrii Tereshchenko To: David Ahern Cc: Stephen Hemminger , Steffen Klassert , Herbert Xu , Christian Hopps , Sabrina Dubroca , netdev@vger.kernel.org, ipsec@lists.linux.dev Subject: [PATCH iproute2-next] ip: xfrm: add IP-TFS mode and iptfs-opts Date: Sun, 29 Nov 2026 18:36:02 -0700 Message-ID: <310fdfc1-7a77-48eb-bcc7-2437ff3a653e@mid.andrii.net> X-Mailer: git-send-email 2.56.0 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-Transfer-Encoding: 7bit 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 --- 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