at_rmx.c revision 165972
1139827Simp/*-
215885Sjulian * Copyright 1994, 1995 Massachusetts Institute of Technology
315885Sjulian *
415885Sjulian * Permission to use, copy, modify, and distribute this software and
515885Sjulian * its documentation for any purpose and without fee is hereby
615885Sjulian * granted, provided that both the above copyright notice and this
715885Sjulian * permission notice appear in all copies, that both the above
815885Sjulian * copyright notice and this permission notice appear in all
915885Sjulian * supporting documentation, and that the name of M.I.T. not be used
1015885Sjulian * in advertising or publicity pertaining to distribution of the
1115885Sjulian * software without specific, written prior permission.  M.I.T. makes
1215885Sjulian * no representations about the suitability of this software for any
1315885Sjulian * purpose.  It is provided "as is" without express or implied
1415885Sjulian * warranty.
1515885Sjulian *
1615885Sjulian * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
1715885Sjulian * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
1815885Sjulian * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1915885Sjulian * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
2015885Sjulian * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2115885Sjulian * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2215885Sjulian * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2315885Sjulian * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2415885Sjulian * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2515885Sjulian * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2615885Sjulian * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2715885Sjulian * SUCH DAMAGE.
2815885Sjulian *
2915885Sjulian * at_rmx.c,v 1.13 1995/05/30 08:09:31 rgrimes Exp
30127291Srwatson * $FreeBSD: head/sys/netatalk/at_rmx.c 165972 2007-01-12 13:18:08Z rwatson $
3115885Sjulian */
3215885Sjulian
33165972Srwatson/* This code generates debugging traces to the radix code. */
3415885Sjulian
3515885Sjulian#include <sys/param.h>
3615885Sjulian#include <sys/systm.h>
3715885Sjulian#include <sys/socket.h>
3815885Sjulian
3915885Sjulian#include <net/route.h>
4015885Sjulian
41165972Srwatsonint	at_inithead(void **head, int off);
4242571Seivind
43132042Srwatson#define	HEXBUF_LEN	256
4415885Sjulian
45132042Srwatsonstatic const char *
46132042Srwatsonprsockaddr(void *v, char *hexbuf)
4715885Sjulian{
4815885Sjulian	char *bp = &hexbuf[0];
4915885Sjulian	u_char *cp = v;
5015885Sjulian
51127291Srwatson	if (v != NULL) {
5215885Sjulian		int len = *cp;
5315885Sjulian		u_char *cplim = cp + len;
5415885Sjulian
5515885Sjulian		/* return: "(len) hexdump" */
5615885Sjulian
5715885Sjulian		bp += sprintf(bp, "(%d)", len);
58165972Srwatson		for (cp++; cp < cplim && bp < hexbuf + (HEXBUF_LEN - 4);
59165972Srwatson		    cp++) {
6015885Sjulian			*bp++ = "0123456789abcdef"[*cp / 16];
6115885Sjulian			*bp++ = "0123456789abcdef"[*cp % 16];
6215885Sjulian		}
63165972Srwatson	} else
6415885Sjulian		bp+= sprintf(bp, "null");
6515885Sjulian	*bp = '\0';
66132042Srwatson	return (hexbuf);
6715885Sjulian}
6815885Sjulian
6915885Sjulianstatic struct radix_node *
7015885Sjulianat_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
7115885Sjulian	    struct radix_node *treenodes)
7215885Sjulian{
7315885Sjulian	struct radix_node *rn;
74132042Srwatson	char hexbuf[HEXBUF_LEN];
7515885Sjulian
76132042Srwatson	printf("at_addroute: v=%s\n", prsockaddr(v_arg, hexbuf));
77132042Srwatson	printf("at_addroute: n=%s\n", prsockaddr(n_arg, hexbuf));
78165972Srwatson	printf("at_addroute: head=%p treenodes=%p\n", (void *)head,
79165972Srwatson	    (void *)treenodes);
8015885Sjulian
8115885Sjulian	rn = rn_addroute(v_arg, n_arg, head, treenodes);
8215885Sjulian
8338373Sbde	printf("at_addroute: returns rn=%p\n", (void *)rn);
8415885Sjulian
85165972Srwatson	return (rn);
8615885Sjulian}
8715885Sjulian
8815885Sjulianstatic struct radix_node *
8915885Sjulianat_matroute(void *v_arg, struct radix_node_head *head)
9015885Sjulian{
9115885Sjulian	struct radix_node *rn;
92132042Srwatson	char hexbuf[HEXBUF_LEN];
9315885Sjulian
94132042Srwatson	printf("at_matroute: v=%s\n", prsockaddr(v_arg, hexbuf));
9538373Sbde	printf("at_matroute: head=%p\n", (void *)head);
9615885Sjulian
9715885Sjulian	rn = rn_match(v_arg, head);
9815885Sjulian
9938373Sbde	printf("at_matroute: returnr rn=%p\n", (void *)rn);
10015885Sjulian
101165972Srwatson	return (rn);
10215885Sjulian}
10315885Sjulian
10415885Sjulianstatic struct radix_node *
10515885Sjulianat_lookup(void *v_arg, void *m_arg, struct radix_node_head *head)
10615885Sjulian{
10715885Sjulian	struct radix_node *rn;
108132042Srwatson	char hexbuf[HEXBUF_LEN];
10915885Sjulian
110132042Srwatson	printf("at_lookup: v=%s\n", prsockaddr(v_arg, hexbuf));
111132042Srwatson	printf("at_lookup: n=%s\n", prsockaddr(m_arg, hexbuf));
11238373Sbde	printf("at_lookup: head=%p\n", (void *)head);
11315885Sjulian
11415885Sjulian	rn = rn_lookup(v_arg, m_arg, head);
11515885Sjulian
11638373Sbde	printf("at_lookup: returns rn=%p\n", (void *)rn);
11715885Sjulian
118165972Srwatson	return (rn);
11915885Sjulian}
12015885Sjulian
121165972Srwatsonstatic struct radix_node *
12215885Sjulianat_delroute(void *v_arg, void *netmask_arg, struct radix_node_head *head)
12315885Sjulian{
12415885Sjulian	struct radix_node *rn;
125132042Srwatson	char hexbuf[HEXBUF_LEN];
12615885Sjulian
127132042Srwatson	printf("at_delroute: v=%s\n", prsockaddr(v_arg, hexbuf));
128132042Srwatson	printf("at_delroute: n=%s\n", prsockaddr(netmask_arg, hexbuf));
12938373Sbde	printf("at_delroute: head=%p\n", (void *)head);
13015885Sjulian
13115885Sjulian	rn = rn_delete(v_arg, netmask_arg, head);
13215885Sjulian
13338373Sbde	printf("at_delroute: returns rn=%p\n", (void *)rn);
13415885Sjulian
135165972Srwatson	return (rn);
13615885Sjulian}
13715885Sjulian
13815885Sjulian/*
13915885Sjulian * Initialize our routing tree with debugging hooks.
14015885Sjulian */
14142571Seivindint
14215885Sjulianat_inithead(void **head, int off)
14315885Sjulian{
14415885Sjulian	struct radix_node_head *rnh;
14515885Sjulian
146165972Srwatson	if (!rn_inithead(head, off))
147165972Srwatson		return (0);
14815885Sjulian
14915885Sjulian	rnh = *head;
15015885Sjulian	rnh->rnh_addaddr = at_addroute;
15115885Sjulian	rnh->rnh_deladdr = at_delroute;
15215885Sjulian	rnh->rnh_matchaddr = at_matroute;
15315885Sjulian	rnh->rnh_lookup = at_lookup;
154165972Srwatson	return (1);
15515885Sjulian}
156