tc: add the psp action and flower psp matches
Subsystems (4)
v2 cover tc: add the psp action and flower psp matches
This adds tc support for socket-less PSP associations, from the net-next series:
https://lore.kernel.org/netdev/[email protected]
- The psp action: attach a PSP Tx association to a packet, for the PSP device to encrypt on transmit (encap), or remove the PSP Rx state of a packet the device decrypted (decap).
- Flower matches on that Rx state: psp_spi, psp_ver and psp_dev.
The selftests in the kernel series, drivers/net psp.py and tc-testing psp.json, use them.
The kernel series isn't merged yet. Patch 1 copies its uapi headers, so that this builds and can be tested with it; it can be replaced by the regular header sync once the kernel series is merged. Please apply this series only after the kernel series is merged into net-next. The tc uapi is unchanged in the kernel series' v2.
Testing: with the kernel series on netdevsim, drivers/net psp.py (57 tests) and tc-testing psp.json (17 tests) pass with this tc.
Changes in v2 (Stephen):
- psp action: match keywords with strcmp() instead of matches().
- psp action: reject "decap assoc", and a repeated "assoc".
- psp action: print psp_action as a string in JSON for any value, and only when the kernel reports it.
- psp action: list "jump" in CONTROL, in the usage and the man page.
- psp action: check "encap" and "assoc" also with "index", and list the bare "index INDEX" form, which references an existing action.
- flower: parse psp_ver and psp_dev as decimal.
v1: https://lore.kernel.org/netdev/[email protected]
Todd Freed (3):
uapi: add the tc psp action and flower psp keys
tc: add the psp action
tc: flower: add matches psp_spi, psp_ver and psp_dev
include/uapi/linux/pkt_cls.h | 6 + include/uapi/linux/tc_act/tc_psp.h | 28 +++++ man/man8/tc-flower.8 | 29 +++++ man/man8/tc-psp.8 | 98 ++++++++++++++++ tc/Makefile | 1 + tc/f_flower.c | 71 ++++++++++++ tc/m_psp.c | 173 +++++++++++++++++++++++++++++ 7 files changed, 406 insertions(+) create mode 100644 include/uapi/linux/tc_act/tc_psp.h create mode 100644 man/man8/tc-psp.8 create mode 100644 tc/m_psp.c
base-commit: 204a721033556114c81c47d00375f2d52e98e463 --
2.53.0-Meta
PATCH v2 1/3 uapi: add the tc psp action and flower psp keys
The tc psp action (TCA_ID_PSP, tc_act/tc_psp.h) and the flower psp matches (TCA_FLOWER_KEY_PSP_SPI, _SPI_MASK, _VERSION, _DEV), as added by the net-next socket-less psp series.
To be replaced by the regular header sync once that is merged.
--- include/uapi/linux/pkt_cls.h | 6 ++++++ include/uapi/linux/tc_act/tc_psp.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 include/uapi/linux/tc_act/tc_psp.h
include/uapi/linux/pkt_cls.h +6 -0
@@ -139,6 +139,7 @@ enum tca_id {TCA_ID_MPLS ,TCA_ID_CT ,TCA_ID_GATE , +TCA_ID_PSP ,/* other actions go here */ __TCA_ID_MAX = 255 };
@@ -560,6 +561,11 @@ enum {TCA_FLOWER_KEY_ENC_FLAGS ,/* be32 */ TCA_FLOWER_KEY_ENC_FLAGS_MASK ,/* be32 */ +TCA_FLOWER_KEY_PSP_SPI ,/* be32 */ +TCA_FLOWER_KEY_PSP_SPI_MASK ,/* be32 */ +TCA_FLOWER_KEY_PSP_VERSION ,/* u8, enum psp_version */ +TCA_FLOWER_KEY_PSP_DEV ,/* u32, PSP device ID */ + __TCA_FLOWER_MAX, };
include/uapi/linux/tc_act/tc_psp.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __LINUX_TC_PSP_H +#define __LINUX_TC_PSP_H + +#include <linux/pkt_cls.h> + +#define TCA_PSP_ACT_ENCAP 1/* attach a PSP association */ +#define TCA_PSP_ACT_DECAP 2/* drop PSP Rx state */ + +struct tc_psp { +tc_gen ; +}; + +enum { +TCA_PSP_UNSPEC , +TCA_PSP_TM , +TCA_PSP_PARMS , +TCA_PSP_PAD , +TCA_PSP_ACTION ,/* u32, TCA_PSP_ACT_* */ +TCA_PSP_ASSOC_ID ,/* u32, encap only: Tx association ID from +* the PSP netlink family (assoc-add) +*/ + __TCA_PSP_MAX, +}; + +#define TCA_PSP_MAX (__TCA_PSP_MAX - 1) + +#endif
Signature · 1 line
2.53.0-Meta
PATCH v2 2/3 tc: add the psp action
In reply to Todd FreedThe psp action applies PSP (PSP Security Protocol) encap and encryption to packets, separately from psp socket offload:
psp encap assoc ASSOC_ID attach a PSP Tx association, created with
assoc-add over the PSP netlink family; the association's device encrypts the packet on transmit
psp decap remove the PSP Rx state of a packet the
PSP device decrypted
decap takes no association. To take only those packets which belong to a single rx-spi-alloc call, a rule applies the corresponding flower psp_spi, psp_ver and psp_dev matches.
In JSON, the verb is psp_action. The action is documented in tc-psp(8).
--- man/man8/tc-psp.8 | 98 ++++++++++++++++++++++++++ tc/Makefile | 1 + tc/m_psp.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 272 insertions(+) create mode 100644 man/man8/tc-psp.8 create mode 100644 tc/m_psp.c
man/man8/tc-psp.8 new file +98 -0
@@ -0,0 +1,98 @@ +.TH "PSP action in tc" 8 "9 Nov 2026" "iproute2" "Linux" + +.SH NAME +psp - PSP transport mode action +.SH SYNOPSIS +.in +8 +.ti -8 +.BR tc " ... " "action psp" " { " +.BI "encap assoc" " ASSOC_ID" +.RB " | " decap " } [ " +.IR CONTROL " ] [ " +.BI index " INDEX" +.RB " ]" + +.ti -8 +.BR tc " ... " "action psp index" +.I INDEX + +.ti -8 +.IR CONTROL " := { " +.BR reclassify " | " pipe " | " drop " | " continue " | " pass " | " goto " " chain " " CHAIN_INDEX " | " jump " " JUMP_COUNT " }" +.SH DESCRIPTION +The +.B psp +action applies PSP (PSP Security Protocol) encapsulation to packets using keys from the PSP netlink +family: Rx SPIs and their keys from rx-spi-alloc, and Tx associations from assoc-add (assoc-get, +assoc-del). The PSP device encrypts and decrypts the packets. +.SH OPTIONS +.TP +.BI "encap assoc" " ASSOC_ID" +Attach the Tx association +.IR ASSOC_ID , +created with the PSP netlink +.B assoc-add +command, to the packet. The packet must then be transmitted on the netdev of +the association's PSP device, which encrypts it. Use encap either on that +netdev's egress, or on another netdev's egress followed by a redirect to it +.RB ( "mirred egress redirect" ). +If it reaches another device the packet is dropped. Encap on ingress is +hardware offload only +.RB ( skip_sw ), +and in software the action drops the packet. +.TP +.B decap +Remove the PSP Rx state of a packet which the PSP device decrypted, so that +it can be forwarded. To take only the packets corresponding to one +rx-spi-alloc, match packets with the +.BR flower " keys " psp_spi ", " psp_ver " and " psp_dev . +.IP +An SPI from +.B rx-spi-alloc +is valid until the PSP device's key has been rotated twice. After that, the +device can allocate the same SPI value again, and a rule which still matches it +takes the packets of the new allocation. Delete such rules before the second +key rotation after the allocation; the PSP netlink family notifies each key +rotation +.RB ( key-rotate-ntf ). +.TP +.I CONTROL +How to continue after this action, see +.BR tc-actions (8). +The default is +.BR pipe . +.TP +.BI index " INDEX" +Use the action of index +.IR INDEX , +to create it, or to reference an existing one. Without +.B encap +or +.BR decap , +reference an existing action. +.SH EXAMPLES +Encrypt the packets to 2001:db8::2 with Tx association 3, of the PSP device +of eth0: + +.RS +.EX +tc filter add dev eth0 egress protocol ipv6 flower dst_ip 2001:db8::2 \\ + action psp encap assoc 3 +.EE +.RE + +Take the packets which eth0's PSP device (ID 1) decrypted with an SPI from +rx-spi-alloc, and remove their PSP state: + +.RS +.EX +tc filter add dev eth0 ingress protocol ipv6 flower \\ + psp_spi 0x80000001 psp_ver 0 psp_dev 1 \\ + action psp decap +.EE +.RE +.SH SEE ALSO +.BR tc (8), +.BR tc-actions (8), +.BR tc-flower (8), +.BR tc-mirred (8)
tc/Makefile +1 -0
@@ -49,6 +49,7 @@ TCMODULES += m_ctinfo.o TCMODULES += m_bpf.o TCMODULES += m_tunnel_key.o TCMODULES += m_sample.o +TCMODULES += m_psp.o TCMODULES += m_ct.o TCMODULES += m_gate.o TCMODULES += p_ip.o
tc/m_psp.c new file +173 -0
173 lines not on this page · raw message
Signature · 1 line
2.53.0-Meta
PATCH v2 3/3 tc: flower: add matches psp_spi, psp_ver and psp_dev
In reply to Todd FreedMatch on the PSP Rx state of a packet the device decrypted: the SPI it was decrypted with (psp_spi, with an optional mask), the PSP version (psp_ver), and the ID of the PSP device which decrypted it (psp_dev).
For example, to take the packets decrypted with one Rx SPI, from rx-spi-alloc, and remove their PSP state:
tc filter add dev eth0 ingress protocol ipv6 flower
psp_spi 0x80000001 psp_ver 0 psp_dev 1 action psp decap
These keys only match decrypted packets, even with a zero mask, so "psp_spi 0/0" matches any decrypted PSP packet.
psp_spi and its mask are hexadecimal, like spi. tc-flower(8) documents the keys.
--- man/man8/tc-flower.8 | 29 ++++++++++++++++++ tc/f_flower.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+)
man/man8/tc-flower.8 +29 -0
@@ -56,6 +56,12 @@ flower \- flow based traffic control filter .IR TTL " | " .B l2tpv3_sid .IR LSID " | " +.B psp_spi +.IR SPI "[/" MASK "] | " +.B psp_ver +.IR VERSION " | " +.B psp_dev +.IR PSP_DEV_ID " | " .BR ip_proto " { " tcp " | " udp " | " sctp " | " icmp " | " icmpv6 " | " l2tp " | " .IR IP_PROTO " } | " .B ip_tos
@@ -323,6 +329,29 @@ Match on L2TPv3 session id field transported over IPv4 or IPv6. .I LSID is an unsigned 32 bit value in decimal format. .TP +.BI psp_spi " SPI[/MASK]" +Match on the SPI which a PSP device decrypted the packet with. +.I SPI +and +.I MASK +are unsigned 32 bit values in hexadecimal format. +.TP +.BI psp_ver " VERSION" +Match on the PSP version which the packet was decrypted with, as numbered +by the PSP netlink family (0 for hdr0-aes-gcm-128, 1 for hdr0-aes-gcm-256, +2 for hdr0-aes-gmac-128, 3 for hdr0-aes-gmac-256). +.TP +.BI psp_dev " PSP_DEV_ID" +Match on the ID of the PSP device which decrypted the packet, from the PSP +netlink family. +.IP +The PSP keys only ever match packets which a PSP device decrypted, even with +a zero mask: +.B psp_spi 0/0 +matches any packet decrypted with PSP. See +.BR tc-psp (8) +for an example. +.TP .BI ip_proto " IP_PROTO" Match on layer four protocol. .I IP_PROTO
tc/f_flower.c +71 -0
95 lines not on this page · raw message
Signature · 1 line
2.53.0-Meta