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
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
29 * at_rmx.c,v 1.13 1995/05/30 08:09:31 rgrimes 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 #define HEXBUF_LEN 256
46 prsockaddr(void *v, char *hexbuf)
48 char *bp = &hexbuf[0];
53 u_char *cplim = cp + len;
55 /* return: "(len) hexdump" */
57 bp += sprintf(bp, "(%d)", len);
58 for (cp++; cp < cplim && bp < hexbuf + (HEXBUF_LEN - 4);
60 *bp++ = "0123456789abcdef"[*cp / 16];
61 *bp++ = "0123456789abcdef"[*cp % 16];
64 bp+= sprintf(bp, "null");
69 static struct radix_node *
70 at_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
71 struct radix_node *treenodes)
73 struct radix_node *rn;
74 char hexbuf[HEXBUF_LEN];
76 printf("at_addroute: v=%s\n", prsockaddr(v_arg, hexbuf));
77 printf("at_addroute: n=%s\n", prsockaddr(n_arg, hexbuf));
78 printf("at_addroute: head=%p treenodes=%p\n", (void *)head,
81 rn = rn_addroute(v_arg, n_arg, head, treenodes);
83 printf("at_addroute: returns rn=%p\n", (void *)rn);
88 static struct radix_node *
89 at_matroute(void *v_arg, struct radix_node_head *head)
91 struct radix_node *rn;
92 char hexbuf[HEXBUF_LEN];
94 printf("at_matroute: v=%s\n", prsockaddr(v_arg, hexbuf));
95 printf("at_matroute: head=%p\n", (void *)head);
97 rn = rn_match(v_arg, head);
99 printf("at_matroute: returnr rn=%p\n", (void *)rn);
104 static struct radix_node *
105 at_lookup(void *v_arg, void *m_arg, struct radix_node_head *head)
107 struct radix_node *rn;
108 char hexbuf[HEXBUF_LEN];
110 printf("at_lookup: v=%s\n", prsockaddr(v_arg, hexbuf));
111 printf("at_lookup: n=%s\n", prsockaddr(m_arg, hexbuf));
112 printf("at_lookup: head=%p\n", (void *)head);
114 rn = rn_lookup(v_arg, m_arg, head);
116 printf("at_lookup: returns rn=%p\n", (void *)rn);
121 static struct radix_node *
122 at_delroute(void *v_arg, void *netmask_arg, struct radix_node_head *head)
124 struct radix_node *rn;
125 char hexbuf[HEXBUF_LEN];
127 printf("at_delroute: v=%s\n", prsockaddr(v_arg, hexbuf));
128 printf("at_delroute: n=%s\n", prsockaddr(netmask_arg, hexbuf));
129 printf("at_delroute: head=%p\n", (void *)head);
131 rn = rn_delete(v_arg, netmask_arg, head);
133 printf("at_delroute: returns rn=%p\n", (void *)rn);
139 * Initialize our routing tree with debugging hooks.
142 at_inithead(void **head, int off)
144 struct radix_node_head *rnh;
146 if (!rn_inithead(head, off))
150 rnh->rnh_addaddr = at_addroute;
151 rnh->rnh_deladdr = at_delroute;
152 rnh->rnh_matchaddr = at_matroute;
153 rnh->rnh_lookup = at_lookup;