xfrm: Add encapsulation header offsets while SKB is not encrypted
authorIlan Tayari <ilant@mellanox.com>
Fri, 14 Apr 2017 08:07:39 +0000 (10:07 +0200)
committerSteffen Klassert <steffen.klassert@secunet.com>
Fri, 14 Apr 2017 08:07:39 +0000 (10:07 +0200)
Both esp4 and esp6 used to assume that the SKB payload is encrypted
and therefore the inner_network and inner_transport offsets are
not relevant.
When doing crypto offload in the NIC, this is no longer the case
and the NIC driver needs these offsets so it can do TX TCP checksum
offloading.
This patch sets the inner_network and inner_transport members of
the SKB, as well as encapsulation, to reflect the actual positions
of these headers, and removes them only once encryption is done
on the payload.

Signed-off-by: Ilan Tayari <ilant@mellanox.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/ipv4/xfrm4_mode_transport.c
net/ipv4/xfrm4_mode_tunnel.c
net/ipv6/xfrm6_mode_transport.c
net/ipv6/xfrm6_mode_tunnel.c
net/xfrm/xfrm_output.c

index 6c2411d0938631d7391b0774fd79aebe30f497da..3d36644890bb6d3b0a755c811c60e920ad5cd8b8 100644 (file)
@@ -24,6 +24,8 @@ static int xfrm4_transport_output(struct xfrm_state *x, struct sk_buff *skb)
        struct iphdr *iph = ip_hdr(skb);
        int ihl = iph->ihl * 4;
 
+       skb_set_inner_transport_header(skb, skb_transport_offset(skb));
+
        skb_set_network_header(skb, -x->props.header_len);
        skb->mac_header = skb->network_header +
                          offsetof(struct iphdr, protocol);
index d3f2434fa0b862ab13a3581c46cfd64f725b0333..e6265e2c274e48a54cfc08afb9fee6c9fc2ad194 100644 (file)
@@ -33,6 +33,9 @@ static int xfrm4_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
        struct iphdr *top_iph;
        int flags;
 
+       skb_set_inner_network_header(skb, skb_network_offset(skb));
+       skb_set_inner_transport_header(skb, skb_transport_offset(skb));
+
        skb_set_network_header(skb, -x->props.header_len);
        skb->mac_header = skb->network_header +
                          offsetof(struct iphdr, protocol);
index eb9b36b06c1dfcf97cf1c35967d1c4c2fa8f4c90..7a92c0f3191250118ce3572ca91ee9116460bce8 100644 (file)
@@ -27,6 +27,7 @@ static int xfrm6_transport_output(struct xfrm_state *x, struct sk_buff *skb)
        int hdr_len;
 
        iph = ipv6_hdr(skb);
+       skb_set_inner_transport_header(skb, skb_transport_offset(skb));
 
        hdr_len = x->type->hdr_offset(x, skb, &prevhdr);
        skb_set_mac_header(skb, (prevhdr - x->props.header_len) - skb->data);
index 19a60fc4c29b0021d0fd675dd60074bf917640b6..02556e356f87e94830e76bb6f4f519e4cf1eb4d7 100644 (file)
@@ -36,6 +36,9 @@ static int xfrm6_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
        struct ipv6hdr *top_iph;
        int dsfield;
 
+       skb_set_inner_network_header(skb, skb_network_offset(skb));
+       skb_set_inner_transport_header(skb, skb_transport_offset(skb));
+
        skb_set_network_header(skb, -x->props.header_len);
        skb->mac_header = skb->network_header +
                          offsetof(struct ipv6hdr, nexthdr);
index a15088613a6c1667f8c8b2e9d9ee17122dc36d15..8c0b6722aaa87c6d346d0ba57c2e541a6703c79d 100644 (file)
@@ -205,6 +205,7 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
        int err;
 
        secpath_reset(skb);
+       skb->encapsulation = 0;
 
        if (xfrm_dev_offload_ok(skb, x)) {
                struct sec_path *sp;
@@ -218,6 +219,7 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
                if (skb->sp)
                        secpath_put(skb->sp);
                skb->sp = sp;
+               skb->encapsulation = 1;
 
                sp->olen++;
                sp->xvec[skb->sp->len++] = x;