aboutsummaryrefslogtreecommitdiff
path: root/sys/net/radix.c
diff options
context:
space:
mode:
authorLuigi Rizzo <luigi@FreeBSD.org>2004-04-19 17:28:39 +0000
committerLuigi Rizzo <luigi@FreeBSD.org>2004-04-19 17:28:39 +0000
commit9aed3aa34a8719a4694bbd47cd7bd2a442cd1b38 (patch)
tree3570c0f10685f30a4e0dc60f678aabd907a1e490 /sys/net/radix.c
parentf4247b5934d62cf9f1ee59d3584ac09df3fc4e70 (diff)
downloadsrc-9aed3aa34a8719a4694bbd47cd7bd2a442cd1b38.tar.gz
src-9aed3aa34a8719a4694bbd47cd7bd2a442cd1b38.zip
Add some comments, move a static array of constants in the only place
where it is used, and replace R_Malloc with R_Zalloc in a couple of places removing the corresponding bzero()'s
Notes
Notes: svn path=/head/; revision=128433
Diffstat (limited to 'sys/net/radix.c')
-rw-r--r--sys/net/radix.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/sys/net/radix.c b/sys/net/radix.c
index e4e42212d9b1..cfc2143f4dc5 100644
--- a/sys/net/radix.c
+++ b/sys/net/radix.c
@@ -61,9 +61,11 @@ static struct radix_node
static int max_keylen;
static struct radix_mask *rn_mkfreelist;
static struct radix_node_head *mask_rnhead;
-static char *addmask_key;
-static char normal_chars[] = {0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, -1};
-static char *rn_zeros, *rn_ones;
+/*
+ * Work area -- the following point to 3 buffers of size max_keylen,
+ * allocated in this order in a block of memory malloc'ed by rn_init.
+ */
+static char *rn_zeros, *rn_ones, *addmask_key;
#define MKGet(m) { \
if (rn_mkfreelist) { \
@@ -469,10 +471,9 @@ rn_addmask(n_arg, search, skip)
x = 0;
if (x || search)
return (x);
- R_Malloc(x, struct radix_node *, max_keylen + 2 * sizeof (*x));
+ R_Zalloc(x, struct radix_node *, max_keylen + 2 * sizeof (*x));
if ((saved_x = x) == 0)
return (0);
- bzero(x, max_keylen + 2 * sizeof (*x));
netmask = cp = (caddr_t)(x + 2);
bcopy(addmask_key, cp, mlen);
x = rn_insert(cp, mask_rnhead, &maskduplicated, x);
@@ -483,11 +484,19 @@ rn_addmask(n_arg, search, skip)
}
/*
* Calculate index of mask, and check for normalcy.
+ * First find the first byte with a 0 bit, then if there are
+ * more bits left (remember we already trimmed the trailing 0's),
+ * the pattern must be one of those in normal_chars[], or we have
+ * a non-contiguous mask.
*/
- cplim = netmask + mlen; isnormal = 1;
+ cplim = netmask + mlen;
+ isnormal = 1;
for (cp = netmask + skip; (cp < cplim) && *(u_char *)cp == 0xff;)
cp++;
if (cp != cplim) {
+ static char normal_chars[] = {
+ 0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff};
+
for (j = 0x80; (j & *cp) != 0; j >>= 1)
b++;
if (*cp != normal_chars[b] || cp != (cplim - 1))
@@ -1027,10 +1036,9 @@ rn_inithead(head, off)
register struct radix_node *t, *tt, *ttt;
if (*head)
return (1);
- R_Malloc(rnh, struct radix_node_head *, sizeof (*rnh));
+ R_Zalloc(rnh, struct radix_node_head *, sizeof (*rnh));
if (rnh == 0)
return (0);
- bzero(rnh, sizeof (*rnh));
#ifdef _KERNEL
RADIX_NODE_HEAD_LOCK_INIT(rnh);
#endif