Skip to content

Commit e51a647

Browse files
ilantayariklassert
authored andcommitted
esp6: Support RX checksum with crypto offload
Keep the device's reported ip_summed indication in case crypto was offloaded by the device. Subtract the csum values of the stripped parts (esp header+iv, esp trailer+auth_data) to keep value correct. Note: CHECKSUM_COMPLETE should be indicated only if skb->csum has the post-decryption offload csum value. Signed-off-by: Ariel Levkovich <lariel@mellanox.com> Signed-off-by: Ilan Tayari <ilant@mellanox.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent ec9567a commit e51a647

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

net/ipv6/esp6.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ int esp6_input_done2(struct sk_buff *skb, int err)
470470
int hlen = sizeof(struct ip_esp_hdr) + crypto_aead_ivsize(aead);
471471
int elen = skb->len - hlen;
472472
int hdr_len = skb_network_header_len(skb);
473-
int padlen;
473+
int padlen, trimlen;
474+
__wsum csumdiff;
474475
u8 nexthdr[2];
475476

476477
if (!xo || (xo && !(xo->flags & CRYPTO_DONE)))
@@ -492,8 +493,15 @@ int esp6_input_done2(struct sk_buff *skb, int err)
492493

493494
/* ... check padding bits here. Silly. :-) */
494495

495-
pskb_trim(skb, skb->len - alen - padlen - 2);
496-
__skb_pull(skb, hlen);
496+
trimlen = alen + padlen + 2;
497+
if (skb->ip_summed == CHECKSUM_COMPLETE) {
498+
csumdiff = skb_checksum(skb, skb->len - trimlen, trimlen, 0);
499+
skb->csum = csum_block_sub(skb->csum, csumdiff,
500+
skb->len - trimlen);
501+
}
502+
pskb_trim(skb, skb->len - trimlen);
503+
504+
skb_pull_rcsum(skb, hlen);
497505
if (x->props.mode == XFRM_MODE_TUNNEL)
498506
skb_reset_transport_header(skb);
499507
else

net/ipv6/esp6_offload.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,13 @@ static struct sk_buff *esp6_gso_segment(struct sk_buff *skb,
209209
static int esp6_input_tail(struct xfrm_state *x, struct sk_buff *skb)
210210
{
211211
struct crypto_aead *aead = x->data;
212+
struct xfrm_offload *xo = xfrm_offload(skb);
212213

213214
if (!pskb_may_pull(skb, sizeof(struct ip_esp_hdr) + crypto_aead_ivsize(aead)))
214215
return -EINVAL;
215216

216-
skb->ip_summed = CHECKSUM_NONE;
217+
if (!(xo->flags & CRYPTO_DONE))
218+
skb->ip_summed = CHECKSUM_NONE;
217219

218220
return esp6_input_done2(skb, 0);
219221
}

0 commit comments

Comments
 (0)