summaryrefslogtreecommitdiffstats
path: root/net/xfrm
diff options
context:
space:
mode:
authorwangfe <wangfe@google.com>2024-08-22 13:02:52 -0700
committerSteffen Klassert <steffen.klassert@secunet.com>2024-08-27 11:28:58 +0200
commite7cd191f83fd899c233dfbe7dc6d96ef703dcbbd (patch)
treeb07284964902eb6ef491c970989ff52c59a17bf4 /net/xfrm
parent5ce90c842ef57bceb515503347306174e231575f (diff)
downloadlinux-stable-e7cd191f83fd899c233dfbe7dc6d96ef703dcbbd.tar.gz
linux-stable-e7cd191f83fd899c233dfbe7dc6d96ef703dcbbd.tar.bz2
linux-stable-e7cd191f83fd899c233dfbe7dc6d96ef703dcbbd.zip
xfrm: add SA information to the offloaded packet
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. This SA info helps HW offload match packets to their correct security policies. The XFRM interface ID is included, which is crucial in setups with multiple XFRM interfaces where source/destination addresses alone can't pinpoint the right policy. Signed-off-by: wangfe <wangfe@google.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Diffstat (limited to 'net/xfrm')
-rw-r--r--net/xfrm/xfrm_output.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
index e5722c95b8bb..a12588e7b060 100644
--- a/net/xfrm/xfrm_output.c
+++ b/net/xfrm/xfrm_output.c
@@ -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);
}