Skip to content

Commit d96535a

Browse files
Tom Herbertdavem330
authored andcommitted
net: Infrastructure for checksum unnecessary conversions
For normal path, added skb_checksum_try_convert which is called to attempt to convert CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE. The primary condition to allow this is that ip_summed is CHECKSUM_NONE and csum_valid is true, which will be the state after consuming a CHECKSUM_UNNECESSARY. For GRO path, added skb_gro_checksum_try_convert which is the GRO analogue of skb_checksum_try_convert. The primary condition to allow this is that NAPI_GRO_CB(skb)->csum_cnt == 0 and NAPI_GRO_CB(skb)->csum_valid is set. This implies that we have consumed all available CHECKSUM_UNNECESSARY checksums in the GRO path. Signed-off-by: Tom Herbert <therbert@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5a21232 commit d96535a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

include/linux/netdevice.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,26 @@ static inline void skb_gro_incr_csum_unnecessary(struct sk_buff *skb)
22332233
#define skb_gro_checksum_simple_validate(skb) \
22342234
__skb_gro_checksum_validate(skb, 0, false, 0, null_compute_pseudo)
22352235

2236+
static inline bool __skb_gro_checksum_convert_check(struct sk_buff *skb)
2237+
{
2238+
return (NAPI_GRO_CB(skb)->csum_cnt == 0 &&
2239+
!NAPI_GRO_CB(skb)->csum_valid);
2240+
}
2241+
2242+
static inline void __skb_gro_checksum_convert(struct sk_buff *skb,
2243+
__sum16 check, __wsum pseudo)
2244+
{
2245+
NAPI_GRO_CB(skb)->csum = ~pseudo;
2246+
NAPI_GRO_CB(skb)->csum_valid = 1;
2247+
}
2248+
2249+
#define skb_gro_checksum_try_convert(skb, proto, check, compute_pseudo) \
2250+
do { \
2251+
if (__skb_gro_checksum_convert_check(skb)) \
2252+
__skb_gro_checksum_convert(skb, check, \
2253+
compute_pseudo(skb, proto)); \
2254+
} while (0)
2255+
22362256
static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
22372257
unsigned short type,
22382258
const void *daddr, const void *saddr,

include/linux/skbuff.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,6 +2942,26 @@ static inline __wsum null_compute_pseudo(struct sk_buff *skb, int proto)
29422942
#define skb_checksum_simple_validate(skb) \
29432943
__skb_checksum_validate(skb, 0, true, false, 0, null_compute_pseudo)
29442944

2945+
static inline bool __skb_checksum_convert_check(struct sk_buff *skb)
2946+
{
2947+
return (skb->ip_summed == CHECKSUM_NONE &&
2948+
skb->csum_valid && !skb->csum_bad);
2949+
}
2950+
2951+
static inline void __skb_checksum_convert(struct sk_buff *skb,
2952+
__sum16 check, __wsum pseudo)
2953+
{
2954+
skb->csum = ~pseudo;
2955+
skb->ip_summed = CHECKSUM_COMPLETE;
2956+
}
2957+
2958+
#define skb_checksum_try_convert(skb, proto, check, compute_pseudo) \
2959+
do { \
2960+
if (__skb_checksum_convert_check(skb)) \
2961+
__skb_checksum_convert(skb, check, \
2962+
compute_pseudo(skb, proto)); \
2963+
} while (0)
2964+
29452965
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
29462966
void nf_conntrack_destroy(struct nf_conntrack *nfct);
29472967
static inline void nf_conntrack_put(struct nf_conntrack *nfct)

0 commit comments

Comments
 (0)