net: explain __skb_checksum_complete() with comments
Subsystems (2)
PATCH 1/1 net: explain __skb_checksum_complete() with comments
Cc Herbert Xu <[email protected]>
Signed-off-by Cong Wang <[email protected]>
--- net/core/dev.c | 1 + net/core/skbuff.c | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-)
net/core/dev.c +1 -0
@@ -5787,6 +5787,7 @@ __sum16 __skb_gro_checksum_complete(struct sk_buff *skb)/* NAPI_GRO_CB(skb)->csum holds pseudo checksum */ sum =csum_fold (csum_add (NAPI_GRO_CB (skb)->csum, wsum)); +/* See comments in __skb_checksum_complete(). */ if (likely (!sum)) {if (unlikely (skb->ip_summed ==CHECKSUM_COMPLETE ) && !skb->csum_complete_sw)
net/core/skbuff.c +17 -1
@@ -2637,6 +2637,7 @@ __sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len)__sum16 sum; sum =csum_fold (skb_checksum (skb,0 , len, skb->csum)); +/* See comments in __skb_checksum_complete(). */ if (likely (!sum)) {if (unlikely (skb->ip_summed ==CHECKSUM_COMPLETE ) && !skb->csum_complete_sw)
@@ -2648,6 +2649,15 @@ __sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len) }EXPORT_SYMBOL (__skb_checksum_complete_head); +/* This function assumes skb->csum already holds pseudo header's checksum, +* which has been changed from the hardware checksum, for example, by +* __skb_checksum_validate_complete(). And, the original skb->csum must +* have been validated unsuccessfully for CHECKSUM_COMPLETE case. +* +* It returns non-zero if the recomputed checksum is still invalid, otherwise +* zero. The new checksum is stored back into skb->csum unless the skb is +* shared. +*/ __sum16 __skb_checksum_complete (struct sk_buff *skb) {__wsum csum;
@@ -2655,8 +2665,14 @@ __sum16 __skb_checksum_complete(struct sk_buff *skb) csum =skb_checksum (skb,0 , skb->len,0 ); -/* skb->csum holds pseudo checksum */ sum =csum_fold (csum_add (skb->csum, csum)); +/* This check is inverted, because we already knew the hardware +* checksum is invalid before calling this function. So, if the +* re-computed checksum is valid instead, then we have a mismatch +* between the original skb->csum and skb_checksum(). This means either +* the original hardware checksum is incorrect or we screw up skb->csum +* when moving skb->data around. +*/ if (likely (!sum)) {if (unlikely (skb->ip_summed ==CHECKSUM_COMPLETE ) && !skb->csum_complete_sw)
Signature · 1 line
2.19.1
From: Cong Wang <[email protected]>
Date: Mon, 26 Nov 2018 09:31:26 -0800
Quoted 2 lines
Cc Herbert Xu <[email protected]>Signed-off-by Cong Wang <[email protected]>
Applied, thanks Cong.