net: Add inet_proto_csum_replace_by_diff utility function
authorTom Herbert <tom@herbertland.com>
Mon, 17 Aug 2015 20:42:26 +0000 (13:42 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 18 Aug 2015 04:33:06 +0000 (21:33 -0700)
This function updates a checksum field value and skb->csum based on
a value which is the difference between the old and new checksum.

Signed-off-by: Tom Herbert <tom@herbertland.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/checksum.h
net/core/utils.c

index 619f3445d57e73dc5601974b1185084b3d5f742a..9fcaedf994ee2ba5db20a0635c78ceed06f57cc1 100644 (file)
@@ -144,6 +144,8 @@ void inet_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb,
 void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb,
                               const __be32 *from, const __be32 *to,
                               bool pseudohdr);
+void inet_proto_csum_replace_by_diff(__sum16 *sum, struct sk_buff *skb,
+                                    __wsum diff, bool pseudohdr);
 
 static inline void inet_proto_csum_replace2(__sum16 *sum, struct sk_buff *skb,
                                            __be16 from, __be16 to,
index cd7d202f340efe0a0cb92b65062e45d88a5cc05b..3dffce953c39fc0209e8d0f553817e972f854303 100644 (file)
@@ -336,6 +336,19 @@ void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb,
 }
 EXPORT_SYMBOL(inet_proto_csum_replace16);
 
+void inet_proto_csum_replace_by_diff(__sum16 *sum, struct sk_buff *skb,
+                                    __wsum diff, bool pseudohdr)
+{
+       if (skb->ip_summed != CHECKSUM_PARTIAL) {
+               *sum = csum_fold(csum_add(diff, ~csum_unfold(*sum)));
+               if (skb->ip_summed == CHECKSUM_COMPLETE && pseudohdr)
+                       skb->csum = ~csum_add(diff, ~skb->csum);
+       } else if (pseudohdr) {
+               *sum = ~csum_fold(csum_add(diff, csum_unfold(*sum)));
+       }
+}
+EXPORT_SYMBOL(inet_proto_csum_replace_by_diff);
+
 struct __net_random_once_work {
        struct work_struct work;
        struct static_key *key;