From c0809b34e345209dac623530f276decaa09eea2a Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Tue, 5 Jun 2018 03:24:01 +0100 Subject: [PATCH] skb: Add skb_postpush_rcsum() This is based on commit f8ffad69c9f8b8dfb0b633425d4ef4d2493ba61a upstream, "bpf: add skb_postpush_rcsum and fix dev_forward_skb occasions". We don't need the bpf fixes here, just the new function. Cc: Daniel Borkmann Cc: David S. Miller Signed-off-by: Ben Hutchings --- include/linux/skbuff.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 93431a42f2f9..9b31b6d38da2 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2477,6 +2477,23 @@ static inline void skb_postpull_rcsum(struct sk_buff *skb, unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len); +static inline void skb_postpush_rcsum(struct sk_buff *skb, + const void *start, unsigned int len) +{ + /* For performing the reverse operation to skb_postpull_rcsum(), + * we can instead of ... + * + * skb->csum = csum_add(skb->csum, csum_partial(start, len, 0)); + * + * ... just use this equivalent version here to save a few + * instructions. Feeding csum of 0 in csum_partial() and later + * on adding skb->csum is equivalent to feed skb->csum in the + * first place. + */ + if (skb->ip_summed == CHECKSUM_COMPLETE) + skb->csum = csum_partial(start, len, skb->csum); +} + /** * pskb_trim_rcsum - trim received skb and update checksum * @skb: buffer to trim