Skip to contentSkip to conversation

xfrm: add SA information to the offloaded packet

PATCH In review Feng Wang 2 participants 3 messages Aug 12, 2024 – Aug 22, 2024

Subsystems (3)
lore
Share & tools
lore

Feng Wang

author
#0 lore raw

PATCH 1/1 xfrm: add SA information to the offloaded packet

From: wangfe <[email protected]>

In packet offload mode, append Security Association (SA) information to each packet, replicating the crypto offload implementation. The XFRM_XMIT flag is set to enable packet to be returned immediately from the validate_xmit_xfrm function, thus aligning with the existing code path for packet offload mode.

---
 net/xfrm/xfrm_output.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
net/xfrm/xfrm_output.c +21 -0
index e5722c95b8bb..a12588e7b060 100644
@@ -706,6 +706,8 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
 	struct xfrm_state *x = skb_dst(skb)->xfrm;
 	int family;
 	int err;
+	struct xfrm_offload *xo;
+	struct sec_path *sp;
 
 	family = (x->xso.type != XFRM_DEV_OFFLOAD_PACKET) ? x->outer_mode.family
 		: skb_dst(skb)->ops->family;
@@ -728,6 +730,25 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
 			kfree_skb(skb);
 			return -EHOSTUNREACH;
 		}
+		sp = secpath_set(skb);
+		if (!sp) {
+			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
+			kfree_skb(skb);
+			return -ENOMEM;
+		}
+
+		sp->olen++;
+		sp->xvec[sp->len++] = x;
+		xfrm_state_hold(x);
+
+		xo = xfrm_offload(skb);
+		if (!xo) {
+			secpath_reset(skb);
+			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
+			kfree_skb(skb);
+			return -EINVAL;
+		}
+		xo->flags |= XFRM_XMIT;
 
 		return xfrm_output_resume(sk, skb, 0);
 	}
Signature · 1 line
2.46.0.rc2.264.g509ed76dc8-goog
maintainer
#1 lore raw
Quoted 7 lines · Feng Wang

From: wangfe <[email protected]>

In packet offload mode, append Security Association (SA) information to each packet, replicating the crypto offload implementation. The XFRM_XMIT flag is set to enable packet to be returned immediately from the validate_xmit_xfrm function, thus aligning with the existing code path for packet offload mode.

Please explain in the commit message _why_ we need that change.

Thanks!

author
#2 lore raw

Hi Steffen,

I have added the reason why SA info is needed in the commit message. The new patch is
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

Thanks for your review.

Feng

Quoted 13 lines · Steffen Klassert
Quoted 7 lines · Feng Wang

From: wangfe <[email protected]>

In packet offload mode, append Security Association (SA) information to each packet, replicating the crypto offload implementation. The XFRM_XMIT flag is set to enable packet to be returned immediately from the validate_xmit_xfrm function, thus aligning with the existing code path for packet offload mode.

Please explain in the commit message _why_ we need that change.

Thanks!