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