xref: /netbsd/sys/netatalk/at_rmx.c (revision bf9ec67e)
1 /*	$NetBSD: at_rmx.c,v 1.2 2001/11/13 00:00:58 lukem 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/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: at_rmx.c,v 1.2 2001/11/13 00:00:58 lukem Exp $");
38 
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/queue.h>
43 #include <sys/socket.h>
44 #include <sys/socketvar.h>
45 #include <sys/mbuf.h>
46 #include <sys/syslog.h>
47 
48 #include <net/if.h>
49 #include <net/route.h>
50 
51 #include <netatalk/at.h>
52 #include <netatalk/at_extern.h>
53 
54 static char     hexbuf[256];
55 
56 char           *
57 prsockaddr(void *v)
58 {
59 	char           *bp = &hexbuf[0];
60 	u_char         *cp = v;
61 
62 	if (v) {
63 		int             len = *cp;
64 		u_char         *cplim = cp + len;
65 
66 		/* return: "(len) hexdump" */
67 
68 		bp += sprintf(bp, "(%d)", len);
69 		for (cp++; cp < cplim && bp < hexbuf + 252; cp++) {
70 			*bp++ = "0123456789abcdef"[*cp / 16];
71 			*bp++ = "0123456789abcdef"[*cp % 16];
72 		}
73 	} else {
74 		bp += sprintf(bp, "null");
75 	}
76 	*bp = '\0';
77 
78 	return &hexbuf[0];
79 }
80 
81 static struct radix_node *
82 at_addroute(void *v_arg, void *n_arg, struct radix_node_head * head,
83 	    struct radix_node * treenodes)
84 {
85 	struct radix_node *rn;
86 
87 	printf("at_addroute: v=%s\n", prsockaddr(v_arg));
88 	printf("at_addroute: n=%s\n", prsockaddr(n_arg));
89 	printf("at_addroute: head=%x treenodes=%x\n", head, treenodes);
90 
91 	rn = rn_addroute(v_arg, n_arg, head, treenodes);
92 
93 	printf("at_addroute: returns rn=%x\n", rn);
94 
95 	return rn;
96 }
97 
98 static struct radix_node *
99 at_matroute(void *v_arg, struct radix_node_head * head)
100 {
101 	struct radix_node *rn;
102 
103 	printf("at_matroute: v=%s\n", prsockaddr(v_arg));
104 	printf("at_matroute: head=%x\n", head);
105 
106 	rn = rn_match(v_arg, head);
107 
108 	printf("at_matroute: returns rn=%x\n", rn);
109 
110 	return rn;
111 }
112 
113 static struct radix_node *
114 at_lookup(void *v_arg, void *m_arg, struct radix_node_head * head)
115 {
116 	struct radix_node *rn;
117 
118 	printf("at_lookup: v=%s\n", prsockaddr(v_arg));
119 	printf("at_lookup: n=%s\n", prsockaddr(m_arg));
120 	printf("at_lookup: head=%x\n", head);
121 
122 	rn = rn_lookup(v_arg, m_arg, head);
123 
124 	printf("at_lookup: returns rn=%x\n", rn);
125 
126 	return rn;
127 }
128 
129 static struct radix_node *
130 at_delroute(void *v_arg, void *netmask_arg, struct radix_node_head * head)
131 {
132 	struct radix_node *rn;
133 
134 	printf("at_delroute: v=%s\n", prsockaddr(v_arg));
135 	printf("at_delroute: n=%s\n", prsockaddr(netmask_arg));
136 	printf("at_delroute: head=%x\n", head);
137 
138 	rn = rn_delete(v_arg, netmask_arg, head);
139 
140 	printf("at_delroute: returns rn=%x\n", rn);
141 
142 	return rn;
143 }
144 
145 /*
146  * Initialize our routing tree with debugging hooks.
147  */
148 int
149 at_inithead(void **head, int off)
150 {
151 	struct radix_node_head *rnh;
152 
153 	if (!rn_inithead(head, off))
154 		return 0;
155 
156 	rnh = *head;
157 	rnh->rnh_addaddr = at_addroute;
158 	rnh->rnh_deladdr = at_delroute;
159 	rnh->rnh_matchaddr = at_matroute;
160 	rnh->rnh_lookup = at_lookup;
161 	return 1;
162 }
163