summaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2001-11-14 23:30:37 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2001-11-14 23:30:37 +0000
commit3036624aed4efedc388713838b3c2717594f62f3 (patch)
tree93072cd1f863dbdbc737702e75cada0744e2f50f /sys/net
parent3c1b567342074ccdaa689f0d10e08caacd16e8a6 (diff)
use substract when comparing keys, for ip addrs as well.
those happen as signed integers and seem to work fine. saves whole bunch of useless code. dhartmei@ ok
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/pf.c58
1 files changed, 16 insertions, 42 deletions
diff --git a/sys/net/pf.c b/sys/net/pf.c
index 341b68853b4..bf9ab54e90e 100644
--- a/sys/net/pf.c
+++ b/sys/net/pf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf.c,v 1.166 2001/11/13 17:45:26 frantzen Exp $ */
+/* $OpenBSD: pf.c,v 1.167 2001/11/14 23:30:36 mickey Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -282,7 +282,8 @@ pf_tree_key_compare(struct pf_tree_key *a, struct pf_tree_key *b)
/*
* could use memcmp(), but with the best manual order, we can
- * minimize the number of average compares. what is faster?
+ * minimize the average number of substractions and jumps.
+ * what is faster?
*/
if ((diff = a->proto - b->proto) != 0)
return (diff);
@@ -291,50 +292,23 @@ pf_tree_key_compare(struct pf_tree_key *a, struct pf_tree_key *b)
switch (a->af) {
#ifdef INET
case AF_INET:
- if (a->addr[0].addr32[0] > b->addr[0].addr32[0])
- return 1;
- if (a->addr[0].addr32[0] < b->addr[0].addr32[0])
- return -1;
- if (a->addr[1].addr32[0] > b->addr[1].addr32[0])
- return 1;
- if (a->addr[1].addr32[0] < b->addr[1].addr32[0])
- return -1;
+ if ((diff = a->addr[0].addr32[0] - b->addr[0].addr32[0]) ||
+ (diff = a->addr[1].addr32[0] - b->addr[1].addr32[0]))
+ return diff;
break;
#endif /* INET */
#ifdef INET6
case AF_INET6:
- if (a->addr[0].addr32[0] > b->addr[0].addr32[0])
- return 1;
- if (a->addr[0].addr32[0] < b->addr[0].addr32[0])
- return -1;
- if (a->addr[0].addr32[1] > b->addr[0].addr32[1])
- return 1;
- if (a->addr[0].addr32[1] < b->addr[0].addr32[1])
- return -1;
- if (a->addr[0].addr32[2] > b->addr[0].addr32[2])
- return 1;
- if (a->addr[0].addr32[2] < b->addr[0].addr32[2])
- return -1;
- if (a->addr[0].addr32[3] > b->addr[0].addr32[3])
- return 1;
- if (a->addr[0].addr32[3] < b->addr[0].addr32[3])
- return -1;
- if (a->addr[1].addr32[0] > b->addr[1].addr32[0])
- return 1;
- if (a->addr[1].addr32[0] < b->addr[1].addr32[0])
- return -1;
- if (a->addr[1].addr32[1] > b->addr[1].addr32[1])
- return 1;
- if (a->addr[1].addr32[1] < b->addr[1].addr32[1])
- return -1;
- if (a->addr[1].addr32[2] > b->addr[1].addr32[2])
- return 1;
- if (a->addr[1].addr32[2] < b->addr[1].addr32[2])
- return -1;
- if (a->addr[1].addr32[3] > b->addr[1].addr32[3])
- return 1;
- if (a->addr[1].addr32[3] < b->addr[1].addr32[3])
- return -1;
+ if ((diff = a->addr[0].addr32[0] - b->addr[0].addr32[0]) ||
+ (diff = a->addr[0].addr32[1] - b->addr[0].addr32[1]) ||
+ (diff = a->addr[0].addr32[2] - b->addr[0].addr32[2]) ||
+ (diff = a->addr[0].addr32[3] - b->addr[0].addr32[3]) ||
+ (diff = a->addr[1].addr32[0] - b->addr[1].addr32[0]) ||
+ (diff = a->addr[1].addr32[1] - b->addr[1].addr32[1]) ||
+ (diff = a->addr[1].addr32[2] - b->addr[1].addr32[2]) ||
+ (diff = a->addr[1].addr32[3] - b->addr[1].addr32[3]))
+ return diff;
+
break;
#endif /* INET6 */
}