npf_addr_mix: use xor rather than sum. trunk
authorrmind <rmind@NetBSD.org>
Fri, 22 Nov 2013 01:24:21 +0000
branchtrunk
changeset 222622 791ceec04cc3
parent 222621 df4e8373a71e
child 222623 249a3286d042
npf_addr_mix: use xor rather than sum.
sys/net/npf/npf_impl.h
sys/net/npf/npf_inet.c
sys/net/npf/npf_session.c
--- a/sys/net/npf/npf_impl.h	Fri Nov 22 01:09:11 2013 +0000
+++ b/sys/net/npf/npf_impl.h	Fri Nov 22 01:24:21 2013 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_impl.h,v 1.41 2013/11/22 00:25:51 rmind Exp $	*/
+/*	$NetBSD: npf_impl.h,v 1.42 2013/11/22 01:24:21 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
@@ -193,7 +193,7 @@
 uint16_t	npf_fixup32_cksum(uint16_t, uint32_t, uint32_t);
 uint16_t	npf_addr_cksum(uint16_t, int, const npf_addr_t *,
 		    const npf_addr_t *);
-uint32_t	npf_addr_sum(const int, const npf_addr_t *, const npf_addr_t *);
+uint32_t	npf_addr_mix(const int, const npf_addr_t *, const npf_addr_t *);
 int		npf_addr_cmp(const npf_addr_t *, const npf_netmask_t,
 		    const npf_addr_t *, const npf_netmask_t, const int);
 void		npf_addr_mask(const npf_addr_t *, const npf_netmask_t,
--- a/sys/net/npf/npf_inet.c	Fri Nov 22 01:09:11 2013 +0000
+++ b/sys/net/npf/npf_inet.c	Fri Nov 22 01:24:21 2013 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_inet.c,v 1.25 2013/10/30 08:41:38 mrg Exp $	*/
+/*	$NetBSD: npf_inet.c,v 1.26 2013/11/22 01:24:21 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2009-2012 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_inet.c,v 1.25 2013/10/30 08:41:38 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_inet.c,v 1.26 2013/11/22 01:24:21 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -109,20 +109,19 @@
 }
 
 /*
- * npf_addr_sum: provide IP address as a summed (if needed) 32-bit integer.
+ * npf_addr_sum: provide IP addresses as a XORed 32-bit integer.
  * Note: used for hash function.
  */
 uint32_t
-npf_addr_sum(const int sz, const npf_addr_t *a1, const npf_addr_t *a2)
+npf_addr_mix(const int sz, const npf_addr_t *a1, const npf_addr_t *a2)
 {
 	uint32_t mix = 0;
-	int i;
 
 	KASSERT(sz > 0 && a1 != NULL && a2 != NULL);
 
-	for (i = 0; i < (sz >> 2); i++) {
-		mix += a1->s6_addr32[i];
-		mix += a2->s6_addr32[i];
+	for (int i = 0; i < (sz >> 2); i++) {
+		mix ^= a1->s6_addr32[i];
+		mix ^= a2->s6_addr32[i];
 	}
 	return mix;
 }
--- a/sys/net/npf/npf_session.c	Fri Nov 22 01:09:11 2013 +0000
+++ b/sys/net/npf/npf_session.c	Fri Nov 22 01:24:21 2013 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_session.c,v 1.27 2013/11/08 00:38:26 rmind Exp $	*/
+/*	$NetBSD: npf_session.c,v 1.28 2013/11/22 01:24:21 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2010-2013 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_session.c,v 1.27 2013/11/08 00:38:26 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_session.c,v 1.28 2013/11/22 01:24:21 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -314,7 +314,7 @@
 
 	mix[0] = (scid->proto ^ scid->ifid) << 16;
 	mix[0] |= sen->se_src_id ^ sen->se_dst_id;
-	mix[1] = npf_addr_sum(sz, &sen->se_src_addr, &sen->se_dst_addr);
+	mix[1] = npf_addr_mix(sz, &sen->se_src_addr, &sen->se_dst_addr);
 	hash = murmurhash2(mix, sizeof(mix), sess_hash_seed);
 
 	return &stbl[hash & SESS_HASH_MASK];