lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.2.02.1404041717020.20947@tomh.mtv.corp.google.com>
Date:	Fri, 4 Apr 2014 17:27:19 -0700 (PDT)
From:	Tom Herbert <therbert@...gle.com>
To:	davem@...emloft.net, netdev@...r.kernel.org
Subject: [PATCH net-next 3/6] net: Generalize checksum_init functions

Create a general __skb_checksum_validate function to subsume the
various checksum_init functions. This function can either init
the checksums, or do the full validation (logically check_init+
skb_check_complete)-- a flag to the function sets that.

Added several stub functions for calling __skb_checksum_validate.

Signed-off-by: Tom Herbert <therbert@...gle.com>
---
 include/linux/skbuff.h | 35 +++++++++++++++++++++++++++++++++++
 net/core/checksum.c    | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 08074a8..6cfbd52 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2741,6 +2741,41 @@ static inline __sum16 skb_checksum_complete(struct sk_buff *skb)
 	       0 : __skb_checksum_complete(skb);
 }
 
+__sum16 __skb_checksum_validate(struct sk_buff *skb, int proto, bool complete,
+		bool zero_check_okay, __sum16 check,
+		__wsum (*compute_pseudo)(struct sk_buff *skb, int proto));
+
+static inline __sum16 skb_checksum_init(struct sk_buff *skb, int proto,
+		__wsum (*compute_pseudo)(struct sk_buff *skb, int proto)) {
+	return __skb_checksum_validate(skb, proto, false, false,
+				       0, compute_pseudo);
+}
+
+static inline __sum16 skb_checksum_init_zero_check(struct sk_buff *skb,
+		int proto, __sum16 check,
+		__wsum (*compute_pseudo)(struct sk_buff *skb, int proto)) {
+	return __skb_checksum_validate(skb, proto, false, true,
+				       check, compute_pseudo);
+}
+
+static inline __sum16 skb_checksum_validate(struct sk_buff *skb, int proto,
+		__wsum (*compute_pseudo)(struct sk_buff *skb, int proto)) {
+	return __skb_checksum_validate(skb, proto, true, false,
+				       0, compute_pseudo);
+}
+
+static inline __sum16 skb_checksum_simple_validate(struct sk_buff *skb)
+{
+	return __skb_checksum_validate(skb, 0, true, false, 0, NULL);
+}
+
+static inline __sum16 skb_checksum_validate_zero_check(struct sk_buff *skb,
+	       int proto, __sum16 check,
+	       __wsum (*compute_pseudo)(struct sk_buff *skb, int proto)) {
+	return __skb_checksum_validate(skb, proto, true, true,
+				       check, compute_pseudo);
+}
+
 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
 void nf_conntrack_destroy(struct nf_conntrack *nfct);
 static inline void nf_conntrack_put(struct nf_conntrack *nfct)
diff --git a/net/core/checksum.c b/net/core/checksum.c
index 2954f86..b0df8c7 100644
--- a/net/core/checksum.c
+++ b/net/core/checksum.c
@@ -24,3 +24,35 @@ __sum16 __skb_checksum_complete(struct sk_buff *skb)
 	return __skb_checksum_complete_head(skb, skb->len);
 }
 EXPORT_SYMBOL(__skb_checksum_complete);
+
+
+__sum16 __skb_checksum_validate(struct sk_buff *skb, int proto, bool complete,
+				bool zero_check_okay, __sum16 check,
+				__wsum (*compute_pseudo)(struct sk_buff *skb,
+							 int proto))
+{
+	__wsum psum;
+
+	if (skb_csum_unnecessary(skb)) {
+		return 0;
+	} else if (zero_check_okay && !check) {
+		skb->ip_summed = CHECKSUM_UNNECESSARY;
+		return 0;
+	}
+
+	psum = compute_pseudo ? compute_pseudo(skb, proto) : 0;
+
+	if (skb->ip_summed == CHECKSUM_COMPLETE) {
+		if (!csum_fold(csum_add(psum, skb->csum))) {
+			skb->ip_summed = CHECKSUM_UNNECESSARY;
+			return 0;
+		}
+	}
+
+	skb->csum = psum;
+
+	if (complete || skb->len <= 76)
+		return __skb_checksum_complete(skb);
+
+	return 0;
+}
-- 
1.9.1.423.g4596e3a

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ