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$ 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 43194818Srwatson#if 0 44132042Srwatson#define HEXBUF_LEN 256 4515885Sjulian 46132042Srwatsonstatic const char * 47132042Srwatsonprsockaddr(void *v, char *hexbuf) 4815885Sjulian{ 4915885Sjulian char *bp = &hexbuf[0]; 5015885Sjulian u_char *cp = v; 5115885Sjulian 52127291Srwatson if (v != NULL) { 5315885Sjulian int len = *cp; 5415885Sjulian u_char *cplim = cp + len; 5515885Sjulian 5615885Sjulian /* return: "(len) hexdump" */ 5715885Sjulian 5815885Sjulian bp += sprintf(bp, "(%d)", len); 59165972Srwatson for (cp++; cp < cplim && bp < hexbuf + (HEXBUF_LEN - 4); 60165972Srwatson cp++) { 6115885Sjulian *bp++ = "0123456789abcdef"[*cp / 16]; 6215885Sjulian *bp++ = "0123456789abcdef"[*cp % 16]; 6315885Sjulian } 64165972Srwatson } else 6515885Sjulian bp+= sprintf(bp, "null"); 6615885Sjulian *bp = '\0'; 67132042Srwatson return (hexbuf); 6815885Sjulian} 69194818Srwatson#endif 7015885Sjulian 7115885Sjulianstatic struct radix_node * 7215885Sjulianat_addroute(void *v_arg, void *n_arg, struct radix_node_head *head, 7315885Sjulian struct radix_node *treenodes) 7415885Sjulian{ 7515885Sjulian 76194818Srwatson return (rn_addroute(v_arg, n_arg, head, treenodes)); 7715885Sjulian} 7815885Sjulian 7915885Sjulianstatic struct radix_node * 8015885Sjulianat_matroute(void *v_arg, struct radix_node_head *head) 8115885Sjulian{ 8215885Sjulian 83194818Srwatson return (rn_match(v_arg, head)); 8415885Sjulian} 8515885Sjulian 8615885Sjulianstatic struct radix_node * 8715885Sjulianat_lookup(void *v_arg, void *m_arg, struct radix_node_head *head) 8815885Sjulian{ 8915885Sjulian 90194818Srwatson return (rn_lookup(v_arg, m_arg, head)); 9115885Sjulian} 9215885Sjulian 93165972Srwatsonstatic struct radix_node * 9415885Sjulianat_delroute(void *v_arg, void *netmask_arg, struct radix_node_head *head) 9515885Sjulian{ 9615885Sjulian 97194818Srwatson return (rn_delete(v_arg, netmask_arg, head)); 9815885Sjulian} 9915885Sjulian 10015885Sjulian/* 10115885Sjulian * Initialize our routing tree with debugging hooks. 10215885Sjulian */ 10342571Seivindint 10415885Sjulianat_inithead(void **head, int off) 10515885Sjulian{ 10615885Sjulian struct radix_node_head *rnh; 10715885Sjulian 108165972Srwatson if (!rn_inithead(head, off)) 109165972Srwatson return (0); 11015885Sjulian 11115885Sjulian rnh = *head; 11215885Sjulian rnh->rnh_addaddr = at_addroute; 11315885Sjulian rnh->rnh_deladdr = at_delroute; 11415885Sjulian rnh->rnh_matchaddr = at_matroute; 11515885Sjulian rnh->rnh_lookup = at_lookup; 116165972Srwatson return (1); 11715885Sjulian} 118