88static unsigned char normal_chars[] = {0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xFF};
92#define rn_masktop (squid_mask_rnhead->rnh_treetop)
93#define rn_dupedkey rn_u.rn_leaf.rn_Dupedkey
94#define rn_off rn_u.rn_node.rn_Off
95#define rn_l rn_u.rn_node.rn_L
96#define rn_r rn_u.rn_node.rn_R
97#define rm_mask rm_rmu.rmu_mask
98#define rm_leaf rm_rmu.rmu_leaf
101#define squid_R_Malloc(p, t, n) (p = (t) xmalloc((unsigned int)(n)))
102#define squid_Free(p) xfree((char *)p)
103#define squid_MKGet(m) {\
104 if (squid_rn_mkfreelist) {\
105 m = squid_rn_mkfreelist; \
106 squid_rn_mkfreelist = (m)->rm_mklist; \
108 squid_R_Malloc(m, struct squid_radix_mask *, sizeof (*(m)));\
111#define squid_MKFree(m) { (m)->rm_mklist = squid_rn_mkfreelist; squid_rn_mkfreelist = (m);}
114#define min(x,y) ((x)<(y)? (x) : (y))
155 for (x =
head, v = v_arg; x->
rn_b >= 0;) {
167 register char *v = v_arg, *m = m_arg;
182 register char *m = m_arg, *n = n_arg;
183 register char *lim, *lim2 = lim = n + *(u_char *) n;
184 int longer = (*(u_char *) n++) - (
int) (*(u_char *) m++);
185 int masks_are_equal = 1;
198 if (masks_are_equal && (longer < 0))
199 for (lim2 = m - longer; m < lim2;)
202 return (!masks_are_equal);
208 char *netmask =
NULL;
217 while (x && x->rn_mask != netmask)
226 register char *cp = trial, *cp2 = leaf->rn_key, *cp3 = leaf->rn_mask;
228 int length =
min(*(u_char *) cp, *(u_char *) cp2);
233 length =
min(length, *(u_char *) cp3);
237 for (cp += skip; cp < cplim; cp++, cp2++, cp3++)
238 if ((*cp ^ *cp2) & *cp3)
247 register char *cp = v, *cp2;
250 int off = t->rn_off, vlen = *(u_char *) cp, matched_off;
251 register int test, b,
rn_b;
257 for (; t->
rn_b >= 0;) {
275 vlen = *(u_char *) t->rn_mask;
277 cp2 = t->rn_key + off;
279 for (; cp < cplim; cp++, cp2++)
290 test = (*cp ^ *cp2) & 0xff;
291 for (b = 7; (test >>= 1) > 0;)
293 matched_off = cp - v;
294 b += matched_off << 3;
299 if ((saved_t = t)->rn_mask == 0)
301 for (; t; t = t->rn_dupedkey)
329 off =
min(t->rn_off, matched_off);
331 while (x && x->rn_mask != m->rm_mask)
346 t->rn_bmask = 0x80 >> (b & 7);
350 tt->rn_key = (
char *) v;
360 int head_off = top->rn_off, vlen = (
int) *((u_char *) v);
362 register char *cp = v + head_off;
369 register char *cp2 = t->rn_key + head_off;
370 register int cmp_res;
371 char *cplim = v + vlen;
380 cmp_res = (cp[-1] ^ cp2[-1]) & 0xff;
381 for (b = (cp - v) << 3; cmp_res; b--)
393 }
while (b > (
unsigned) x->
rn_b);
396 if ((cp[p->rn_off] & p->
rn_bmask) == 0)
402 if ((cp[t->rn_off] & t->
rn_bmask) == 0) {
414 char *netmask = (
char *) n_arg;
416 register char *cp, *cplim;
417 register int b = 0, mlen, j;
418 int maskduplicated, m0, isnormal;
420 static int last_zeroed = 0;
430 if ((m0 = mlen) > skip)
431 memcpy(
addmask_key + skip, netmask + skip, mlen - skip);
439 if (m0 >= last_zeroed)
443 if (m0 < last_zeroed)
452 if ((saved_x = x) == 0)
455 netmask = cp = (
char *) (x + 2);
458 if (maskduplicated) {
459 fprintf(stderr,
"squid_rn_addmask: mask impossibly already in tree");
466 cplim = netmask + mlen;
468 for (cp = netmask + skip; (cp < cplim) && *(u_char *) cp == 0xff;)
471 for (j = 0x80; (j & *cp) != 0; j >>= 1)
476 b += (cp - netmask) << 3;
486 register u_char *mp = m_arg, *np = n_arg, *lim;
491 for (lim = mp + *mp; mp < lim;)
503 fprintf(stderr,
"Mask for route not entered\n");
506 memset(m,
'\0',
sizeof *m);
512 m->rm_mask = tt->rn_mask;
520 char *v = (
char *) v_arg, *netmask = (
char *) n_arg;
523 short b = 0, b_leaf = 0;
547 for (t = tt; tt; t = tt, tt = tt->rn_dupedkey) {
548 if (tt->rn_mask == netmask)
552 ((b_leaf < tt->rn_b) ||
567 if (tt == saved_tt) {
573 tt->rn_p = x = t->
rn_p;
582 tt->rn_dupedkey = t->rn_dupedkey;
585 tt->rn_key = (
char *) v;
593 tt->rn_mask = netmask;
600 b_leaf = -1 - t->
rn_b;
601 if (t->rn_r == saved_tt)
607 for (mp = &t->
rn_mklist; x; x = x->rn_dupedkey)
608 if (x->rn_mask && (x->
rn_b >= b_leaf) && x->
rn_mklist == 0) {
617 if (m->
rm_b >= b_leaf)
624 if ((netmask == 0) || (b > t->
rn_b))
630 }
while (b <= t->
rn_b && x != top);
638 if (m->
rm_b < b_leaf)
640 if (m->
rm_b > b_leaf)
643 mmask = m->rm_leaf->rn_mask;
646 "Non-unique normal route, mask not entered");
651 if (mmask == netmask) {
669 int b, head_off, vlen;
672 netmask = netmask_arg;
673 x =
head->rnh_treetop;
675 head_off = x->rn_off;
676 vlen = *(u_char *) v;
680 memcmp(v + head_off, tt->rn_key + head_off, vlen - head_off))
689 while (tt->rn_mask != netmask)
690 if ((tt = tt->rn_dupedkey) == 0)
693 if (tt->rn_mask == 0 || (saved_m = m = tt->
rn_mklist) == 0)
696 if (m->rm_leaf != tt || m->
rm_refs > 0) {
697 fprintf(stderr,
"squid_rn_delete: inconsistent annotation\n");
701 if (m->rm_mask != tt->rn_mask) {
702 fprintf(stderr,
"squid_rn_delete: inconsistent annotation\n");
715 }
while (b <= t->
rn_b && x != top);
723 fprintf(stderr,
"squid_rn_delete: couldn't find our annotation\n");
734 if ((dupedkey = saved_tt->rn_dupedkey)) {
735 if (tt == saved_tt) {
743 for (x = p = saved_tt; p && p->rn_dupedkey != tt;)
746 p->rn_dupedkey = tt->rn_dupedkey;
748 fprintf(stderr,
"squid_rn_delete: couldn't find us\n");
785 for (m = t->
rn_mklist; m && x; x = x->rn_dupedkey)
828 while (rn->
rn_b >= 0)
836 for (rn = rn->
rn_p->rn_r; rn->
rn_b >= 0;)
840 while ((rn = base)) {
841 base = rn->rn_dupedkey;
862 memset(rnh,
'\0',
sizeof(*rnh));
889 for (dom = domains; dom; dom = dom->dom_next)
895 "squid_rn_init: radix functions require squid_max_keylen be set\n");
900 fprintf(stderr,
"squid_rn_init failed.\n");
909 fprintf(stderr,
"rn_init2 failed.\n");
void error(char *format,...)
squidaio_request_t * head
int squid_rn_walktree(struct squid_radix_node_head *h, int(*f)(struct squid_radix_node *, void *), void *w)
struct squid_radix_node * squid_rn_addroute(void *v_arg, void *n_arg, struct squid_radix_node_head *head, struct squid_radix_node treenodes[2])
struct squid_radix_node_head * squid_mask_rnhead
int squid_rn_refines(void *m_arg, void *n_arg)
struct squid_radix_node * squid_rn_lookup(void *v_arg, void *m_arg, struct squid_radix_node_head *head)
static struct squid_radix_mask * rn_new_radix_mask(struct squid_radix_node *tt, struct squid_radix_mask *next)
static unsigned char normal_chars[]
int squid_rn_inithead(struct squid_radix_node_head **head, int off)
struct squid_radix_mask * squid_rn_mkfreelist
static int rn_lexobetter(void *m_arg, void *n_arg)
#define squid_R_Malloc(p, t, n)
static char * addmask_key
struct squid_radix_node * squid_rn_newpair(void *v, int b, struct squid_radix_node nodes[2])
struct squid_radix_node * squid_rn_addmask(void *n_arg, int search, int skip)
struct squid_radix_node * squid_rn_search_m(void *v_arg, struct squid_radix_node *head, void *m_arg)
struct squid_radix_node * squid_rn_search(void *v_arg, struct squid_radix_node *head)
struct squid_radix_node * squid_rn_insert(void *v_arg, struct squid_radix_node_head *head, int *dupentry, struct squid_radix_node nodes[2])
struct squid_radix_node * squid_rn_match(void *v_arg, struct squid_radix_node_head *head)
struct squid_radix_node * squid_rn_delete(void *v_arg, void *netmask_arg, struct squid_radix_node_head *head)
static int rn_satsifies_leaf(char *trial, register struct squid_radix_node *leaf, int skip)
struct squid_radix_mask * rm_mklist
struct squid_radix_node * rnh_deladdr(void *v, void *mask, struct squid_radix_node_head *head)
struct squid_radix_node * rnh_lookup(void *v, void *mask, struct squid_radix_node_head *head)
struct squid_radix_node * rnh_matchaddr(void *v, struct squid_radix_node_head *head)
int rnh_walktree(struct squid_radix_node_head *head, int(*f)(struct squid_radix_node *, void *), void *w)
struct squid_radix_node * rnh_treetop
struct squid_radix_node * rnh_addaddr(void *v, void *mask, struct squid_radix_node_head *head, struct squid_radix_node nodes[])
struct squid_radix_node rnh_nodes[3]
struct squid_radix_node * rn_p
struct squid_radix_mask * rn_mklist