Commit 791521e2 authored by Eric Dumazet's avatar Eric Dumazet Committed by Greg Kroah-Hartman

net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends

After working on IP defragmentation lately, I found that some large
packets defeat CHECKSUM_COMPLETE optimization because of NIC adding
zero paddings on the last (small) fragment.

While removing the padding with pskb_trim_rcsum(), we set skb->ip_summed
to CHECKSUM_NONE, forcing a full csum validation, even if all prior
fragments had CHECKSUM_COMPLETE set.

We can instead compute the checksum of the part we are trimming,
usually smaller than the part we keep.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
(cherry picked from commit 88078d98)
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a8444b1c
...@@ -2954,6 +2954,7 @@ static inline unsigned char *skb_push_rcsum(struct sk_buff *skb, ...@@ -2954,6 +2954,7 @@ static inline unsigned char *skb_push_rcsum(struct sk_buff *skb,
return skb->data; return skb->data;
} }
int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned int len);
/** /**
* pskb_trim_rcsum - trim received skb and update checksum * pskb_trim_rcsum - trim received skb and update checksum
* @skb: buffer to trim * @skb: buffer to trim
...@@ -2967,9 +2968,7 @@ static inline int pskb_trim_rcsum(struct sk_buff *skb, unsigned int len) ...@@ -2967,9 +2968,7 @@ static inline int pskb_trim_rcsum(struct sk_buff *skb, unsigned int len)
{ {
if (likely(len >= skb->len)) if (likely(len >= skb->len))
return 0; return 0;
if (skb->ip_summed == CHECKSUM_COMPLETE) return pskb_trim_rcsum_slow(skb, len);
skb->ip_summed = CHECKSUM_NONE;
return __pskb_trim(skb, len);
} }
static inline int __skb_trim_rcsum(struct sk_buff *skb, unsigned int len) static inline int __skb_trim_rcsum(struct sk_buff *skb, unsigned int len)
......
...@@ -1578,6 +1578,20 @@ int ___pskb_trim(struct sk_buff *skb, unsigned int len) ...@@ -1578,6 +1578,20 @@ int ___pskb_trim(struct sk_buff *skb, unsigned int len)
} }
EXPORT_SYMBOL(___pskb_trim); EXPORT_SYMBOL(___pskb_trim);
/* Note : use pskb_trim_rcsum() instead of calling this directly
*/
int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned int len)
{
if (skb->ip_summed == CHECKSUM_COMPLETE) {
int delta = skb->len - len;
skb->csum = csum_sub(skb->csum,
skb_checksum(skb, len, delta, 0));
}
return __pskb_trim(skb, len);
}
EXPORT_SYMBOL(pskb_trim_rcsum_slow);
/** /**
* __pskb_pull_tail - advance tail of skb header * __pskb_pull_tail - advance tail of skb header
* @skb: buffer to reallocate * @skb: buffer to reallocate
......
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