removed old FreeS/WAN cvs revision entries
[strongswan.git] / src / libfreeswan / radij.h
1 /*
2 * RCSID $Id: radij.h,v 1.1 2004/03/15 20:35:25 as Exp $
3 */
4
5 /*
6 * This file is defived from ${SRC}/sys/net/radix.h of BSD 4.4lite
7 *
8 * Variable and procedure names have been modified so that they don't
9 * conflict with the original BSD code, as a small number of modifications
10 * have been introduced and we may want to reuse this code in BSD.
11 *
12 * The `j' in `radij' is pronounced as a voiceless guttural (like a Greek
13 * chi or a German ch sound (as `doch', not as in `milch'), or even a
14 * spanish j as in Juan. It is not as far back in the throat like
15 * the corresponding Hebrew sound, nor is it a soft breath like the English h.
16 * It has nothing to do with the Dutch ij sound.
17 *
18 * Here is the appropriate copyright notice:
19 */
20
21 /*
22 * Copyright (c) 1988, 1989, 1993
23 * The Regents of the University of California. All rights reserved.
24 *
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
27 * are met:
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 * 3. All advertising materials mentioning features or use of this software
34 * must display the following acknowledgement:
35 * This product includes software developed by the University of
36 * California, Berkeley and its contributors.
37 * 4. Neither the name of the University nor the names of its contributors
38 * may be used to endorse or promote products derived from this software
39 * without specific prior written permission.
40 *
41 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * @(#)radix.h 8.1 (Berkeley) 6/10/93
54 */
55
56 #ifndef _RADIJ_H_
57 #define _RADIJ_H_
58
59 /*
60 #define RJ_DEBUG
61 */
62
63 #ifdef __KERNEL__
64
65 #ifndef __P
66 #ifdef __STDC__
67 #define __P(x) x
68 #else
69 #define __P(x) ()
70 #endif
71 #endif
72
73 /*
74 * Radix search tree node layout.
75 */
76
77 struct radij_node
78 {
79 struct radij_mask *rj_mklist; /* list of masks contained in subtree */
80 struct radij_node *rj_p; /* parent */
81 short rj_b; /* bit offset; -1-index(netmask) */
82 char rj_bmask; /* node: mask for bit test*/
83 u_char rj_flags; /* enumerated next */
84 #define RJF_NORMAL 1 /* leaf contains normal route */
85 #define RJF_ROOT 2 /* leaf is root leaf for tree */
86 #define RJF_ACTIVE 4 /* This node is alive (for rtfree) */
87 union {
88 struct { /* leaf only data: */
89 caddr_t rj_Key; /* object of search */
90 caddr_t rj_Mask; /* netmask, if present */
91 struct radij_node *rj_Dupedkey;
92 } rj_leaf;
93 struct { /* node only data: */
94 int rj_Off; /* where to start compare */
95 struct radij_node *rj_L;/* progeny */
96 struct radij_node *rj_R;/* progeny */
97 }rj_node;
98 } rj_u;
99 #ifdef RJ_DEBUG
100 int rj_info;
101 struct radij_node *rj_twin;
102 struct radij_node *rj_ybro;
103 #endif
104 };
105
106 #define rj_dupedkey rj_u.rj_leaf.rj_Dupedkey
107 #define rj_key rj_u.rj_leaf.rj_Key
108 #define rj_mask rj_u.rj_leaf.rj_Mask
109 #define rj_off rj_u.rj_node.rj_Off
110 #define rj_l rj_u.rj_node.rj_L
111 #define rj_r rj_u.rj_node.rj_R
112
113 /*
114 * Annotations to tree concerning potential routes applying to subtrees.
115 */
116
117 extern struct radij_mask {
118 short rm_b; /* bit offset; -1-index(netmask) */
119 char rm_unused; /* cf. rj_bmask */
120 u_char rm_flags; /* cf. rj_flags */
121 struct radij_mask *rm_mklist; /* more masks to try */
122 caddr_t rm_mask; /* the mask */
123 int rm_refs; /* # of references to this struct */
124 } *rj_mkfreelist;
125
126 #define MKGet(m) {\
127 if (rj_mkfreelist) {\
128 m = rj_mkfreelist; \
129 rj_mkfreelist = (m)->rm_mklist; \
130 } else \
131 R_Malloc(m, struct radij_mask *, sizeof (*(m))); }\
132
133 #define MKFree(m) { (m)->rm_mklist = rj_mkfreelist; rj_mkfreelist = (m);}
134
135 struct radij_node_head {
136 struct radij_node *rnh_treetop;
137 int rnh_addrsize; /* permit, but not require fixed keys */
138 int rnh_pktsize; /* permit, but not require fixed keys */
139 #if 0
140 struct radij_node *(*rnh_addaddr) /* add based on sockaddr */
141 __P((void *v, void *mask,
142 struct radij_node_head *head, struct radij_node nodes[]));
143 #endif
144 int (*rnh_addaddr) /* add based on sockaddr */
145 __P((void *v, void *mask,
146 struct radij_node_head *head, struct radij_node nodes[]));
147 struct radij_node *(*rnh_addpkt) /* add based on packet hdr */
148 __P((void *v, void *mask,
149 struct radij_node_head *head, struct radij_node nodes[]));
150 #if 0
151 struct radij_node *(*rnh_deladdr) /* remove based on sockaddr */
152 __P((void *v, void *mask, struct radij_node_head *head));
153 #endif
154 int (*rnh_deladdr) /* remove based on sockaddr */
155 __P((void *v, void *mask, struct radij_node_head *head, struct radij_node **node));
156 struct radij_node *(*rnh_delpkt) /* remove based on packet hdr */
157 __P((void *v, void *mask, struct radij_node_head *head));
158 struct radij_node *(*rnh_matchaddr) /* locate based on sockaddr */
159 __P((void *v, struct radij_node_head *head));
160 struct radij_node *(*rnh_matchpkt) /* locate based on packet hdr */
161 __P((void *v, struct radij_node_head *head));
162 int (*rnh_walktree) /* traverse tree */
163 __P((struct radij_node_head *head, int (*f)(struct radij_node *rn, void *w), void *w));
164 struct radij_node rnh_nodes[3]; /* empty tree for common case */
165 };
166
167
168 #define Bcmp(a, b, n) memcmp(((caddr_t)(b)), ((caddr_t)(a)), (unsigned)(n))
169 #define Bcopy(a, b, n) memmove(((caddr_t)(b)), ((caddr_t)(a)), (unsigned)(n))
170 #define Bzero(p, n) memset((caddr_t)(p), 0, (unsigned)(n))
171 #define R_Malloc(p, t, n) ((p = (t) kmalloc((size_t)(n), GFP_ATOMIC)), Bzero((p),(n)))
172 #define Free(p) kfree((caddr_t)p);
173
174 void rj_init __P((void));
175 int rj_inithead __P((void **, int));
176 int rj_refines __P((void *, void *));
177 int rj_walktree __P((struct radij_node_head *head, int (*f)(struct radij_node *rn, void *w), void *w));
178 struct radij_node
179 *rj_addmask __P((void *, int, int)) /* , rgb */ ;
180 int /* * */ rj_addroute __P((void *, void *, struct radij_node_head *,
181 struct radij_node [2])) /* , rgb */ ;
182 int /* * */ rj_delete __P((void *, void *, struct radij_node_head *, struct radij_node **)) /* , rgb */ ;
183 struct radij_node /* rgb */
184 *rj_insert __P((void *, struct radij_node_head *, int *,
185 struct radij_node [2])),
186 *rj_match __P((void *, struct radij_node_head *)),
187 *rj_newpair __P((void *, int, struct radij_node[2])),
188 *rj_search __P((void *, struct radij_node *)),
189 *rj_search_m __P((void *, struct radij_node *, void *));
190
191 void rj_deltree(struct radij_node_head *);
192 void rj_delnodes(struct radij_node *);
193 void rj_free_mkfreelist(void);
194 int radijcleartree(void);
195 int radijcleanup(void);
196
197 extern struct radij_node_head *mask_rjhead;
198 extern int maj_keylen;
199 #endif /* __KERNEL__ */
200
201 #endif /* _RADIJ_H_ */