summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Herbert <therbert@google.com>2014-11-25 11:21:19 -0800
committerDavid S. Miller <davem@davemloft.net>2014-11-26 12:25:43 -0500
commit7c967b224a9a7061009ccbc47e1a0b605f1b6d81 (patch)
treebcb2343db0c704f7deb25246dec535d1b106e467
parentced7a04e394fe1df41d13b833baab5cfcb1d03b3 (diff)
downloadlwn-7c967b224a9a7061009ccbc47e1a0b605f1b6d81.tar.gz
lwn-7c967b224a9a7061009ccbc47e1a0b605f1b6d81.zip
net: Add remcsum_adjust as common function for remote checksum offload
This function does the work to update a checksum field as part of remote checksum offload. remcsum_adjust does the following: 1) Subtract out the calculated checksum from the beginning of the packet (ptr arg) to the start offset. 2) Adjust the checksum field indicated by offset based on the modified checksum value from above step. 3) Return the difference in the old checksum field value and the new one. The caller will use this to update skb->csum and NAPI csum. Signed-off-by: Tom Herbert <therbert@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/checksum.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/net/checksum.h b/include/net/checksum.h
index 6465bae80a4f..e339a9513e29 100644
--- a/include/net/checksum.h
+++ b/include/net/checksum.h
@@ -151,4 +151,20 @@ static inline void inet_proto_csum_replace2(__sum16 *sum, struct sk_buff *skb,
(__force __be32)to, pseudohdr);
}
+static inline __wsum remcsum_adjust(void *ptr, __wsum csum,
+ int start, int offset)
+{
+ __sum16 *psum = (__sum16 *)(ptr + offset);
+ __wsum delta;
+
+ /* Subtract out checksum up to start */
+ csum = csum_sub(csum, csum_partial(ptr, start, 0));
+
+ /* Set derived checksum in packet */
+ delta = csum_sub(csum_fold(csum), *psum);
+ *psum = csum_fold(csum);
+
+ return delta;
+}
+
#endif