summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2001-11-16 11:07:21 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2001-11-16 11:07:21 +0000
commit4bc4e191eb2b3e3bc53a3ab8dacf1502ac60a9fd (patch)
treef5702afce3d436690c0fa53dc38562e236570da4 /sys
parentba79a6e511aa8c23cbc9d60d7b6860d73294ecfa (diff)
yes, signed substraction does not work because of underflows, revert the previous
Diffstat (limited to 'sys')
-rw-r--r--sys/net/pf.c58
1 files changed, 42 insertions, 16 deletions
diff --git a/sys/net/pf.c b/sys/net/pf.c
index bf9ab54e90e..deaeb82c137 100644
--- a/sys/net/pf.c
+++ b/sys/net/pf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf.c,v 1.167 2001/11/14 23:30:36 mickey Exp $ */
+/* $OpenBSD: pf.c,v 1.168 2001/11/16 11:07:20 mickey Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -282,8 +282,7 @@ 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 average number of substractions and jumps.
- * what is faster?
+ * minimize the average number of compares. what is faster?
*/
if ((diff = a->proto - b->proto) != 0)
return (diff);
@@ -292,23 +291,50 @@ pf_tree_key_compare(struct pf_tree_key *a, struct pf_tree_key *b)
switch (a->af) {
#ifdef INET
case AF_INET:
- 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;
+ 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;
break;
#endif /* INET */
#ifdef INET6
case AF_INET6:
- 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;
-
+ 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;
break;
#endif /* INET6 */
}