Skip to content

Commit fa45352

Browse files
Huy NguyenSaeed Mahameed
authored andcommitted
net/xfrm: Add inner_ipproto into sec_path
The inner_ipproto saves the inner IP protocol of the plain text packet. This allows vendor's IPsec feature making offload decision at skb's features_check and configuring hardware at ndo_start_xmit. For example, ConnectX6-DX IPsec device needs the plaintext's IP protocol to support partial checksum offload on VXLAN/GENEVE packet over IPsec transport mode tunnel. Signed-off-by: Raed Salem <[email protected]> Signed-off-by: Huy Nguyen <[email protected]> Cc: Steffen Klassert <[email protected]> Acked-by: Steffen Klassert <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent dd7cf00 commit fa45352

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

include/net/xfrm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ struct xfrm_offload {
10241024
#define CRYPTO_INVALID_PROTOCOL 128
10251025

10261026
__u8 proto;
1027+
__u8 inner_ipproto;
10271028
};
10281029

10291030
struct sec_path {

net/xfrm/xfrm_output.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,42 @@ static int xfrm_output_gso(struct net *net, struct sock *sk, struct sk_buff *skb
565565
return 0;
566566
}
567567

568+
/* For partial checksum offload, the outer header checksum is calculated
569+
* by software and the inner header checksum is calculated by hardware.
570+
* This requires hardware to know the inner packet type to calculate
571+
* the inner header checksum. Save inner ip protocol here to avoid
572+
* traversing the packet in the vendor's xmit code.
573+
* If the encap type is IPIP, just save skb->inner_ipproto. Otherwise,
574+
* get the ip protocol from the IP header.
575+
*/
576+
static void xfrm_get_inner_ipproto(struct sk_buff *skb)
577+
{
578+
struct xfrm_offload *xo = xfrm_offload(skb);
579+
const struct ethhdr *eth;
580+
581+
if (!xo)
582+
return;
583+
584+
if (skb->inner_protocol_type == ENCAP_TYPE_IPPROTO) {
585+
xo->inner_ipproto = skb->inner_ipproto;
586+
return;
587+
}
588+
589+
if (skb->inner_protocol_type != ENCAP_TYPE_ETHER)
590+
return;
591+
592+
eth = (struct ethhdr *)skb_inner_mac_header(skb);
593+
594+
switch (ntohs(eth->h_proto)) {
595+
case ETH_P_IPV6:
596+
xo->inner_ipproto = inner_ipv6_hdr(skb)->nexthdr;
597+
break;
598+
case ETH_P_IP:
599+
xo->inner_ipproto = inner_ip_hdr(skb)->protocol;
600+
break;
601+
}
602+
}
603+
568604
int xfrm_output(struct sock *sk, struct sk_buff *skb)
569605
{
570606
struct net *net = dev_net(skb_dst(skb)->dev);
@@ -594,12 +630,15 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
594630
kfree_skb(skb);
595631
return -ENOMEM;
596632
}
597-
skb->encapsulation = 1;
598633

599634
sp->olen++;
600635
sp->xvec[sp->len++] = x;
601636
xfrm_state_hold(x);
602637

638+
if (skb->encapsulation)
639+
xfrm_get_inner_ipproto(skb);
640+
skb->encapsulation = 1;
641+
603642
if (skb_is_gso(skb)) {
604643
if (skb->inner_protocol)
605644
return xfrm_output_gso(net, sk, skb);

0 commit comments

Comments
 (0)