Skip to content

Commit 6bf32cd

Browse files
edumazetgregkh
authored andcommitted
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: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 88078d9) Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5123ffd commit 6bf32cd

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

include/linux/skbuff.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,6 +3135,7 @@ static inline void *skb_push_rcsum(struct sk_buff *skb, unsigned int len)
31353135
return skb->data;
31363136
}
31373137

3138+
int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned int len);
31383139
/**
31393140
* pskb_trim_rcsum - trim received skb and update checksum
31403141
* @skb: buffer to trim
@@ -3148,9 +3149,7 @@ static inline int pskb_trim_rcsum(struct sk_buff *skb, unsigned int len)
31483149
{
31493150
if (likely(len >= skb->len))
31503151
return 0;
3151-
if (skb->ip_summed == CHECKSUM_COMPLETE)
3152-
skb->ip_summed = CHECKSUM_NONE;
3153-
return __pskb_trim(skb, len);
3152+
return pskb_trim_rcsum_slow(skb, len);
31543153
}
31553154

31563155
static inline int __skb_trim_rcsum(struct sk_buff *skb, unsigned int len)

net/core/skbuff.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,20 @@ int ___pskb_trim(struct sk_buff *skb, unsigned int len)
18391839
}
18401840
EXPORT_SYMBOL(___pskb_trim);
18411841

1842+
/* Note : use pskb_trim_rcsum() instead of calling this directly
1843+
*/
1844+
int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned int len)
1845+
{
1846+
if (skb->ip_summed == CHECKSUM_COMPLETE) {
1847+
int delta = skb->len - len;
1848+
1849+
skb->csum = csum_sub(skb->csum,
1850+
skb_checksum(skb, len, delta, 0));
1851+
}
1852+
return __pskb_trim(skb, len);
1853+
}
1854+
EXPORT_SYMBOL(pskb_trim_rcsum_slow);
1855+
18421856
/**
18431857
* __pskb_pull_tail - advance tail of skb header
18441858
* @skb: buffer to reallocate

0 commit comments

Comments
 (0)