at_rmx.c revision 1.1 1 /* $NetBSD: at_rmx.c,v 1.1 1997/04/02 21:31:07 christos Exp $ */
2
3 /*
4 * Copyright 1994, 1995 Massachusetts Institute of Technology
5 *
6 * Permission to use, copy, modify, and distribute this software and
7 * its documentation for any purpose and without fee is hereby
8 * granted, provided that both the above copyright notice and this
9 * permission notice appear in all copies, that both the above
10 * copyright notice and this permission notice appear in all
11 * supporting documentation, and that the name of M.I.T. not be used
12 * in advertising or publicity pertaining to distribution of the
13 * software without specific, written prior permission. M.I.T. makes
14 * no representations about the suitability of this software for any
15 * purpose. It is provided "as is" without express or implied
16 * warranty.
17 *
18 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
19 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
22 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * at_rmx.c,v 1.13 1995/05/30 08:09:31 rgrimes Exp
32 */
33
34 /* This code generates debugging traces to the radix code */
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/queue.h>
40 #include <sys/socket.h>
41 #include <sys/socketvar.h>
42 #include <sys/mbuf.h>
43 #include <sys/syslog.h>
44
45 #include <net/if.h>
46 #include <net/route.h>
47
48 #include <netatalk/at.h>
49 #include <netatalk/at_extern.h>
50
51 static char hexbuf[256];
52
53 char *
54 prsockaddr(void *v)
55 {
56 char *bp = &hexbuf[0];
57 u_char *cp = v;
58
59 if (v) {
60 int len = *cp;
61 u_char *cplim = cp + len;
62
63 /* return: "(len) hexdump" */
64
65 bp += sprintf(bp, "(%d)", len);
66 for (cp++; cp < cplim && bp < hexbuf + 252; cp++) {
67 *bp++ = "0123456789abcdef"[*cp / 16];
68 *bp++ = "0123456789abcdef"[*cp % 16];
69 }
70 } else {
71 bp += sprintf(bp, "null");
72 }
73 *bp = '\0';
74
75 return &hexbuf[0];
76 }
77
78 static struct radix_node *
79 at_addroute(void *v_arg, void *n_arg, struct radix_node_head * head,
80 struct radix_node * treenodes)
81 {
82 struct radix_node *rn;
83
84 printf("at_addroute: v=%s\n", prsockaddr(v_arg));
85 printf("at_addroute: n=%s\n", prsockaddr(n_arg));
86 printf("at_addroute: head=%x treenodes=%x\n", head, treenodes);
87
88 rn = rn_addroute(v_arg, n_arg, head, treenodes);
89
90 printf("at_addroute: returns rn=%x\n", rn);
91
92 return rn;
93 }
94
95 static struct radix_node *
96 at_matroute(void *v_arg, struct radix_node_head * head)
97 {
98 struct radix_node *rn;
99
100 printf("at_matroute: v=%s\n", prsockaddr(v_arg));
101 printf("at_matroute: head=%x\n", head);
102
103 rn = rn_match(v_arg, head);
104
105 printf("at_matroute: returns rn=%x\n", rn);
106
107 return rn;
108 }
109
110 static struct radix_node *
111 at_lookup(void *v_arg, void *m_arg, struct radix_node_head * head)
112 {
113 struct radix_node *rn;
114
115 printf("at_lookup: v=%s\n", prsockaddr(v_arg));
116 printf("at_lookup: n=%s\n", prsockaddr(m_arg));
117 printf("at_lookup: head=%x\n", head);
118
119 rn = rn_lookup(v_arg, m_arg, head);
120
121 printf("at_lookup: returns rn=%x\n", rn);
122
123 return rn;
124 }
125
126 static struct radix_node *
127 at_delroute(void *v_arg, void *netmask_arg, struct radix_node_head * head)
128 {
129 struct radix_node *rn;
130
131 printf("at_delroute: v=%s\n", prsockaddr(v_arg));
132 printf("at_delroute: n=%s\n", prsockaddr(netmask_arg));
133 printf("at_delroute: head=%x\n", head);
134
135 rn = rn_delete(v_arg, netmask_arg, head);
136
137 printf("at_delroute: returns rn=%x\n", rn);
138
139 return rn;
140 }
141
142 /*
143 * Initialize our routing tree with debugging hooks.
144 */
145 int
146 at_inithead(void **head, int off)
147 {
148 struct radix_node_head *rnh;
149
150 if (!rn_inithead(head, off))
151 return 0;
152
153 rnh = *head;
154 rnh->rnh_addaddr = at_addroute;
155 rnh->rnh_deladdr = at_delroute;
156 rnh->rnh_matchaddr = at_matroute;
157 rnh->rnh_lookup = at_lookup;
158 return 1;
159 }
160