Skip to contentSkip to conversation

Add IP-TFS mode to xfrm

RFC Superseded Christian Hopps 8 participants 34 messages Nov 13, 2023 – Mar 10, 2024

Subsystems (6)

v2 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add IP-TFS mode to xfrm

From: Christian Hopps <[email protected]>

This patchset adds a new xfrm mode implementing on-demand IP-TFS. IP-TFS (AggFrag encapsulation) has been standardized in RFC9347.

This feature supports demand driven (i.e., non-constant send rate) IP-TFS to take advantage of the AGGFRAG ESP payload encapsulation. This payload type supports aggregation and fragmentation of the inner IP packet stream which in turn yields higher small-packet bandwidth as well as reducing MTU/PMTU issues. Congestion control is unimplementated as the send rate is demand driven rather than constant.

In order to allow loading this fucntionality as a module a set of callbacks xfrm_mode_cbs has been added to xfrm as well.

#1 lore raw

RFC v2 1/8 iptfs: config: add CONFIG_XFRM_IPTFS

From: Christian Hopps <[email protected]>

Add new Kconfig option to enable IP-TFS (RFC9347) functionality.

---
 net/xfrm/Kconfig | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
net/xfrm/Kconfig +16 -0
index 3adf31a83a79..7a41d36bb080 100644
@@ -134,6 +134,22 @@ config NET_KEY_MIGRATE
 
 	  If unsure, say N.
 
+config XFRM_IPTFS
+	bool "IPsec IP-TFS/AGGFRAG (RFC 9347) encapsulation support"
+	depends on XFRM
+	help
+	  Information on the IP-TFS/AGGFRAG encapsulation can be found
+	  in RFC 9347. This feature supports demand driven (i.e.,
+	  non-constant send rate) IP-TFS to take advantage of the
+	  AGGFRAG ESP payload encapsulation. This payload type
+	  supports aggregation and fragmentation of the inner IP
+	  packet stream which in turn yields higher small-packet
+	  bandwidth as well as reducing MTU/PMTU issues. Congestion
+	  control is unimplementated as the send rate is demand driven
+	  rather than constant.
+
+	  If unsure, say N.
+
 config XFRM_ESPINTCP
 	bool
 
Signature · 1 line
2.42.0
#2 lore raw

RFC v2 2/8 iptfs: uapi: ip: add ip_tfs_*_hdr packet formats

In reply to Christian Hopps

From: Christian Hopps <[email protected]>

Add the on-wire basic and congestion-control IP-TFS packet headers.

---
 include/uapi/linux/ip.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
include/uapi/linux/ip.h +17 -0
index 283dec7e3645..cc83878ecf08 100644
@@ -137,6 +137,23 @@ struct ip_beet_phdr {
 	__u8 reserved;
 };
 
+struct ip_iptfs_hdr {
+	__u8 subtype;		/* 0*: basic, 1: CC */
+	__u8 flags;
+	__be16 block_offset;
+};
+
+struct ip_iptfs_cc_hdr {
+	__u8 subtype;		/* 0: basic, 1*: CC */
+	__u8 flags;
+	__be16 block_offset;
+	__be32 loss_rate;
+	__u8 rtt_and_adelay1[4];
+	__u8 adelay2_and_xdelay[4];
+	__be32 tval;
+	__be32 techo;
+};
+
 /* index values for the variables in ipv4_devconf */
 enum
 {
Signature · 1 line
2.42.0
#3 lore raw

Re: [RFC ipsec-next v2 2/8] iptfs: uapi: ip: add ip_tfs_*_hdr packet formats

Quoted 20 lines · Christian Hopps

From: Christian Hopps <[email protected]>

Add the on-wire basic and congestion-control IP-TFS packet headers.

---
 include/uapi/linux/ip.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
include/uapi/linux/ip.h +3 -0
index 283dec7e3645..cc83878ecf08 100644
@@ -137,6 +137,23 @@ struct ip_beet_phdr {
 	__u8 reserved;
 };
 
+struct ip_iptfs_hdr {
+	__u8 subtype;		/* 0*: basic, 1: CC */
+	__u8 flags;

include/uapi/linux/ip.h struct ip_beet_phdr { · line 152

Quoted 10 lines
include/uapi/linux/ip.h +10 -0
+	__be16 block_offset;
+};
+
+struct ip_iptfs_cc_hdr {
+	__u8 subtype;		/* 0: basic, 1*: CC */
+	__u8 flags;
+	__be16 block_offset;
+	__be32 loss_rate;
+	__u8 rtt_and_adelay1[4];
+	__u8 adelay2_and_xdelay[4];

Given how the fields are split, wouldn't it be more convenient to have a single __be64, rather than reading some bits from multiple __u8?

include/uapi/linux/ip.h struct ip_beet_phdr { · line 155

Quoted 3 lines
include/uapi/linux/ip.h +3 -0
+	__be32 tval;
+	__be32 techo;
+};

I don't think these need to be part of uapi. Can we move them to include/net/iptfs.h (or possibly net/xfrm/xfrm_iptfs.c)? It would also make more sense to have them near the definitions for IPTFS_SUBTYPE_*. And it would be easier to change how we split and name fields for kernel consumption if we're not stuck with whatever we put in uapi.

Signature · 1 line
Sabrina
#4 lore raw

Re: [RFC ipsec-next v2 2/8] iptfs: uapi: ip: add ip_tfs_*_hdr packet formats

Quoted 18 lines · Sabrina Dubroca
Quoted 17 lines · Christian Hopps

From: Christian Hopps <[email protected]>

Add the on-wire basic and congestion-control IP-TFS packet headers.

---
 include/uapi/linux/ip.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
include/uapi/linux/ip.h +0 -0
index 283dec7e3645..cc83878ecf08 100644
@@ -137,6 +137,23 @@ struct ip_beet_phdr {
 	__u8 reserved;
 };
 
Quoted 16 lines

include/uapi/linux/ip.h struct ip_beet_phdr { · line 152

Quoted 13 lines
include/uapi/linux/ip.h +13 -0
+struct ip_iptfs_hdr {
+	__u8 subtype;		/* 0*: basic, 1: CC */
+	__u8 flags;
+	__be16 block_offset;
+};
+
+struct ip_iptfs_cc_hdr {
+	__u8 subtype;		/* 0: basic, 1*: CC */
+	__u8 flags;
+	__be16 block_offset;
+	__be32 loss_rate;
+	__u8 rtt_and_adelay1[4];
+	__u8 adelay2_and_xdelay[4];

Given how the fields are split, wouldn't it be more convenient to have a single __be64, rather than reading some bits from multiple __u8?

This is a good point, I carried this over from an earlier implementation, let me give it some though but probably change it.

Quoted 10 lines

include/uapi/linux/ip.h struct ip_beet_phdr { · line 155

Quoted 3 lines
include/uapi/linux/ip.h +3 -0
+	__be32 tval;
+	__be32 techo;
+};

I don't think these need to be part of uapi. Can we move them to include/net/iptfs.h (or possibly net/xfrm/xfrm_iptfs.c)? It would also make more sense to have them near the definitions for IPTFS_SUBTYPE_*. And it would be easier to change how we split and name fields for kernel consumption if we're not stuck with whatever we put in uapi.

The other ipsec modes headers were added here, so I was simply following along. I don't mind moving things but would like to understand why iptfs would be different from the other modes, for example, struct ip_comp_hdr and struct ip_beet_phdr appears in this file.

Thanks!
Chris.

#5 lore raw

Re: [RFC ipsec-next v2 2/8] iptfs: uapi: ip: add ip_tfs_*_hdr packet formats

Quoted 51 lines · Christian Hopps
Quoted 18 lines · Sabrina Dubroca
Quoted 17 lines · Christian Hopps

From: Christian Hopps <[email protected]>

Add the on-wire basic and congestion-control IP-TFS packet headers.

---
 include/uapi/linux/ip.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
include/uapi/linux/ip.h +0 -0
index 283dec7e3645..cc83878ecf08 100644
@@ -137,6 +137,23 @@ struct ip_beet_phdr {
 	__u8 reserved;
 };
 
Quoted 16 lines

include/uapi/linux/ip.h struct ip_beet_phdr { · line 152

Quoted 13 lines
include/uapi/linux/ip.h +13 -0
+struct ip_iptfs_hdr {
+	__u8 subtype;		/* 0*: basic, 1: CC */
+	__u8 flags;
+	__be16 block_offset;
+};
+
+struct ip_iptfs_cc_hdr {
+	__u8 subtype;		/* 0: basic, 1*: CC */
+	__u8 flags;
+	__be16 block_offset;
+	__be32 loss_rate;
+	__u8 rtt_and_adelay1[4];
+	__u8 adelay2_and_xdelay[4];

Given how the fields are split, wouldn't it be more convenient to have a single __be64, rather than reading some bits from multiple __u8?

This is a good point, I carried this over from an earlier implementation, let me give it some though but probably change it.

Quoted 10 lines

include/uapi/linux/ip.h struct ip_beet_phdr { · line 155

Quoted 3 lines
include/uapi/linux/ip.h +3 -0
+	__be32 tval;
+	__be32 techo;
+};

I don't think these need to be part of uapi. Can we move them to include/net/iptfs.h (or possibly net/xfrm/xfrm_iptfs.c)? It would also make more sense to have them near the definitions for IPTFS_SUBTYPE_*. And it would be easier to change how we split and name fields for kernel consumption if we're not stuck with whatever we put in uapi.

Quoted 5 lines

The other ipsec modes headers were added here, so I was simply following along. I don't mind moving things but would like to understand why iptfs would be different from the other modes, for example, struct ip_comp_hdr and struct ip_beet_phdr appears in this file.

IMHO it was a mistake that was made when include/uapi was created, they should not have been part of uapi since there's never an exchange between kernel and userspace using those. I guess it's less problematic because the header formats are simple (everything fits nicely into a u8/u16/u32) and they were already used in the kernel for a long time so pretty much stable (ie no doubt about whether the split and naming that was chosen was right).

But if others feel strongly about putting those structs in uapi, I can live with that.

I'll send comments on the rest of the series as I continue making my way through it. The main patch is going to take me a while :(

Signature · 1 line
Sabrina
#6 lore raw

Re: [RFC ipsec-next v2 2/8] iptfs: uapi: ip: add ip_tfs_*_hdr packet formats

In reply to Sabrina Dubroca
Quoted 18 lines · Sabrina Dubroca
Quoted 17 lines · Christian Hopps

From: Christian Hopps <[email protected]>

Add the on-wire basic and congestion-control IP-TFS packet headers.

---
 include/uapi/linux/ip.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
include/uapi/linux/ip.h +0 -0
index 283dec7e3645..cc83878ecf08 100644
@@ -137,6 +137,23 @@ struct ip_beet_phdr {
 	__u8 reserved;
 };
 
Quoted 16 lines

include/uapi/linux/ip.h struct ip_beet_phdr { · line 152

Quoted 13 lines
include/uapi/linux/ip.h +13 -0
+struct ip_iptfs_hdr {
+	__u8 subtype;		/* 0*: basic, 1: CC */
+	__u8 flags;
+	__be16 block_offset;
+};
+
+struct ip_iptfs_cc_hdr {
+	__u8 subtype;		/* 0: basic, 1*: CC */
+	__u8 flags;
+	__be16 block_offset;
+	__be32 loss_rate;
+	__u8 rtt_and_adelay1[4];
+	__u8 adelay2_and_xdelay[4];

Given how the fields are split, wouldn't it be more convenient to have a single __be64, rather than reading some bits from multiple __u8?

Changed this to __be64.

Quoted 10 lines

include/uapi/linux/ip.h struct ip_beet_phdr { · line 155

Quoted 3 lines
include/uapi/linux/ip.h +3 -0
+	__be32 tval;
+	__be32 techo;
+};

I don't think these need to be part of uapi. Can we move them to include/net/iptfs.h (or possibly net/xfrm/xfrm_iptfs.c)? It would also make more sense to have them near the definitions for IPTFS_SUBTYPE_*. And it would be easier to change how we split and name fields for kernel consumption if we're not stuck with whatever we put in uapi.

I saw this also as the place documenting the packet format. Userland can have raw packets delivered to them... Mostly though I was following the pattern that existed already.

Thanks,
Chris.

#7 lore raw

RFC v2 3/8 iptfs: uapi: IPPROTO_AGGFRAG AGGFRAG in ESP

In reply to Christian Hopps

From: Christian Hopps <[email protected]>

Add the RFC assigned IP protocol number for AGGFRAG.

---
 include/uapi/linux/in.h | 2 ++
 1 file changed, 2 insertions(+)
include/uapi/linux/in.h +2 -0
index e682ab628dfa..e6a1f3e4c58c 100644
@@ -79,6 +79,8 @@ enum {
 #define IPPROTO_MPLS		IPPROTO_MPLS
   IPPROTO_ETHERNET = 143,	/* Ethernet-within-IPv6 Encapsulation	*/
 #define IPPROTO_ETHERNET	IPPROTO_ETHERNET
+  IPPROTO_AGGFRAG = 144,	/* AGGFRAG in ESP (RFC 9347)		*/
+#define IPPROTO_AGGFRAG		IPPROTO_AGGFRAG
   IPPROTO_RAW = 255,		/* Raw IP packets			*/
 #define IPPROTO_RAW		IPPROTO_RAW
   IPPROTO_MPTCP = 262,		/* Multipath TCP connection		*/
Signature · 1 line
2.42.0
#8 lore raw

RFC v2 4/8 iptfs: sysctl: allow configuration of global default values

In reply to Christian Hopps

From: Christian Hopps <[email protected]>

Add sysctls for the changing the IPTFS default SA values.

---
 Documentation/networking/xfrm_sysctl.rst | 29 ++++++++++++++++++
 include/net/netns/xfrm.h                 |  6 ++++
 include/net/xfrm.h                       |  7 +++++
 net/xfrm/xfrm_sysctl.c                   | 38 ++++++++++++++++++++++++
 4 files changed, 80 insertions(+)
Documentation/networking/xfrm_sysctl.rst +29 -0
index 47b9bbdd0179..9e628806c110 100644
@@ -9,3 +9,32 @@ XFRM Syscall
 
 xfrm_acq_expires - INTEGER
 	default 30 - hard timeout in seconds for acquire requests
+
+xfrm_iptfs_maxqsize - UNSIGNED INTEGER
+        The default IPTFS max output queue size in octets. The output queue is
+        where received packets destined for output over an IPTFS tunnel are
+        stored prior to being output in aggregated/fragmented form over the
+        IPTFS tunnel.
+
+        Default 1M.
+
+xfrm_iptfs_drptime - UNSIGNED INTEGER
+        The default IPTFS drop time in microseconds. The drop time is the amount
+        of time before a missing out-of-order IPTFS tunnel packet is considered
+        lost. See also the reorder window.
+
+        Default 1s (1000000).
+
+xfrm_iptfs_idelay - UNSIGNED INTEGER
+        The default IPTFS initial output delay in microseconds. The initial
+        output delay is the amount of time prior to servicing the output queue
+        after queueing the first packet on said queue.
+
+        Default 0.
+
+xfrm_iptfs_rewin - UNSIGNED INTEGER
+        The default IPTFS reorder window size. The reorder window size dictates
+        the maximum number of IPTFS tunnel packets in a sequence that may arrive
+        out of order.
+
+        Default 3.
include/net/netns/xfrm.h +6 -0
index bd7c3be4af5d..d5ad2155d0bb 100644
@@ -65,6 +65,12 @@ struct netns_xfrm {
 	u32			sysctl_aevent_rseqth;
 	int			sysctl_larval_drop;
 	u32			sysctl_acq_expires;
+#if IS_ENABLED(CONFIG_XFRM_IPTFS)
+	u32			sysctl_iptfs_drptime;
+	u32			sysctl_iptfs_idelay;
+	u32			sysctl_iptfs_maxqsize;
+	u32			sysctl_iptfs_rewin;
+#endif
 
 	u8			policy_default[XFRM_POLICY_MAX];
 
include/net/xfrm.h +7 -0
index c9bb0f892f55..d2e87344d175 100644
@@ -2190,4 +2190,11 @@ static inline int register_xfrm_interface_bpf(void)
 
 #endif
 
+#if IS_ENABLED(CONFIG_XFRM_IPTFS)
+#define XFRM_IPTFS_DEFAULT_MAX_QUEUE_SIZE (1024 * 1024)
+#define XFRM_IPTFS_DEFAULT_INIT_DELAY_USECS (0)
+#define XFRM_IPTFS_DEFAULT_DROP_TIME_USECS (1000000)
+#define XFRM_IPTFS_DEFAULT_REORDER_WINDOW (3)
+#endif
+
 #endif	/* _NET_XFRM_H */
net/xfrm/xfrm_sysctl.c +38 -0
index 7fdeafc838a7..bf8e73a6c38e 100644
@@ -10,6 +10,12 @@ static void __net_init __xfrm_sysctl_init(struct net *net)
 	net->xfrm.sysctl_aevent_rseqth = XFRM_AE_SEQT_SIZE;
 	net->xfrm.sysctl_larval_drop = 1;
 	net->xfrm.sysctl_acq_expires = 30;
+#if IS_ENABLED(CONFIG_XFRM_IPTFS)
+	net->xfrm.sysctl_iptfs_maxqsize = XFRM_IPTFS_DEFAULT_MAX_QUEUE_SIZE;
+	net->xfrm.sysctl_iptfs_drptime = XFRM_IPTFS_DEFAULT_DROP_TIME_USECS;
+	net->xfrm.sysctl_iptfs_idelay = XFRM_IPTFS_DEFAULT_INIT_DELAY_USECS;
+	net->xfrm.sysctl_iptfs_rewin = XFRM_IPTFS_DEFAULT_REORDER_WINDOW;
+#endif
 }
 
 #ifdef CONFIG_SYSCTL
@@ -38,6 +44,32 @@ static struct ctl_table xfrm_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec
 	},
+#if IS_ENABLED(CONFIG_XFRM_IPTFS)
+	{
+		.procname	= "xfrm_iptfs_drptime",
+		.maxlen		= sizeof(uint),
+		.mode		= 0644,
+		.proc_handler	= proc_douintvec
+	},
+	{
+		.procname	= "xfrm_iptfs_idelay",
+		.maxlen		= sizeof(uint),
+		.mode		= 0644,
+		.proc_handler	= proc_douintvec
+	},
+	{
+		.procname	= "xfrm_iptfs_maxqsize",
+		.maxlen		= sizeof(uint),
+		.mode		= 0644,
+		.proc_handler	= proc_douintvec
+	},
+	{
+		.procname	= "xfrm_iptfs_rewin",
+		.maxlen		= sizeof(uint),
+		.mode		= 0644,
+		.proc_handler	= proc_douintvec
+	},
+#endif
 	{}
 };
 
@@ -55,6 +87,12 @@ int __net_init xfrm_sysctl_init(struct net *net)
 	table[1].data = &net->xfrm.sysctl_aevent_rseqth;
 	table[2].data = &net->xfrm.sysctl_larval_drop;
 	table[3].data = &net->xfrm.sysctl_acq_expires;
+#if IS_ENABLED(CONFIG_XFRM_IPTFS)
+	table[4].data = &net->xfrm.sysctl_iptfs_drptime;
+	table[5].data = &net->xfrm.sysctl_iptfs_idelay;
+	table[6].data = &net->xfrm.sysctl_iptfs_maxqsize;
+	table[7].data = &net->xfrm.sysctl_iptfs_rewin;
+#endif
 
 	/* Don't export sysctls to unprivileged users */
 	if (net->user_ns != &init_user_ns) {
Signature · 1 line
2.42.0
#9 lore raw

Re: [RFC ipsec-next v2 4/8] iptfs: sysctl: allow configuration of global default values

Quoted 20 lines · Christian Hopps

From: Christian Hopps <[email protected]>

Add sysctls for the changing the IPTFS default SA values.

---
 Documentation/networking/xfrm_sysctl.rst | 29 ++++++++++++++++++
 include/net/netns/xfrm.h                 |  6 ++++
 include/net/xfrm.h                       |  7 +++++
 net/xfrm/xfrm_sysctl.c                   | 38 ++++++++++++++++++++++++
 4 files changed, 80 insertions(+)
Documentation/networking/xfrm_sysctl.rst +0 -0
index 47b9bbdd0179..9e628806c110 100644
@@ -9,3 +9,32 @@ XFRM Syscall
 
 xfrm_acq_expires - INTEGER
 	default 30 - hard timeout in seconds for acquire requests

Documentation/networking/xfrm_sysctl.rst XFRM Syscall · line 21

Quoted 10 lines
Documentation/networking/xfrm_sysctl.rst +10 -0
+
+xfrm_iptfs_maxqsize - UNSIGNED INTEGER
+        The default IPTFS max output queue size in octets. The output queue is
+        where received packets destined for output over an IPTFS tunnel are
+        stored prior to being output in aggregated/fragmented form over the
+        IPTFS tunnel.
+
+        Default 1M.
+
+xfrm_iptfs_drptime - UNSIGNED INTEGER

nit: Can we make those names a bit more human-readable? xfrm_iptfs_droptime, or possibly xfrm_iptfs_drop_time for better consistency with the netlink API.

Documentation/networking/xfrm_sysctl.rst XFRM Syscall · line 28

Quoted 7 lines
Documentation/networking/xfrm_sysctl.rst +7 -0
+        The default IPTFS drop time in microseconds. The drop time is the amount
+        of time before a missing out-of-order IPTFS tunnel packet is considered
+        lost. See also the reorder window.
+
+        Default 1s (1000000).
+
+xfrm_iptfs_idelay - UNSIGNED INTEGER

I would suggest xfrm_iptfs_initial_delay (or at least init_delay like the netlink attribute).

Documentation/networking/xfrm_sysctl.rst XFRM Syscall · line 31

Quoted 3 lines
Documentation/networking/xfrm_sysctl.rst +3 -0
+        The default IPTFS initial output delay in microseconds. The initial
+        output delay is the amount of time prior to servicing the output queue
+        after queueing the first packet on said queue.

Does that also apply if the queue was fully drained (no traffic for a while) and starts being used again? That might be worth documenting either way (sorry, I haven't processed the main patch far enough to answer this question myself yet).

And it might be worth mentioning that all these sysctls can be overridden per SA via the netlink API.

Documentation/networking/xfrm_sysctl.rst XFRM Syscall · line 35

Quoted 3 lines
Documentation/networking/xfrm_sysctl.rst +3 -0
+        Default 0.
+
+xfrm_iptfs_rewin - UNSIGNED INTEGER

xfrm_iptfs_reorderwin (or reorder_win, or reorder_window)? I'd also make the equivalent netlink attribute's name a bit longer (at least spell out REORDER, I can live with WIN for WINDOW).

[...]

Quoted 5 lines
include/net/xfrm.h +0 -0
index c9bb0f892f55..d2e87344d175 100644

include/net/xfrm.h static inline int register_xfrm_interface_bpf(void) · line 2198

Quoted 9 lines
include/net/xfrm.h +6 -0
@@ -2190,4 +2190,11 @@ static inline int register_xfrm_interface_bpf(void)
 
 #endif
 
+#if IS_ENABLED(CONFIG_XFRM_IPTFS)
+#define XFRM_IPTFS_DEFAULT_MAX_QUEUE_SIZE (1024 * 1024)
+#define XFRM_IPTFS_DEFAULT_INIT_DELAY_USECS (0)
+#define XFRM_IPTFS_DEFAULT_DROP_TIME_USECS (1000000)
+#define XFRM_IPTFS_DEFAULT_REORDER_WINDOW (3)
+#endif

nit: move those to net/xfrm/xfrm_sysctl.c ? they're only used in that file.

Quoted 4 lines
net/xfrm/xfrm_sysctl.c +0 -0
index 7fdeafc838a7..bf8e73a6c38e 100644

[...]

net/xfrm/xfrm_sysctl.c int __net_init xfrm_sysctl_init(struct net *net) · line 95

Quoted 10 lines
net/xfrm/xfrm_sysctl.c +6 -0
@@ -55,6 +87,12 @@ int __net_init xfrm_sysctl_init(struct net *net)
 	table[1].data = &net->xfrm.sysctl_aevent_rseqth;
 	table[2].data = &net->xfrm.sysctl_larval_drop;
 	table[3].data = &net->xfrm.sysctl_acq_expires;
+#if IS_ENABLED(CONFIG_XFRM_IPTFS)
+	table[4].data = &net->xfrm.sysctl_iptfs_drptime;
+	table[5].data = &net->xfrm.sysctl_iptfs_idelay;
+	table[6].data = &net->xfrm.sysctl_iptfs_maxqsize;
+	table[7].data = &net->xfrm.sysctl_iptfs_rewin;
+#endif

Is it time to switch to a loop like in ipv6_sysctl_net_init? See commit d2f7e56d1e40 ("ipv6: Use math to point per net sysctls into the appropriate struct net"). OTOH we don't add sysctls for xfrm very often so it's not critical.

Signature · 1 line
Sabrina
#10 lore raw

Re: [RFC ipsec-next v2 4/8] iptfs: sysctl: allow configuration of global default values

Quoted 19 lines · Sabrina Dubroca
Quoted 18 lines · Christian Hopps

From: Christian Hopps <[email protected]>

Add sysctls for the changing the IPTFS default SA values.

---
 Documentation/networking/xfrm_sysctl.rst | 29 ++++++++++++++++++
 include/net/netns/xfrm.h                 |  6 ++++
 include/net/xfrm.h                       |  7 +++++
 net/xfrm/xfrm_sysctl.c                   | 38 ++++++++++++++++++++++++
 4 files changed, 80 insertions(+)
Documentation/networking/xfrm_sysctl.rst +0 -0
index 47b9bbdd0179..9e628806c110 100644
@@ -9,3 +9,32 @@ XFRM Syscall
 
Quoted 16 lines

Documentation/networking/xfrm_sysctl.rst XFRM Syscall · line 21

Quoted 12 lines
Documentation/networking/xfrm_sysctl.rst +10 -0
 xfrm_acq_expires - INTEGER
 	default 30 - hard timeout in seconds for acquire requests
+
+xfrm_iptfs_maxqsize - UNSIGNED INTEGER
+        The default IPTFS max output queue size in octets. The output queue is
+        where received packets destined for output over an IPTFS tunnel are
+        stored prior to being output in aggregated/fragmented form over the
+        IPTFS tunnel.
+
+        Default 1M.
+
+xfrm_iptfs_drptime - UNSIGNED INTEGER

nit: Can we make those names a bit more human-readable? xfrm_iptfs_droptime, or possibly xfrm_iptfs_drop_time for better consistency with the netlink API.

Changed to xfrm_iptfs_drop_time.

Quoted 10 lines

Documentation/networking/xfrm_sysctl.rst XFRM Syscall · line 28

Quoted 7 lines
Documentation/networking/xfrm_sysctl.rst +7 -0
+        The default IPTFS drop time in microseconds. The drop time is the amount
+        of time before a missing out-of-order IPTFS tunnel packet is considered
+        lost. See also the reorder window.
+
+        Default 1s (1000000).
+
+xfrm_iptfs_idelay - UNSIGNED INTEGER

I would suggest xfrm_iptfs_initial_delay (or at least init_delay like the netlink attribute).

Changed to xfrm_iptfs_init_delay.

Quoted 9 lines

Documentation/networking/xfrm_sysctl.rst XFRM Syscall · line 31

Quoted 4 lines
Documentation/networking/xfrm_sysctl.rst +3 -0
+        The default IPTFS initial output delay in microseconds. The initial
+        output delay is the amount of time prior to servicing the output queue
+        after queueing the first packet on said queue.

Does that also apply if the queue was fully drained (no traffic for a while) and starts being used again? That might be worth documenting either way (sorry, I haven't processed the main patch far enough to answer this question myself yet).

Added: "This applies anytime the output queue was previously empty."

Quoted 2 lines

And it might be worth mentioning that all these sysctls can be overridden per SA via the netlink API.

The description of these values as the "default"s implies the fact that they can be changed, I think.

Quoted 8 lines

Documentation/networking/xfrm_sysctl.rst XFRM Syscall · line 35

Quoted 3 lines
Documentation/networking/xfrm_sysctl.rst +3 -0
+        Default 0.
+
+xfrm_iptfs_rewin - UNSIGNED INTEGER

xfrm_iptfs_reorderwin (or reorder_win, or reorder_window)? I'd also make the equivalent netlink attribute's name a bit longer (at least spell out REORDER, I can live with WIN for WINDOW).

Changed to xfrm_iptfs_reorder_window.

Also renamed the netlink attribute REORD_WIN to match (i.e., not XFRMA_IPTFS_REORDER_WINDOW).

Quoted 9 lines

[...]

Quoted 8 lines
include/net/xfrm.h +0 -0
index c9bb0f892f55..d2e87344d175 100644
@@ -2190,4 +2190,11 @@ static inline int register_xfrm_interface_bpf(void)
 
 #endif
 
Quoted 8 lines

include/net/xfrm.h static inline int register_xfrm_interface_bpf(void) · line 2198

Quoted 6 lines
include/net/xfrm.h +6 -0
+#if IS_ENABLED(CONFIG_XFRM_IPTFS)
+#define XFRM_IPTFS_DEFAULT_MAX_QUEUE_SIZE (1024 * 1024)
+#define XFRM_IPTFS_DEFAULT_INIT_DELAY_USECS (0)
+#define XFRM_IPTFS_DEFAULT_DROP_TIME_USECS (1000000)
+#define XFRM_IPTFS_DEFAULT_REORDER_WINDOW (3)
+#endif

nit: move those to net/xfrm/xfrm_sysctl.c ? they're only used in that file.

Rather than move them directly above where they are only used I just removed them entirely.

Thanks,
Chris.

Quoted 20 lines
Quoted 4 lines
net/xfrm/xfrm_sysctl.c +0 -0
index 7fdeafc838a7..bf8e73a6c38e 100644

[...]

net/xfrm/xfrm_sysctl.c int __net_init xfrm_sysctl_init(struct net *net) · line 95

Quoted 10 lines
net/xfrm/xfrm_sysctl.c +6 -0
@@ -55,6 +87,12 @@ int __net_init xfrm_sysctl_init(struct net *net)
 	table[1].data = &net->xfrm.sysctl_aevent_rseqth;
 	table[2].data = &net->xfrm.sysctl_larval_drop;
 	table[3].data = &net->xfrm.sysctl_acq_expires;
+#if IS_ENABLED(CONFIG_XFRM_IPTFS)
+	table[4].data = &net->xfrm.sysctl_iptfs_drptime;
+	table[5].data = &net->xfrm.sysctl_iptfs_idelay;
+	table[6].data = &net->xfrm.sysctl_iptfs_maxqsize;
+	table[7].data = &net->xfrm.sysctl_iptfs_rewin;
+#endif

Is it time to switch to a loop like in ipv6_sysctl_net_init? See commit d2f7e56d1e40 ("ipv6: Use math to point per net sysctls into the appropriate struct net"). OTOH we don't add sysctls for xfrm very often so it's not critical.

#11 lore raw

RFC v2 5/8 iptfs: netlink: add config (netlink) options

In reply to Christian Hopps

From: Christian Hopps <[email protected]>

Add netlink options for configuring IP-TFS SAs.

---
 include/uapi/linux/xfrm.h |  9 ++++++++-
 net/xfrm/xfrm_compat.c    | 10 ++++++++--
 net/xfrm/xfrm_user.c      | 16 ++++++++++++++++
 3 files changed, 32 insertions(+), 3 deletions(-)
include/uapi/linux/xfrm.h +8 -1
index 6a77328be114..3e98d45d70a6 100644
@@ -153,7 +153,8 @@ enum {
 #define XFRM_MODE_ROUTEOPTIMIZATION 2
 #define XFRM_MODE_IN_TRIGGER 3
 #define XFRM_MODE_BEET 4
-#define XFRM_MODE_MAX 5
+#define XFRM_MODE_IPTFS 5
+#define XFRM_MODE_MAX 6
 
 /* Netlink configuration messages.  */
 enum {
@@ -315,6 +316,12 @@ enum xfrm_attr_type_t {
 	XFRMA_SET_MARK_MASK,	/* __u32 */
 	XFRMA_IF_ID,		/* __u32 */
 	XFRMA_MTIMER_THRESH,	/* __u32 in seconds for input SA */
+	XFRMA_IPTFS_PKT_SIZE,	/* __u32 Size of outer packet, 0 for PMTU */
+	XFRMA_IPTFS_MAX_QSIZE,	/* __u32 max ingress queue size */
+	XFRMA_IPTFS_DONT_FRAG,	/* don't use fragmentation */
+	XFRMA_IPTFS_DROP_TIME,	/* __u32 usec to wait for next seq */
+	XFRMA_IPTFS_REORD_WIN,	/* __u16 reorder window size */
+	XFRMA_IPTFS_INIT_DELAY,	/* __u32 initial packet wait delay (usec) */
 	__XFRMA_MAX
 
 #define XFRMA_OUTPUT_MARK XFRMA_SET_MARK	/* Compatibility */
net/xfrm/xfrm_compat.c +8 -2
index 655fe4ff8621..35b2abf33e54 100644
@@ -277,9 +277,15 @@ static int xfrm_xlate64_attr(struct sk_buff *dst, const struct nlattr *src)
 	case XFRMA_SET_MARK_MASK:
 	case XFRMA_IF_ID:
 	case XFRMA_MTIMER_THRESH:
+	case XFRMA_IPTFS_PKT_SIZE:
+	case XFRMA_IPTFS_MAX_QSIZE:
+	case XFRMA_IPTFS_DONT_FRAG:
+	case XFRMA_IPTFS_DROP_TIME:
+	case XFRMA_IPTFS_REORD_WIN:
+	case XFRMA_IPTFS_INIT_DELAY:
 		return xfrm_nla_cpy(dst, src, nla_len(src));
 	default:
-		BUILD_BUG_ON(XFRMA_MAX != XFRMA_MTIMER_THRESH);
+		BUILD_BUG_ON(XFRMA_MAX != XFRMA_IPTFS_INIT_DELAY);
 		pr_warn_once("unsupported nla_type %d\n", src->nla_type);
 		return -EOPNOTSUPP;
 	}
@@ -434,7 +440,7 @@ static int xfrm_xlate32_attr(void *dst, const struct nlattr *nla,
 	int err;
 
 	if (type > XFRMA_MAX) {
-		BUILD_BUG_ON(XFRMA_MAX != XFRMA_MTIMER_THRESH);
+		BUILD_BUG_ON(XFRMA_MAX != XFRMA_IPTFS_INIT_DELAY);
 		NL_SET_ERR_MSG(extack, "Bad attribute");
 		return -EOPNOTSUPP;
 	}
net/xfrm/xfrm_user.c +16 -0
index ad01997c3aa9..fa2059de51f5 100644
@@ -272,6 +272,16 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
 			NL_SET_ERR_MSG(extack, "TFC padding can only be used in tunnel mode");
 			goto out;
 		}
+		if ((attrs[XFRMA_IPTFS_PKT_SIZE] ||
+		     attrs[XFRMA_IPTFS_MAX_QSIZE] ||
+		     attrs[XFRMA_IPTFS_DONT_FRAG] ||
+		     attrs[XFRMA_IPTFS_DROP_TIME] ||
+		     attrs[XFRMA_IPTFS_REORD_WIN] ||
+		     attrs[XFRMA_IPTFS_INIT_DELAY]) &&
+		    p->mode != XFRM_MODE_IPTFS) {
+			NL_SET_ERR_MSG(extack, "IPTFS options can only be used in IPTFS mode");
+			goto out;
+		}
 		break;
 
 	case IPPROTO_COMP:
@@ -3046,6 +3056,12 @@ const struct nla_policy xfrma_policy[XFRMA_MAX+1] = {
 	[XFRMA_SET_MARK_MASK]	= { .type = NLA_U32 },
 	[XFRMA_IF_ID]		= { .type = NLA_U32 },
 	[XFRMA_MTIMER_THRESH]   = { .type = NLA_U32 },
+	[XFRMA_IPTFS_PKT_SIZE]	= { .type = NLA_U32 },
+	[XFRMA_IPTFS_MAX_QSIZE]	= { .type = NLA_U32 },
+	[XFRMA_IPTFS_DONT_FRAG]	= { .type = NLA_FLAG },
+	[XFRMA_IPTFS_DROP_TIME]	= { .type = NLA_U32 },
+	[XFRMA_IPTFS_REORD_WIN]	= { .type = NLA_U16 },
+	[XFRMA_IPTFS_INIT_DELAY] = { .type = NLA_U32 },
 };
 EXPORT_SYMBOL_GPL(xfrma_policy);
 
Signature · 1 line
2.42.0
#12 lore raw

Re: [RFC ipsec-next v2 5/8] iptfs: netlink: add config (netlink) options

net/xfrm/xfrm_user.c const struct nla_policy xfrma_policy[XFRMA_MAX+1] = { · line 3061

Quoted 7 lines · Christian Hopps
net/xfrm/xfrm_user.c +3 -0
@@ -3046,6 +3056,12 @@ const struct nla_policy xfrma_policy[XFRMA_MAX+1] = {
 	[XFRMA_SET_MARK_MASK]	= { .type = NLA_U32 },
 	[XFRMA_IF_ID]		= { .type = NLA_U32 },
 	[XFRMA_MTIMER_THRESH]   = { .type = NLA_U32 },
+	[XFRMA_IPTFS_PKT_SIZE]	= { .type = NLA_U32 },
+	[XFRMA_IPTFS_MAX_QSIZE]	= { .type = NLA_U32 },
+	[XFRMA_IPTFS_DONT_FRAG]	= { .type = NLA_FLAG },

Do we want to be able to turn this off with an update? Flags don't really allow this.

Signature · 1 line
Sabrina
#13 lore raw

RFC v2 6/8 iptfs: xfrm: Add mode_cbs module functionality

In reply to Christian Hopps

From: Christian Hopps <[email protected]>

Add a set of callbacks xfrm_mode_cbs to xfrm_state. These callbacks enable the addition of new xfrm modes, such as IP-TFS to be defined in modules.

---
 include/net/xfrm.h     | 36 ++++++++++++++++++++++++++++++++++++
 net/xfrm/xfrm_device.c |  3 ++-
 net/xfrm/xfrm_input.c  | 14 ++++++++++++--
 net/xfrm/xfrm_output.c |  9 +++++++--
 net/xfrm/xfrm_policy.c | 18 +++++++++++-------
 net/xfrm/xfrm_state.c  | 41 +++++++++++++++++++++++++++++++++++++++++
 net/xfrm/xfrm_user.c   | 10 ++++++++++
 7 files changed, 119 insertions(+), 12 deletions(-)
include/net/xfrm.h +36 -0
index d2e87344d175..aeeadadc9545 100644
@@ -204,6 +204,7 @@ struct xfrm_state {
 		u16		family;
 		xfrm_address_t	saddr;
 		int		header_len;
+		int		enc_hdr_len;
 		int		trailer_len;
 		u32		extra_flags;
 		struct xfrm_mark	smark;
@@ -289,6 +290,9 @@ struct xfrm_state {
 	/* Private data of this transformer, format is opaque,
 	 * interpreted by xfrm_type methods. */
 	void			*data;
+
+	const struct xfrm_mode_cbs	*mode_cbs;
+	void				*mode_data;
 };
 
 static inline struct net *xs_net(struct xfrm_state *x)
@@ -441,6 +445,38 @@ struct xfrm_type_offload {
 int xfrm_register_type_offload(const struct xfrm_type_offload *type, unsigned short family);
 void xfrm_unregister_type_offload(const struct xfrm_type_offload *type, unsigned short family);
 
+struct xfrm_mode_cbs {
+	struct module	*owner;
+	/* Add/delete state in the new xfrm_state in `x`. */
+	int	(*create_state)(struct xfrm_state *x);
+	void	(*delete_state)(struct xfrm_state *x);
+
+	/* Called while handling the user netlink options. */
+	int	(*user_init)(struct net *net, struct xfrm_state *x,
+			     struct nlattr **attrs);
+	int	(*copy_to_user)(struct xfrm_state *x, struct sk_buff *skb);
+
+	u32	(*get_inner_mtu)(struct xfrm_state *x, int outer_mtu);
+
+	/* Called to handle received xfrm (egress) packets. */
+	int	(*input)(struct xfrm_state *x, struct sk_buff *skb);
+
+	/* Placed in dst_output of the dst when an xfrm_state is bound. */
+	int	(*output)(struct net *net, struct sock *sk, struct sk_buff *skb);
+
+	/**
+	 * Prepare the skb for output for the given mode. Returns:
+	 *    Error value, if 0 then skb values should be as follows:
+	 *    transport_header should point at ESP header
+	 *    network_header should point at Outer IP header
+	 *    mac_header should point at protocol/nexthdr of the outer IP
+	 */
+	int	(*prepare_output)(struct xfrm_state *x, struct sk_buff *skb);
+};
+
+int xfrm_register_mode_cbs(u8 mode, const struct xfrm_mode_cbs *mode_cbs);
+void xfrm_unregister_mode_cbs(u8 mode);
+
 static inline int xfrm_af2proto(unsigned int family)
 {
 	switch(family) {
net/xfrm/xfrm_device.c +2 -1
index 3784534c9185..8b848540ea47 100644
@@ -42,7 +42,8 @@ static void __xfrm_mode_tunnel_prep(struct xfrm_state *x, struct sk_buff *skb,
 		skb->transport_header = skb->network_header + hsize;
 
 	skb_reset_mac_len(skb);
-	pskb_pull(skb, skb->mac_len + x->props.header_len);
+	pskb_pull(skb,
+		  skb->mac_len + x->props.header_len - x->props.enc_hdr_len);
 }
 
 static void __xfrm_mode_beet_prep(struct xfrm_state *x, struct sk_buff *skb,
net/xfrm/xfrm_input.c +12 -2
index bd4ce21d76d7..824f7b7f90e0 100644
@@ -437,6 +437,9 @@ static int xfrm_inner_mode_input(struct xfrm_state *x,
 		WARN_ON_ONCE(1);
 		break;
 	default:
+		if (x->mode_cbs && x->mode_cbs->input)
+			return x->mode_cbs->input(x, skb);
+
 		WARN_ON_ONCE(1);
 		break;
 	}
@@ -479,6 +482,10 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 
 		family = x->props.family;
 
+		/* An encap_type of -3 indicates reconstructed inner packet */
+		if (encap_type == -3)
+			goto resume_decapped;
+
 		/* An encap_type of -1 indicates async resumption. */
 		if (encap_type == -1) {
 			async = 1;
@@ -660,11 +667,14 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 
 		XFRM_MODE_SKB_CB(skb)->protocol = nexthdr;
 
-		if (xfrm_inner_mode_input(x, skb)) {
+		err = xfrm_inner_mode_input(x, skb);
+		if (err == -EINPROGRESS)
+			return 0;
+		else if (err) {
 			XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMODEERROR);
 			goto drop;
 		}
-
+resume_decapped:
 		if (x->outer_mode.flags & XFRM_MODE_FLAG_TUNNEL) {
 			decaps = 1;
 			break;
net/xfrm/xfrm_output.c +7 -2
index 662c83beb345..4390c111410d 100644
@@ -280,7 +280,9 @@ static int xfrm4_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_inner_network_header(skb, skb_network_offset(skb));
 	skb_set_inner_transport_header(skb, skb_transport_offset(skb));
 
-	skb_set_network_header(skb, -x->props.header_len);
+	/* backup to add space for the outer encap */
+	skb_set_network_header(skb,
+			       -x->props.header_len + x->props.enc_hdr_len);
 	skb->mac_header = skb->network_header +
 			  offsetof(struct iphdr, protocol);
 	skb->transport_header = skb->network_header + sizeof(*top_iph);
@@ -325,7 +327,8 @@ static int xfrm6_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_inner_network_header(skb, skb_network_offset(skb));
 	skb_set_inner_transport_header(skb, skb_transport_offset(skb));
 
-	skb_set_network_header(skb, -x->props.header_len);
+	skb_set_network_header(skb,
+			       -x->props.header_len + x->props.enc_hdr_len);
 	skb->mac_header = skb->network_header +
 			  offsetof(struct ipv6hdr, nexthdr);
 	skb->transport_header = skb->network_header + sizeof(*top_iph);
@@ -472,6 +475,8 @@ static int xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb)
 		WARN_ON_ONCE(1);
 		break;
 	default:
+		if (x->mode_cbs->prepare_output)
+			return x->mode_cbs->prepare_output(x, skb);
 		WARN_ON_ONCE(1);
 		break;
 	}
net/xfrm/xfrm_policy.c +11 -7
index d2dddc570f4f..3220b01121f3 100644
@@ -2707,13 +2707,17 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
 
 		dst1->input = dst_discard;
 
-		rcu_read_lock();
-		afinfo = xfrm_state_afinfo_get_rcu(inner_mode->family);
-		if (likely(afinfo))
-			dst1->output = afinfo->output;
-		else
-			dst1->output = dst_discard_out;
-		rcu_read_unlock();
+		if (xfrm[i]->mode_cbs && xfrm[i]->mode_cbs->output) {
+			dst1->output = xfrm[i]->mode_cbs->output;
+		} else {
+			rcu_read_lock();
+			afinfo = xfrm_state_afinfo_get_rcu(inner_mode->family);
+			if (likely(afinfo))
+				dst1->output = afinfo->output;
+			else
+				dst1->output = dst_discard_out;
+			rcu_read_unlock();
+		}
 
 		xdst_prev = xdst;
 
net/xfrm/xfrm_state.c +41 -0

65 lines not on this page · raw message

net/xfrm/xfrm_user.c +10 -0
index fa2059de51f5..795da945fbc2 100644
@@ -779,6 +779,12 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
 			goto error;
 	}
 
+	if (x->mode_cbs && x->mode_cbs->user_init) {
+		err = x->mode_cbs->user_init(net, x, attrs);
+		if (err)
+			goto error;
+	}
+
 	return x;
 
 error:
@@ -1192,6 +1198,10 @@ static int copy_to_user_state_extra(struct xfrm_state *x,
 		if (ret)
 			goto out;
 	}
+	if (x->mode_cbs && x->mode_cbs->copy_to_user)
+		ret = x->mode_cbs->copy_to_user(x, skb);
+	if (ret)
+		goto out;
 	if (x->mapping_maxage)
 		ret = nla_put_u32(skb, XFRMA_MTIMER_THRESH, x->mapping_maxage);
 out:
Signature · 1 line
2.42.0
#14 lore raw

Re: [devel-ipsec] [RFC ipsec-next v2 6/8] iptfs: xfrm: Add mode_cbs module functionality

Hi Chris,

I got couple of more questions. I am trying flush them out. Here is one. And I am still formulating another question.

Quoted 43 lines · Christian Hopps via Devel

From: Christian Hopps <[email protected]>

Add a set of callbacks xfrm_mode_cbs to xfrm_state. These callbacks enable the addition of new xfrm modes, such as IP-TFS to be defined in modules.

---
 include/net/xfrm.h     | 36 ++++++++++++++++++++++++++++++++++++
 net/xfrm/xfrm_device.c |  3 ++-
 net/xfrm/xfrm_input.c  | 14 ++++++++++++--
 net/xfrm/xfrm_output.c |  9 +++++++--
 net/xfrm/xfrm_policy.c | 18 +++++++++++-------
 net/xfrm/xfrm_state.c  | 41 +++++++++++++++++++++++++++++++++++++++++
 net/xfrm/xfrm_user.c   | 10 ++++++++++
 7 files changed, 119 insertions(+), 12 deletions(-)
include/net/xfrm.h +4 -0
index d2e87344d175..aeeadadc9545 100644
@@ -204,6 +204,7 @@ struct xfrm_state {
 		u16		family;
 		xfrm_address_t	saddr;
 		int		header_len;
+		int		enc_hdr_len;
 		int		trailer_len;
 		u32		extra_flags;
 		struct xfrm_mark	smark;
@@ -289,6 +290,9 @@ struct xfrm_state {
 	/* Private data of this transformer, format is opaque,
 	 * interpreted by xfrm_type methods. */
 	void			*data;
+
+	const struct xfrm_mode_cbs	*mode_cbs;
+	void				*mode_data;
 };
 
 static inline struct net *xs_net(struct xfrm_state *x)
@@ -441,6 +445,38 @@ struct xfrm_type_offload {
 int xfrm_register_type_offload(const struct xfrm_type_offload *type, unsigned short family);
 void xfrm_unregister_type_offload(const struct xfrm_type_offload *type, unsigned short family);
 

include/net/xfrm.h struct xfrm_type_offload { · line 457

Quoted 10 lines
include/net/xfrm.h +10 -0
+struct xfrm_mode_cbs {
+	struct module	*owner;
+	/* Add/delete state in the new xfrm_state in `x`. */
+	int	(*create_state)(struct xfrm_state *x);
+	void	(*delete_state)(struct xfrm_state *x);
+
+	/* Called while handling the user netlink options. */
+	int	(*user_init)(struct net *net, struct xfrm_state *x,
+			     struct nlattr **attrs);
+	int	(*copy_to_user)(struct xfrm_state *x, struct sk_buff *skb);

I'm curious about how xfrm_state_clone() is supported, particularly when it's called in this sequence:

XFRM_MSG_MIGRATE
xfrm_do_migrate()
xfrm_migrate()
xfrm_state_migrate()
xfrm_state_clone()

I've been pondering if perhaps IP-TFS is missing clone support? It seems like something along the lines of the attached fragment might be needed.

And speaking of clone, it got me thinking: could there be packet drops when XFRM_MSG_UPDSA triggers iptfs_delete_state()? Given that an update creates a new state and deletes the old one, it's possible there might be some packet loss. Maybe it's unavoidable?

Also, I've been wondering state timers or limits expire. What happens when the byte or packet limit exceeds and the state gets deleted? Could that lead to packet loss? The same question applies to rekeying from userspace IKEd. Users are often very sensitive to packet loss during rekeying, and a lot of effort has gone into minimizing it. I'm curious if this has been carefully handled, or if there are considerations we should be aware of."

Quoted 252 lines
include/net/xfrm.h +22 -0
+
+	u32	(*get_inner_mtu)(struct xfrm_state *x, int outer_mtu);
+
+	/* Called to handle received xfrm (egress) packets. */
+	int	(*input)(struct xfrm_state *x, struct sk_buff *skb);
+
+	/* Placed in dst_output of the dst when an xfrm_state is bound. */
+	int	(*output)(struct net *net, struct sock *sk, struct sk_buff *skb);
+
+	/**
+	 * Prepare the skb for output for the given mode. Returns:
+	 *    Error value, if 0 then skb values should be as follows:
+	 *    transport_header should point at ESP header
+	 *    network_header should point at Outer IP header
+	 *    mac_header should point at protocol/nexthdr of the outer IP
+	 */
+	int	(*prepare_output)(struct xfrm_state *x, struct sk_buff *skb);
+};
+
+int xfrm_register_mode_cbs(u8 mode, const struct xfrm_mode_cbs *mode_cbs);
+void xfrm_unregister_mode_cbs(u8 mode);
+
 static inline int xfrm_af2proto(unsigned int family)
 {
 	switch(family) {
net/xfrm/xfrm_device.c +2 -1
index 3784534c9185..8b848540ea47 100644
@@ -42,7 +42,8 @@ static void __xfrm_mode_tunnel_prep(struct xfrm_state *x, struct sk_buff *skb,
 		skb->transport_header = skb->network_header + hsize;
 
 	skb_reset_mac_len(skb);
-	pskb_pull(skb, skb->mac_len + x->props.header_len);
+	pskb_pull(skb,
+		  skb->mac_len + x->props.header_len - x->props.enc_hdr_len);
 }
 
 static void __xfrm_mode_beet_prep(struct xfrm_state *x, struct sk_buff *skb,
net/xfrm/xfrm_input.c +12 -2
index bd4ce21d76d7..824f7b7f90e0 100644
@@ -437,6 +437,9 @@ static int xfrm_inner_mode_input(struct xfrm_state *x,
 		WARN_ON_ONCE(1);
 		break;
 	default:
+		if (x->mode_cbs && x->mode_cbs->input)
+			return x->mode_cbs->input(x, skb);
+
 		WARN_ON_ONCE(1);
 		break;
 	}
@@ -479,6 +482,10 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 
 		family = x->props.family;
 
+		/* An encap_type of -3 indicates reconstructed inner packet */
+		if (encap_type == -3)
+			goto resume_decapped;
+
 		/* An encap_type of -1 indicates async resumption. */
 		if (encap_type == -1) {
 			async = 1;
@@ -660,11 +667,14 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 
 		XFRM_MODE_SKB_CB(skb)->protocol = nexthdr;
 
-		if (xfrm_inner_mode_input(x, skb)) {
+		err = xfrm_inner_mode_input(x, skb);
+		if (err == -EINPROGRESS)
+			return 0;
+		else if (err) {
 			XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMODEERROR);
 			goto drop;
 		}
-
+resume_decapped:
 		if (x->outer_mode.flags & XFRM_MODE_FLAG_TUNNEL) {
 			decaps = 1;
 			break;
net/xfrm/xfrm_output.c +7 -2
index 662c83beb345..4390c111410d 100644
@@ -280,7 +280,9 @@ static int xfrm4_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_inner_network_header(skb, skb_network_offset(skb));
 	skb_set_inner_transport_header(skb, skb_transport_offset(skb));
 
-	skb_set_network_header(skb, -x->props.header_len);
+	/* backup to add space for the outer encap */
+	skb_set_network_header(skb,
+			       -x->props.header_len + x->props.enc_hdr_len);
 	skb->mac_header = skb->network_header +
 			  offsetof(struct iphdr, protocol);
 	skb->transport_header = skb->network_header + sizeof(*top_iph);
@@ -325,7 +327,8 @@ static int xfrm6_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_inner_network_header(skb, skb_network_offset(skb));
 	skb_set_inner_transport_header(skb, skb_transport_offset(skb));
 
-	skb_set_network_header(skb, -x->props.header_len);
+	skb_set_network_header(skb,
+			       -x->props.header_len + x->props.enc_hdr_len);
 	skb->mac_header = skb->network_header +
 			  offsetof(struct ipv6hdr, nexthdr);
 	skb->transport_header = skb->network_header + sizeof(*top_iph);
@@ -472,6 +475,8 @@ static int xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb)
 		WARN_ON_ONCE(1);
 		break;
 	default:
+		if (x->mode_cbs->prepare_output)
+			return x->mode_cbs->prepare_output(x, skb);
 		WARN_ON_ONCE(1);
 		break;
 	}
net/xfrm/xfrm_policy.c +11 -7
index d2dddc570f4f..3220b01121f3 100644
@@ -2707,13 +2707,17 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
 
 		dst1->input = dst_discard;
 
-		rcu_read_lock();
-		afinfo = xfrm_state_afinfo_get_rcu(inner_mode->family);
-		if (likely(afinfo))
-			dst1->output = afinfo->output;
-		else
-			dst1->output = dst_discard_out;
-		rcu_read_unlock();
+		if (xfrm[i]->mode_cbs && xfrm[i]->mode_cbs->output) {
+			dst1->output = xfrm[i]->mode_cbs->output;
+		} else {
+			rcu_read_lock();
+			afinfo = xfrm_state_afinfo_get_rcu(inner_mode->family);
+			if (likely(afinfo))
+				dst1->output = afinfo->output;
+			else
+				dst1->output = dst_discard_out;
+			rcu_read_unlock();
+		}
 
 		xdst_prev = xdst;
 
net/xfrm/xfrm_state.c +41 -0
index bda5327bf34d..f5e1a17ebf74 100644
@@ -513,6 +513,36 @@ static const struct xfrm_mode *xfrm_get_mode(unsigned int encap, int family)
 	return NULL;
 }
 
+static struct xfrm_mode_cbs xfrm_mode_cbs_map[XFRM_MODE_MAX];
+
+int xfrm_register_mode_cbs(u8 mode, const struct xfrm_mode_cbs *mode_cbs)
+{
+	if (mode >= XFRM_MODE_MAX)
+		return -EINVAL;
+
+	xfrm_mode_cbs_map[mode] = *mode_cbs;
+	return 0;
+}
+EXPORT_SYMBOL(xfrm_register_mode_cbs);
+
+void xfrm_unregister_mode_cbs(u8 mode)
+{
+	if (mode >= XFRM_MODE_MAX)
+		return;
+
+	memset(&xfrm_mode_cbs_map[mode], 0, sizeof(xfrm_mode_cbs_map[mode]));
+}
+EXPORT_SYMBOL(xfrm_unregister_mode_cbs);
+
+static const struct xfrm_mode_cbs *xfrm_get_mode_cbs(u8 mode)
+{
+	if (mode >= XFRM_MODE_MAX)
+		return NULL;
+	if (mode == XFRM_MODE_IPTFS && !xfrm_mode_cbs_map[mode].create_state)
+		request_module("xfrm-iptfs");
+	return &xfrm_mode_cbs_map[mode];
+}
+
 void xfrm_state_free(struct xfrm_state *x)
 {
 	kmem_cache_free(xfrm_state_cache, x);
@@ -521,6 +551,8 @@ EXPORT_SYMBOL(xfrm_state_free);
 
 static void ___xfrm_state_destroy(struct xfrm_state *x)
 {
+	if (x->mode_cbs && x->mode_cbs->delete_state)
+		x->mode_cbs->delete_state(x);
 	hrtimer_cancel(&x->mtimer);
 	del_timer_sync(&x->rtimer);
 	kfree(x->aead);
@@ -2765,6 +2797,9 @@ u32 xfrm_state_mtu(struct xfrm_state *x, int mtu)
 	case XFRM_MODE_TUNNEL:
 		break;
 	default:
+		if (x->mode_cbs && x->mode_cbs->get_inner_mtu)
+			return x->mode_cbs->get_inner_mtu(x, mtu);
+
 		WARN_ON_ONCE(1);
 		break;
 	}
@@ -2850,6 +2885,12 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload,
 			goto error;
 	}
 
+	x->mode_cbs = xfrm_get_mode_cbs(x->props.mode);
+	if (x->mode_cbs && x->mode_cbs->create_state) {
+		err = x->mode_cbs->create_state(x);
+		if (err)
+			goto error;
+	}
 error:
 	return err;
 }
net/xfrm/xfrm_user.c +10 -0
index fa2059de51f5..795da945fbc2 100644
@@ -779,6 +779,12 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
 			goto error;
 	}
 
+	if (x->mode_cbs && x->mode_cbs->user_init) {
+		err = x->mode_cbs->user_init(net, x, attrs);
+		if (err)
+			goto error;
+	}
+
 	return x;
 
 error:
@@ -1192,6 +1198,10 @@ static int copy_to_user_state_extra(struct xfrm_state *x,
 		if (ret)
 			goto out;
 	}
+	if (x->mode_cbs && x->mode_cbs->copy_to_user)
+		ret = x->mode_cbs->copy_to_user(x, skb);
+	if (ret)
+		goto out;
 	if (x->mapping_maxage)
 		ret = nla_put_u32(skb, XFRMA_MTIMER_THRESH, x->mapping_maxage);
 out:
Signature · 6 lines
2.42.0

-- 
Devel mailing list
[email protected]
https://linux-ipsec.org/mailman/listinfo/devel

From 00fc5af96f90846f1e1882b141699fb62a9f0a73 Mon Sep 17 00:00:00 2001
From: Antony Antony <[email protected]>
Date: Mon, 13 Nov 2023 14:20:45 +0100
Subject: [PATCH] xfrm iptfs migrate poc

proof of concept for IP-TFS migrate support

---
 include/net/xfrm.h    |  1 +
 net/xfrm/xfrm_iptfs.c | 20 ++++++++++++++++++++
 net/xfrm/xfrm_state.c |  6 ++++++
 3 files changed, 27 insertions(+)
include/net/xfrm.h +1 -0
index a6e0e848918d..176ab5ac436e 100644
@@ -456,6 +456,7 @@ struct xfrm_mode_cbs {
 	int	(*user_init)(struct net *net, struct xfrm_state *x,
 			     struct nlattr **attrs);
 	int	(*copy_to_user)(struct xfrm_state *x, struct sk_buff *skb);
+	int     (*clone)(struct xfrm_state *orig, struct xfrm_state *x);
 
 	u32	(*get_inner_mtu)(struct xfrm_state *x, int outer_mtu);
 
net/xfrm/xfrm_iptfs.c +20 -0
index 65f7acdbe6a8..cef269a02b11 100644
@@ -2613,6 +2613,25 @@ static int iptfs_copy_to_user(struct xfrm_state *x, struct sk_buff *skb)
 	return ret;
 }
 
+static int iptfs_clone(struct xfrm_state *orig,  struct xfrm_state *x)
+{
+
+	x->mode_data = kmemdup(orig->mode_data, sizeof(*x->mode_data),
+			       GFP_KERNEL);
+	/**  may be some values, such as the following, should not be copied ??
+	 * and need different handling ?
+	 * xtfs->iptfs_timer;
+	 * xtfs->drop_timer
+         * xtfs->drop_lock
+         * xtfs->w_saved
+         * xtfs;
+	 */
+
+	if (!x->mode_data)
+		return -ENOMEM;
+
+	return 0;
+}
 static int iptfs_create_state(struct xfrm_state *x)
 {
 	struct xfrm_iptfs_data *xtfs;
@@ -2667,6 +2686,7 @@ static const struct xfrm_mode_cbs iptfs_mode_cbs = {
 	.delete_state = iptfs_delete_state,
 	.user_init = iptfs_user_init,
 	.copy_to_user = iptfs_copy_to_user,
+	.clone = iptfs_clone,
 	.get_inner_mtu = iptfs_get_inner_mtu,
 	.input = iptfs_input,
 	.output = iptfs_output_collect,
net/xfrm/xfrm_state.c +6 -0
index 786f3fc0d428..c56d3be56229 100644
@@ -720,6 +720,7 @@ struct xfrm_state *xfrm_state_alloc(struct net *net)
 		x->replay_maxage = 0;
 		x->replay_maxdiff = 0;
 		spin_lock_init(&x->lock);
+		x->mode_data = NULL;
 	}
 	return x;
 }
@@ -1787,6 +1788,11 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
 	x->new_mapping = 0;
 	x->new_mapping_sport = 0;
 
+	if (x->mode_cbs && x->mode_cbs->clone && orig->mode_data) {
+		if (!x->mode_cbs->clone(x,orig))
+			goto error;
+	}
+
 	return x;
 
  error:
Signature · 1 line
2.42.0
#15 lore raw

Re: [devel-ipsec] [RFC ipsec-next v2 6/8] iptfs: xfrm: Add mode_cbs module functionality

Hi Chris,

Quoted 71 lines · Antony Antony

Hi Chris,

I got couple of more questions. I am trying flush them out. Here is one. And I am still formulating another question.

Quoted 43 lines · Christian Hopps via Devel

From: Christian Hopps <[email protected]>

Add a set of callbacks xfrm_mode_cbs to xfrm_state. These callbacks enable the addition of new xfrm modes, such as IP-TFS to be defined in modules.

---
 include/net/xfrm.h     | 36 ++++++++++++++++++++++++++++++++++++
 net/xfrm/xfrm_device.c |  3 ++-
 net/xfrm/xfrm_input.c  | 14 ++++++++++++--
 net/xfrm/xfrm_output.c |  9 +++++++--
 net/xfrm/xfrm_policy.c | 18 +++++++++++-------
 net/xfrm/xfrm_state.c  | 41 +++++++++++++++++++++++++++++++++++++++++
 net/xfrm/xfrm_user.c   | 10 ++++++++++
 7 files changed, 119 insertions(+), 12 deletions(-)
include/net/xfrm.h +4 -0
index d2e87344d175..aeeadadc9545 100644
@@ -204,6 +204,7 @@ struct xfrm_state {
 		u16		family;
 		xfrm_address_t	saddr;
 		int		header_len;
+		int		enc_hdr_len;
 		int		trailer_len;
 		u32		extra_flags;
 		struct xfrm_mark	smark;
@@ -289,6 +290,9 @@ struct xfrm_state {
 	/* Private data of this transformer, format is opaque,
 	 * interpreted by xfrm_type methods. */
 	void			*data;
+
+	const struct xfrm_mode_cbs	*mode_cbs;
+	void				*mode_data;
 };
 
 static inline struct net *xs_net(struct xfrm_state *x)
@@ -441,6 +445,38 @@ struct xfrm_type_offload {
 int xfrm_register_type_offload(const struct xfrm_type_offload *type, unsigned short family);
 void xfrm_unregister_type_offload(const struct xfrm_type_offload *type, unsigned short family);
 

include/net/xfrm.h struct xfrm_type_offload { · line 457

Quoted 10 lines
include/net/xfrm.h +10 -0
+struct xfrm_mode_cbs {
+	struct module	*owner;
+	/* Add/delete state in the new xfrm_state in `x`. */
+	int	(*create_state)(struct xfrm_state *x);
+	void	(*delete_state)(struct xfrm_state *x);
+
+	/* Called while handling the user netlink options. */
+	int	(*user_init)(struct net *net, struct xfrm_state *x,
+			     struct nlattr **attrs);
+	int	(*copy_to_user)(struct xfrm_state *x, struct sk_buff *skb);

I'm curious about how xfrm_state_clone() is supported, particularly when it's called in this sequence:

XFRM_MSG_MIGRATE
xfrm_do_migrate()
xfrm_migrate()
xfrm_state_migrate()
xfrm_state_clone()

Quoted 3 lines

I've been pondering if perhaps IP-TFS is missing clone support? It seems like something along the lines of the attached fragment might be needed.

Here's a tested fix that supports XFRM_MSG_MIGRATE with iptfs. I tested it using IPv4, and it's working. I included some memset with zeros to be sure those timers are initialized properly. May be it is not necessary!

Quoted 354 lines

And speaking of clone, it got me thinking: could there be packet drops when XFRM_MSG_UPDSA triggers iptfs_delete_state()? Given that an update creates a new state and deletes the old one, it's possible there might be some packet loss. Maybe it's unavoidable?

Also, I've been wondering state timers or limits expire. What happens when the byte or packet limit exceeds and the state gets deleted? Could that lead to packet loss? The same question applies to rekeying from userspace IKEd. Users are often very sensitive to packet loss during rekeying, and a lot of effort has gone into minimizing it. I'm curious if this has been carefully handled, or if there are considerations we should be aware of."

Quoted 252 lines
include/net/xfrm.h +22 -0
+
+	u32	(*get_inner_mtu)(struct xfrm_state *x, int outer_mtu);
+
+	/* Called to handle received xfrm (egress) packets. */
+	int	(*input)(struct xfrm_state *x, struct sk_buff *skb);
+
+	/* Placed in dst_output of the dst when an xfrm_state is bound. */
+	int	(*output)(struct net *net, struct sock *sk, struct sk_buff *skb);
+
+	/**
+	 * Prepare the skb for output for the given mode. Returns:
+	 *    Error value, if 0 then skb values should be as follows:
+	 *    transport_header should point at ESP header
+	 *    network_header should point at Outer IP header
+	 *    mac_header should point at protocol/nexthdr of the outer IP
+	 */
+	int	(*prepare_output)(struct xfrm_state *x, struct sk_buff *skb);
+};
+
+int xfrm_register_mode_cbs(u8 mode, const struct xfrm_mode_cbs *mode_cbs);
+void xfrm_unregister_mode_cbs(u8 mode);
+
 static inline int xfrm_af2proto(unsigned int family)
 {
 	switch(family) {
net/xfrm/xfrm_device.c +2 -1
index 3784534c9185..8b848540ea47 100644
@@ -42,7 +42,8 @@ static void __xfrm_mode_tunnel_prep(struct xfrm_state *x, struct sk_buff *skb,
 		skb->transport_header = skb->network_header + hsize;
 
 	skb_reset_mac_len(skb);
-	pskb_pull(skb, skb->mac_len + x->props.header_len);
+	pskb_pull(skb,
+		  skb->mac_len + x->props.header_len - x->props.enc_hdr_len);
 }
 
 static void __xfrm_mode_beet_prep(struct xfrm_state *x, struct sk_buff *skb,
net/xfrm/xfrm_input.c +12 -2
index bd4ce21d76d7..824f7b7f90e0 100644
@@ -437,6 +437,9 @@ static int xfrm_inner_mode_input(struct xfrm_state *x,
 		WARN_ON_ONCE(1);
 		break;
 	default:
+		if (x->mode_cbs && x->mode_cbs->input)
+			return x->mode_cbs->input(x, skb);
+
 		WARN_ON_ONCE(1);
 		break;
 	}
@@ -479,6 +482,10 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 
 		family = x->props.family;
 
+		/* An encap_type of -3 indicates reconstructed inner packet */
+		if (encap_type == -3)
+			goto resume_decapped;
+
 		/* An encap_type of -1 indicates async resumption. */
 		if (encap_type == -1) {
 			async = 1;
@@ -660,11 +667,14 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 
 		XFRM_MODE_SKB_CB(skb)->protocol = nexthdr;
 
-		if (xfrm_inner_mode_input(x, skb)) {
+		err = xfrm_inner_mode_input(x, skb);
+		if (err == -EINPROGRESS)
+			return 0;
+		else if (err) {
 			XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMODEERROR);
 			goto drop;
 		}
-
+resume_decapped:
 		if (x->outer_mode.flags & XFRM_MODE_FLAG_TUNNEL) {
 			decaps = 1;
 			break;
net/xfrm/xfrm_output.c +7 -2
index 662c83beb345..4390c111410d 100644
@@ -280,7 +280,9 @@ static int xfrm4_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_inner_network_header(skb, skb_network_offset(skb));
 	skb_set_inner_transport_header(skb, skb_transport_offset(skb));
 
-	skb_set_network_header(skb, -x->props.header_len);
+	/* backup to add space for the outer encap */
+	skb_set_network_header(skb,
+			       -x->props.header_len + x->props.enc_hdr_len);
 	skb->mac_header = skb->network_header +
 			  offsetof(struct iphdr, protocol);
 	skb->transport_header = skb->network_header + sizeof(*top_iph);
@@ -325,7 +327,8 @@ static int xfrm6_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_inner_network_header(skb, skb_network_offset(skb));
 	skb_set_inner_transport_header(skb, skb_transport_offset(skb));
 
-	skb_set_network_header(skb, -x->props.header_len);
+	skb_set_network_header(skb,
+			       -x->props.header_len + x->props.enc_hdr_len);
 	skb->mac_header = skb->network_header +
 			  offsetof(struct ipv6hdr, nexthdr);
 	skb->transport_header = skb->network_header + sizeof(*top_iph);
@@ -472,6 +475,8 @@ static int xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb)
 		WARN_ON_ONCE(1);
 		break;
 	default:
+		if (x->mode_cbs->prepare_output)
+			return x->mode_cbs->prepare_output(x, skb);
 		WARN_ON_ONCE(1);
 		break;
 	}
net/xfrm/xfrm_policy.c +11 -7
index d2dddc570f4f..3220b01121f3 100644
@@ -2707,13 +2707,17 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
 
 		dst1->input = dst_discard;
 
-		rcu_read_lock();
-		afinfo = xfrm_state_afinfo_get_rcu(inner_mode->family);
-		if (likely(afinfo))
-			dst1->output = afinfo->output;
-		else
-			dst1->output = dst_discard_out;
-		rcu_read_unlock();
+		if (xfrm[i]->mode_cbs && xfrm[i]->mode_cbs->output) {
+			dst1->output = xfrm[i]->mode_cbs->output;
+		} else {
+			rcu_read_lock();
+			afinfo = xfrm_state_afinfo_get_rcu(inner_mode->family);
+			if (likely(afinfo))
+				dst1->output = afinfo->output;
+			else
+				dst1->output = dst_discard_out;
+			rcu_read_unlock();
+		}
 
 		xdst_prev = xdst;
 
net/xfrm/xfrm_state.c +41 -0
index bda5327bf34d..f5e1a17ebf74 100644
@@ -513,6 +513,36 @@ static const struct xfrm_mode *xfrm_get_mode(unsigned int encap, int family)
 	return NULL;
 }
 
+static struct xfrm_mode_cbs xfrm_mode_cbs_map[XFRM_MODE_MAX];
+
+int xfrm_register_mode_cbs(u8 mode, const struct xfrm_mode_cbs *mode_cbs)
+{
+	if (mode >= XFRM_MODE_MAX)
+		return -EINVAL;
+
+	xfrm_mode_cbs_map[mode] = *mode_cbs;
+	return 0;
+}
+EXPORT_SYMBOL(xfrm_register_mode_cbs);
+
+void xfrm_unregister_mode_cbs(u8 mode)
+{
+	if (mode >= XFRM_MODE_MAX)
+		return;
+
+	memset(&xfrm_mode_cbs_map[mode], 0, sizeof(xfrm_mode_cbs_map[mode]));
+}
+EXPORT_SYMBOL(xfrm_unregister_mode_cbs);
+
+static const struct xfrm_mode_cbs *xfrm_get_mode_cbs(u8 mode)
+{
+	if (mode >= XFRM_MODE_MAX)
+		return NULL;
+	if (mode == XFRM_MODE_IPTFS && !xfrm_mode_cbs_map[mode].create_state)
+		request_module("xfrm-iptfs");
+	return &xfrm_mode_cbs_map[mode];
+}
+
 void xfrm_state_free(struct xfrm_state *x)
 {
 	kmem_cache_free(xfrm_state_cache, x);
@@ -521,6 +551,8 @@ EXPORT_SYMBOL(xfrm_state_free);
 
 static void ___xfrm_state_destroy(struct xfrm_state *x)
 {
+	if (x->mode_cbs && x->mode_cbs->delete_state)
+		x->mode_cbs->delete_state(x);
 	hrtimer_cancel(&x->mtimer);
 	del_timer_sync(&x->rtimer);
 	kfree(x->aead);
@@ -2765,6 +2797,9 @@ u32 xfrm_state_mtu(struct xfrm_state *x, int mtu)
 	case XFRM_MODE_TUNNEL:
 		break;
 	default:
+		if (x->mode_cbs && x->mode_cbs->get_inner_mtu)
+			return x->mode_cbs->get_inner_mtu(x, mtu);
+
 		WARN_ON_ONCE(1);
 		break;
 	}
@@ -2850,6 +2885,12 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload,
 			goto error;
 	}
 
+	x->mode_cbs = xfrm_get_mode_cbs(x->props.mode);
+	if (x->mode_cbs && x->mode_cbs->create_state) {
+		err = x->mode_cbs->create_state(x);
+		if (err)
+			goto error;
+	}
 error:
 	return err;
 }
net/xfrm/xfrm_user.c +10 -0
index fa2059de51f5..795da945fbc2 100644
@@ -779,6 +779,12 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
 			goto error;
 	}
 
+	if (x->mode_cbs && x->mode_cbs->user_init) {
+		err = x->mode_cbs->user_init(net, x, attrs);
+		if (err)
+			goto error;
+	}
+
 	return x;
 
 error:
@@ -1192,6 +1198,10 @@ static int copy_to_user_state_extra(struct xfrm_state *x,
 		if (ret)
 			goto out;
 	}
+	if (x->mode_cbs && x->mode_cbs->copy_to_user)
+		ret = x->mode_cbs->copy_to_user(x, skb);
+	if (ret)
+		goto out;
 	if (x->mapping_maxage)
 		ret = nla_put_u32(skb, XFRMA_MTIMER_THRESH, x->mapping_maxage);
 out:
Signature · 6 lines
2.42.0

-- 
Devel mailing list
[email protected]
https://linux-ipsec.org/mailman/listinfo/devel

From 00fc5af96f90846f1e1882b141699fb62a9f0a73 Mon Sep 17 00:00:00 2001
From: Antony Antony <[email protected]>
Date: Mon, 13 Nov 2023 14:20:45 +0100
Subject: [PATCH] xfrm iptfs migrate poc

proof of concept for IP-TFS migrate support

---
 include/net/xfrm.h    |  1 +
 net/xfrm/xfrm_iptfs.c | 20 ++++++++++++++++++++
 net/xfrm/xfrm_state.c |  6 ++++++
 3 files changed, 27 insertions(+)
include/net/xfrm.h +1 -0
index a6e0e848918d..176ab5ac436e 100644
@@ -456,6 +456,7 @@ struct xfrm_mode_cbs {
 	int	(*user_init)(struct net *net, struct xfrm_state *x,
 			     struct nlattr **attrs);
 	int	(*copy_to_user)(struct xfrm_state *x, struct sk_buff *skb);
+	int     (*clone)(struct xfrm_state *orig, struct xfrm_state *x);
 
 	u32	(*get_inner_mtu)(struct xfrm_state *x, int outer_mtu);
 
net/xfrm/xfrm_iptfs.c +20 -0
index 65f7acdbe6a8..cef269a02b11 100644
@@ -2613,6 +2613,25 @@ static int iptfs_copy_to_user(struct xfrm_state *x, struct sk_buff *skb)
 	return ret;
 }
 
+static int iptfs_clone(struct xfrm_state *orig,  struct xfrm_state *x)
+{
+
+	x->mode_data = kmemdup(orig->mode_data, sizeof(*x->mode_data),
+			       GFP_KERNEL);
+	/**  may be some values, such as the following, should not be copied ??
+	 * and need different handling ?
+	 * xtfs->iptfs_timer;
+	 * xtfs->drop_timer
+         * xtfs->drop_lock
+         * xtfs->w_saved
+         * xtfs;
+	 */
+
+	if (!x->mode_data)
+		return -ENOMEM;
+
+	return 0;
+}
 static int iptfs_create_state(struct xfrm_state *x)
 {
 	struct xfrm_iptfs_data *xtfs;
@@ -2667,6 +2686,7 @@ static const struct xfrm_mode_cbs iptfs_mode_cbs = {
 	.delete_state = iptfs_delete_state,
 	.user_init = iptfs_user_init,
 	.copy_to_user = iptfs_copy_to_user,
+	.clone = iptfs_clone,
 	.get_inner_mtu = iptfs_get_inner_mtu,
 	.input = iptfs_input,
 	.output = iptfs_output_collect,
net/xfrm/xfrm_state.c +6 -0
index 786f3fc0d428..c56d3be56229 100644
@@ -720,6 +720,7 @@ struct xfrm_state *xfrm_state_alloc(struct net *net)
 		x->replay_maxage = 0;
 		x->replay_maxdiff = 0;
 		spin_lock_init(&x->lock);
+		x->mode_data = NULL;
 	}
 	return x;
 }
@@ -1787,6 +1788,11 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
 	x->new_mapping = 0;
 	x->new_mapping_sport = 0;
 
+	if (x->mode_cbs && x->mode_cbs->clone && orig->mode_data) {
+		if (!x->mode_cbs->clone(x,orig))
+			goto error;
+	}
+
 	return x;
 
  error:
Signature · 1 line
2.42.0

From 6d1ec5adddbe3a904591f465ff8487bc694de139 Mon Sep 17 00:00:00 2001
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Antony Antony <[email protected]>
Date: Mon, 13 Nov 2023 14:20:45 +0100
Subject: [PATCH] xfrm iptfs migrate poc
To: Christian Hopps <[email protected]>
Cc: [email protected],
[email protected],
Christian Hopps <[email protected]>,
Steffen Klassert via Devel <[email protected]>

From: Antony Antony <[email protected]>

proof of concept for IP-TFS migrate support

---
 include/net/xfrm.h    |  1 +
 net/xfrm/xfrm_iptfs.c | 42 ++++++++++++++++++++++++++++++++++++------
 net/xfrm/xfrm_state.c |  6 ++++++
 3 files changed, 43 insertions(+), 6 deletions(-)
include/net/xfrm.h +1 -0
index a6e0e848918d..176ab5ac436e 100644
@@ -456,6 +456,7 @@ struct xfrm_mode_cbs {
 	int	(*user_init)(struct net *net, struct xfrm_state *x,
 			     struct nlattr **attrs);
 	int	(*copy_to_user)(struct xfrm_state *x, struct sk_buff *skb);
+	int     (*clone)(struct xfrm_state *orig, struct xfrm_state *x);
 
 	u32	(*get_inner_mtu)(struct xfrm_state *x, int outer_mtu);
 
net/xfrm/xfrm_iptfs.c +36 -6

60 lines not on this page · raw message

net/xfrm/xfrm_state.c +6 -0
index 786f3fc0d428..fd592bf4d311 100644
@@ -720,6 +720,7 @@ struct xfrm_state *xfrm_state_alloc(struct net *net)
 		x->replay_maxage = 0;
 		x->replay_maxdiff = 0;
 		spin_lock_init(&x->lock);
+		x->mode_data = NULL;
 	}
 	return x;
 }
@@ -1787,6 +1788,11 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
 	x->new_mapping = 0;
 	x->new_mapping_sport = 0;
 
+	if (orig->mode_cbs && orig->mode_cbs->clone && orig->mode_data) {
+		if (orig->mode_cbs->clone(orig, x))
+			goto error;
+	}
+
 	return x;
 
  error:
Signature · 1 line
2.42.0
#16 lore raw

Re: [RFC ipsec-next v2 6/8] iptfs: xfrm: Add mode_cbs module functionality

In reply to Christian Hopps
Quoted 5 lines · Christian Hopps

From: Christian Hopps <[email protected]>

Add a set of callbacks xfrm_mode_cbs to xfrm_state. These callbacks enable the addition of new xfrm modes, such as IP-TFS to be defined in modules.

Not a big fan of bringing back modes in modules :( Florian's work made the code a lot more readable.

net/xfrm/xfrm_output.c static int xfrm4_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb) · line 285

Quoted 12 lines
net/xfrm/xfrm_output.c +3 -1
index 662c83beb345..4390c111410d 100644
@@ -280,7 +280,9 @@ static int xfrm4_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_inner_network_header(skb, skb_network_offset(skb));
 	skb_set_inner_transport_header(skb, skb_transport_offset(skb));
 
-	skb_set_network_header(skb, -x->props.header_len);
+	/* backup to add space for the outer encap */
+	skb_set_network_header(skb,
+			       -x->props.header_len + x->props.enc_hdr_len);

Since this only gets called for XFRM_MODE_TUNNEL, and only iptfs sets enc_hdr_len, do we need this change? (and same for xfrm6_tunnel_encap_add)

Quoted 14 lines
net/xfrm/xfrm_output.c +2 -1
 	skb->mac_header = skb->network_header +
 			  offsetof(struct iphdr, protocol);
 	skb->transport_header = skb->network_header + sizeof(*top_iph);
@@ -325,7 +327,8 @@ static int xfrm6_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_inner_network_header(skb, skb_network_offset(skb));
 	skb_set_inner_transport_header(skb, skb_transport_offset(skb));
 
-	skb_set_network_header(skb, -x->props.header_len);
+	skb_set_network_header(skb,
+			       -x->props.header_len + x->props.enc_hdr_len);
 	skb->mac_header = skb->network_header +
 			  offsetof(struct ipv6hdr, nexthdr);
 	skb->transport_header = skb->network_header + sizeof(*top_iph);

net/xfrm/xfrm_output.c static int xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb) · line 478

Quoted 4 lines
net/xfrm/xfrm_output.c +1 -0
@@ -472,6 +475,8 @@ static int xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb)
 		WARN_ON_ONCE(1);
 		break;
 	default:
+		if (x->mode_cbs->prepare_output)

Can x->mode_cbs be NULL here? Every other use of mode_cbs does

    if (x->mode_cbs && x->mode_cbs->FOO)

(I think not at the moment since only IPTFS (and IN_TRIGGER) can reach this, but this inconsistency with the rest of the series struck me)

Signature · 1 line
Sabrina
#17 lore raw

Re: [RFC ipsec-next v2 6/8] iptfs: xfrm: Add mode_cbs module functionality

Quoted 18 lines · Sabrina Dubroca
Quoted 5 lines · Christian Hopps

From: Christian Hopps <[email protected]>

Add a set of callbacks xfrm_mode_cbs to xfrm_state. These callbacks enable the addition of new xfrm modes, such as IP-TFS to be defined in modules.

Not a big fan of bringing back modes in modules :( Florian's work made the code a lot more readable.

Quoted 8 lines
net/xfrm/xfrm_output.c +0 -0
index 662c83beb345..4390c111410d 100644
@@ -280,7 +280,9 @@ static int xfrm4_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_inner_network_header(skb, skb_network_offset(skb));
 	skb_set_inner_transport_header(skb, skb_transport_offset(skb));
 
Quoted 7 lines

net/xfrm/xfrm_output.c static int xfrm4_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb) · line 285

Quoted 4 lines
net/xfrm/xfrm_output.c +3 -1
-	skb_set_network_header(skb, -x->props.header_len);
+	/* backup to add space for the outer encap */
+	skb_set_network_header(skb,
+			       -x->props.header_len + x->props.enc_hdr_len);

Since this only gets called for XFRM_MODE_TUNNEL, and only iptfs sets enc_hdr_len, do we need this change? (and same for xfrm6_tunnel_encap_add)

You're right, removed. This particular code actually predated the callbacks.

Quoted 20 lines
Quoted 14 lines
net/xfrm/xfrm_output.c +2 -1
 	skb->mac_header = skb->network_header +
 			  offsetof(struct iphdr, protocol);
 	skb->transport_header = skb->network_header + sizeof(*top_iph);
@@ -325,7 +327,8 @@ static int xfrm6_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_inner_network_header(skb, skb_network_offset(skb));
 	skb_set_inner_transport_header(skb, skb_transport_offset(skb));
 
-	skb_set_network_header(skb, -x->props.header_len);
+	skb_set_network_header(skb,
+			       -x->props.header_len + x->props.enc_hdr_len);
 	skb->mac_header = skb->network_header +
 			  offsetof(struct ipv6hdr, nexthdr);
 	skb->transport_header = skb->network_header + sizeof(*top_iph);

net/xfrm/xfrm_output.c static int xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb) · line 478

Quoted 4 lines
net/xfrm/xfrm_output.c +1 -0
@@ -472,6 +475,8 @@ static int xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb)
 		WARN_ON_ONCE(1);
 		break;
 	default:
+		if (x->mode_cbs->prepare_output)

Can x->mode_cbs be NULL here? Every other use of mode_cbs does

Quoted 4 lines
    if (x->mode_cbs && x->mode_cbs->FOO)

(I think not at the moment since only IPTFS (and IN_TRIGGER) can reach this, but this inconsistency with the rest of the series struck me)

Still worth putting the guard in, fixed.

Thanks,
Chris.

#18 lore raw

RFC v2 7/8 iptfs: xfrm: add generic iptfs defines and functionality

In reply to Christian Hopps

From: Christian Hopps <[email protected]>

Define XFRM_MODE_IPTFS and IPSEC_MODE_IPTFS constants, and add these to switch case and conditionals adjacent with the existing TUNNEL modes.

---
 include/net/xfrm.h         |  1 +
 include/uapi/linux/ipsec.h |  3 ++-
 include/uapi/linux/snmp.h  |  2 ++
 net/ipv4/esp4.c            |  3 ++-
 net/ipv6/esp6.c            |  3 ++-
 net/netfilter/nft_xfrm.c   |  3 ++-
 net/xfrm/xfrm_device.c     |  1 +
 net/xfrm/xfrm_output.c     |  4 ++++
 net/xfrm/xfrm_policy.c     |  8 ++++++--
 net/xfrm/xfrm_proc.c       |  2 ++
 net/xfrm/xfrm_state.c      | 12 ++++++++++++
 net/xfrm/xfrm_user.c       |  3 +++
 12 files changed, 39 insertions(+), 6 deletions(-)
include/net/xfrm.h +1 -0
index aeeadadc9545..a6e0e848918d 100644
@@ -37,6 +37,7 @@
 #define XFRM_PROTO_COMP		108
 #define XFRM_PROTO_IPIP		4
 #define XFRM_PROTO_IPV6		41
+#define XFRM_PROTO_IPTFS	IPPROTO_AGGFRAG
 #define XFRM_PROTO_ROUTING	IPPROTO_ROUTING
 #define XFRM_PROTO_DSTOPTS	IPPROTO_DSTOPTS
 
include/uapi/linux/ipsec.h +2 -1
index 50d8ee1791e2..696b790f4346 100644
@@ -14,7 +14,8 @@ enum {
 	IPSEC_MODE_ANY		= 0,	/* We do not support this for SA */
 	IPSEC_MODE_TRANSPORT	= 1,
 	IPSEC_MODE_TUNNEL	= 2,
-	IPSEC_MODE_BEET         = 3
+	IPSEC_MODE_BEET         = 3,
+	IPSEC_MODE_IPTFS        = 4
 };
 
 enum {
include/uapi/linux/snmp.h +2 -0
index 26f33a4c253d..d0b45f4c22c7 100644
@@ -331,6 +331,8 @@ enum
 	LINUX_MIB_XFRMFWDHDRERROR,		/* XfrmFwdHdrError*/
 	LINUX_MIB_XFRMOUTSTATEINVALID,		/* XfrmOutStateInvalid */
 	LINUX_MIB_XFRMACQUIREERROR,		/* XfrmAcquireError */
+	LINUX_MIB_XFRMINIPTFSERROR,		/* XfrmInIptfsError */
+	LINUX_MIB_XFRMOUTNOQSPACE,		/* XfrmOutNoQueueSpace */
 	__LINUX_MIB_XFRMMAX
 };
 
net/ipv4/esp4.c +2 -1
index 2be2d4922557..b7047c0dd7ea 100644
@@ -816,7 +816,8 @@ int esp_input_done2(struct sk_buff *skb, int err)
 	}
 
 	skb_pull_rcsum(skb, hlen);
-	if (x->props.mode == XFRM_MODE_TUNNEL)
+	if (x->props.mode == XFRM_MODE_TUNNEL ||
+	    x->props.mode == XFRM_MODE_IPTFS)
 		skb_reset_transport_header(skb);
 	else
 		skb_set_transport_header(skb, -ihl);
net/ipv6/esp6.c +2 -1
index fddd0cbdede1..10f2190207a8 100644
@@ -865,7 +865,8 @@ int esp6_input_done2(struct sk_buff *skb, int err)
 	skb_postpull_rcsum(skb, skb_network_header(skb),
 			   skb_network_header_len(skb));
 	skb_pull_rcsum(skb, hlen);
-	if (x->props.mode == XFRM_MODE_TUNNEL)
+	if (x->props.mode == XFRM_MODE_TUNNEL ||
+	    x->props.mode == XFRM_MODE_IPTFS)
 		skb_reset_transport_header(skb);
 	else
 		skb_set_transport_header(skb, -hdr_len);
net/netfilter/nft_xfrm.c +2 -1
index 452f8587adda..291b029391cd 100644
@@ -112,7 +112,8 @@ static bool xfrm_state_addr_ok(enum nft_xfrm_keys k, u8 family, u8 mode)
 		return true;
 	}
 
-	return mode == XFRM_MODE_BEET || mode == XFRM_MODE_TUNNEL;
+	return mode == XFRM_MODE_BEET || mode == XFRM_MODE_TUNNEL ||
+	       mode == XFRM_MODE_IPTFS;
 }
 
 static void nft_xfrm_state_get_key(const struct nft_xfrm *priv,
net/xfrm/xfrm_device.c +1 -0
index 8b848540ea47..a40f5e09829e 100644
@@ -69,6 +69,7 @@ static void __xfrm_mode_beet_prep(struct xfrm_state *x, struct sk_buff *skb,
 static void xfrm_outer_mode_prep(struct xfrm_state *x, struct sk_buff *skb)
 {
 	switch (x->outer_mode.encap) {
+	case XFRM_MODE_IPTFS:
 	case XFRM_MODE_TUNNEL:
 		if (x->outer_mode.family == AF_INET)
 			return __xfrm_mode_tunnel_prep(x, skb,
net/xfrm/xfrm_output.c +4 -0
index 4390c111410d..16c981ca61ca 100644
@@ -680,6 +680,10 @@ static void xfrm_get_inner_ipproto(struct sk_buff *skb, struct xfrm_state *x)
 
 		return;
 	}
+	if (x->outer_mode.encap == XFRM_MODE_IPTFS) {
+		xo->inner_ipproto = IPPROTO_AGGFRAG;
+		return;
+	}
 
 	/* non-Tunnel Mode */
 	if (!skb->encapsulation)
net/xfrm/xfrm_policy.c +6 -2
index 3220b01121f3..94e5889a77d6 100644
@@ -2468,6 +2468,7 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, const struct flowi *fl,
 		struct xfrm_tmpl *tmpl = &policy->xfrm_vec[i];
 
 		if (tmpl->mode == XFRM_MODE_TUNNEL ||
+		    tmpl->mode == XFRM_MODE_IPTFS ||
 		    tmpl->mode == XFRM_MODE_BEET) {
 			remote = &tmpl->id.daddr;
 			local = &tmpl->saddr;
@@ -3252,7 +3253,8 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net,
 ok:
 	xfrm_pols_put(pols, drop_pols);
 	if (dst && dst->xfrm &&
-	    dst->xfrm->props.mode == XFRM_MODE_TUNNEL)
+	    (dst->xfrm->props.mode == XFRM_MODE_TUNNEL ||
+	     dst->xfrm->props.mode == XFRM_MODE_IPTFS))
 		dst->flags |= DST_XFRM_TUNNEL;
 	return dst;
 
@@ -4353,6 +4355,7 @@ static int migrate_tmpl_match(const struct xfrm_migrate *m, const struct xfrm_tm
 		switch (t->mode) {
 		case XFRM_MODE_TUNNEL:
 		case XFRM_MODE_BEET:
+		case XFRM_MODE_IPTFS:
 			if (xfrm_addr_equal(&t->id.daddr, &m->old_daddr,
 					    m->old_family) &&
 			    xfrm_addr_equal(&t->saddr, &m->old_saddr,
@@ -4395,7 +4398,8 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
 				continue;
 			n++;
 			if (pol->xfrm_vec[i].mode != XFRM_MODE_TUNNEL &&
-			    pol->xfrm_vec[i].mode != XFRM_MODE_BEET)
+			    pol->xfrm_vec[i].mode != XFRM_MODE_BEET &&
+			    pol->xfrm_vec[i].mode != XFRM_MODE_IPTFS)
 				continue;
 			/* update endpoints */
 			memcpy(&pol->xfrm_vec[i].id.daddr, &mp->new_daddr,
net/xfrm/xfrm_proc.c +2 -0
index fee9b5cf37a7..d92b1b760749 100644
@@ -41,6 +41,8 @@ static const struct snmp_mib xfrm_mib_list[] = {
 	SNMP_MIB_ITEM("XfrmFwdHdrError", LINUX_MIB_XFRMFWDHDRERROR),
 	SNMP_MIB_ITEM("XfrmOutStateInvalid", LINUX_MIB_XFRMOUTSTATEINVALID),
 	SNMP_MIB_ITEM("XfrmAcquireError", LINUX_MIB_XFRMACQUIREERROR),
+	SNMP_MIB_ITEM("XfrmInIptfsError", LINUX_MIB_XFRMINIPTFSERROR),
+	SNMP_MIB_ITEM("XfrmOutNoQueueSpace", LINUX_MIB_XFRMOUTNOQSPACE),
 	SNMP_MIB_SENTINEL
 };
 
net/xfrm/xfrm_state.c +12 -0
index f5e1a17ebf74..786f3fc0d428 100644
@@ -465,6 +465,11 @@ static const struct xfrm_mode xfrm4_mode_map[XFRM_MODE_MAX] = {
 		.flags = XFRM_MODE_FLAG_TUNNEL,
 		.family = AF_INET,
 	},
+	[XFRM_MODE_IPTFS] = {
+		.encap = XFRM_MODE_IPTFS,
+		.flags = XFRM_MODE_FLAG_TUNNEL,
+		.family = AF_INET,
+	},
 };
 
 static const struct xfrm_mode xfrm6_mode_map[XFRM_MODE_MAX] = {
@@ -486,6 +491,11 @@ static const struct xfrm_mode xfrm6_mode_map[XFRM_MODE_MAX] = {
 		.flags = XFRM_MODE_FLAG_TUNNEL,
 		.family = AF_INET6,
 	},
+	[XFRM_MODE_IPTFS] = {
+		.encap = XFRM_MODE_IPTFS,
+		.flags = XFRM_MODE_FLAG_TUNNEL,
+		.family = AF_INET6,
+	},
 };
 
 static const struct xfrm_mode *xfrm_get_mode(unsigned int encap, int family)
@@ -2083,6 +2093,7 @@ static int __xfrm6_state_sort_cmp(const void *p)
 #endif
 	case XFRM_MODE_TUNNEL:
 	case XFRM_MODE_BEET:
+	case XFRM_MODE_IPTFS:
 		return 4;
 	}
 	return 5;
@@ -2109,6 +2120,7 @@ static int __xfrm6_tmpl_sort_cmp(const void *p)
 #endif
 	case XFRM_MODE_TUNNEL:
 	case XFRM_MODE_BEET:
+	case XFRM_MODE_IPTFS:
 		return 3;
 	}
 	return 4;
net/xfrm/xfrm_user.c +3 -0
index 795da945fbc2..4b0e462d5e31 100644
@@ -353,6 +353,7 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
 	case XFRM_MODE_TUNNEL:
 	case XFRM_MODE_ROUTEOPTIMIZATION:
 	case XFRM_MODE_BEET:
+	case XFRM_MODE_IPTFS:
 		break;
 
 	default:
@@ -1830,6 +1831,8 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family,
 				return -EINVAL;
 			}
 			break;
+		case XFRM_MODE_IPTFS:
+			break;
 		default:
 			if (ut[i].family != prev_family) {
 				NL_SET_ERR_MSG(extack, "Mode in template doesn't support a family change");
Signature · 1 line
2.42.0
#19 lore raw

RFC v2 8/8 iptfs: impl: add new iptfs xfrm mode impl

In reply to Christian Hopps

From: Christian Hopps <[email protected]>

Add a new xfrm mode implementing AggFrag/IP-TFS from RFC9347.

This utilizes the new xfrm_mode_cbs to implement demand-driven IP-TFS functionality. This functionality can be used to increase bandwidth utilization through small packet aggregation, as well as help solve PMTU issues through it's efficient use of fragmentation.

---
 include/net/iptfs.h    |   18 +
 net/xfrm/Makefile      |    1 +
 net/xfrm/trace_iptfs.h |  224 ++++
 net/xfrm/xfrm_iptfs.c  | 2696 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 2939 insertions(+)
 create mode 100644 include/net/iptfs.h
 create mode 100644 net/xfrm/trace_iptfs.h
 create mode 100644 net/xfrm/xfrm_iptfs.c
include/net/iptfs.h new file +18 -0
new file mode 100644
index 000000000000..d8f2e494f251
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _NET_IPTFS_H
+#define _NET_IPTFS_H
+
+#include <linux/types.h>
+#include <linux/ip.h>
+
+#define IPTFS_SUBTYPE_BASIC 0
+#define IPTFS_SUBTYPE_CC 1
+#define IPTFS_SUBTYPE_LAST IPTFS_SUBTYPE_CC
+
+#define IPTFS_CC_FLAGS_ECN_CE 0x1
+#define IPTFS_CC_FLAGS_PLMTUD 0x2
+
+extern void xfrm_iptfs_get_rtt_and_delays(struct ip_iptfs_cc_hdr *cch, u32 *rtt,
+					  u32 *actual_delay, u32 *xmit_delay);
+
+#endif /* _NET_IPTFS_H */
net/xfrm/Makefile +1 -0
index cd47f88921f5..9b870a3274a7 100644
@@ -20,4 +20,5 @@ obj-$(CONFIG_XFRM_USER) += xfrm_user.o
 obj-$(CONFIG_XFRM_USER_COMPAT) += xfrm_compat.o
 obj-$(CONFIG_XFRM_IPCOMP) += xfrm_ipcomp.o
 obj-$(CONFIG_XFRM_INTERFACE) += xfrm_interface.o
+obj-$(CONFIG_XFRM_IPTFS) += xfrm_iptfs.o
 obj-$(CONFIG_XFRM_ESPINTCP) += espintcp.o
net/xfrm/trace_iptfs.h new file +224 -0

224 lines not on this page · raw message

net/xfrm/xfrm_iptfs.c new file +2696 -0

2,696 lines not on this page · raw message

Signature · 1 line
2.42.0
#20 lore raw

Re: [RFC ipsec-next v2 8/8] iptfs: impl: add new iptfs xfrm mode impl

kernel test robot noticed the following build warnings:

Hi Christian,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on klassert-ipsec-next/master]
[also build test WARNING on klassert-ipsec/master netfilter-nf/main linus/master v6.7-rc1 next-20231113] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Hopps/iptfs-config-add-CONFIG_XFRM_IPTFS/20231113-115642
base:   https://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git master
patch link:    https://lore.kernel.org/r/20231113035219.920136-9-chopps%40chopps.org
patch subject: [RFC ipsec-next v2 8/8] iptfs: impl: add new iptfs xfrm mode impl
config: nios2-allmodconfig (https://download.01.org/0day-ci/archive/20231113/[email protected]/config)
compiler: nios2-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231113/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

net/xfrm/xfrm_iptfs.c:468:17: warning: no previous prototype for 'iptfs_pskb_add_frags' [-Wmissing-prototypes]
468 | struct sk_buff *iptfs_pskb_add_frags(struct sk_buff *tpl,
| ^~~~~~~~~~~~~~~~~~~~
net/xfrm/xfrm_iptfs.c: In function '__iptfs_reassem_done':
net/xfrm/xfrm_iptfs.c:629:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]

     629 |         int ret;
         |             ^~~
   net/xfrm/xfrm_iptfs.c: In function '__reorder_drop':
   net/xfrm/xfrm_iptfs.c:1234:13: warning: variable 'wantseq' set but not used [-Wunused-but-set-variable]
    1234 |         u64 wantseq = xtfs->w_wantseq;
         |             ^~~~~~~
   net/xfrm/xfrm_iptfs.c: In function '__reorder_this':
   net/xfrm/xfrm_iptfs.c:1283:13: warning: variable 'wantseq' set but not used [-Wunused-but-set-variable]
    1283 |         u64 wantseq = xtfs->w_wantseq;
         |             ^~~~~~~
   net/xfrm/xfrm_iptfs.c: In function '__reorder_future_shifts':
   net/xfrm/xfrm_iptfs.c:1405:13: warning: variable 'last_drop_seq' set but not used [-Wunused-but-set-variable]
    1405 |         u64 last_drop_seq = xtfs->w_wantseq;
         |             ^~~~~~~~~~~~~
   net/xfrm/xfrm_iptfs.c: In function 'iptfs_drop_timer':
   net/xfrm/xfrm_iptfs.c:1625:20: warning: variable 'fcount' set but not used [-Wunused-but-set-variable]
    1625 |         u32 count, fcount;
         |                    ^~~~~~
   net/xfrm/xfrm_iptfs.c: In function 'iptfs_delay_timer':
   net/xfrm/xfrm_iptfs.c:2357:16: warning: variable 'osize' set but not used [-Wunused-but-set-variable]
    2357 |         size_t osize;
         |                ^~~~~
   net/xfrm/xfrm_iptfs.c: In function 'iptfs_encap_add_ipv4':
   net/xfrm/xfrm_iptfs.c:2405:13: warning: variable 'flags' set but not used [-Wunused-but-set-variable]
    2405 |         int flags;
         |             ^~~~~
   net/xfrm/xfrm_iptfs.c: At top level:
   net/xfrm/xfrm_iptfs.c:100:12: warning: '__trace_ip_proto_seq' defined but not used [-Wunused-function]
     100 | static u32 __trace_ip_proto_seq(struct iphdr *iph)
         |            ^~~~~~~~~~~~~~~~~~~~
>> net/xfrm/xfrm_iptfs.c:93:12: warning: '__trace_ip_proto' defined but not used [-Wunused-function]

93 | static u32 __trace_ip_proto(struct iphdr *iph)
| ^~~~~~~~~~~~~~~~

vim +/__trace_ip_proto +93 net/xfrm/xfrm_iptfs.c

    92	
  > 93	static u32 __trace_ip_proto(struct iphdr *iph)
    94	{
    95		if (iph->version == 4)
    96			return iph->protocol;
    97		return ((struct ipv6hdr *)iph)->nexthdr;
    98	}
    99	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#21 lore raw

Re: [RFC ipsec-next v2 8/8] iptfs: impl: add new iptfs xfrm mode impl

In reply to Christian Hopps

include/net/iptfs.h

Quoted 27 lines · Christian Hopps

From: Christian Hopps <[email protected]>

Add a new xfrm mode implementing AggFrag/IP-TFS from RFC9347.

This utilizes the new xfrm_mode_cbs to implement demand-driven IP-TFS functionality. This functionality can be used to increase bandwidth utilization through small packet aggregation, as well as help solve PMTU issues through it's efficient use of fragmentation.

---
 include/net/iptfs.h    |   18 +
 net/xfrm/Makefile      |    1 +
 net/xfrm/trace_iptfs.h |  224 ++++
 net/xfrm/xfrm_iptfs.c  | 2696 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 2939 insertions(+)
 create mode 100644 include/net/iptfs.h
 create mode 100644 net/xfrm/trace_iptfs.h
 create mode 100644 net/xfrm/xfrm_iptfs.c
include/net/iptfs.h new file +0 -0
new file mode 100644
index 000000000000..d8f2e494f251

Is this header needed? It's only included by net/xfrm/xfrm_iptfs.c, why not put those #defines directly in the file?

include/net/iptfs.h line 10

Quoted 11 lines
include/net/iptfs.h new file +10 -0
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _NET_IPTFS_H
+#define _NET_IPTFS_H
+
+#include <linux/types.h>
+#include <linux/ip.h>
+
+#define IPTFS_SUBTYPE_BASIC 0
+#define IPTFS_SUBTYPE_CC 1
+#define IPTFS_SUBTYPE_LAST IPTFS_SUBTYPE_CC

_LAST is never used.

include/net/iptfs.h line 13

Quoted 2 lines
include/net/iptfs.h new file +2 -0
+#define IPTFS_CC_FLAGS_ECN_CE 0x1
+#define IPTFS_CC_FLAGS_PLMTUD 0x2

Not used either.

include/net/iptfs.h line 16

Quoted 2 lines
include/net/iptfs.h new file +2 -0
+extern void xfrm_iptfs_get_rtt_and_delays(struct ip_iptfs_cc_hdr *cch, u32 *rtt,
+					  u32 *actual_delay, u32 *xmit_delay);

Not implemented in this series, drop this.

[...]

Quoted 5 lines
net/xfrm/xfrm_iptfs.c new file +0 -0
new file mode 100644
index 000000000000..65f7acdbe6a8

[...]

Quoted 1 line

+struct sk_buff *iptfs_pskb_add_frags(struct sk_buff *tpl,

nit: static? afaict it's not used outside this file.

Quoted 4 lines
net/xfrm/xfrm_iptfs.c new file +4 -0
+				     struct skb_frag_walk *walk, u32 off,
+				     u32 len, struct skb_seq_state *st,
+				     u32 copy_len)
+{

[...]

net/xfrm/xfrm_iptfs.c line 877

Quoted 8 lines
net/xfrm/xfrm_iptfs.c new file +8 -0
+
+/**
+ * iptfs_input_ordered() - handle next in order IPTFS payload.
+ *
+ * Process the IPTFS payload in `skb` and consume it afterwards.
+ */
+static int iptfs_input_ordered(struct xfrm_state *x, struct sk_buff *skb)
+{

Can we try to not introduce a worse problem than xfrm_input already is? 326 lines and 20+ local variables is way too much. And then it calls another 200+ lines function...

I did try to understand what the main loop does but I got completely lost the 3 times I tried :/

net/xfrm/xfrm_iptfs.c line 1279

Quoted 3 lines
net/xfrm/xfrm_iptfs.c new file +3 -0
+static u32 __reorder_this(struct xfrm_iptfs_data *xtfs, struct sk_buff *inskb,
+			  struct list_head *list)
+

nit: extra blank line

Quoted 1 line

+{

[...]

Quoted 7 lines

+/**
+ * iptfs_input() - handle receipt of iptfs payload
+ * @x: xfrm state.
+ * @skb: the packet.
+ *
+ * We have an IPTFS payload order it if needed, then process newly in order
+ * packetsA.

typo? "packetsA"

[...]

Quoted 22 lines
net/xfrm/xfrm_iptfs.c new file +22 -0
+/* IPv4/IPv6 packet ingress to IPTFS tunnel, arrange to send in IPTFS payload
+ * (i.e., aggregating or fragmenting as appropriate).
+ * This is set in dst->output for an SA.
+ */
+static int iptfs_output_collect(struct net *net, struct sock *sk,
+				struct sk_buff *skb)
+{
+	struct dst_entry *dst = skb_dst(skb);
+	struct xfrm_state *x = dst->xfrm;
+	struct xfrm_iptfs_data *xtfs = x->mode_data;
+	struct sk_buff *segs, *nskb;
+	u32 count, qcount;
+	u32 pmtu = 0;
+	bool ok = true;
+	bool was_gso;
+
+	/* We have hooked into dst_entry->output which means we have skipped the
+	 * protocol specific netfilter (see xfrm4_output, xfrm6_output).
+	 * when our timer runs we will end up calling xfrm_output directly on
+	 * the encapsulated traffic.
+	 *
+	 * For both cases this is the NF_INET_POST_ROUTING hook which allows

net/xfrm/xfrm_iptfs.c line 1817

Quoted 10 lines
net/xfrm/xfrm_iptfs.c new file +10 -0
+	 * changing the skb->dst entry which then may not be xfrm based anymore
+	 * in which case a REROUTED flag is set. and dst_output is called.
+	 *
+	 * For IPv6 we are also skipping fragmentation handling for local
+	 * sockets, which may or may not be good depending on our tunnel DF
+	 * setting. Normally with fragmentation supported we want to skip this
+	 * fragmentation.
+	 */
+
+	BUG_ON(!xtfs);

Or drop the packet and add a DEBUG_NET_WARN_ON_ONCE? This should never happen, but why crash the system when we have a way to deal with this error?

Quoted 14 lines
net/xfrm/xfrm_iptfs.c new file +14 -0
+
+	if (xtfs->cfg.dont_frag)
+		pmtu = iptfs_get_cur_pmtu(x, xtfs, skb);
+
+	/* Break apart GSO skbs. If the queue is nearing full then we want the
+	 * accounting and queuing to be based on the individual packets not on the
+	 * aggregate GSO buffer.
+	 */
+	was_gso = skb_is_gso(skb);
+	if (!was_gso) {
+		segs = skb;
+	} else {
+		segs = skb_gso_segment(skb, 0);
+		if (IS_ERR_OR_NULL(segs)) {

net/xfrm/xfrm_iptfs.c line 1841

Quoted 10 lines
net/xfrm/xfrm_iptfs.c new file +10 -0
+			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
+			kfree_skb(skb);
+			return PTR_ERR(segs);
+		}
+		consume_skb(skb);
+		skb = NULL;
+	}
+
+	count = 0;
+	qcount = 0;

nit: both of those get incremented through the main loop but never read

Quoted 22 lines
net/xfrm/xfrm_iptfs.c new file +22 -0
+
+	/* We can be running on multiple cores and from the network softirq or
+	 * from user context depending on where the packet is coming from.
+	 */
+	spin_lock_bh(&x->lock);
+
+	skb_list_walk_safe(segs, skb, nskb) {
+		skb_mark_not_on_list(skb);
+		count++;
+
+		/* Once we drop due to no queue space we continue to drop the
+		 * rest of the packets from that GRO.
+		 */
+		if (!ok) {
+nospace:
+			trace_iptfs_no_queue_space(skb, xtfs, pmtu, was_gso);
+			XFRM_INC_STATS(dev_net(skb->dev), LINUX_MIB_XFRMOUTNOQSPACE);
+			kfree_skb_reason(skb, SKB_DROP_REASON_FULL_RING);
+			continue;
+		}
+
+		/* If the user indicated no iptfs fragmenting check before

net/xfrm/xfrm_iptfs.c line 1873

Quoted 10 lines
net/xfrm/xfrm_iptfs.c new file +10 -0
+		 * enqueue.
+		 */
+		if (xtfs->cfg.dont_frag && iptfs_is_too_big(sk, skb, pmtu)) {
+			trace_iptfs_too_big(skb, xtfs, pmtu, was_gso);
+			kfree_skb_reason(skb, SKB_DROP_REASON_PKT_TOO_BIG);
+			continue;
+		}
+
+		/* Enqueue to send in tunnel */
+

nit: unneeded blank line

net/xfrm/xfrm_iptfs.c line 1885

Quoted 12 lines
net/xfrm/xfrm_iptfs.c new file +12 -0
+		ok = iptfs_enqueue(xtfs, skb);
+		if (!ok)
+			goto nospace;
+
+		trace_iptfs_enqueue(skb, xtfs, pmtu, was_gso);
+		qcount++;
+	}
+
+	/* Start a delay timer if we don't have one yet */
+	if (!hrtimer_is_queued(&xtfs->iptfs_timer)) {
+		/* softirq blocked lest the timer fire and interrupt us */
+		BUG_ON(!in_interrupt());

Why is that a fatal condition?

Quoted 11 lines
net/xfrm/xfrm_iptfs.c new file +11 -0
+		hrtimer_start(&xtfs->iptfs_timer, xtfs->init_delay_ns,
+			      IPTFS_HRTIMER_MODE);
+
+		xtfs->iptfs_settime = ktime_get_raw_fast_ns();
+		trace_iptfs_timer_start(xtfs, xtfs->init_delay_ns);
+	}
+
+	spin_unlock_bh(&x->lock);
+	return 0;
+}
+

[...]

Quoted 3 lines
net/xfrm/xfrm_iptfs.c new file +3 -0
+static int iptfs_copy_create_frags(struct sk_buff **skbp,
+				   struct xfrm_iptfs_data *xtfs, u32 mtu)
+{

[...]

net/xfrm/xfrm_iptfs.c line 2046

Quoted 7 lines
net/xfrm/xfrm_iptfs.c new file +7 -0
+	/* prepare the initial fragment with an iptfs header */
+	iptfs_output_prepare_skb(skb, 0);
+
+	/* Send all but last fragment. */
+	list_for_each_entry_safe(skb, nskb, &sublist, list) {
+		skb_list_del_init(skb);
+		xfrm_output(NULL, skb);

Should we stop if xfrm_output fails? Or is it still useful to send the rest of the iptfs frags if we lose one in the middle?

Quoted 5 lines
net/xfrm/xfrm_iptfs.c new file +5 -0
+	}
+
+	return 0;
+}
+

[...]

Quoted 15 lines
net/xfrm/xfrm_iptfs.c new file +15 -0
+static int iptfs_first_skb(struct sk_buff **skbp, struct xfrm_iptfs_data *xtfs,
+			   u32 mtu)
+{
+	struct sk_buff *skb = *skbp;
+	int err;
+
+	/* Classic ESP skips the don't fragment ICMP error if DF is clear on
+	 * the inner packet or ignore_df is set. Otherwise it will send an ICMP
+	 * or local error if the inner packet won't fit it's MTU.
+	 *
+	 * With IPTFS we do not care about the inner packet DF bit. If the
+	 * tunnel is configured to "don't fragment" we error back if things
+	 * don't fit in our max packet size. Otherwise we iptfs-fragment as
+	 * normal.
+	 */

net/xfrm/xfrm_iptfs.c line 2119

Quoted 10 lines
net/xfrm/xfrm_iptfs.c new file +10 -0
+
+	/* The opportunity for HW offload has ended */
+	if (skb->ip_summed == CHECKSUM_PARTIAL) {
+		err = skb_checksum_help(skb);
+		if (err)
+			return err;
+	}
+
+	/* We've split these up before queuing */
+	BUG_ON(skb_is_gso(skb));

Drop and DEBUG_NET_WARN_ON_ONCE?

net/xfrm/xfrm_iptfs.c line 2131

Quoted 12 lines
net/xfrm/xfrm_iptfs.c new file +12 -0
+
+	trace_iptfs_first_dequeue(skb, mtu, 0, ip_hdr(skb));
+
+	/* Simple case -- it fits. `mtu` accounted for all the overhead
+	 * including the basic IPTFS header.
+	 */
+	if (skb->len <= mtu) {
+		iptfs_output_prepare_skb(skb, 0);
+		return 0;
+	}
+
+	BUG_ON(xtfs->cfg.dont_frag);

and here?

net/xfrm/xfrm_iptfs.c

Quoted 2 lines
net/xfrm/xfrm_iptfs.c new file +2 -0
+	if (iptfs_first_should_copy(skb, mtu))
+		return iptfs_copy_create_frags(skbp, xtfs, mtu);

Since we end up copying anyway, drop this (and iptfs_first_should_copy). You can introduce the optimization later on.

net/xfrm/xfrm_iptfs.c line 2145

Quoted 10 lines
net/xfrm/xfrm_iptfs.c new file +10 -0
+	/* For now we always copy */
+	return iptfs_copy_create_frags(skbp, xtfs, mtu);
+}
+
+static struct sk_buff **iptfs_rehome_fraglist(struct sk_buff **nextp,
+					      struct sk_buff *child)
+{
+	u32 fllen = 0;
+
+	BUG_ON(!skb_has_frag_list(child));

Not needed, this was tested just before calling this function.

net/xfrm/xfrm_iptfs.c line 2152

Quoted 7 lines
net/xfrm/xfrm_iptfs.c new file +7 -0
+
+	/* It might be possible to account for a frag list in addition to page
+	 * fragment if it's a valid state to be in. The page fragments size
+	 * should be kept as data_len so only the frag_list size is removed,
+	 * this must be done above as well took
+	 */
+	BUG_ON(skb_shinfo(child)->nr_frags);

Again not worth crashing the system?

Quoted 12 lines
net/xfrm/xfrm_iptfs.c new file +12 -0
+	*nextp = skb_shinfo(child)->frag_list;
+	while (*nextp) {
+		fllen += (*nextp)->len;
+		nextp = &(*nextp)->next;
+	}
+	skb_frag_list_init(child);
+	BUG_ON(fllen > child->data_len);
+	child->len -= fllen;
+	child->data_len -= fllen;
+
+	return nextp;
+}

[...]

Quoted 9 lines
net/xfrm/xfrm_iptfs.c new file +9 -0
+static void iptfs_output_queued(struct xfrm_state *x, struct sk_buff_head *list)
+{
+	struct xfrm_iptfs_data *xtfs = x->mode_data;
+	u32 payload_mtu = xtfs->payload_mtu;
+	struct sk_buff *skb, *skb2, **nextp;
+	struct skb_shared_info *shi, *shi2;
+
+	/* For now we are just outputting packets as fast as we can, so if we
+	 * are fragmenting we will do so until the last inner packet has been

net/xfrm/xfrm_iptfs.c line 2213

Quoted 10 lines
net/xfrm/xfrm_iptfs.c new file +10 -0
+	 * consumed.
+	 *
+	 * When we are fragmenting we need to output all outer packets that
+	 * contain the fragments of a single inner packet, consecutively (ESP
+	 * seq-wise). So we need a lock to keep another CPU from sending the
+	 * next batch of packets (it's `list`) and trying to output those, while
+	 * we output our `list` resuling with interleaved non-spec-client inner
+	 * packet streams. Thus we need to lock the IPTFS output on a per SA
+	 * basis while we process this list.
+	 */

This talks about a lock but I don't see one. What am I missing?

Quoted 14 lines
net/xfrm/xfrm_iptfs.c new file +14 -0
+
+	/* NOTE: for the future, for timed packet sends, if our queue is not
+	 * growing longer (i.e., we are keeping up) and a packet we are about to
+	 * fragment will not fragment in then next outer packet, we might consider
+	 * holding on to it to send whole in the next slot. The question then is
+	 * does this introduce a continuous delay in the inner packet stream
+	 * with certain packet rates and sizes?
+	 */
+
+	/* and send them on their way */
+
+	while ((skb = __skb_dequeue(list))) {
+		struct xfrm_dst *xdst = (struct xfrm_dst *)skb_dst(skb);
+		u32 mtu = __iptfs_get_inner_mtu(x, xdst->child_mtu_cached);

net/xfrm/xfrm_iptfs.c line 2237

Quoted 10 lines
net/xfrm/xfrm_iptfs.c new file +10 -0
+		bool share_ok = true;
+		int remaining;
+
+		/* protocol comes to us cleared sometimes */
+		skb->protocol = x->outer_mode.family == AF_INET ?
+					htons(ETH_P_IP) :
+					htons(ETH_P_IPV6);
+
+		if (payload_mtu && payload_mtu < mtu)
+			mtu = payload_mtu;

Isn't that iptfs_get_cur_pmtu?

[...]

Quoted 13 lines
net/xfrm/xfrm_iptfs.c new file +13 -0
+static enum hrtimer_restart iptfs_delay_timer(struct hrtimer *me)
+{
+	struct sk_buff_head list;
+	struct xfrm_iptfs_data *xtfs;
+	struct xfrm_state *x;
+	time64_t settime;
+	size_t osize;
+
+	xtfs = container_of(me, typeof(*xtfs), iptfs_timer);
+	x = xtfs->x;
+
+	/* Process all the queued packets
+	 *

net/xfrm/xfrm_iptfs.c line 2373

Quoted 10 lines
net/xfrm/xfrm_iptfs.c new file +10 -0
+	 * softirq execution order: timer > tasklet > hrtimer
+	 *
+	 * Network rx will have run before us giving one last chance to queue
+	 * ingress packets for us to process and transmit.
+	 */
+
+	spin_lock(&x->lock);
+	__skb_queue_head_init(&list);
+	skb_queue_splice_init(&xtfs->queue, &list);
+	osize = xtfs->queue_size;

Unused variable?

[...]

net/xfrm/xfrm_iptfs.c line 2549

Quoted 8 lines
net/xfrm/xfrm_iptfs.c new file +8 -0
+static int iptfs_user_init(struct net *net, struct xfrm_state *x,
+			   struct nlattr **attrs)
+{
+	struct xfrm_iptfs_data *xtfs = x->mode_data;
+	struct xfrm_iptfs_config *xc;
+
+	if (x->props.mode != XFRM_MODE_IPTFS)
+		return -EINVAL;

Is that necessary? This only gets called via ->user_init for this mode.

Quoted 5 lines
net/xfrm/xfrm_iptfs.c new file +5 -0
+	xc = &xtfs->cfg;
+	xc->reorder_win_size = net->xfrm.sysctl_iptfs_rewin;
+	xc->max_queue_size = net->xfrm.sysctl_iptfs_maxqsize;
+	xc->init_delay_us = net->xfrm.sysctl_iptfs_idelay;
+	xc->drop_time_us = net->xfrm.sysctl_iptfs_drptime;

net/xfrm/xfrm_iptfs.c line 2565

Quoted 10 lines
net/xfrm/xfrm_iptfs.c new file +10 -0
+
+	if (attrs[XFRMA_IPTFS_DONT_FRAG])
+		xc->dont_frag = true;
+	if (attrs[XFRMA_IPTFS_REORD_WIN])
+		xc->reorder_win_size =
+			nla_get_u16(attrs[XFRMA_IPTFS_REORD_WIN]);
+	/* saved array is for saving 1..N seq nums from wantseq */
+	if (xc->reorder_win_size)
+		xtfs->w_saved = kcalloc(xc->reorder_win_size,
+					sizeof(*xtfs->w_saved), GFP_KERNEL);

We probably need a reasonable bound on reorder_win_size so that we don't try to allocate crazy amounts of memory here.

net/xfrm/xfrm_iptfs.c line 2569

Quoted 4 lines
net/xfrm/xfrm_iptfs.c new file +4 -0
+	if (attrs[XFRMA_IPTFS_PKT_SIZE]) {
+		xc->pkt_size = nla_get_u32(attrs[XFRMA_IPTFS_PKT_SIZE]);
+		if (!xc->pkt_size)
+			xtfs->payload_mtu = 0;

That's already set to 0 via kzalloc, right? So passing 0 as XFRMA_IPTFS_PKT_SIZE is equivalent to not providing it?

net/xfrm/xfrm_iptfs.c line 2573

Quoted 4 lines
net/xfrm/xfrm_iptfs.c new file +4 -0
+		else if (xc->pkt_size > x->props.header_len)
+			xtfs->payload_mtu = xc->pkt_size - x->props.header_len;
+		else
+			return -EINVAL;

This could probably use an extack to explain why the value was rejected.

net/xfrm/xfrm_iptfs.c line 2584

Quoted 11 lines
net/xfrm/xfrm_iptfs.c new file +11 -0
+	}
+	if (attrs[XFRMA_IPTFS_MAX_QSIZE])
+		xc->max_queue_size = nla_get_u32(attrs[XFRMA_IPTFS_MAX_QSIZE]);
+	if (attrs[XFRMA_IPTFS_DROP_TIME])
+		xc->drop_time_us = nla_get_u32(attrs[XFRMA_IPTFS_DROP_TIME]);
+	if (attrs[XFRMA_IPTFS_INIT_DELAY])
+		xc->init_delay_us = nla_get_u32(attrs[XFRMA_IPTFS_INIT_DELAY]);
+
+	xtfs->ecn_queue_size = (u64)xc->max_queue_size * 95 / 100;
+	xtfs->drop_time_ns = xc->drop_time_us * NSECS_IN_USEC;
+	xtfs->init_delay_ns = xc->init_delay_us * NSECS_IN_USEC;

Can't we get rid of the _us version? Why store both in kernel memory?

[...]

net/xfrm/xfrm_iptfs.c line 2652

Quoted 5 lines
net/xfrm/xfrm_iptfs.c new file +5 -0
+static void iptfs_delete_state(struct xfrm_state *x)
+{
+	struct xfrm_iptfs_data *xtfs = x->mode_data;
+
+	if (IS_ERR_OR_NULL(xtfs))

Can mode_data ever be an error pointer?

Quoted 30 lines
net/xfrm/xfrm_iptfs.c new file +30 -0
+		return;
+
+	spin_lock(&xtfs->drop_lock);
+	hrtimer_cancel(&xtfs->iptfs_timer);
+	hrtimer_cancel(&xtfs->drop_timer);
+	spin_unlock(&xtfs->drop_lock);
+
+	kfree_sensitive(xtfs->w_saved);
+	kfree_sensitive(xtfs);
+}
+
+static const struct xfrm_mode_cbs iptfs_mode_cbs = {
+	.owner = THIS_MODULE,
+	.create_state = iptfs_create_state,
+	.delete_state = iptfs_delete_state,
+	.user_init = iptfs_user_init,
+	.copy_to_user = iptfs_copy_to_user,
+	.get_inner_mtu = iptfs_get_inner_mtu,
+	.input = iptfs_input,
+	.output = iptfs_output_collect,
+	.prepare_output = iptfs_prepare_output,
+};
+
+static int __init xfrm_iptfs_init(void)
+{
+	int err;
+
+	pr_info("xfrm_iptfs: IPsec IP-TFS tunnel mode module\n");
+
+	err = xfrm_register_mode_cbs(XFRM_MODE_IPTFS, &iptfs_mode_cbs);

net/xfrm/xfrm_iptfs.c line 2692

Quoted 10 lines
net/xfrm/xfrm_iptfs.c new file +10 -0
+	if (err < 0)
+		pr_info("%s: can't register IP-TFS\n", __func__);
+
+	return err;
+}
+
+static void __exit xfrm_iptfs_fini(void)
+{
+	xfrm_unregister_mode_cbs(XFRM_MODE_IPTFS);
+}

If the module is unloaded, existing xfrm states will be left but silently broken?

Signature · 1 line
Sabrina
#22 lore raw

Re: [RFC ipsec-next v2 8/8] iptfs: impl: add new iptfs xfrm mode impl

Quoted 23 lines · Sabrina Dubroca
Quoted 22 lines · Christian Hopps

From: Christian Hopps <[email protected]>

Add a new xfrm mode implementing AggFrag/IP-TFS from RFC9347.

This utilizes the new xfrm_mode_cbs to implement demand-driven IP-TFS functionality. This functionality can be used to increase bandwidth utilization through small packet aggregation, as well as help solve PMTU issues through it's efficient use of fragmentation.

---
 include/net/iptfs.h    |   18 +
 net/xfrm/Makefile      |    1 +
 net/xfrm/trace_iptfs.h |  224 ++++
 net/xfrm/xfrm_iptfs.c  | 2696 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 2939 insertions(+)
 create mode 100644 include/net/iptfs.h
 create mode 100644 net/xfrm/trace_iptfs.h
 create mode 100644 net/xfrm/xfrm_iptfs.c
Quoted 8 lines

include/net/iptfs.h

Quoted 5 lines
include/net/iptfs.h new file +0 -0
new file mode 100644
index 000000000000..d8f2e494f251

Is this header needed? It's only included by net/xfrm/xfrm_iptfs.c, why not put those #defines directly in the file?

Moved into xfrm_iptfs.c and removed this file.

Quoted 14 lines

include/net/iptfs.h line 10

Quoted 12 lines
include/net/iptfs.h new file +10 -0
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _NET_IPTFS_H
+#define _NET_IPTFS_H
+
+#include <linux/types.h>
+#include <linux/ip.h>
+
+#define IPTFS_SUBTYPE_BASIC 0
+#define IPTFS_SUBTYPE_CC 1
+#define IPTFS_SUBTYPE_LAST IPTFS_SUBTYPE_CC

_LAST is never used.

Removed.

Quoted 4 lines

include/net/iptfs.h line 13

Quoted 2 lines
include/net/iptfs.h new file +2 -0
+#define IPTFS_CC_FLAGS_ECN_CE 0x1
+#define IPTFS_CC_FLAGS_PLMTUD 0x2

Not used either.

Removed (until we need them).

Quoted 4 lines

include/net/iptfs.h line 16

Quoted 2 lines
include/net/iptfs.h new file +2 -0
+extern void xfrm_iptfs_get_rtt_and_delays(struct ip_iptfs_cc_hdr *cch, u32 *rtt,
+					  u32 *actual_delay, u32 *xmit_delay);

Not implemented in this series, drop this.

Gone.

Quoted 10 lines

[...]

Quoted 5 lines
net/xfrm/xfrm_iptfs.c new file +0 -0
new file mode 100644
index 000000000000..65f7acdbe6a8

[...]

Quoted 1 line

+struct sk_buff *iptfs_pskb_add_frags(struct sk_buff *tpl,

nit: static? afaict it's not used outside this file.

static node.

Quoted 20 lines
Quoted 4 lines
net/xfrm/xfrm_iptfs.c new file +4 -0
+				     struct skb_frag_walk *walk, u32 off,
+				     u32 len, struct skb_seq_state *st,
+				     u32 copy_len)
+{

[...]

net/xfrm/xfrm_iptfs.c line 877

Quoted 8 lines
net/xfrm/xfrm_iptfs.c new file +8 -0
+
+/**
+ * iptfs_input_ordered() - handle next in order IPTFS payload.
+ *
+ * Process the IPTFS payload in `skb` and consume it afterwards.
+ */
+static int iptfs_input_ordered(struct xfrm_state *x, struct sk_buff *skb)
+{

Can we try to not introduce a worse problem than xfrm_input already is? 326 lines and 20+ local variables is way too much. And then it calls another 200+ lines function...

Quoted 2 lines

I did try to understand what the main loop does but I got completely lost the 3 times I tried :/

I'm not sure what to do with this comment. :)

Its a fairly complex process of reassembling the fragmented inner packets, and it's already divided into 2 functions as you noted. I don't think breaking this up more is going to do much for simplification b/c now we'll need to be passing pointers to what are currently local variables to maintain the state, and the singular concept of what is going on would be fragmented (no pun intended) across multiple functions when it's really just a single process.

Quoted 5 lines

net/xfrm/xfrm_iptfs.c line 1279

Quoted 3 lines
net/xfrm/xfrm_iptfs.c new file +3 -0
+static u32 __reorder_this(struct xfrm_iptfs_data *xtfs, struct sk_buff *inskb,
+			  struct list_head *list)
+

nit: extra blank line

Fixed.

Quoted 12 lines
Quoted 1 line

+{

[...]

Quoted 7 lines

+/**
+ * iptfs_input() - handle receipt of iptfs payload
+ * @x: xfrm state.
+ * @skb: the packet.
+ *
+ * We have an IPTFS payload order it if needed, then process newly in order
+ * packetsA.

Quoted 1 line

typo? "packetsA"

Fixed.

Quoted 29 lines

[...]

Quoted 28 lines
net/xfrm/xfrm_iptfs.c new file +28 -0
+/* IPv4/IPv6 packet ingress to IPTFS tunnel, arrange to send in IPTFS payload
+ * (i.e., aggregating or fragmenting as appropriate).
+ * This is set in dst->output for an SA.
+ */
+static int iptfs_output_collect(struct net *net, struct sock *sk,
+				struct sk_buff *skb)
+{
+	struct dst_entry *dst = skb_dst(skb);
+	struct xfrm_state *x = dst->xfrm;
+	struct xfrm_iptfs_data *xtfs = x->mode_data;
+	struct sk_buff *segs, *nskb;
+	u32 count, qcount;
+	u32 pmtu = 0;
+	bool ok = true;
+	bool was_gso;
+
+	/* We have hooked into dst_entry->output which means we have skipped the
+	 * protocol specific netfilter (see xfrm4_output, xfrm6_output).
+	 * when our timer runs we will end up calling xfrm_output directly on
+	 * the encapsulated traffic.
+	 *
+	 * For both cases this is the NF_INET_POST_ROUTING hook which allows
+	 * changing the skb->dst entry which then may not be xfrm based anymore
+	 * in which case a REROUTED flag is set. and dst_output is called.
+	 *
+	 * For IPv6 we are also skipping fragmentation handling for local
+	 * sockets, which may or may not be good depending on our tunnel DF
+	 * setting. Normally with fragmentation supported we want to skip this
Quoted 8 lines

net/xfrm/xfrm_iptfs.c line 1817

Quoted 4 lines
net/xfrm/xfrm_iptfs.c new file +4 -0
+	 * fragmentation.
+	 */
+
+	BUG_ON(!xtfs);

Or drop the packet and add a DEBUG_NET_WARN_ON_ONCE? This should never happen, but why crash the system when we have a way to deal with this error?

So this is running into basic assert philosophy I suppose. For true invariant's I like to simplify things by asserting them being true (which also documents them) rather than create more logic branches in the code. The added complexity of those extra branches becomes more apparent when you are doing code-coverage analysis. I'd rather not add code that will never execute that I then have to create impossible situation tests to test.

Quoted 17 lines
Quoted 17 lines
net/xfrm/xfrm_iptfs.c new file +17 -0
+	if (xtfs->cfg.dont_frag)
+		pmtu = iptfs_get_cur_pmtu(x, xtfs, skb);
+
+	/* Break apart GSO skbs. If the queue is nearing full then we want the
+	 * accounting and queuing to be based on the individual packets not on the
+	 * aggregate GSO buffer.
+	 */
+	was_gso = skb_is_gso(skb);
+	if (!was_gso) {
+		segs = skb;
+	} else {
+		segs = skb_gso_segment(skb, 0);
+		if (IS_ERR_OR_NULL(segs)) {
+			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
+			kfree_skb(skb);
+			return PTR_ERR(segs);
+		}
Quoted 8 lines

net/xfrm/xfrm_iptfs.c line 1841

Quoted 6 lines
net/xfrm/xfrm_iptfs.c new file +6 -0
+		consume_skb(skb);
+		skb = NULL;
+	}
+
+	count = 0;
+	qcount = 0;

nit: both of those get incremented through the main loop but never read

Removed.

Quoted 26 lines
Quoted 26 lines
net/xfrm/xfrm_iptfs.c new file +26 -0
+
+	/* We can be running on multiple cores and from the network softirq or
+	 * from user context depending on where the packet is coming from.
+	 */
+	spin_lock_bh(&x->lock);
+
+	skb_list_walk_safe(segs, skb, nskb) {
+		skb_mark_not_on_list(skb);
+		count++;
+
+		/* Once we drop due to no queue space we continue to drop the
+		 * rest of the packets from that GRO.
+		 */
+		if (!ok) {
+nospace:
+			trace_iptfs_no_queue_space(skb, xtfs, pmtu, was_gso);
+			XFRM_INC_STATS(dev_net(skb->dev), LINUX_MIB_XFRMOUTNOQSPACE);
+			kfree_skb_reason(skb, SKB_DROP_REASON_FULL_RING);
+			continue;
+		}
+
+		/* If the user indicated no iptfs fragmenting check before
+		 * enqueue.
+		 */
+		if (xtfs->cfg.dont_frag && iptfs_is_too_big(sk, skb, pmtu)) {
+			trace_iptfs_too_big(skb, xtfs, pmtu, was_gso);
Quoted 8 lines

net/xfrm/xfrm_iptfs.c line 1873

Quoted 6 lines
net/xfrm/xfrm_iptfs.c new file +6 -0
+			kfree_skb_reason(skb, SKB_DROP_REASON_PKT_TOO_BIG);
+			continue;
+		}
+
+		/* Enqueue to send in tunnel */
+

nit: unneeded blank line

A style choice, it's an important point in the code, and I was trying to call that out. I'll remove the newline though.

Quoted 15 lines

net/xfrm/xfrm_iptfs.c line 1885

Quoted 13 lines
net/xfrm/xfrm_iptfs.c new file +12 -0
+		ok = iptfs_enqueue(xtfs, skb);
+		if (!ok)
+			goto nospace;
+
+		trace_iptfs_enqueue(skb, xtfs, pmtu, was_gso);
+		qcount++;
+	}
+
+	/* Start a delay timer if we don't have one yet */
+	if (!hrtimer_is_queued(&xtfs->iptfs_timer)) {
+		/* softirq blocked lest the timer fire and interrupt us */
+		BUG_ON(!in_interrupt());

Why is that a fatal condition?

Removed this.

Quoted 18 lines
Quoted 12 lines
net/xfrm/xfrm_iptfs.c new file +11 -0
+		hrtimer_start(&xtfs->iptfs_timer, xtfs->init_delay_ns,
+			      IPTFS_HRTIMER_MODE);
+
+		xtfs->iptfs_settime = ktime_get_raw_fast_ns();
+		trace_iptfs_timer_start(xtfs, xtfs->init_delay_ns);
+	}
+
+	spin_unlock_bh(&x->lock);
+	return 0;
+}
+

[...]

Quoted 3 lines
net/xfrm/xfrm_iptfs.c new file +3 -0
+static int iptfs_copy_create_frags(struct sk_buff **skbp,
+				   struct xfrm_iptfs_data *xtfs, u32 mtu)
+{

[...]

Quoted 10 lines

net/xfrm/xfrm_iptfs.c line 2046

Quoted 7 lines
net/xfrm/xfrm_iptfs.c new file +7 -0
+	/* prepare the initial fragment with an iptfs header */
+	iptfs_output_prepare_skb(skb, 0);
+
+	/* Send all but last fragment. */
+	list_for_each_entry_safe(skb, nskb, &sublist, list) {
+		skb_list_del_init(skb);
+		xfrm_output(NULL, skb);

Should we stop if xfrm_output fails? Or is it still useful to send the rest of the iptfs frags if we lose one in the middle?

At the time it didn't seem worth handling this special case, but I've added freeing the rest now if an xfrm_output returns an error.

Quoted 26 lines
Quoted 5 lines
net/xfrm/xfrm_iptfs.c new file +5 -0
+	}
+
+	return 0;
+}
+

[...]

Quoted 19 lines
net/xfrm/xfrm_iptfs.c new file +19 -0
+static int iptfs_first_skb(struct sk_buff **skbp, struct xfrm_iptfs_data *xtfs,
+			   u32 mtu)
+{
+	struct sk_buff *skb = *skbp;
+	int err;
+
+	/* Classic ESP skips the don't fragment ICMP error if DF is clear on
+	 * the inner packet or ignore_df is set. Otherwise it will send an ICMP
+	 * or local error if the inner packet won't fit it's MTU.
+	 *
+	 * With IPTFS we do not care about the inner packet DF bit. If the
+	 * tunnel is configured to "don't fragment" we error back if things
+	 * don't fit in our max packet size. Otherwise we iptfs-fragment as
+	 * normal.
+	 */
+
+	/* The opportunity for HW offload has ended */
+	if (skb->ip_summed == CHECKSUM_PARTIAL) {
+		err = skb_checksum_help(skb);
Quoted 8 lines

net/xfrm/xfrm_iptfs.c line 2119

Quoted 6 lines
net/xfrm/xfrm_iptfs.c new file +6 -0
+		if (err)
+			return err;
+	}
+
+	/* We've split these up before queuing */
+	BUG_ON(skb_is_gso(skb));

Drop and DEBUG_NET_WARN_ON_ONCE?

Earlier comment on asserts applies here.

Quoted 6 lines
Quoted 6 lines
net/xfrm/xfrm_iptfs.c new file +6 -0
+
+	trace_iptfs_first_dequeue(skb, mtu, 0, ip_hdr(skb));
+
+	/* Simple case -- it fits. `mtu` accounted for all the overhead
+	 * including the basic IPTFS header.
+	 */
Quoted 8 lines

net/xfrm/xfrm_iptfs.c line 2131

Quoted 6 lines
net/xfrm/xfrm_iptfs.c new file +6 -0
+	if (skb->len <= mtu) {
+		iptfs_output_prepare_skb(skb, 0);
+		return 0;
+	}
+
+	BUG_ON(xtfs->cfg.dont_frag);

and here?

I'll just drop this one.

Quoted 5 lines

net/xfrm/xfrm_iptfs.c

Quoted 2 lines
net/xfrm/xfrm_iptfs.c new file +2 -0
+	if (iptfs_first_should_copy(skb, mtu))
+		return iptfs_copy_create_frags(skbp, xtfs, mtu);

Since we end up copying anyway, drop this (and iptfs_first_should_copy). You can introduce the optimization later on.

I was going to remove this, but I'd really like to leave it. It provides the start of the optimized code, as well as making it obvious to someone coming after me that there is something that can be (somewhat easily?) done here to finish it. So I see a real loss in removing this code, but I don't see any real gain in doing so.

Quoted 4 lines
Quoted 4 lines
net/xfrm/xfrm_iptfs.c new file +4 -0
+	/* For now we always copy */
+	return iptfs_copy_create_frags(skbp, xtfs, mtu);
+}
+
Quoted 8 lines

net/xfrm/xfrm_iptfs.c line 2145

Quoted 6 lines
net/xfrm/xfrm_iptfs.c new file +6 -0
+static struct sk_buff **iptfs_rehome_fraglist(struct sk_buff **nextp,
+					      struct sk_buff *child)
+{
+	u32 fllen = 0;
+
+	BUG_ON(!skb_has_frag_list(child));

Not needed, this was tested just before calling this function.

Removed.

Quoted 9 lines

net/xfrm/xfrm_iptfs.c line 2152

Quoted 7 lines
net/xfrm/xfrm_iptfs.c new file +7 -0
+
+	/* It might be possible to account for a frag list in addition to page
+	 * fragment if it's a valid state to be in. The page fragments size
+	 * should be kept as data_len so only the frag_list size is removed,
+	 * this must be done above as well took
+	 */
+	BUG_ON(skb_shinfo(child)->nr_frags);

Again not worth crashing the system?

The function does not handle this unexpected case, so this seems like a valid use of BUG_ON() even if one doesn't subscribe to the general assert philosophy I mentioned above. :)

Quoted 27 lines
Quoted 12 lines
net/xfrm/xfrm_iptfs.c new file +12 -0
+	*nextp = skb_shinfo(child)->frag_list;
+	while (*nextp) {
+		fllen += (*nextp)->len;
+		nextp = &(*nextp)->next;
+	}
+	skb_frag_list_init(child);
+	BUG_ON(fllen > child->data_len);
+	child->len -= fllen;
+	child->data_len -= fllen;
+
+	return nextp;
+}

[...]

Quoted 13 lines
net/xfrm/xfrm_iptfs.c new file +13 -0
+static void iptfs_output_queued(struct xfrm_state *x, struct sk_buff_head *list)
+{
+	struct xfrm_iptfs_data *xtfs = x->mode_data;
+	u32 payload_mtu = xtfs->payload_mtu;
+	struct sk_buff *skb, *skb2, **nextp;
+	struct skb_shared_info *shi, *shi2;
+
+	/* For now we are just outputting packets as fast as we can, so if we
+	 * are fragmenting we will do so until the last inner packet has been
+	 * consumed.
+	 *
+	 * When we are fragmenting we need to output all outer packets that
+	 * contain the fragments of a single inner packet, consecutively (ESP
Quoted 8 lines

net/xfrm/xfrm_iptfs.c line 2213

Quoted 6 lines
net/xfrm/xfrm_iptfs.c new file +6 -0
+	 * seq-wise). So we need a lock to keep another CPU from sending the
+	 * next batch of packets (it's `list`) and trying to output those, while
+	 * we output our `list` resuling with interleaved non-spec-client inner
+	 * packet streams. Thus we need to lock the IPTFS output on a per SA
+	 * basis while we process this list.
+	 */

This talks about a lock but I don't see one. What am I missing?

I will fix the comment as no (further) locking is required here. The reason is that iptfs_output_queued() is always being run from a timer (iptfs_delay_timer()) which will only be running on a single CPU at any given time.

Quoted 17 lines
Quoted 17 lines
net/xfrm/xfrm_iptfs.c new file +17 -0
+	/* NOTE: for the future, for timed packet sends, if our queue is not
+	 * growing longer (i.e., we are keeping up) and a packet we are about to
+	 * fragment will not fragment in then next outer packet, we might consider
+	 * holding on to it to send whole in the next slot. The question then is
+	 * does this introduce a continuous delay in the inner packet stream
+	 * with certain packet rates and sizes?
+	 */
+
+	/* and send them on their way */
+
+	while ((skb = __skb_dequeue(list))) {
+		struct xfrm_dst *xdst = (struct xfrm_dst *)skb_dst(skb);
+		u32 mtu = __iptfs_get_inner_mtu(x, xdst->child_mtu_cached);
+		bool share_ok = true;
+		int remaining;
+
+		/* protocol comes to us cleared sometimes */
Quoted 8 lines

net/xfrm/xfrm_iptfs.c line 2237

Quoted 6 lines
net/xfrm/xfrm_iptfs.c new file +6 -0
+		skb->protocol = x->outer_mode.family == AF_INET ?
+					htons(ETH_P_IP) :
+					htons(ETH_P_IPV6);
+
+		if (payload_mtu && payload_mtu < mtu)
+			mtu = payload_mtu;

Isn't that iptfs_get_cur_pmtu?

You're right; replaced the locals and conditional with iptfs_get_cur_pmtu instead.

Quoted 18 lines

[...]

Quoted 17 lines
net/xfrm/xfrm_iptfs.c new file +17 -0
+static enum hrtimer_restart iptfs_delay_timer(struct hrtimer *me)
+{
+	struct sk_buff_head list;
+	struct xfrm_iptfs_data *xtfs;
+	struct xfrm_state *x;
+	time64_t settime;
+	size_t osize;
+
+	xtfs = container_of(me, typeof(*xtfs), iptfs_timer);
+	x = xtfs->x;
+
+	/* Process all the queued packets
+	 *
+	 * softirq execution order: timer > tasklet > hrtimer
+	 *
+	 * Network rx will have run before us giving one last chance to queue
+	 * ingress packets for us to process and transmit.
Quoted 8 lines

net/xfrm/xfrm_iptfs.c line 2373

Quoted 6 lines
net/xfrm/xfrm_iptfs.c new file +6 -0
+	 */
+
+	spin_lock(&x->lock);
+	__skb_queue_head_init(&list);
+	skb_queue_splice_init(&xtfs->queue, &list);
+	osize = xtfs->queue_size;

Unused variable?

Removed.

Quoted 12 lines

[...]

net/xfrm/xfrm_iptfs.c line 2549

Quoted 8 lines
net/xfrm/xfrm_iptfs.c new file +8 -0
+static int iptfs_user_init(struct net *net, struct xfrm_state *x,
+			   struct nlattr **attrs)
+{
+	struct xfrm_iptfs_data *xtfs = x->mode_data;
+	struct xfrm_iptfs_config *xc;
+
+	if (x->props.mode != XFRM_MODE_IPTFS)
+		return -EINVAL;

Is that necessary? This only gets called via ->user_init for this mode.

It predated the callbacks. I've removed it.

Quoted 10 lines
Quoted 10 lines
net/xfrm/xfrm_iptfs.c new file +10 -0
+	xc = &xtfs->cfg;
+	xc->reorder_win_size = net->xfrm.sysctl_iptfs_rewin;
+	xc->max_queue_size = net->xfrm.sysctl_iptfs_maxqsize;
+	xc->init_delay_us = net->xfrm.sysctl_iptfs_idelay;
+	xc->drop_time_us = net->xfrm.sysctl_iptfs_drptime;
+
+	if (attrs[XFRMA_IPTFS_DONT_FRAG])
+		xc->dont_frag = true;
+	if (attrs[XFRMA_IPTFS_REORD_WIN])
+		xc->reorder_win_size =
Quoted 8 lines

net/xfrm/xfrm_iptfs.c line 2565

Quoted 5 lines
net/xfrm/xfrm_iptfs.c new file +5 -0
+			nla_get_u16(attrs[XFRMA_IPTFS_REORD_WIN]);
+	/* saved array is for saving 1..N seq nums from wantseq */
+	if (xc->reorder_win_size)
+		xtfs->w_saved = kcalloc(xc->reorder_win_size,
+					sizeof(*xtfs->w_saved), GFP_KERNEL);

We probably need a reasonable bound on reorder_win_size so that we don't try to allocate crazy amounts of memory here.

It's a u16 so there's a built in limit. :)

Quoted 7 lines

net/xfrm/xfrm_iptfs.c line 2569

Quoted 4 lines
net/xfrm/xfrm_iptfs.c new file +4 -0
+	if (attrs[XFRMA_IPTFS_PKT_SIZE]) {
+		xc->pkt_size = nla_get_u32(attrs[XFRMA_IPTFS_PKT_SIZE]);
+		if (!xc->pkt_size)
+			xtfs->payload_mtu = 0;

That's already set to 0 via kzalloc, right? So passing 0 as XFRMA_IPTFS_PKT_SIZE is equivalent to not providing it?

Not providing is supposed to mean don't change. You're right they are equivalent currently.

Quoted 6 lines

net/xfrm/xfrm_iptfs.c line 2573

Quoted 4 lines
net/xfrm/xfrm_iptfs.c new file +4 -0
+		else if (xc->pkt_size > x->props.header_len)
+			xtfs->payload_mtu = xc->pkt_size - x->props.header_len;
+		else
+			return -EINVAL;

This could probably use an extack to explain why the value was rejected.

OK, also added extack to the callback so to be able to do this.

Quoted 5 lines
Quoted 5 lines
net/xfrm/xfrm_iptfs.c new file +5 -0
+	}
+	if (attrs[XFRMA_IPTFS_MAX_QSIZE])
+		xc->max_queue_size = nla_get_u32(attrs[XFRMA_IPTFS_MAX_QSIZE]);
+	if (attrs[XFRMA_IPTFS_DROP_TIME])
+		xc->drop_time_us = nla_get_u32(attrs[XFRMA_IPTFS_DROP_TIME]);
Quoted 8 lines

net/xfrm/xfrm_iptfs.c line 2584

Quoted 6 lines
net/xfrm/xfrm_iptfs.c new file +6 -0
+	if (attrs[XFRMA_IPTFS_INIT_DELAY])
+		xc->init_delay_us = nla_get_u32(attrs[XFRMA_IPTFS_INIT_DELAY]);
+
+	xtfs->ecn_queue_size = (u64)xc->max_queue_size * 95 / 100;
+	xtfs->drop_time_ns = xc->drop_time_us * NSECS_IN_USEC;
+	xtfs->init_delay_ns = xc->init_delay_us * NSECS_IN_USEC;

Can't we get rid of the _us version? Why store both in kernel memory?

Removed the *_us copies from the config struct.

Quoted 8 lines

[...]

net/xfrm/xfrm_iptfs.c line 2652

Quoted 5 lines
net/xfrm/xfrm_iptfs.c new file +5 -0
+static void iptfs_delete_state(struct xfrm_state *x)
+{
+	struct xfrm_iptfs_data *xtfs = x->mode_data;
+
+	if (IS_ERR_OR_NULL(xtfs))

Can mode_data ever be an error pointer?

I don't believe so, changed to (!xtfs).

Quoted 35 lines
Quoted 35 lines
net/xfrm/xfrm_iptfs.c new file +35 -0
+		return;
+
+	spin_lock(&xtfs->drop_lock);
+	hrtimer_cancel(&xtfs->iptfs_timer);
+	hrtimer_cancel(&xtfs->drop_timer);
+	spin_unlock(&xtfs->drop_lock);
+
+	kfree_sensitive(xtfs->w_saved);
+	kfree_sensitive(xtfs);
+}
+
+static const struct xfrm_mode_cbs iptfs_mode_cbs = {
+	.owner = THIS_MODULE,
+	.create_state = iptfs_create_state,
+	.delete_state = iptfs_delete_state,
+	.user_init = iptfs_user_init,
+	.copy_to_user = iptfs_copy_to_user,
+	.get_inner_mtu = iptfs_get_inner_mtu,
+	.input = iptfs_input,
+	.output = iptfs_output_collect,
+	.prepare_output = iptfs_prepare_output,
+};
+
+static int __init xfrm_iptfs_init(void)
+{
+	int err;
+
+	pr_info("xfrm_iptfs: IPsec IP-TFS tunnel mode module\n");
+
+	err = xfrm_register_mode_cbs(XFRM_MODE_IPTFS, &iptfs_mode_cbs);
+	if (err < 0)
+		pr_info("%s: can't register IP-TFS\n", __func__);
+
+	return err;
+}
Quoted 8 lines

net/xfrm/xfrm_iptfs.c line 2692

Quoted 5 lines
net/xfrm/xfrm_iptfs.c new file +5 -0
+
+static void __exit xfrm_iptfs_fini(void)
+{
+	xfrm_unregister_mode_cbs(XFRM_MODE_IPTFS);
+}

If the module is unloaded, existing xfrm states will be left but silently broken?

You're right. I've added try_module_get()/module_put() calls in the create and delete state callbacks now.

All the changes noted above will be in the next published patch set.

Thanks for the thorough review!
Chris.

maintainer
#23 lore raw
In reply to Christian Hopps
Quoted 14 lines · Christian Hopps

From: Christian Hopps <[email protected]>

This patchset adds a new xfrm mode implementing on-demand IP-TFS. IP-TFS (AggFrag encapsulation) has been standardized in RFC9347.

This feature supports demand driven (i.e., non-constant send rate) IP-TFS to take advantage of the AGGFRAG ESP payload encapsulation. This payload type supports aggregation and fragmentation of the inner IP packet stream which in turn yields higher small-packet bandwidth as well as reducing MTU/PMTU issues. Congestion control is unimplementated as the send rate is demand driven rather than constant.

Quoted 2 lines

In order to allow loading this fucntionality as a module a set of callbacks xfrm_mode_cbs has been added to xfrm as well.

I did a multiple days peer review with Chris on this pachset. So my concerns are already addressed.

Further reviews are welcome! This is a bigger change and it would be nice if more people could look at it.

Thanks!

#24 lore raw
Quoted 5 lines

I did a multiple days peer review with Chris on this pachset. So my concerns are already addressed.

Further reviews are welcome! This is a bigger change and it would be nice if more people could look at it.

I have a usability question. What name should appear when a user interacts with and sees log messages from this feature?
ip-tfs, IP-TFS, IP_TFS
or:
iptfs, IPTFS, ...

#25 lore raw
Quoted 11 lines · Andrew Cagney
Quoted 5 lines

I did a multiple days peer review with Chris on this pachset. So my concerns are already addressed.

Further reviews are welcome! This is a bigger change and it would be nice if more people could look at it.

I have a usability question. What name should appear when a user interacts with and sees log messages from this feature?
ip-tfs, IP-TFS, IP_TFS
or:

   iptfs, IPTFS, ...

I think no - or _ in the code/api. For documentation it is probably better to hew closer to the RFC and use IP-TFS.

Thanks,
Chris.

#26 lore raw
Quoted 9 lines · Christian Hopps via Devel
Quoted 6 lines · Andrew Cagney
Quoted 5 lines

I did a multiple days peer review with Chris on this pachset. So my concerns are already addressed.

Further reviews are welcome! This is a bigger change and it would be nice if more people could look at it.

Quoted 7 lines
Quoted 5 lines

I have a usability question. What name should appear when a user interacts with and sees log messages from this feature?
ip-tfs, IP-TFS, IP_TFS
or:

   iptfs, IPTFS, ...

I think no - or _ in the code/api. For documentation it is probably better to hew closer to the RFC and use IP-TFS.

That sounds good. However,
iproute2 output, ip xfrm state, or "ip xfrm policy" is that documentation or code?

current unsubmitted patch shows: "iptfs"

src 192.1.2.23 dst 192.1.2.45

	proto esp spi 0x76ee6b87(1995336583) reqid 16389(0x00004005) mode iptfs

root@west:/testing/pluto/ikev2-74-iptfs-01 (iptfs-aa-20231120)# ip x p src 192.0.1.0/24 dst 192.0.2.0/24
dir out priority 1757393 ptype main
tmpl src 192.1.2.45 dst 192.1.2.23
proto esp reqid 16389 mode iptfs

-antony

#27 lore raw
Quoted 18 lines · Antony Antony
Quoted 9 lines · Christian Hopps via Devel
Quoted 6 lines · Andrew Cagney
Quoted 5 lines

I did a multiple days peer review with Chris on this pachset. So my concerns are already addressed.

Further reviews are welcome! This is a bigger change and it would be nice if more people could look at it.

Quoted 7 lines
Quoted 5 lines

I have a usability question. What name should appear when a user interacts with and sees log messages from this feature?
ip-tfs, IP-TFS, IP_TFS
or:

   iptfs, IPTFS, ...

I think no - or _ in the code/api. For documentation it is probably better to hew closer to the RFC and use IP-TFS.

Quoted 7 lines

That sounds good. However,
iproute2 output, ip xfrm state, or "ip xfrm policy" is that documentation or code?

current unsubmitted patch shows: "iptfs"

src 192.1.2.23 dst 192.1.2.45

	proto esp spi 0x76ee6b87(1995336583) reqid 16389(0x00004005) mode iptfs

there also the following line further down in ip x s

iptfs-opts pkt-size 0 max-queue-size 1048576 drop-time 1000000 reorder-window 3 init-delay 0

Quoted 8 lines

root@west:/testing/pluto/ikev2-74-iptfs-01 (iptfs-aa-20231120)# ip x p src 192.0.1.0/24 dst 192.0.2.0/24
dir out priority 1757393 ptype main
tmpl src 192.1.2.45 dst 192.1.2.23
proto esp reqid 16389 mode iptfs

-antony

#28 lore raw
In reply to Antony Antony
Quoted 16 lines · Antony Antony
Quoted 15 lines · Christian Hopps via Devel
Quoted 11 lines · Andrew Cagney
Quoted 5 lines

I did a multiple days peer review with Chris on this pachset. So my concerns are already addressed.

Further reviews are welcome! This is a bigger change and it would be nice if more people could look at it.

I have a usability question. What name should appear when a user interacts with and sees log messages from this feature?
ip-tfs, IP-TFS, IP_TFS
or:

   iptfs, IPTFS, ...
Quoted 6 lines
Quoted 1 line

I think no - or _ in the code/api. For documentation it is probably better to hew closer to the RFC and use IP-TFS.

That sounds good. However,
iproute2 output, ip xfrm state, or "ip xfrm policy" is that documentation or code?

current unsubmitted patch shows: "iptfs"

That's code/api. I was thinking ui/api when I said api.

Documentation would be something ending in a .rst or within a comment as that might be referring to the RFC too.

I will go through and make sure things are consistent in the next version.

Thanks,
Chris.

Quoted 11 lines

src 192.1.2.23 dst 192.1.2.45

	proto esp spi 0x76ee6b87(1995336583) reqid 16389(0x00004005) mode iptfs

root@west:/testing/pluto/ikev2-74-iptfs-01 (iptfs-aa-20231120)# ip x p src 192.0.1.0/24 dst 192.0.2.0/24
dir out priority 1757393 ptype main
tmpl src 192.1.2.45 dst 192.1.2.23
proto esp reqid 16389 mode iptfs

-antony

#29 lore raw
In reply to Steffen Klassert
Quoted 15 lines · Steffen Klassert via Devel
Quoted 14 lines · Christian Hopps

From: Christian Hopps <[email protected]>

This patchset adds a new xfrm mode implementing on-demand IP-TFS. IP-TFS (AggFrag encapsulation) has been standardized in RFC9347.

This feature supports demand driven (i.e., non-constant send rate) IP-TFS to take advantage of the AGGFRAG ESP payload encapsulation. This payload type supports aggregation and fragmentation of the inner IP packet stream which in turn yields higher small-packet bandwidth as well as reducing MTU/PMTU issues. Congestion control is unimplementated as the send rate is demand driven rather than constant.

Quoted 8 lines
Quoted 2 lines

In order to allow loading this fucntionality as a module a set of callbacks xfrm_mode_cbs has been added to xfrm as well.

I did a multiple days peer review with Chris on this pachset. So my concerns are already addressed.

Further reviews are welcome! This is a bigger change and it would be nice if more people could look at it.

I'd like to pose a basic question to understand the new IP-TFS config options for an SA.

When configuring IP-TFS parameters on an SA, are all parameters actively used by that SA? or does their usage vary based on the direction of the traffic?
Currently, each IP-TFS SA includes both init-delay and drop-time parameters. I would like to understand whether both parameters are necessary for every SA.

ip xfrm state

src 2001:db8:1:2::45 dst 2001:db8:1:2::23
proto esp spi 0x32af1f6d reqid 16389 mode iptfs
replay-window 0 flag af-unspec esn
aead rfc4106(gcm(aes)) 0x0... 128
anti-replay esn context:
seq-hi 0x0, seq 0x0, oseq-hi 0x0, oseq 0x0
replay_window 128, bitmap-length 4
00000000 00000000 00000000 00000000
iptfs-opts pkt-size 0 max-queue-size 1048576 drop-time 1000000 reorder-window 3 init-delay 0

Chris, would like to you share which of iptfs-opts are for input and which are for output?

My current understanding suggests that, depending on the traffic direction, onlysome of these parameters might be in active use for each SA. If this is indeed the case, I propose we discuss the possibility of refining our configuration approach. Could we consider making these parameters mutually exclusive and dependent on the traffic direction? Furthermore, given that the xfrm community has previously discussed the idea of adding direction to the SA — a concept also used in hardware offload scenarios — why not explore adding direction to the SA?

We currently have DIR with offload.

ip xfrm state { add | update } ... offload [ crypto|packet ] dev DEV dir DIR

Implementing direction could imply that an IP-TFS SA would require only fewer parameters
– init-delay or drop-time, depending on the specified direction. This would make ip x s output simple and comprehensible, thereby reducing potential confusion. Also avoid confusing when creating state say input, why add output parameters to an input SA?"

#30 lore raw
In reply to Christian Hopps
Quoted 14 lines · Christian Hopps via Devel

From: Christian Hopps <[email protected]>

This patchset adds a new xfrm mode implementing on-demand IP-TFS. IP-TFS (AggFrag encapsulation) has been standardized in RFC9347.

This feature supports demand driven (i.e., non-constant send rate) IP-TFS to take advantage of the AGGFRAG ESP payload encapsulation. This payload type supports aggregation and fragmentation of the inner IP packet stream which in turn yields higher small-packet bandwidth as well as reducing MTU/PMTU issues. Congestion control is unimplementated as the send rate is demand driven rather than constant.

Quoted 2 lines

In order to allow loading this fucntionality as a module a set of callbacks xfrm_mode_cbs has been added to xfrm as well.

Hi Chris,

I have further reviewed the code and have a few minor questions, mainly related to handling of XFRM_MODE_IPTFS. It appears to me be either some case missing support or/and in a few places it should be prohibited. I have three types of questions:

1. missing XFRM_MODE_IPTFS support?
2. Will XFRM_MODE_IPTFS be supported this combination?
3. Should be prohibited combination with XFRM_MODE_IPTFS

1. Missing:

a. wouldn't xfrm_sa_len() need extending?

I could not find support for XFRM_MODE_IPTFS explicitly.

However, I'm not sure how the following code is working when xfrm_sa_len is missing IP-TFS xfrm_sa_len:

copy_to_user_state_extra() {
    if (x->mode_cbs && x->mode_cbs->copy_to_user)
        ret = x->mode_cbs->copy_to_user(x, skb);
}

I have attached what I imagine is a fix. Check with Steffen or others if this is necessary.

b. esp6_init_state() and esp_init_state():
These functions do not seem to handle XFRM_MODE_IPTFS. Would they default to work with it?

2. Would xfrm4_outer_mode_gso_segment() xfrm6_outer_mode_gso_segment():
support XFRM_MODE_IPTFS?
These functions appear to be missing. Is it possible that you don't support GSO and GRO?

3: Shouldn't these combinations return error?

a. ipcomp and XFRM_MODE_IPTFS
I'm guessing that ipcomp would generate an error when userspace tries to add an SA with XFRM_MODE_IPTFS. ipcomp6_init_state()
ipcomp4_init_state()

b: In xfrm_state_construct():

if (attrs[XFRMA_TFCPAD])

    x->tfcpad = nla_get_u32(attrs[XFRMA_TFCPAD]);

-antony

From 3d9ad9fab35f4efd6c2fb17853aaca986e7daaf3 Mon Sep 17 00:00:00 2001
From: Antony Antony <[email protected]>
Date: Thu, 16 Nov 2023 16:46:54 +0100
Subject: [PATCH] xfrm: iptfs extend xfrm_sa_len

think this extension is necessary. I wonder how it works now:) May it is alreday handled:)

---
 include/net/xfrm.h    |  1 +
 net/xfrm/xfrm_iptfs.c | 18 ++++++++++++++++++
 net/xfrm/xfrm_user.c  |  3 +++
 3 files changed, 22 insertions(+)
include/net/xfrm.h +1 -0
index 176ab5ac436e..7ca508b0c46c 100644
@@ -474,6 +474,7 @@ struct xfrm_mode_cbs {
 	 *    mac_header should point at protocol/nexthdr of the outer IP
 	 */
 	int	(*prepare_output)(struct xfrm_state *x, struct sk_buff *skb);
+	unsigned int (*xfrm_sa_len)(const struct xfrm_state *x);
 };
 
 int xfrm_register_mode_cbs(u8 mode, const struct xfrm_mode_cbs *mode_cbs);
net/xfrm/xfrm_iptfs.c +18 -0
index 910c5e060931..d8b02cc3073b 100644
@@ -2613,6 +2613,23 @@ static int iptfs_copy_to_user(struct xfrm_state *x, struct sk_buff *skb)
 	return ret;
 }
 
+static unsigned int iptfs_xfrm_sa_len(const struct xfrm_state *x)
+{
+	struct xfrm_iptfs_data *xtfs = x->mode_data;
+        struct xfrm_iptfs_config *xc = &xtfs->cfg;
+	unsigned int l = 0;
+
+	if (xc->dont_frag)
+		l += nla_total_size(sizeof(xc->reorder_win_size));
+	l += nla_total_size(sizeof(xc->reorder_win_size));
+	l += nla_total_size(sizeof(xc->pkt_size));
+	l += nla_total_size(sizeof(xc->max_queue_size));
+	l += nla_total_size(sizeof(xc->drop_time_us));
+	l += nla_total_size(sizeof(xc->init_delay_us));
+
+	return l;
+}
+
 static int iptfs_create_state(struct xfrm_state *x)
 {
 	struct xfrm_iptfs_data *xtfs;
@@ -2701,6 +2718,7 @@ static const struct xfrm_mode_cbs iptfs_mode_cbs = {
 	.input = iptfs_input,
 	.output = iptfs_output_collect,
 	.prepare_output = iptfs_prepare_output,
+	.xfrm_sa_len = iptfs_xfrm_sa_len,
 };
 
 static int __init xfrm_iptfs_init(void)
net/xfrm/xfrm_user.c +3 -0
index 4b0e462d5e31..737636b2c267 100644
@@ -3350,6 +3350,9 @@ static inline unsigned int xfrm_sa_len(struct xfrm_state *x)
 	if (x->mapping_maxage)
 		l += nla_total_size(sizeof(x->mapping_maxage));
 
+	if (x->mode_cbs && x->mode_cbs->copy_to_user)
+                l += x->mode_cbs->xfrm_sa_len(x);
+
 	return l;
 }
 
Signature · 1 line
2.42.0
#31 lore raw
Quoted 38 lines · Antony Antony
Quoted 14 lines · Christian Hopps via Devel

From: Christian Hopps <[email protected]>

This patchset adds a new xfrm mode implementing on-demand IP-TFS. IP-TFS (AggFrag encapsulation) has been standardized in RFC9347.

This feature supports demand driven (i.e., non-constant send rate) IP-TFS to take advantage of the AGGFRAG ESP payload encapsulation. This payload type supports aggregation and fragmentation of the inner IP packet stream which in turn yields higher small-packet bandwidth as well as reducing MTU/PMTU issues. Congestion control is unimplementated as the send rate is demand driven rather than constant.

Quoted 2 lines

In order to allow loading this fucntionality as a module a set of callbacks xfrm_mode_cbs has been added to xfrm as well.

Hi Chris,

I have further reviewed the code and have a few minor questions, mainly related to handling of XFRM_MODE_IPTFS. It appears to me be either some case missing support or/and in a few places it should be prohibited. I have three types of questions:

1. missing XFRM_MODE_IPTFS support?
2. Will XFRM_MODE_IPTFS be supported this combination?
3. Should be prohibited combination with XFRM_MODE_IPTFS

1. Missing:

a. wouldn't xfrm_sa_len() need extending?

I could not find support for XFRM_MODE_IPTFS explicitly.

However, I'm not sure how the following code is working when xfrm_sa_len is missing IP-TFS xfrm_sa_len:

Quoted 7 lines
copy_to_user_state_extra() {
    if (x->mode_cbs && x->mode_cbs->copy_to_user)
        ret = x->mode_cbs->copy_to_user(x, skb);
}

I have attached what I imagine is a fix. Check with Steffen or others if this is necessary.

I have adopted this change with a couple small changes, thanks!

Quoted 2 lines

b. esp6_init_state() and esp_init_state():
These functions do not seem to handle XFRM_MODE_IPTFS. Would they default to work with it?

That's b/c IPTFS uses ESP w/o modification. IP-TFS makes its own mode based changes (similar to what esp_init_state() does) in it's create_state callback which like esp_init_state() is called from __xfrm_init_state().

Quoted 3 lines

2. Would xfrm4_outer_mode_gso_segment() xfrm6_outer_mode_gso_segment():
support XFRM_MODE_IPTFS?
These functions appear to be missing. Is it possible that you don't support GSO and GRO?

Correct.

Quoted 6 lines

3: Shouldn't these combinations return error?

a. ipcomp and XFRM_MODE_IPTFS
I'm guessing that ipcomp would generate an error when userspace tries to add an SA with XFRM_MODE_IPTFS. ipcomp6_init_state()
ipcomp4_init_state()

Correct.

Quoted 4 lines

b: In xfrm_state_construct():

if (attrs[XFRMA_TFCPAD])

    x->tfcpad = nla_get_u32(attrs[XFRMA_TFCPAD]);

Can you explain this more?

Thanks,
Chris.

Quoted 4 lines

-antony

[2. text/plain; 0001-xfrm-iptfs-extend-xfrm_sa_len.patch]...

#32 lore raw
Quoted 7 lines · Christian Hopps
Quoted 3 lines · Antony Antony
Quoted 2 lines · Christian Hopps via Devel

From: Christian Hopps <[email protected]>

Quoted 6 lines
Quoted 4 lines

b: In xfrm_state_construct():

if (attrs[XFRMA_TFCPAD])

    x->tfcpad = nla_get_u32(attrs[XFRMA_TFCPAD]);

Can you explain this more?

I haven't used it. I just know it from *swan code. And I wondered how it would work with IP-TFS. Looking in the kernel code, I noticed, it is not allowed in xfrm_user.c

270 if (attrs[XFRMA_TFCPAD] &&
271 p->mode != XFRM_MODE_TUNNEL) {
272 NL_SET_ERR_MSG(extack, "TFC padding can only be used in tunnel mode");
273 goto out;
274 }

#33 lore raw
In reply to Christian Hopps

Hi Chris,

I got a crash when running inside a namespace using veth. I got twice. It is not 100% reproducable.

Note: I have KASAN enabled.

[  226.323824] BUG: KASAN: null-ptr-deref in 
iptfs_output_collect+0x1f5/0x61a
[  226.325155] Read of size 8 at addr 0000000000000478 by task ping/5276
[  226.325980]
[  226.326220] CPU: 2 PID: 5276 Comm: ping Not tainted 6.6.0-rc1-00528-gadd9146753b7 #95
[  226.327219] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
[  226.328396] Call Trace:
[  226.328791]  <TASK>
[  226.329099]  dump_stack_lvl+0x33/0x42
[  226.329597]  kasan_report+0xa0/0xc3
[  226.330074]  ? iptfs_output_collect+0x1f5/0x61a
[  226.330678]  iptfs_output_collect+0x1f5/0x61a
[  226.331259]  ip_send_skb+0x25/0x58
[  226.331724]  raw_sendmsg+0xec4/0xfee
[  226.332223]  ? raw_hash_sk+0x224/0x224
[  226.332741]  ? kasan_unpoison+0x44/0x52
[  226.333258]  ? kernel_init_pages+0x42/0x51
[  226.333810]  ? post_alloc_hook+0xba/0xe0
[  226.334339]  ? prep_new_page+0x44/0x51
[  226.334849]  ? ma_data_end+0x6e/0x88
[  226.335338]  ? preempt_count_sub+0x14/0xb5
[  226.335894]  ? zone_watermark_fast.isra.0+0x12b/0x12b
[  226.336577]  ? __might_resched+0x8d/0x248
[  226.337116]  ? __might_sleep+0x27/0xa2
[  226.337626]  ? first_zones_zonelist+0x2c/0x43
[  226.338211]  ? do_raw_spin_lock+0x72/0xbb
[  226.338752]  ? __might_resched+0x8d/0x248
[  226.339291]  ? __might_sleep+0x27/0xa2
[  226.339801]  ? inet_send_prepare+0x59/0x59
[  226.340356]  ? sock_sendmsg_nosec+0x42/0x6c
[  226.340924]  sock_sendmsg_nosec+0x42/0x6c
[  226.341465]  __sys_sendto+0x172/0x1e1
[  226.341964]  ? __x64_sys_getpeername+0x44/0x44
[  226.342558]  ? folio_batch_add_and_move+0x6a/0x7d
[  226.343189]  ? find_vma+0x6b/0x8b
[  226.343646]  ? find_vma_intersection+0x8a/0x8a
[  226.344246]  ? handle_mm_fault+0xfa/0x163
[  226.344788]  ? preempt_latency_start+0x41/0x4c
[  226.345385]  ? preempt_count_sub+0x14/0xb5
[  226.345937]  __x64_sys_sendto+0x76/0x82
[  226.346456]  do_syscall_64+0x58/0x78
[  226.346946]  entry_SYSCALL_64_after_hwframe+0x46/0xb0
[  226.347611] RIP: 0033:0x7f378b00ba73
[  226.348095] Code: 8b 15 a9 83 0c 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b8 0f 1f 00 80 3d 71 0b 0d 00 00 41 89 ca 74 14 b8 2c 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 75 c3 0f 1f 40 00 55 48 83 ec 30 44 89 4c 24
[  226.350433] RSP: 002b:00007fff58f9c148 EFLAGS: 00000202 ORIG_RAX: 000000000000002c
[  226.351400] RAX: ffffffffffffffda RBX: 00005591b05fa340 RCX: 00007f378b00ba73
[  226.352318] RDX: 0000000000000040 RSI: 00005591b06003c0 RDI: 0000000000000003
[  226.353233] RBP: 00005591b06003c0 R08: 00005591b05fc5c0 R09: 0000000000000010
[  226.354147] R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000040
[  226.355061] R13: 00007fff58f9d830 R14: 0000001d00000001 R15: 00005591b05fd680
[  226.355978]  </TASK>
[  226.356301] ==================================================================
[  226.357274] Disabling lock debugging due to kernel taint
[  226.357973] BUG: kernel NULL pointer dereference, address: 0000000000000478
[  226.358865] #PF: supervisor read access in kernel mode
[  226.359540] #PF: error_code(0x0000) - not-present page
[  226.360220] PGD 0 P4D 0
[  226.360594] Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC KASAN
[  226.361346] CPU: 2 PID: 5276 Comm: ping Tainted: G    B              6.6.0-rc1-00528-gadd9146753b7 #95
[  226.362520] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
[  226.363693] RIP: 0010:iptfs_output_collect+0x1f5/0x61a
[  226.364376] Code: c1 ff ff 65 ff 0d 12 29 35 7e 75 05 e8 c3 f0 31 ff 48 8d 7b 10 e8 4b 16 6b ff 4c 8b 73 10 49 8d be 78 04 00 00 e8 3b 16 6b ff <4d> 8b b6 78 04 00 00 49 8d be c0 01 00 00 e8 28 16 6b ff 49 8b 86
[  226.366704] RSP: 0018:ffffc9000a357998 EFLAGS: 00010296
[  226.367389] RAX: 0000000000000001 RBX: ffff8881123a7a00 RCX: fffffbfff075e9f5
[  226.368308] RDX: fffffbfff075e9f5 RSI: fffffbfff075e9f5 RDI: ffffffff83af4fa0
[  226.369237] RBP: ffff88810f45ac00 R08: 0000000000000008 R09: 0000000000000001
[  226.370154] R10: ffffffff83af4fa7 R11: fffffbfff075e9f4 R12: 0000000000000000
[  226.371070] R13: 0000000000000000 R14: 0000000000000000 R15: ffff888114cbeb01
[  226.371984] FS:  00007f378ad4fc40(0000) GS:ffff88815ad00000(0000) knlGS:0000000000000000
[  226.373029] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  226.373777] CR2: 0000000000000478 CR3: 00000001083e9000 CR4: 0000000000350ee0
[  226.374693] Call Trace:
[  226.375042]  <TASK>
[  226.375352]  ? __die_body+0x1a/0x58
[  226.375828]  ? page_fault_oops+0x459/0x4c7
[  226.376387]  ? irq_work_queue+0x2c/0x41
[  226.376915]  ? dump_pagetable+0x1db/0x1db
[  226.377453]  ? vprintk_emit+0x187/0x195
[  226.377972]  ? iptfs_output_collect+0x1f5/0x61a
[  226.378576]  ? _printk+0xb2/0xe1
[  226.379021]  ? syslog_print+0x340/0x340
[  226.379541]  ? do_user_addr_fault+0x156/0x59f
[  226.380713]  ? exc_page_fault+0xaa/0xc3
[  226.381234]  ? asm_exc_page_fault+0x22/0x30
[  226.381795]  ? iptfs_output_collect+0x1f5/0x61a
[  226.382399]  ? iptfs_output_collect+0x1f5/0x61a
[  226.383002]  ip_send_skb+0x25/0x58
[  226.383469]  raw_sendmsg+0xec4/0xfee
[  226.383958]  ? raw_hash_sk+0x224/0x224
[  226.385083]  ? kasan_unpoison+0x44/0x52
[  226.385866]  ? kernel_init_pages+0x42/0x51
[  226.386687]  ? post_alloc_hook+0xba/0xe0
[  226.387559]  ? prep_new_page+0x44/0x51
[  226.388522]  ? ma_data_end+0x6e/0x88
[  226.389365]  ? preempt_count_sub+0x14/0xb5
[  226.390575]  ? zone_watermark_fast.isra.0+0x12b/0x12b
[  226.391555]  ? __might_resched+0x8d/0x248
[  226.392127]  ? __might_sleep+0x27/0xa2
[  226.392794]  ? first_zones_zonelist+0x2c/0x43
[  226.393684]  ? do_raw_spin_lock+0x72/0xbb
[  226.394501]  ? __might_resched+0x8d/0x248
[  226.395324]  ? __might_sleep+0x27/0xa2
[  226.396204]  ? inet_send_prepare+0x59/0x59
[  226.397042]  ? sock_sendmsg_nosec+0x42/0x6c
[  226.397879]  sock_sendmsg_nosec+0x42/0x6c
[  226.398704]  __sys_sendto+0x172/0x1e1
[  226.399465]  ? __x64_sys_getpeername+0x44/0x44
[  226.400367]  ? folio_batch_add_and_move+0x6a/0x7d
[  226.401327]  ? find_vma+0x6b/0x8b
[  226.401812]  ? find_vma_intersection+0x8a/0x8a
[  226.402442]  ? handle_mm_fault+0xfa/0x163
[  226.403014]  ? preempt_latency_start+0x41/0x4c
[  226.403641]  ? preempt_count_sub+0x14/0xb5
[  226.404224]  __x64_sys_sendto+0x76/0x82
[  226.404790]  do_syscall_64+0x58/0x78
[  226.405306]  entry_SYSCALL_64_after_hwframe+0x46/0xb0
[  226.406010] RIP: 0033:0x7f378b00ba73
[  226.406524] Code: 8b 15 a9 83 0c 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b8 0f 1f 00 80 3d 71 0b 0d 00 00 41 89 ca 74 14 b8 2c 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 75 c3 0f 1f 40 00 55 48 83 ec 30 44 89 4c 24
[  226.408990] RSP: 002b:00007fff58f9c148 EFLAGS: 00000202 ORIG_RAX: 000000000000002c
[  226.410020] RAX: ffffffffffffffda RBX: 00005591b05fa340 RCX: 00007f378b00ba73
[  226.410992] RDX: 0000000000000040 RSI: 00005591b06003c0 RDI: 0000000000000003
[  226.411968] RBP: 00005591b06003c0 R08: 00005591b05fc5c0 R09: 0000000000000010
[  226.412948] R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000040
[  226.413923] R13: 00007fff58f9d830 R14: 0000001d00000001 R15: 00005591b05fd680
[  226.414904]  </TASK>
[  226.415243] Modules linked in:
[  226.415697] CR2: 0000000000000478
[  226.416181] ---[ end trace 0000000000000000 ]---
[  226.416848] RIP: 0010:iptfs_output_collect+0x1f5/0x61a
[  226.417569] Code: c1 ff ff 65 ff 0d 12 29 35 7e 75 05 e8 c3 f0 31 ff 48 8d 7b 10 e8 4b 16 6b ff 4c 8b 73 10 49 8d be 78 04 00 00 e8 3b 16 6b ff <4d> 8b b6 78 04 00 00 49 8d be c0 01 00 00 e8 28 16 6b ff 49 8b 86
[  226.420031] RSP: 0018:ffffc9000a357998 EFLAGS: 00010296
[  226.420764] RAX: 0000000000000001 RBX: ffff8881123a7a00 RCX: fffffbfff075e9f5
[  226.421733] RDX: fffffbfff075e9f5 RSI: fffffbfff075e9f5 RDI: ffffffff83af4fa0
[  226.422704] RBP: ffff88810f45ac00 R08: 0000000000000008 R09: 0000000000000001
[  226.423671] R10: ffffffff83af4fa7 R11: fffffbfff075e9f4 R12: 0000000000000000
[  226.424646] R13: 0000000000000000 R14: 0000000000000000 R15: ffff888114cbeb01
[  226.425616] FS:  00007f378ad4fc40(0000) GS:ffff88815ad00000(0000) knlGS:0000000000000000
[  226.426709] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  226.427501] CR2: 0000000000000478 CR3: 00000001083e9000 CR4: 0000000000350ee0
[  226.428492] Kernel panic - not syncing: Fatal exception in interrupt
[  226.429587] Kernel Offset: disabled
[  226.430096] ---[ end Kernel panic - not syncing: Fatal exception in interrupt ]---

(gdb) list *iptfs_output_collect+0x1f5
0xffffffff81ce40d6 is in iptfs_output_collect (./include/net/net_namespace.h:385).
380 }
381
382 static inline struct net *read_pnet(const possible_net_t *pnet)
383 {
384 #ifdef CONFIG_NET_NS
385 return pnet->net;
386 #else
387 return &init_net;
388 #endif
389 }

Quoted 20 lines · Christian Hopps via Devel

From: Christian Hopps <[email protected]>

This patchset adds a new xfrm mode implementing on-demand IP-TFS. IP-TFS (AggFrag encapsulation) has been standardized in RFC9347.

This feature supports demand driven (i.e., non-constant send rate) IP-TFS to take advantage of the AGGFRAG ESP payload encapsulation. This payload type supports aggregation and fragmentation of the inner IP packet stream which in turn yields higher small-packet bandwidth as well as reducing MTU/PMTU issues. Congestion control is unimplementated as the send rate is demand driven rather than constant.

In order to allow loading this fucntionality as a module a set of callbacks xfrm_mode_cbs has been added to xfrm as well.

Signature · 3 lines
Devel mailing list
[email protected]
https://linux-ipsec.org/mailman/listinfo/devel