Skip to content

Commit e7cd191

Browse files
wangfeklassert
authored andcommitted
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 <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 5ce90c8 commit e7cd191

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

net/xfrm/xfrm_output.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,8 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
706706
struct xfrm_state *x = skb_dst(skb)->xfrm;
707707
int family;
708708
int err;
709+
struct xfrm_offload *xo;
710+
struct sec_path *sp;
709711

710712
family = (x->xso.type != XFRM_DEV_OFFLOAD_PACKET) ? x->outer_mode.family
711713
: skb_dst(skb)->ops->family;
@@ -728,6 +730,25 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
728730
kfree_skb(skb);
729731
return -EHOSTUNREACH;
730732
}
733+
sp = secpath_set(skb);
734+
if (!sp) {
735+
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
736+
kfree_skb(skb);
737+
return -ENOMEM;
738+
}
739+
740+
sp->olen++;
741+
sp->xvec[sp->len++] = x;
742+
xfrm_state_hold(x);
743+
744+
xo = xfrm_offload(skb);
745+
if (!xo) {
746+
secpath_reset(skb);
747+
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
748+
kfree_skb(skb);
749+
return -EINVAL;
750+
}
751+
xo->flags |= XFRM_XMIT;
731752

732753
return xfrm_output_resume(sk, skb, 0);
733754
}

0 commit comments

Comments
 (0)