Skip to content

Commit ec9567a

Browse files
ilantayariklassert
authored andcommitted
esp4: 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 cb5b136 commit ec9567a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

net/ipv4/esp4.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,8 @@ int esp_input_done2(struct sk_buff *skb, int err)
510510
int elen = skb->len - hlen;
511511
int ihl;
512512
u8 nexthdr[2];
513-
int padlen;
513+
int padlen, trimlen;
514+
__wsum csumdiff;
514515

515516
if (!xo || (xo && !(xo->flags & CRYPTO_DONE)))
516517
kfree(ESP_SKB_CB(skb)->tmp);
@@ -568,8 +569,15 @@ int esp_input_done2(struct sk_buff *skb, int err)
568569
skb->ip_summed = CHECKSUM_UNNECESSARY;
569570
}
570571

571-
pskb_trim(skb, skb->len - alen - padlen - 2);
572-
__skb_pull(skb, hlen);
572+
trimlen = alen + padlen + 2;
573+
if (skb->ip_summed == CHECKSUM_COMPLETE) {
574+
csumdiff = skb_checksum(skb, skb->len - trimlen, trimlen, 0);
575+
skb->csum = csum_block_sub(skb->csum, csumdiff,
576+
skb->len - trimlen);
577+
}
578+
pskb_trim(skb, skb->len - trimlen);
579+
580+
skb_pull_rcsum(skb, hlen);
573581
if (x->props.mode == XFRM_MODE_TUNNEL)
574582
skb_reset_transport_header(skb);
575583
else

net/ipv4/esp4_offload.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,13 @@ static struct sk_buff *esp4_gso_segment(struct sk_buff *skb,
182182
static int esp_input_tail(struct xfrm_state *x, struct sk_buff *skb)
183183
{
184184
struct crypto_aead *aead = x->data;
185+
struct xfrm_offload *xo = xfrm_offload(skb);
185186

186187
if (!pskb_may_pull(skb, sizeof(struct ip_esp_hdr) + crypto_aead_ivsize(aead)))
187188
return -EINVAL;
188189

189-
skb->ip_summed = CHECKSUM_NONE;
190+
if (!(xo->flags & CRYPTO_DONE))
191+
skb->ip_summed = CHECKSUM_NONE;
190192

191193
return esp_input_done2(skb, 0);
192194
}

0 commit comments

Comments
 (0)