diff options
author | luigi <luigi@FreeBSD.org> | 2004-04-19 17:28:39 +0000 |
---|---|---|
committer | luigi <luigi@FreeBSD.org> | 2004-04-19 17:28:39 +0000 |
commit | cb1916d8830bd1cb5453f8c4e33c627b79dff9d9 (patch) | |
tree | 3570c0f10685f30a4e0dc60f678aabd907a1e490 /sys/net | |
parent | aeac3672f4085078db2f2898c11d80bbc9c782c2 (diff) | |
download | FreeBSD-src-cb1916d8830bd1cb5453f8c4e33c627b79dff9d9.zip FreeBSD-src-cb1916d8830bd1cb5453f8c4e33c627b79dff9d9.tar.gz |
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
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/radix.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/sys/net/radix.c b/sys/net/radix.c index e4e4221..cfc2143 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 |