at_rmx.c revision 15885
1/*
2 * Copyright 1994, 1995 Massachusetts Institute of Technology
3 *
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.
15 *
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.
28 *
29 * at_rmx.c,v 1.13 1995/05/30 08:09:31 rgrimes Exp
30 */
31
32/* This code generates debugging traces to the radix code */
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/kernel.h>
37#include <sys/queue.h>
38#include <sys/socket.h>
39#include <sys/socketvar.h>
40#include <sys/mbuf.h>
41#include <sys/syslog.h>
42
43#include <net/if.h>
44#include <net/route.h>
45
46#include <netatalk/at.h>
47#include <netatalk/at_extern.h>
48
49static char hexbuf[256];
50
51char *
52prsockaddr(void *v)
53{
54	char *bp = &hexbuf[0];
55	u_char *cp = v;
56
57	if (v) {
58		int len = *cp;
59		u_char *cplim = cp + len;
60
61		/* return: "(len) hexdump" */
62
63		bp += sprintf(bp, "(%d)", len);
64		for (cp++; cp < cplim && bp < hexbuf+252; cp++) {
65			*bp++ = "0123456789abcdef"[*cp / 16];
66			*bp++ = "0123456789abcdef"[*cp % 16];
67		}
68	} else {
69		bp+= sprintf(bp, "null");
70	}
71	*bp = '\0';
72
73	return &hexbuf[0];
74}
75
76static struct radix_node *
77at_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
78	    struct radix_node *treenodes)
79{
80	struct radix_node *rn;
81	struct sockaddr_at *dst = v_arg, *mask = n_arg;
82
83	printf("at_addroute: v=%s\n", prsockaddr(v_arg));
84	printf("at_addroute: n=%s\n", prsockaddr(n_arg));
85	printf("at_addroute: head=%x treenodes=%x\n", head, treenodes);
86
87	rn = rn_addroute(v_arg, n_arg, head, treenodes);
88
89	printf("at_addroute: returns rn=%x\n", rn);
90
91	return rn;
92}
93
94static struct radix_node *
95at_matroute(void *v_arg, struct radix_node_head *head)
96{
97	struct radix_node *rn;
98	struct sockaddr_at *dst = v_arg;
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
110static struct radix_node *
111at_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
126static struct radix_node *
127at_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 */
145int
146at_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
161