1 /* 2 * Copyright (c) 1988, 1989 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * @(#)radix.h 7.3 (Berkeley) 04/22/89 18 */ 19 20 /* 21 * Radix search tree node layout. 22 */ 23 24 struct radix_node { 25 struct radix_mask *rn_mklist; /* list of masks contained in subtree */ 26 struct radix_node *rn_p; /* parent */ 27 short rn_b; /* bit offset; -1-index(netmask) */ 28 char rn_bmask; /* node: mask for bit test*/ 29 u_char rn_flags; /* enumerated next */ 30 #define RNF_NORMAL 1 /* leaf contains normal route */ 31 #define RNF_ROOT 2 /* leaf is root leaf for tree */ 32 #define RNF_ACTIVE 4 /* This node is alive (for rtfree) */ 33 union { 34 struct { /* leaf only data: */ 35 caddr_t rn_Key; /* object of search */ 36 caddr_t rn_Mask; /* netmask, if present */ 37 struct radix_node *rn_Dupedkey; 38 } rn_leaf; 39 struct { /* node only data: */ 40 int rn_Off; /* where to start compare */ 41 struct radix_node *rn_L;/* progeny */ 42 struct radix_node *rn_R;/* progeny */ 43 }rn_node; 44 } rn_u; 45 #ifdef RN_DEBUG 46 int rn_info; 47 struct radix_node *rn_twin; 48 struct radix_node *rn_ybro; 49 #endif 50 }; 51 52 #define MAXKEYLEN 32 53 54 #define rn_dupedkey rn_u.rn_leaf.rn_Dupedkey 55 #define rn_key rn_u.rn_leaf.rn_Key 56 #define rn_mask rn_u.rn_leaf.rn_Mask 57 #define rn_off rn_u.rn_node.rn_Off 58 #define rn_l rn_u.rn_node.rn_L 59 #define rn_r rn_u.rn_node.rn_R 60 61 /* 62 * Annotations to tree concerning potential routes applying to subtrees. 63 */ 64 65 extern struct radix_mask { 66 short rm_b; /* bit offset; -1-index(netmask) */ 67 char rm_unused; /* cf. rn_bmask */ 68 u_char rm_flags; /* cf. rn_flags */ 69 struct radix_mask *rm_mklist; /* more masks to try */ 70 caddr_t rm_mask; /* the mask */ 71 int rm_refs; /* # of references to this struct */ 72 } *rn_mkfreelist; 73 74 #define MKGet(m) {\ 75 if (rn_mkfreelist) {\ 76 m = rn_mkfreelist; \ 77 rn_mkfreelist = (m)->rm_mklist; \ 78 } else \ 79 R_Malloc(m, struct radix_mask *, sizeof (*(m))); }\ 80 81 #define MKFree(m) { (m)->rm_mklist = rn_mkfreelist; rn_mkfreelist = (m);} 82 83 extern struct radix_node_head { 84 struct radix_node_head *rnh_next; 85 struct radix_node *rnh_treetop; 86 int rnh_af; 87 struct radix_node rnh_nodes[3]; 88 } *radix_node_head; 89 90 91 #ifndef KERNEL 92 #define Bcmp(a, b, n) bcmp(((char *)(a)), ((char *)(b)), (n)) 93 #define Bzero(p, n) bzero((char *)(p), (int)(n)); 94 #define R_Malloc(p, t, n) (p = (t) malloc((unsigned int)(n))) 95 #define Free(p) free((char *)p); 96 #else 97 #define Bcmp(a, b, n) bcmp(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n)) 98 #define Bcopy(a, b, n) bcopy(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n)) 99 #define Bzero(p, n) bzero((caddr_t)(p), (unsigned)(n)); 100 #define R_Malloc(p, t, n) (p = (t) malloc((unsigned long)(n), M_RTABLE, M_DONTWAIT)) 101 #define Free(p) free((caddr_t)p, M_RTABLE); 102 #endif /*KERNEL*/ 103