]> git.hungrycats.org Git - linux/commitdiff
skb: Add skb_postpush_rcsum()
authorBen Hutchings <ben@decadent.org.uk>
Tue, 5 Jun 2018 02:24:01 +0000 (03:24 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 16 Jun 2018 21:22:43 +0000 (22:22 +0100)
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 <daniel@iogearbox.net>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
include/linux/skbuff.h

index 93431a42f2f91fd4ce66b7bd5398765f49fb9592..9b31b6d38da272165efed36de0934ebac6bdec90 100644 (file)
@@ -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