/* * © Copyright 1976, 2004 Hewlett-Packard Development Company, L.P. * * Confidential computer software. Valid license from HP and/or its * subsidiaries required for possession, use, or copying. * * Consistent with FAR 12.211 and 12.212, Commercial Computer Software, * Computer Software Documentation, and Technical Data for Commercial * Items are licensed to the U.S. Government under vendor's standard * commercial license. * * Neither HP nor any of its subsidiaries shall be liable for technical * or editorial errors or omissions contained herein. The information * in this document is provided "as is" without warranty of any kind * and is subject to change without notice. The warranties for HP * products are set forth in the express limited warranty statements * accompanying such products. Nothing herein should be construed as * constituting an additional warranty. */ /* * HISTORY */ /* * @(#)$RCSfile: radix.h,v $ $Revision: 4.2.12.3 $ (DEC) $Date: 2000/01/25 17:39:02 $ */ /* */ /* * (c) Copyright 1990, OPEN SOFTWARE FOUNDATION, INC. * ALL RIGHTS RESERVED */ /* * OSF/1 Release 1.0 */ /* * Copyright (c) 1988, 1989 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted provided * that: (1) source distributions retain this entire copyright notice and * comment, and (2) distributions including binaries display the following * acknowledgement: ``This product includes software developed by the * University of California, Berkeley and its contributors'' in the * documentation or other materials provided with the distribution and in * all advertising materials mentioning features or use of this software. * Neither the name of the University nor the names of its contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Base: radix.h 7.3 (Berkeley) 4/22/89 * Merged: radix.h 7.4 (Berkeley) 6/28/90 */ #ifndef _RADIX_H_ #define _RADIX_H_ #ifdef __cplusplus extern "C" { /* forward decls for C++ */ struct radix_mask; struct rad; #endif /* * Radix search tree node layout. */ struct radix_node { struct radix_mask *rn_mklist; /* list of masks contained in subtree */ struct radix_node *rn_p; /* parent */ short rn_b; /* bit offset; -1-index(netmask) */ char rn_bmask; /* node: mask for bit test*/ u_char rn_flags; /* enumerated next */ #define RNF_NORMAL 1 /* leaf contains normal route */ #define RNF_ROOT 2 /* leaf is root leaf for tree */ #define RNF_ACTIVE 4 /* This node is alive (for rtfree) */ union { struct { /* leaf only data: */ caddr_t rn_Key; /* object of search */ caddr_t rn_Mask; /* netmask, if present */ struct radix_node *rn_Dupedkey; } rn_leaf; struct { /* node only data: */ int rn_Off; /* where to start compare */ struct radix_node *rn_L;/* progeny */ struct radix_node *rn_R;/* progeny */ }rn_node; } rn_u; #ifdef RN_DEBUG int rn_info; struct radix_node *rn_twin; struct radix_node *rn_ybro; #endif }; #define MAXKEYLEN 32 #define rn_dupedkey rn_u.rn_leaf.rn_Dupedkey #define rn_key rn_u.rn_leaf.rn_Key #define rn_mask rn_u.rn_leaf.rn_Mask #define rn_off rn_u.rn_node.rn_Off #define rn_l rn_u.rn_node.rn_L #define rn_r rn_u.rn_node.rn_R /* * Annotations to tree concerning potential routes applying to subtrees. */ struct radix_mask { short rm_b; /* bit offset; -1-index(netmask) */ char rm_unused; /* cf. rn_bmask */ u_char rm_flags; /* cf. rn_flags */ struct radix_mask *rm_mklist; /* more masks to try */ caddr_t rm_mask; /* the mask */ int rm_refs; /* # of references to this struct */ }; #define MKGet(m, radid) \ RAD_MALLOC((m), struct radix_mask *, sizeof (*(m)), \ M_RTABLE, M_NOWAIT|M_ZERO, (radid)) #define MKFree(m) FREE((m), M_RTABLE) extern struct radix_node_head { struct radix_node_head *rnh_next; struct radix_node *rnh_treetop; int rnh_af; struct radix_node rnh_nodes[3]; } *radix_node_head; #ifndef _KERNEL #define Bcmp(a, b, n) bcmp(((char *)(a)), ((char *)(b)), (n)) #define Bzero(p, n) bzero((char *)(p), (int)(n)); #define R_Malloc(p, t, n) (p = (t) malloc((unsigned int)(n))) #define Free(p) free((char *)p); #else #define Bcmp(a, b, n) bcmp(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n)) #define Bcopy(a, b, n) bcopy(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n)) #define Bzero(p, n) bzero((caddr_t)(p), (unsigned)(n)); #define R_Malloc(p, t, n) NET_MALLOC(p, t, n, M_RTABLE, M_NOWAIT) #define Free(p) NET_FREE(p, M_RTABLE); /* the lock that protects the radix mask tree (AF_UNSPEC) */ extern simple_lock_data_t radix_mask_spin_lock; #define RADIX_MASK_SPIN_LOCKINIT() simple_lock_setup(&radix_mask_spin_lock, radix_mask_spin_li) #define RADIX_MASK_SPIN_LOCK() simple_lock(&radix_mask_spin_lock) #define RADIX_MASK_SPIN_UNLOCK() simple_unlock(&radix_mask_spin_lock) /* * Puts a valid radix_node_head in "head" if found, else NULL. * The "global" argument determines if a search should fall-back * to the global radix_node_head if no RAD-specific one exists. */ #define Radix_head_search(head, af, radid, global) \ /* struct radix_node_head *head; */ \ /* u_int af; */ \ /* int radid; */ \ /* int global; */ \ { \ struct rad *_rad; \ struct radix_node_head *_rnh; \ _rad = rad_id_to_rad((radid)); \ /* make sure RAD is valid */ \ if (_rad == NULL) { \ (head) = NULL; \ } else { \ _rnh = _rad->radix_node_head; \ /* Huh? Can we try the global one? */ \ if (_rnh == NULL && global) \ _rnh = radix_node_head; \ for (; _rnh && ((af) != _rnh->rnh_af);) \ _rnh = _rnh->rnh_next; \ (head) = _rnh; \ } \ } #endif #ifdef __cplusplus } #endif #endif