Improve packet offload for dual stack
Subsystems (3)
cover Improve packet offload for dual stack
In the XFRM stack, whether a packet is forwarded to the IPv4 or IPv6 stack depends on the family field of the matched SA. This does not completely work for IPsec packet offload in some scenario, for example, sending an IPv6 packet that will be encrypted and encapsulated as an IPv4 packet in HW.
Here are the patches to make IPsec packet offload work on the mentioned scenario.
Mike Yu (2):
xfrm: fix xfrm child route lookup for packet offload
xfrm: set skb control buffer based on packet offload as well
net/xfrm/xfrm_output.c | 6 +++++- net/xfrm/xfrm_policy.c | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-)
Signature · 1 line
2.44.0.rc1.240.g4c46232300-goog
PATCH 1/2 xfrm: fix xfrm child route lookup for packet offload
In current code, xfrm_bundle_create() always uses the matched SA's family type to look up a xfrm child route for the skb. The route returned by xfrm_dst_lookup() will eventually be used in xfrm_output_resume() (skb_dst(skb)->ops->local_out()).
If packet offload is used, the above behavior can lead to calling ip_local_out() for an IPv6 packet or calling ip6_local_out() for an IPv4 packet, which is likely to fail.
This change fixes the behavior by checking if the matched SA has packet offload enabled. If not, keep the same behavior; if yes, use the matched SP's family type for the lookup.
Test: verified IPv6-in-IPv4 packets on Android device with
IPsec packet offload enabled
--- net/xfrm/xfrm_policy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/xfrm/xfrm_policy.c +3 -1
@@ -2695,7 +2695,9 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,if (xfrm[i]->props.smark.v || xfrm[i]->props.smark.m) mark =xfrm_smark_get (fl->flowi_mark, xfrm[i]); - family = xfrm[i]->props.family; +if (xfrm[i]->xso.type !=XFRM_DEV_OFFLOAD_PACKET ) + family = xfrm[i]->props.family; + oif = fl->flowi_oif ? : fl->flowi_l3mdev; dst =xfrm_dst_lookup (xfrm[i], tos, oif, &saddr, &daddr, family, mark);
Signature · 1 line
2.44.0.rc1.240.g4c46232300-goog
PATCH 2/2 xfrm: set skb control buffer based on packet offload as well
In reply to Mike YuIn packet offload, packets are not encrypted in XFRM stack, so the next network layer which the packets will be forwarded to should depend on where the packet came from (either xfrm4_output or xfrm6_output) rather than the matched SA's family type.
Test: verified IPv6-in-IPv4 packets on Android device with
IPsec packet offload enabled
--- net/xfrm/xfrm_output.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/xfrm/xfrm_output.c +5 -1
@@ -704,9 +704,13 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb) {struct net *net =dev_net (skb_dst (skb)->dev);struct xfrm_state *x =skb_dst (skb)->xfrm; +int family;int err; -switch (x->outer_mode.family) { + family = (x->xso.type !=XFRM_DEV_OFFLOAD_PACKET ) ? x->outer_mode.family + :skb_dst (skb)->ops->family; + +switch (family) {case AF_INET :memset (IPCB (skb),0 ,sizeof (*IPCB (skb)));IPCB (skb)->flags |=IPSKB_XFRM_TRANSFORMED ;
Signature · 1 line
2.44.0.rc1.240.g4c46232300-goog
Quoted 6 lines · Mike Yu
In the XFRM stack, whether a packet is forwarded to the IPv4 or IPv6 stack depends on the family field of the matched SA. This does not completely work for IPsec packet offload in some scenario, for example, sending an IPv6 packet that will be encrypted and encapsulated as an IPv4 packet in HW.
Quoted 6 lines
Here are the patches to make IPsec packet offload work on the mentioned scenario.
Mike Yu (2):
xfrm: fix xfrm child route lookup for packet offload
xfrm: set skb control buffer based on packet offload as well
Applied, thanks a lot!