HAMMER Utilities: MFC work to date.
[dragonfly.git] / sys / netproto / atalk / at_rmx.c
blob637d501f2cd605cf0165c89e79c19a4a86ff2e37
1 /*
2 * Copyright 1994, 1995 Massachusetts Institute of Technology
4 * Permission to use, copy, modify, and distribute this software and
5 * its documentation for any purpose and without fee is hereby
6 * granted, provided that both the above copyright notice and this
7 * permission notice appear in all copies, that both the above
8 * copyright notice and this permission notice appear in all
9 * supporting documentation, and that the name of M.I.T. not be used
10 * in advertising or publicity pertaining to distribution of the
11 * software without specific, written prior permission. M.I.T. makes
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied
14 * warranty.
16 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
17 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * at_rmx.c,v 1.13 1995/05/30 08:09:31 rgrimes Exp
30 * $DragonFly: src/sys/netproto/atalk/at_rmx.c,v 1.4 2006/12/22 23:57:53 swildner Exp $
33 /* This code generates debugging traces to the radix code */
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/socket.h>
39 #include <net/route.h>
41 int at_inithead(void **head, int off);
43 static char hexbuf[256];
45 static char *
46 prsockaddr(void *v)
48 char *bp = &hexbuf[0];
49 u_char *cp = v;
51 if (v) {
52 int len = *cp;
53 u_char *cplim = cp + len;
55 /* return: "(len) hexdump" */
57 bp += ksprintf(bp, "(%d)", len);
58 for (cp++; cp < cplim && bp < hexbuf+252; cp++) {
59 *bp++ = "0123456789abcdef"[*cp / 16];
60 *bp++ = "0123456789abcdef"[*cp % 16];
62 } else {
63 bp+= ksprintf(bp, "null");
65 *bp = '\0';
67 return &hexbuf[0];
70 static struct radix_node *
71 at_addroute(char *key, char *mask, struct radix_node_head *head,
72 struct radix_node *treenodes)
74 struct radix_node *rn;
76 kprintf("at_addroute: v=%s\n", prsockaddr(key));
77 kprintf("at_addroute: n=%s\n", prsockaddr(mask));
78 kprintf("at_addroute: head=%p treenodes=%p\n",
79 (void *)head, (void *)treenodes);
81 rn = rn_addroute(key, mask, head, treenodes);
83 kprintf("at_addroute: returns rn=%p\n", (void *)rn);
85 return rn;
88 static struct radix_node *
89 at_matroute(char *key, struct radix_node_head *head)
91 struct radix_node *rn;
93 kprintf("at_matroute: v=%s\n", prsockaddr(key));
94 kprintf("at_matroute: head=%p\n", (void *)head);
96 rn = rn_match(key, head);
98 kprintf("at_matroute: returnr rn=%p\n", (void *)rn);
100 return rn;
103 static struct radix_node *
104 at_lookup(char *key, char *mask, struct radix_node_head *head)
106 struct radix_node *rn;
108 kprintf("at_lookup: v=%s\n", prsockaddr(key));
109 kprintf("at_lookup: n=%s\n", prsockaddr(mask));
110 kprintf("at_lookup: head=%p\n", (void *)head);
112 rn = rn_lookup(key, mask, head);
114 kprintf("at_lookup: returns rn=%p\n", (void *)rn);
116 return rn;
119 static struct radix_node *
120 at_delroute(char *key, char *netmask, struct radix_node_head *head)
122 struct radix_node *rn;
124 kprintf("at_delroute: v=%s\n", prsockaddr(key));
125 kprintf("at_delroute: n=%s\n", prsockaddr(netmask));
126 kprintf("at_delroute: head=%p\n", (void *)head);
128 rn = rn_delete(key, netmask, head);
130 kprintf("at_delroute: returns rn=%p\n", (void *)rn);
132 return rn;
136 * Initialize our routing tree with debugging hooks.
139 at_inithead(void **head, int off)
141 struct radix_node_head *rnh;
143 if(!rn_inithead(head, off))
144 return 0;
146 rnh = *head;
147 rnh->rnh_addaddr = at_addroute;
148 rnh->rnh_deladdr = at_delroute;
149 rnh->rnh_matchaddr = at_matroute;
150 rnh->rnh_lookup = at_lookup;
151 return 1;