summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorangelos <angelos@openbsd.org>2001-06-24 23:41:47 +0000
committerangelos <angelos@openbsd.org>2001-06-24 23:41:47 +0000
commit33cebe5fcfa72c2de4013f227afc1deb91778374 (patch)
tree557255fe0a36b3671d87a909a5bc94420916fedf
parentSync in4_cksum() with NetBSD, and change its use in in_delayed_cksum. (diff)
downloadwireguard-openbsd-33cebe5fcfa72c2de4013f227afc1deb91778374.tar.xz
wireguard-openbsd-33cebe5fcfa72c2de4013f227afc1deb91778374.zip
Import in_cksum_phdr() and in_cksum_addword() from NetBSD.
-rw-r--r--sys/netinet/in.h49
1 files changed, 48 insertions, 1 deletions
diff --git a/sys/netinet/in.h b/sys/netinet/in.h
index 25dcd58b73a..2c91f6673dd 100644
--- a/sys/netinet/in.h
+++ b/sys/netinet/in.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in.h,v 1.50 2001/06/24 23:33:55 angelos Exp $ */
+/* $OpenBSD: in.h,v 1.51 2001/06/24 23:41:47 angelos Exp $ */
/* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */
/*
@@ -494,6 +494,53 @@ struct ip_mreq {
#include <sys/cdefs.h>
+/*
+ * in_cksum_phdr:
+ *
+ * Compute significant parts of the IPv4 checksum pseudo-header
+ * for use in a delayed TCP/UDP checksum calculation.
+ *
+ * Args:
+ *
+ * src Source IP address
+ * dst Destination IP address
+ * lenproto htons(proto-hdr-len + proto-number)
+ */
+static __inline u_int16_t __attribute__((__unused__))
+in_cksum_phdr(u_int32_t src, u_int32_t dst, u_int32_t lenproto)
+{
+ u_int32_t sum;
+
+ sum = lenproto +
+ (u_int16_t)(src >> 16) +
+ (u_int16_t)(src /*& 0xffff*/) +
+ (u_int16_t)(dst >> 16) +
+ (u_int16_t)(dst /*& 0xffff*/);
+
+ sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/);
+
+ if (sum > 0xffff)
+ sum -= 0xffff;
+
+ return (sum);
+}
+
+/*
+ * in_cksum_addword:
+ *
+ * Add the two 16-bit network-order values, carry, and return.
+ */
+static __inline u_int16_t __attribute__((__unused__))
+in_cksum_addword(u_int16_t a, u_int16_t b)
+{
+ u_int32_t sum = a + b;
+
+ if (sum > 0xffff)
+ sum -= 0xffff;
+
+ return (sum);
+}
+
__BEGIN_DECLS
int bindresvport __P((int, struct sockaddr_in *));
struct sockaddr;