Commit f1bd7d65 authored by Ilan Tayari's avatar Ilan Tayari Committed by Steffen Klassert

xfrm: Add encapsulation header offsets while SKB is not encrypted

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: default avatarIlan Tayari <ilant@mellanox.com>
Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
parent f6e27114
...@@ -24,6 +24,8 @@ static int xfrm4_transport_output(struct xfrm_state *x, struct sk_buff *skb) ...@@ -24,6 +24,8 @@ static int xfrm4_transport_output(struct xfrm_state *x, struct sk_buff *skb)
struct iphdr *iph = ip_hdr(skb); struct iphdr *iph = ip_hdr(skb);
int ihl = iph->ihl * 4; 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_set_network_header(skb, -x->props.header_len);
skb->mac_header = skb->network_header + skb->mac_header = skb->network_header +
offsetof(struct iphdr, protocol); offsetof(struct iphdr, protocol);
......
...@@ -33,6 +33,9 @@ static int xfrm4_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb) ...@@ -33,6 +33,9 @@ static int xfrm4_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
struct iphdr *top_iph; struct iphdr *top_iph;
int flags; 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_set_network_header(skb, -x->props.header_len);
skb->mac_header = skb->network_header + skb->mac_header = skb->network_header +
offsetof(struct iphdr, protocol); offsetof(struct iphdr, protocol);
......
...@@ -27,6 +27,7 @@ static int xfrm6_transport_output(struct xfrm_state *x, struct sk_buff *skb) ...@@ -27,6 +27,7 @@ static int xfrm6_transport_output(struct xfrm_state *x, struct sk_buff *skb)
int hdr_len; int hdr_len;
iph = ipv6_hdr(skb); iph = ipv6_hdr(skb);
skb_set_inner_transport_header(skb, skb_transport_offset(skb));
hdr_len = x->type->hdr_offset(x, skb, &prevhdr); hdr_len = x->type->hdr_offset(x, skb, &prevhdr);
skb_set_mac_header(skb, (prevhdr - x->props.header_len) - skb->data); skb_set_mac_header(skb, (prevhdr - x->props.header_len) - skb->data);
......
...@@ -36,6 +36,9 @@ static int xfrm6_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb) ...@@ -36,6 +36,9 @@ static int xfrm6_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
struct ipv6hdr *top_iph; struct ipv6hdr *top_iph;
int dsfield; 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_set_network_header(skb, -x->props.header_len);
skb->mac_header = skb->network_header + skb->mac_header = skb->network_header +
offsetof(struct ipv6hdr, nexthdr); offsetof(struct ipv6hdr, nexthdr);
......
...@@ -205,6 +205,7 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb) ...@@ -205,6 +205,7 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
int err; int err;
secpath_reset(skb); secpath_reset(skb);
skb->encapsulation = 0;
if (xfrm_dev_offload_ok(skb, x)) { if (xfrm_dev_offload_ok(skb, x)) {
struct sec_path *sp; struct sec_path *sp;
...@@ -218,6 +219,7 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb) ...@@ -218,6 +219,7 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
if (skb->sp) if (skb->sp)
secpath_put(skb->sp); secpath_put(skb->sp);
skb->sp = sp; skb->sp = sp;
skb->encapsulation = 1;
sp->olen++; sp->olen++;
sp->xvec[skb->sp->len++] = x; sp->xvec[skb->sp->len++] = x;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment