ip_lookup.c revision 1.2.4.3 1 1.2.4.3 yamt /* $NetBSD: ip_lookup.c,v 1.2.4.3 2012/10/30 17:22:19 yamt Exp $ */
2 1.2.4.2 yamt
3 1.2.4.2 yamt /*
4 1.2.4.3 yamt * Copyright (C) 2012 by Darren Reed.
5 1.2.4.2 yamt *
6 1.2.4.2 yamt * See the IPFILTER.LICENCE file for details on licencing.
7 1.2.4.2 yamt */
8 1.2.4.2 yamt #if defined(KERNEL) || defined(_KERNEL)
9 1.2.4.2 yamt # undef KERNEL
10 1.2.4.2 yamt # undef _KERNEL
11 1.2.4.2 yamt # define KERNEL 1
12 1.2.4.2 yamt # define _KERNEL 1
13 1.2.4.2 yamt #endif
14 1.2.4.2 yamt #if defined(__osf__)
15 1.2.4.2 yamt # define _PROTO_NET_H_
16 1.2.4.2 yamt #endif
17 1.2.4.2 yamt #include <sys/param.h>
18 1.2.4.2 yamt #if defined(__NetBSD__)
19 1.2.4.2 yamt # if (NetBSD >= 199905) && !defined(IPFILTER_LKM) && defined(_KERNEL)
20 1.2.4.2 yamt # include "opt_ipfilter.h"
21 1.2.4.2 yamt # endif
22 1.2.4.2 yamt #endif
23 1.2.4.2 yamt #include <sys/errno.h>
24 1.2.4.2 yamt #include <sys/types.h>
25 1.2.4.2 yamt #include <sys/time.h>
26 1.2.4.2 yamt #include <sys/file.h>
27 1.2.4.2 yamt #if __FreeBSD_version >= 220000 && defined(_KERNEL)
28 1.2.4.2 yamt # include <sys/fcntl.h>
29 1.2.4.2 yamt # include <sys/filio.h>
30 1.2.4.2 yamt #else
31 1.2.4.2 yamt # include <sys/ioctl.h>
32 1.2.4.2 yamt #endif
33 1.2.4.2 yamt #if !defined(_KERNEL)
34 1.2.4.2 yamt # include <stdio.h>
35 1.2.4.2 yamt # include <string.h>
36 1.2.4.2 yamt # include <stdlib.h>
37 1.2.4.2 yamt # define _KERNEL
38 1.2.4.2 yamt # ifdef __OpenBSD__
39 1.2.4.2 yamt struct file;
40 1.2.4.2 yamt # endif
41 1.2.4.2 yamt # include <sys/uio.h>
42 1.2.4.2 yamt # undef _KERNEL
43 1.2.4.2 yamt #endif
44 1.2.4.2 yamt #include <sys/socket.h>
45 1.2.4.2 yamt #include <net/if.h>
46 1.2.4.2 yamt #if defined(__FreeBSD__)
47 1.2.4.2 yamt # include <sys/cdefs.h>
48 1.2.4.2 yamt # include <sys/proc.h>
49 1.2.4.2 yamt #endif
50 1.2.4.2 yamt #if defined(_KERNEL)
51 1.2.4.2 yamt # include <sys/systm.h>
52 1.2.4.2 yamt # if !defined(__SVR4) && !defined(__svr4__)
53 1.2.4.2 yamt # include <sys/mbuf.h>
54 1.2.4.2 yamt # endif
55 1.2.4.2 yamt #else
56 1.2.4.2 yamt # include "ipf.h"
57 1.2.4.2 yamt #endif
58 1.2.4.2 yamt #include <netinet/in.h>
59 1.2.4.2 yamt
60 1.2.4.2 yamt #include "netinet/ip_compat.h"
61 1.2.4.2 yamt #include "netinet/ip_fil.h"
62 1.2.4.2 yamt #include "netinet/ip_lookup.h"
63 1.2.4.2 yamt #include "netinet/ip_pool.h"
64 1.2.4.2 yamt #include "netinet/ip_htable.h"
65 1.2.4.2 yamt #include "netinet/ip_dstlist.h"
66 1.2.4.2 yamt /* END OF INCLUDES */
67 1.2.4.2 yamt
68 1.2.4.2 yamt #if !defined(lint)
69 1.2.4.2 yamt #if defined(__NetBSD__)
70 1.2.4.2 yamt #include <sys/cdefs.h>
71 1.2.4.3 yamt __KERNEL_RCSID(0, "$NetBSD: ip_lookup.c,v 1.2.4.3 2012/10/30 17:22:19 yamt Exp $");
72 1.2.4.2 yamt #else
73 1.2.4.3 yamt static const char rcsid[] = "@(#)Id: ip_lookup.c,v 1.1.1.2 2012/07/22 13:45:21 darrenr Exp";
74 1.2.4.2 yamt #endif
75 1.2.4.2 yamt #endif
76 1.2.4.2 yamt
77 1.2.4.2 yamt /*
78 1.2.4.2 yamt * In this file, ip_pool.c, ip_htable.c and ip_dstlist.c, you will find the
79 1.2.4.2 yamt * range for unit is [-1,IPL_LOGMAX]. The -1 is considered to be a valid number
80 1.2.4.2 yamt * and represents a "wildcard" or "all" units (IPL_LOGALL). The reason for not
81 1.2.4.2 yamt * starting the numbering at 0 is because the numbers [0,IPL_LOGMAX] correspond
82 1.2.4.2 yamt * to the minor device number for their respective device. Thus where there is
83 1.2.4.2 yamt * array indexing on the unit, +1 is used to map [-1.IPL_LOGMAX] to
84 1.2.4.2 yamt * [0.POOL_LOOKUP_MAX].
85 1.2.4.2 yamt */
86 1.2.4.2 yamt static int ipf_lookup_addnode(ipf_main_softc_t *, void *, int);
87 1.2.4.2 yamt static int ipf_lookup_delnode(ipf_main_softc_t *, void *, int);
88 1.2.4.2 yamt static int ipf_lookup_addtable(ipf_main_softc_t *, void *);
89 1.2.4.2 yamt static int ipf_lookup_deltable(ipf_main_softc_t *, void *);
90 1.2.4.2 yamt static int ipf_lookup_stats(ipf_main_softc_t *, void *);
91 1.2.4.2 yamt static int ipf_lookup_flush(ipf_main_softc_t *, void *);
92 1.2.4.2 yamt static int ipf_lookup_iterate(ipf_main_softc_t *, void *, int, void *);
93 1.2.4.2 yamt static int ipf_lookup_deltok(ipf_main_softc_t *, void *, int, void *);
94 1.2.4.2 yamt
95 1.2.4.2 yamt #define MAX_BACKENDS 3
96 1.2.4.2 yamt static ipf_lookup_t *backends[MAX_BACKENDS] = {
97 1.2.4.2 yamt &ipf_pool_backend,
98 1.2.4.2 yamt &ipf_htable_backend,
99 1.2.4.2 yamt &ipf_dstlist_backend
100 1.2.4.2 yamt };
101 1.2.4.2 yamt
102 1.2.4.2 yamt
103 1.2.4.2 yamt typedef struct ipf_lookup_softc_s {
104 1.2.4.2 yamt void *ipf_back[MAX_BACKENDS];
105 1.2.4.2 yamt } ipf_lookup_softc_t;
106 1.2.4.2 yamt
107 1.2.4.2 yamt
108 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
109 1.2.4.2 yamt /* Function: ipf_lookup_init */
110 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
111 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
112 1.2.4.2 yamt /* */
113 1.2.4.2 yamt /* Initialise all of the subcomponents of the lookup infrstructure. */
114 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
115 1.2.4.2 yamt void *
116 1.2.4.2 yamt ipf_lookup_soft_create(ipf_main_softc_t *softc)
117 1.2.4.2 yamt {
118 1.2.4.2 yamt ipf_lookup_softc_t *softl;
119 1.2.4.2 yamt ipf_lookup_t **l;
120 1.2.4.2 yamt int i;
121 1.2.4.2 yamt
122 1.2.4.2 yamt KMALLOC(softl, ipf_lookup_softc_t *);
123 1.2.4.2 yamt if (softl == NULL)
124 1.2.4.2 yamt return NULL;
125 1.2.4.2 yamt
126 1.2.4.2 yamt bzero((char *)softl, sizeof(*softl));
127 1.2.4.2 yamt
128 1.2.4.2 yamt for (i = 0, l = backends; i < MAX_BACKENDS; i++, l++) {
129 1.2.4.2 yamt softl->ipf_back[i] = (*(*l)->ipfl_create)(softc);
130 1.2.4.2 yamt if (softl->ipf_back[i] == NULL) {
131 1.2.4.2 yamt ipf_lookup_soft_destroy(softc, softl);
132 1.2.4.2 yamt return NULL;
133 1.2.4.2 yamt }
134 1.2.4.2 yamt }
135 1.2.4.2 yamt
136 1.2.4.2 yamt return softl;
137 1.2.4.2 yamt }
138 1.2.4.2 yamt
139 1.2.4.2 yamt
140 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
141 1.2.4.2 yamt /* Function: ipf_lookup_soft_init */
142 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
143 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
144 1.2.4.2 yamt /* arg(I) - pointer to local context to use */
145 1.2.4.2 yamt /* */
146 1.2.4.2 yamt /* Initialise all of the subcomponents of the lookup infrstructure. */
147 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
148 1.2.4.2 yamt int
149 1.2.4.2 yamt ipf_lookup_soft_init(ipf_main_softc_t *softc, void *arg)
150 1.2.4.2 yamt {
151 1.2.4.2 yamt ipf_lookup_softc_t *softl = (ipf_lookup_softc_t *)arg;
152 1.2.4.2 yamt int err = 0;
153 1.2.4.2 yamt int i;
154 1.2.4.2 yamt
155 1.2.4.2 yamt for (i = 0; i < MAX_BACKENDS; i++) {
156 1.2.4.2 yamt err = (*backends[i]->ipfl_init)(softc, softl->ipf_back[i]);
157 1.2.4.2 yamt if (err != 0)
158 1.2.4.2 yamt break;
159 1.2.4.2 yamt }
160 1.2.4.2 yamt
161 1.2.4.2 yamt return err;
162 1.2.4.2 yamt }
163 1.2.4.2 yamt
164 1.2.4.2 yamt
165 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
166 1.2.4.2 yamt /* Function: ipf_lookup_soft_fini */
167 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
168 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
169 1.2.4.2 yamt /* arg(I) - pointer to local context to use */
170 1.2.4.2 yamt /* */
171 1.2.4.2 yamt /* Call the fini function in each backend to cleanup all allocated data. */
172 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
173 1.2.4.2 yamt int
174 1.2.4.2 yamt ipf_lookup_soft_fini(ipf_main_softc_t *softc, void *arg)
175 1.2.4.2 yamt {
176 1.2.4.2 yamt ipf_lookup_softc_t *softl = (ipf_lookup_softc_t *)arg;
177 1.2.4.2 yamt int i;
178 1.2.4.2 yamt
179 1.2.4.2 yamt for (i = 0; i < MAX_BACKENDS; i++) {
180 1.2.4.2 yamt if (softl->ipf_back[i] != NULL)
181 1.2.4.2 yamt (*backends[i]->ipfl_fini)(softc,
182 1.2.4.2 yamt softl->ipf_back[i]);
183 1.2.4.2 yamt }
184 1.2.4.2 yamt
185 1.2.4.2 yamt return 0;
186 1.2.4.2 yamt }
187 1.2.4.2 yamt
188 1.2.4.2 yamt
189 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
190 1.2.4.2 yamt /* Function: ipf_lookup_expire */
191 1.2.4.2 yamt /* Returns: Nil */
192 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
193 1.2.4.2 yamt /* */
194 1.2.4.2 yamt /* Step through each of the backends and call their expire functions, */
195 1.2.4.2 yamt /* allowing them to delete any lifetime limited data. */
196 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
197 1.2.4.2 yamt void
198 1.2.4.2 yamt ipf_lookup_expire(ipf_main_softc_t *softc)
199 1.2.4.2 yamt {
200 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
201 1.2.4.2 yamt int i;
202 1.2.4.2 yamt
203 1.2.4.2 yamt WRITE_ENTER(&softc->ipf_poolrw);
204 1.2.4.2 yamt for (i = 0; i < MAX_BACKENDS; i++)
205 1.2.4.2 yamt (*backends[i]->ipfl_expire)(softc, softl->ipf_back[i]);
206 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_poolrw);
207 1.2.4.2 yamt }
208 1.2.4.2 yamt
209 1.2.4.2 yamt
210 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
211 1.2.4.2 yamt /* Function: ipf_lookup_softc_destroy */
212 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
213 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
214 1.2.4.2 yamt /* arg(I) - pointer to local context to use */
215 1.2.4.2 yamt /* */
216 1.2.4.2 yamt /* Free up all pool related memory that has been allocated whilst IPFilter */
217 1.2.4.2 yamt /* has been running. Also, do any other deinitialisation required such */
218 1.2.4.2 yamt /* ipf_lookup_init() can be called again, safely. */
219 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
220 1.2.4.2 yamt void
221 1.2.4.2 yamt ipf_lookup_soft_destroy(ipf_main_softc_t *softc, void *arg)
222 1.2.4.2 yamt {
223 1.2.4.2 yamt ipf_lookup_softc_t *softl = (ipf_lookup_softc_t *)arg;
224 1.2.4.2 yamt int i;
225 1.2.4.2 yamt
226 1.2.4.2 yamt for (i = 0; i < MAX_BACKENDS; i++) {
227 1.2.4.2 yamt if (softl->ipf_back[i] != NULL)
228 1.2.4.2 yamt (*backends[i]->ipfl_destroy)(softc,
229 1.2.4.2 yamt softl->ipf_back[i]);
230 1.2.4.2 yamt }
231 1.2.4.2 yamt
232 1.2.4.2 yamt KFREE(softl);
233 1.2.4.2 yamt }
234 1.2.4.2 yamt
235 1.2.4.2 yamt
236 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
237 1.2.4.2 yamt /* Function: ipf_lookup_ioctl */
238 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
239 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
240 1.2.4.2 yamt /* arg(I) - pointer to local context to use */
241 1.2.4.2 yamt /* data(IO) - pointer to ioctl data to be copied to/from user */
242 1.2.4.2 yamt /* space. */
243 1.2.4.2 yamt /* cmd(I) - ioctl command number */
244 1.2.4.2 yamt /* mode(I) - file mode bits used with open */
245 1.2.4.2 yamt /* uid(I) - uid of process doing ioctl */
246 1.2.4.2 yamt /* ctx(I) - pointer that represents context for uid */
247 1.2.4.2 yamt /* */
248 1.2.4.2 yamt /* Handle ioctl commands sent to the ioctl device. For the most part, this */
249 1.2.4.2 yamt /* involves just calling another function to handle the specifics of each */
250 1.2.4.2 yamt /* command. */
251 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
252 1.2.4.2 yamt int
253 1.2.4.2 yamt ipf_lookup_ioctl(ipf_main_softc_t *softc, void *data, ioctlcmd_t cmd,
254 1.2.4.2 yamt int mode, int uid, void *ctx)
255 1.2.4.2 yamt {
256 1.2.4.2 yamt int err;
257 1.2.4.2 yamt SPL_INT(s);
258 1.2.4.2 yamt
259 1.2.4.2 yamt mode = mode; /* LINT */
260 1.2.4.2 yamt
261 1.2.4.2 yamt SPL_NET(s);
262 1.2.4.2 yamt
263 1.2.4.2 yamt switch (cmd)
264 1.2.4.2 yamt {
265 1.2.4.2 yamt case SIOCLOOKUPADDNODE :
266 1.2.4.2 yamt case SIOCLOOKUPADDNODEW :
267 1.2.4.2 yamt WRITE_ENTER(&softc->ipf_poolrw);
268 1.2.4.2 yamt err = ipf_lookup_addnode(softc, data, uid);
269 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_poolrw);
270 1.2.4.2 yamt break;
271 1.2.4.2 yamt
272 1.2.4.2 yamt case SIOCLOOKUPDELNODE :
273 1.2.4.2 yamt case SIOCLOOKUPDELNODEW :
274 1.2.4.2 yamt WRITE_ENTER(&softc->ipf_poolrw);
275 1.2.4.2 yamt err = ipf_lookup_delnode(softc, data, uid);
276 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_poolrw);
277 1.2.4.2 yamt break;
278 1.2.4.2 yamt
279 1.2.4.2 yamt case SIOCLOOKUPADDTABLE :
280 1.2.4.2 yamt WRITE_ENTER(&softc->ipf_poolrw);
281 1.2.4.2 yamt err = ipf_lookup_addtable(softc, data);
282 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_poolrw);
283 1.2.4.2 yamt break;
284 1.2.4.2 yamt
285 1.2.4.2 yamt case SIOCLOOKUPDELTABLE :
286 1.2.4.2 yamt WRITE_ENTER(&softc->ipf_poolrw);
287 1.2.4.2 yamt err = ipf_lookup_deltable(softc, data);
288 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_poolrw);
289 1.2.4.2 yamt break;
290 1.2.4.2 yamt
291 1.2.4.2 yamt case SIOCLOOKUPSTAT :
292 1.2.4.2 yamt case SIOCLOOKUPSTATW :
293 1.2.4.2 yamt WRITE_ENTER(&softc->ipf_poolrw);
294 1.2.4.2 yamt err = ipf_lookup_stats(softc, data);
295 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_poolrw);
296 1.2.4.2 yamt break;
297 1.2.4.2 yamt
298 1.2.4.2 yamt case SIOCLOOKUPFLUSH :
299 1.2.4.2 yamt WRITE_ENTER(&softc->ipf_poolrw);
300 1.2.4.2 yamt err = ipf_lookup_flush(softc, data);
301 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_poolrw);
302 1.2.4.2 yamt break;
303 1.2.4.2 yamt
304 1.2.4.2 yamt case SIOCLOOKUPITER :
305 1.2.4.2 yamt err = ipf_lookup_iterate(softc, data, uid, ctx);
306 1.2.4.2 yamt break;
307 1.2.4.2 yamt
308 1.2.4.2 yamt case SIOCIPFDELTOK :
309 1.2.4.2 yamt err = ipf_lookup_deltok(softc, data, uid, ctx);
310 1.2.4.2 yamt break;
311 1.2.4.2 yamt
312 1.2.4.2 yamt default :
313 1.2.4.2 yamt IPFERROR(50001);
314 1.2.4.2 yamt err = EINVAL;
315 1.2.4.2 yamt break;
316 1.2.4.2 yamt }
317 1.2.4.2 yamt SPL_X(s);
318 1.2.4.2 yamt return err;
319 1.2.4.2 yamt }
320 1.2.4.2 yamt
321 1.2.4.2 yamt
322 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
323 1.2.4.2 yamt /* Function: ipf_lookup_addnode */
324 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
325 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
326 1.2.4.2 yamt /* data(I) - pointer to data from ioctl call */
327 1.2.4.2 yamt /* */
328 1.2.4.2 yamt /* Add a new data node to a lookup structure. First, check to see if the */
329 1.2.4.2 yamt /* parent structure refered to by name exists and if it does, then go on to */
330 1.2.4.2 yamt /* add a node to it. */
331 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
332 1.2.4.2 yamt static int
333 1.2.4.2 yamt ipf_lookup_addnode(ipf_main_softc_t *softc, void *data, int uid)
334 1.2.4.2 yamt {
335 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
336 1.2.4.2 yamt iplookupop_t op;
337 1.2.4.2 yamt ipf_lookup_t **l;
338 1.2.4.2 yamt int err;
339 1.2.4.2 yamt int i;
340 1.2.4.2 yamt
341 1.2.4.2 yamt err = BCOPYIN(data, &op, sizeof(op));
342 1.2.4.2 yamt if (err != 0) {
343 1.2.4.2 yamt IPFERROR(50002);
344 1.2.4.2 yamt return EFAULT;
345 1.2.4.2 yamt }
346 1.2.4.2 yamt
347 1.2.4.2 yamt if ((op.iplo_unit < 0 || op.iplo_unit > IPL_LOGMAX) &&
348 1.2.4.2 yamt (op.iplo_unit != IPLT_ALL)) {
349 1.2.4.2 yamt IPFERROR(50003);
350 1.2.4.2 yamt return EINVAL;
351 1.2.4.2 yamt }
352 1.2.4.2 yamt
353 1.2.4.2 yamt op.iplo_name[sizeof(op.iplo_name) - 1] = '\0';
354 1.2.4.2 yamt
355 1.2.4.2 yamt for (i = 0, l = backends; i < MAX_BACKENDS; i++, l++) {
356 1.2.4.2 yamt if (op.iplo_type == (*l)->ipfl_type) {
357 1.2.4.2 yamt err = (*(*l)->ipfl_node_add)(softc,
358 1.2.4.2 yamt softl->ipf_back[i],
359 1.2.4.2 yamt &op, uid);
360 1.2.4.2 yamt break;
361 1.2.4.2 yamt }
362 1.2.4.2 yamt }
363 1.2.4.2 yamt
364 1.2.4.2 yamt if (i == MAX_BACKENDS) {
365 1.2.4.2 yamt IPFERROR(50012);
366 1.2.4.2 yamt err = EINVAL;
367 1.2.4.2 yamt }
368 1.2.4.2 yamt
369 1.2.4.2 yamt return err;
370 1.2.4.2 yamt }
371 1.2.4.2 yamt
372 1.2.4.2 yamt
373 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
374 1.2.4.2 yamt /* Function: ipf_lookup_delnode */
375 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
376 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
377 1.2.4.2 yamt /* data(I) - pointer to data from ioctl call */
378 1.2.4.2 yamt /* */
379 1.2.4.2 yamt /* Delete a node from a lookup table by first looking for the table it is */
380 1.2.4.2 yamt /* in and then deleting the entry that gets found. */
381 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
382 1.2.4.2 yamt static int
383 1.2.4.2 yamt ipf_lookup_delnode(ipf_main_softc_t *softc, void *data, int uid)
384 1.2.4.2 yamt {
385 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
386 1.2.4.2 yamt iplookupop_t op;
387 1.2.4.2 yamt ipf_lookup_t **l;
388 1.2.4.2 yamt int err;
389 1.2.4.2 yamt int i;
390 1.2.4.2 yamt
391 1.2.4.2 yamt err = BCOPYIN(data, &op, sizeof(op));
392 1.2.4.2 yamt if (err != 0) {
393 1.2.4.2 yamt IPFERROR(50042);
394 1.2.4.2 yamt return EFAULT;
395 1.2.4.2 yamt }
396 1.2.4.2 yamt
397 1.2.4.2 yamt if ((op.iplo_unit < 0 || op.iplo_unit > IPL_LOGMAX) &&
398 1.2.4.2 yamt (op.iplo_unit != IPLT_ALL)) {
399 1.2.4.2 yamt IPFERROR(50013);
400 1.2.4.2 yamt return EINVAL;
401 1.2.4.2 yamt }
402 1.2.4.2 yamt
403 1.2.4.2 yamt op.iplo_name[sizeof(op.iplo_name) - 1] = '\0';
404 1.2.4.2 yamt
405 1.2.4.2 yamt for (i = 0, l = backends; i < MAX_BACKENDS; i++, l++) {
406 1.2.4.2 yamt if (op.iplo_type == (*l)->ipfl_type) {
407 1.2.4.2 yamt err = (*(*l)->ipfl_node_del)(softc, softl->ipf_back[i],
408 1.2.4.2 yamt &op, uid);
409 1.2.4.2 yamt break;
410 1.2.4.2 yamt }
411 1.2.4.2 yamt }
412 1.2.4.2 yamt
413 1.2.4.2 yamt if (i == MAX_BACKENDS) {
414 1.2.4.2 yamt IPFERROR(50021);
415 1.2.4.2 yamt err = EINVAL;
416 1.2.4.2 yamt }
417 1.2.4.2 yamt return err;
418 1.2.4.2 yamt }
419 1.2.4.2 yamt
420 1.2.4.2 yamt
421 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
422 1.2.4.2 yamt /* Function: ipf_lookup_addtable */
423 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
424 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
425 1.2.4.2 yamt /* data(I) - pointer to data from ioctl call */
426 1.2.4.2 yamt /* */
427 1.2.4.2 yamt /* Create a new lookup table, if one doesn't already exist using the name */
428 1.2.4.2 yamt /* for this one. */
429 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
430 1.2.4.2 yamt static int
431 1.2.4.2 yamt ipf_lookup_addtable(ipf_main_softc_t *softc, void *data)
432 1.2.4.2 yamt {
433 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
434 1.2.4.2 yamt iplookupop_t op;
435 1.2.4.2 yamt ipf_lookup_t **l;
436 1.2.4.2 yamt int err, i;
437 1.2.4.2 yamt
438 1.2.4.2 yamt err = BCOPYIN(data, &op, sizeof(op));
439 1.2.4.2 yamt if (err != 0) {
440 1.2.4.2 yamt IPFERROR(50022);
441 1.2.4.2 yamt return EFAULT;
442 1.2.4.2 yamt }
443 1.2.4.2 yamt
444 1.2.4.2 yamt if ((op.iplo_unit < 0 || op.iplo_unit > IPL_LOGMAX) &&
445 1.2.4.2 yamt (op.iplo_unit != IPLT_ALL)) {
446 1.2.4.2 yamt IPFERROR(50023);
447 1.2.4.2 yamt return EINVAL;
448 1.2.4.2 yamt }
449 1.2.4.2 yamt
450 1.2.4.2 yamt op.iplo_name[sizeof(op.iplo_name) - 1] = '\0';
451 1.2.4.2 yamt
452 1.2.4.2 yamt for (i = 0, l = backends; i < MAX_BACKENDS; i++, l++) {
453 1.2.4.2 yamt if (op.iplo_type == (*l)->ipfl_type) {
454 1.2.4.2 yamt err = (*(*l)->ipfl_table_add)(softc,
455 1.2.4.2 yamt softl->ipf_back[i],
456 1.2.4.2 yamt &op);
457 1.2.4.2 yamt break;
458 1.2.4.2 yamt }
459 1.2.4.2 yamt }
460 1.2.4.2 yamt
461 1.2.4.2 yamt if (i == MAX_BACKENDS) {
462 1.2.4.2 yamt IPFERROR(50026);
463 1.2.4.2 yamt err = EINVAL;
464 1.2.4.2 yamt }
465 1.2.4.2 yamt
466 1.2.4.2 yamt /*
467 1.2.4.2 yamt * For anonymous pools, copy back the operation struct because in the
468 1.2.4.2 yamt * case of success it will contain the new table's name.
469 1.2.4.2 yamt */
470 1.2.4.2 yamt if ((err == 0) && ((op.iplo_arg & LOOKUP_ANON) != 0)) {
471 1.2.4.2 yamt err = BCOPYOUT(&op, data, sizeof(op));
472 1.2.4.2 yamt if (err != 0) {
473 1.2.4.2 yamt IPFERROR(50027);
474 1.2.4.2 yamt err = EFAULT;
475 1.2.4.2 yamt }
476 1.2.4.2 yamt }
477 1.2.4.2 yamt
478 1.2.4.2 yamt return err;
479 1.2.4.2 yamt }
480 1.2.4.2 yamt
481 1.2.4.2 yamt
482 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
483 1.2.4.2 yamt /* Function: ipf_lookup_deltable */
484 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
485 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
486 1.2.4.2 yamt /* data(I) - pointer to data from ioctl call */
487 1.2.4.2 yamt /* */
488 1.2.4.2 yamt /* Decodes ioctl request to remove a particular hash table or pool and */
489 1.2.4.2 yamt /* calls the relevant function to do the cleanup. */
490 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
491 1.2.4.2 yamt static int
492 1.2.4.2 yamt ipf_lookup_deltable(ipf_main_softc_t *softc, void *data)
493 1.2.4.2 yamt {
494 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
495 1.2.4.2 yamt iplookupop_t op;
496 1.2.4.2 yamt ipf_lookup_t **l;
497 1.2.4.2 yamt int err, i;
498 1.2.4.2 yamt
499 1.2.4.2 yamt err = BCOPYIN(data, &op, sizeof(op));
500 1.2.4.2 yamt if (err != 0) {
501 1.2.4.2 yamt IPFERROR(50028);
502 1.2.4.2 yamt return EFAULT;
503 1.2.4.2 yamt }
504 1.2.4.2 yamt
505 1.2.4.2 yamt if ((op.iplo_unit < 0 || op.iplo_unit > IPL_LOGMAX) &&
506 1.2.4.2 yamt (op.iplo_unit != IPLT_ALL)) {
507 1.2.4.2 yamt IPFERROR(50029);
508 1.2.4.2 yamt return EINVAL;
509 1.2.4.2 yamt }
510 1.2.4.2 yamt
511 1.2.4.2 yamt op.iplo_name[sizeof(op.iplo_name) - 1] = '\0';
512 1.2.4.2 yamt
513 1.2.4.2 yamt for (i = 0, l = backends; i < MAX_BACKENDS; i++, l++) {
514 1.2.4.2 yamt if (op.iplo_type == (*l)->ipfl_type) {
515 1.2.4.2 yamt err = (*(*l)->ipfl_table_del)(softc,
516 1.2.4.2 yamt softl->ipf_back[i],
517 1.2.4.2 yamt &op);
518 1.2.4.2 yamt break;
519 1.2.4.2 yamt }
520 1.2.4.2 yamt }
521 1.2.4.2 yamt
522 1.2.4.2 yamt if (i == MAX_BACKENDS) {
523 1.2.4.2 yamt IPFERROR(50030);
524 1.2.4.2 yamt err = EINVAL;
525 1.2.4.2 yamt }
526 1.2.4.2 yamt return err;
527 1.2.4.2 yamt }
528 1.2.4.2 yamt
529 1.2.4.2 yamt
530 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
531 1.2.4.2 yamt /* Function: ipf_lookup_stats */
532 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
533 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
534 1.2.4.2 yamt /* data(I) - pointer to data from ioctl call */
535 1.2.4.2 yamt /* */
536 1.2.4.2 yamt /* Copy statistical information from inside the kernel back to user space. */
537 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
538 1.2.4.2 yamt static int
539 1.2.4.2 yamt ipf_lookup_stats(ipf_main_softc_t *softc, void *data)
540 1.2.4.2 yamt {
541 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
542 1.2.4.2 yamt iplookupop_t op;
543 1.2.4.2 yamt ipf_lookup_t **l;
544 1.2.4.2 yamt int err;
545 1.2.4.2 yamt int i;
546 1.2.4.2 yamt
547 1.2.4.2 yamt err = BCOPYIN(data, &op, sizeof(op));
548 1.2.4.2 yamt if (err != 0) {
549 1.2.4.2 yamt IPFERROR(50031);
550 1.2.4.2 yamt return EFAULT;
551 1.2.4.2 yamt }
552 1.2.4.2 yamt
553 1.2.4.2 yamt if ((op.iplo_unit < 0 || op.iplo_unit > IPL_LOGMAX) &&
554 1.2.4.2 yamt (op.iplo_unit != IPLT_ALL)) {
555 1.2.4.2 yamt IPFERROR(50032);
556 1.2.4.2 yamt return EINVAL;
557 1.2.4.2 yamt }
558 1.2.4.2 yamt
559 1.2.4.2 yamt for (i = 0, l = backends; i < MAX_BACKENDS; i++, l++) {
560 1.2.4.2 yamt if (op.iplo_type == (*l)->ipfl_type) {
561 1.2.4.2 yamt err = (*(*l)->ipfl_stats_get)(softc,
562 1.2.4.2 yamt softl->ipf_back[i],
563 1.2.4.2 yamt &op);
564 1.2.4.2 yamt break;
565 1.2.4.2 yamt }
566 1.2.4.2 yamt }
567 1.2.4.2 yamt
568 1.2.4.2 yamt if (i == MAX_BACKENDS) {
569 1.2.4.2 yamt IPFERROR(50033);
570 1.2.4.2 yamt err = EINVAL;
571 1.2.4.2 yamt }
572 1.2.4.2 yamt
573 1.2.4.2 yamt return err;
574 1.2.4.2 yamt }
575 1.2.4.2 yamt
576 1.2.4.2 yamt
577 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
578 1.2.4.2 yamt /* Function: ipf_lookup_flush */
579 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
580 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
581 1.2.4.2 yamt /* data(I) - pointer to data from ioctl call */
582 1.2.4.2 yamt /* */
583 1.2.4.2 yamt /* A flush is called when we want to flush all the nodes from a particular */
584 1.2.4.2 yamt /* entry in the hash table/pool or want to remove all groups from those. */
585 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
586 1.2.4.2 yamt static int
587 1.2.4.2 yamt ipf_lookup_flush(ipf_main_softc_t *softc, void *data)
588 1.2.4.2 yamt {
589 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
590 1.2.4.2 yamt int err, unit, num, type, i;
591 1.2.4.2 yamt iplookupflush_t flush;
592 1.2.4.2 yamt ipf_lookup_t **l;
593 1.2.4.2 yamt
594 1.2.4.2 yamt err = BCOPYIN(data, &flush, sizeof(flush));
595 1.2.4.2 yamt if (err != 0) {
596 1.2.4.2 yamt IPFERROR(50034);
597 1.2.4.2 yamt return EFAULT;
598 1.2.4.2 yamt }
599 1.2.4.2 yamt
600 1.2.4.2 yamt unit = flush.iplf_unit;
601 1.2.4.2 yamt if ((unit < 0 || unit > IPL_LOGMAX) && (unit != IPLT_ALL)) {
602 1.2.4.2 yamt IPFERROR(50035);
603 1.2.4.2 yamt return EINVAL;
604 1.2.4.2 yamt }
605 1.2.4.2 yamt
606 1.2.4.2 yamt flush.iplf_name[sizeof(flush.iplf_name) - 1] = '\0';
607 1.2.4.2 yamt
608 1.2.4.2 yamt type = flush.iplf_type;
609 1.2.4.2 yamt IPFERROR(50036);
610 1.2.4.2 yamt err = EINVAL;
611 1.2.4.2 yamt num = 0;
612 1.2.4.2 yamt
613 1.2.4.2 yamt for (i = 0, l = backends; i < MAX_BACKENDS; i++, l++) {
614 1.2.4.2 yamt if (type == (*l)->ipfl_type || type == IPLT_ALL) {
615 1.2.4.2 yamt err = 0;
616 1.2.4.2 yamt num += (*(*l)->ipfl_flush)(softc,
617 1.2.4.2 yamt softl->ipf_back[i],
618 1.2.4.2 yamt &flush);
619 1.2.4.2 yamt }
620 1.2.4.2 yamt }
621 1.2.4.2 yamt
622 1.2.4.2 yamt if (err == 0) {
623 1.2.4.2 yamt flush.iplf_count = num;
624 1.2.4.2 yamt err = BCOPYOUT(&flush, data, sizeof(flush));
625 1.2.4.2 yamt if (err != 0) {
626 1.2.4.2 yamt IPFERROR(50037);
627 1.2.4.2 yamt err = EFAULT;
628 1.2.4.2 yamt }
629 1.2.4.2 yamt }
630 1.2.4.2 yamt return err;
631 1.2.4.2 yamt }
632 1.2.4.2 yamt
633 1.2.4.2 yamt
634 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
635 1.2.4.2 yamt /* Function: ipf_lookup_delref */
636 1.2.4.2 yamt /* Returns: void */
637 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
638 1.2.4.2 yamt /* type(I) - table type to operate on */
639 1.2.4.2 yamt /* ptr(I) - pointer to object to remove reference for */
640 1.2.4.2 yamt /* */
641 1.2.4.2 yamt /* This function organises calling the correct deref function for a given */
642 1.2.4.2 yamt /* type of object being passed into it. */
643 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
644 1.2.4.2 yamt void
645 1.2.4.2 yamt ipf_lookup_deref(ipf_main_softc_t *softc, int type, void *ptr)
646 1.2.4.2 yamt {
647 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
648 1.2.4.2 yamt int i;
649 1.2.4.2 yamt
650 1.2.4.2 yamt if (ptr == NULL)
651 1.2.4.2 yamt return;
652 1.2.4.2 yamt
653 1.2.4.2 yamt for (i = 0; i < MAX_BACKENDS; i++) {
654 1.2.4.2 yamt if (type == backends[i]->ipfl_type) {
655 1.2.4.2 yamt WRITE_ENTER(&softc->ipf_poolrw);
656 1.2.4.2 yamt (*backends[i]->ipfl_table_deref)(softc,
657 1.2.4.2 yamt softl->ipf_back[i],
658 1.2.4.2 yamt ptr);
659 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_poolrw);
660 1.2.4.2 yamt break;
661 1.2.4.2 yamt }
662 1.2.4.2 yamt }
663 1.2.4.2 yamt }
664 1.2.4.2 yamt
665 1.2.4.2 yamt
666 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
667 1.2.4.2 yamt /* Function: ipf_lookup_iterate */
668 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
669 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
670 1.2.4.2 yamt /* data(I) - pointer to data from ioctl call */
671 1.2.4.2 yamt /* uid(I) - uid of caller */
672 1.2.4.2 yamt /* ctx(I) - pointer to give the uid context */
673 1.2.4.2 yamt /* */
674 1.2.4.2 yamt /* Decodes ioctl request to step through either hash tables or pools. */
675 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
676 1.2.4.2 yamt static int
677 1.2.4.2 yamt ipf_lookup_iterate(ipf_main_softc_t *softc, void *data, int uid, void *ctx)
678 1.2.4.2 yamt {
679 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
680 1.2.4.2 yamt ipflookupiter_t iter;
681 1.2.4.2 yamt ipftoken_t *token;
682 1.2.4.2 yamt int err, i;
683 1.2.4.2 yamt SPL_INT(s);
684 1.2.4.2 yamt
685 1.2.4.2 yamt err = ipf_inobj(softc, data, NULL, &iter, IPFOBJ_LOOKUPITER);
686 1.2.4.2 yamt if (err != 0)
687 1.2.4.2 yamt return err;
688 1.2.4.2 yamt
689 1.2.4.2 yamt if (iter.ili_unit < IPL_LOGALL && iter.ili_unit > IPL_LOGMAX) {
690 1.2.4.2 yamt IPFERROR(50038);
691 1.2.4.2 yamt return EINVAL;
692 1.2.4.2 yamt }
693 1.2.4.2 yamt
694 1.2.4.2 yamt if (iter.ili_ival != IPFGENITER_LOOKUP) {
695 1.2.4.2 yamt IPFERROR(50039);
696 1.2.4.2 yamt return EINVAL;
697 1.2.4.2 yamt }
698 1.2.4.2 yamt
699 1.2.4.2 yamt SPL_SCHED(s);
700 1.2.4.2 yamt token = ipf_token_find(softc, iter.ili_key, uid, ctx);
701 1.2.4.2 yamt if (token == NULL) {
702 1.2.4.2 yamt SPL_X(s);
703 1.2.4.2 yamt IPFERROR(50040);
704 1.2.4.2 yamt return ESRCH;
705 1.2.4.2 yamt }
706 1.2.4.2 yamt
707 1.2.4.2 yamt for (i = 0; i < MAX_BACKENDS; i++) {
708 1.2.4.2 yamt if (iter.ili_type == backends[i]->ipfl_type) {
709 1.2.4.2 yamt err = (*backends[i]->ipfl_iter_next)(softc,
710 1.2.4.2 yamt softl->ipf_back[i],
711 1.2.4.2 yamt token, &iter);
712 1.2.4.2 yamt break;
713 1.2.4.2 yamt }
714 1.2.4.2 yamt }
715 1.2.4.2 yamt SPL_X(s);
716 1.2.4.2 yamt
717 1.2.4.2 yamt if (i == MAX_BACKENDS) {
718 1.2.4.2 yamt IPFERROR(50041);
719 1.2.4.2 yamt err = EINVAL;
720 1.2.4.2 yamt }
721 1.2.4.2 yamt
722 1.2.4.2 yamt WRITE_ENTER(&softc->ipf_tokens);
723 1.2.4.2 yamt ipf_token_deref(softc, token);
724 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_tokens);
725 1.2.4.2 yamt
726 1.2.4.2 yamt return err;
727 1.2.4.2 yamt }
728 1.2.4.2 yamt
729 1.2.4.2 yamt
730 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
731 1.2.4.2 yamt /* Function: ipf_lookup_iterderef */
732 1.2.4.2 yamt /* Returns: void */
733 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
734 1.2.4.2 yamt /* type(I) - backend type to iterate through */
735 1.2.4.2 yamt /* data(I) - pointer to data from ioctl call */
736 1.2.4.2 yamt /* */
737 1.2.4.2 yamt /* Decodes ioctl request to remove a particular hash table or pool and */
738 1.2.4.2 yamt /* calls the relevant function to do the cleanup. */
739 1.2.4.2 yamt /* Because each of the backend types has a different data structure, */
740 1.2.4.2 yamt /* iteration is limited to one type at a time (i.e. it is not permitted to */
741 1.2.4.2 yamt /* go on from pool types to hash types as part of the "get next".) */
742 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
743 1.2.4.2 yamt void
744 1.2.4.2 yamt ipf_lookup_iterderef(ipf_main_softc_t *softc, u_32_t type, void *data)
745 1.2.4.2 yamt {
746 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
747 1.2.4.2 yamt struct iplookupiterkey *lkey;
748 1.2.4.2 yamt iplookupiterkey_t key;
749 1.2.4.2 yamt int i;
750 1.2.4.2 yamt
751 1.2.4.2 yamt key.ilik_key = type;
752 1.2.4.2 yamt lkey = &key.ilik_unstr;
753 1.2.4.2 yamt
754 1.2.4.2 yamt if (lkey->ilik_ival != IPFGENITER_LOOKUP)
755 1.2.4.2 yamt return;
756 1.2.4.2 yamt
757 1.2.4.2 yamt WRITE_ENTER(&softc->ipf_poolrw);
758 1.2.4.2 yamt
759 1.2.4.2 yamt for (i = 0; i < MAX_BACKENDS; i++) {
760 1.2.4.3 yamt if (lkey->ilik_type == backends[i]->ipfl_type) {
761 1.2.4.2 yamt (*backends[i]->ipfl_iter_deref)(softc,
762 1.2.4.2 yamt softl->ipf_back[i],
763 1.2.4.2 yamt lkey->ilik_otype,
764 1.2.4.2 yamt lkey->ilik_unit,
765 1.2.4.2 yamt data);
766 1.2.4.2 yamt break;
767 1.2.4.2 yamt }
768 1.2.4.2 yamt }
769 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_poolrw);
770 1.2.4.2 yamt }
771 1.2.4.2 yamt
772 1.2.4.2 yamt
773 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
774 1.2.4.2 yamt /* Function: ipf_lookup_deltok */
775 1.2.4.2 yamt /* Returns: int - 0 = success, else error */
776 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
777 1.2.4.2 yamt /* data(I) - pointer to data from ioctl call */
778 1.2.4.2 yamt /* uid(I) - uid of caller */
779 1.2.4.2 yamt /* ctx(I) - pointer to give the uid context */
780 1.2.4.2 yamt /* */
781 1.2.4.2 yamt /* Deletes the token identified by the combination of (type,uid,ctx) */
782 1.2.4.2 yamt /* "key" is a combination of the table type, iterator type and the unit for */
783 1.2.4.2 yamt /* which the token was being used. */
784 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
785 1.2.4.2 yamt int
786 1.2.4.2 yamt ipf_lookup_deltok(ipf_main_softc_t *softc, void *data, int uid, void *ctx)
787 1.2.4.2 yamt {
788 1.2.4.2 yamt int error, key;
789 1.2.4.2 yamt SPL_INT(s);
790 1.2.4.2 yamt
791 1.2.4.2 yamt SPL_SCHED(s);
792 1.2.4.2 yamt error = BCOPYIN(data, &key, sizeof(key));
793 1.2.4.2 yamt if (error == 0)
794 1.2.4.2 yamt error = ipf_token_del(softc, key, uid, ctx);
795 1.2.4.2 yamt SPL_X(s);
796 1.2.4.2 yamt return error;
797 1.2.4.2 yamt }
798 1.2.4.2 yamt
799 1.2.4.2 yamt
800 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
801 1.2.4.2 yamt /* Function: ipf_lookup_res_num */
802 1.2.4.2 yamt /* Returns: void * - NULL = failure, else success. */
803 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
804 1.2.4.2 yamt /* unit(I) - device for which this is for */
805 1.2.4.2 yamt /* type(I) - type of lookup these parameters are for. */
806 1.2.4.2 yamt /* number(I) - table number to use when searching */
807 1.2.4.2 yamt /* funcptr(IO) - pointer to pointer for storing IP address */
808 1.2.4.2 yamt /* searching function. */
809 1.2.4.2 yamt /* */
810 1.2.4.2 yamt /* Search for the "table" number passed in amongst those configured for */
811 1.2.4.2 yamt /* that particular type. If the type is recognised then the function to */
812 1.2.4.2 yamt /* call to do the IP address search will be change, regardless of whether */
813 1.2.4.2 yamt /* or not the "table" number exists. */
814 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
815 1.2.4.2 yamt void *
816 1.2.4.2 yamt ipf_lookup_res_num(ipf_main_softc_t *softc, int unit, u_int type, u_int number,
817 1.2.4.2 yamt lookupfunc_t *funcptr)
818 1.2.4.2 yamt {
819 1.2.4.2 yamt char name[FR_GROUPLEN];
820 1.2.4.2 yamt
821 1.2.4.2 yamt #if defined(SNPRINTF) && defined(_KERNEL)
822 1.2.4.2 yamt SNPRINTF(name, sizeof(name), "%u", number);
823 1.2.4.2 yamt #else
824 1.2.4.2 yamt (void) sprintf(name, "%u", number);
825 1.2.4.2 yamt #endif
826 1.2.4.2 yamt
827 1.2.4.2 yamt return ipf_lookup_res_name(softc, unit, type, name, funcptr);
828 1.2.4.2 yamt }
829 1.2.4.2 yamt
830 1.2.4.2 yamt
831 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
832 1.2.4.2 yamt /* Function: ipf_lookup_res_name */
833 1.2.4.2 yamt /* Returns: void * - NULL = failure, else success. */
834 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
835 1.2.4.2 yamt /* unit(I) - device for which this is for */
836 1.2.4.2 yamt /* type(I) - type of lookup these parameters are for. */
837 1.2.4.2 yamt /* name(I) - table name to use when searching */
838 1.2.4.2 yamt /* funcptr(IO) - pointer to pointer for storing IP address */
839 1.2.4.2 yamt /* searching function. */
840 1.2.4.2 yamt /* */
841 1.2.4.2 yamt /* Search for the "table" number passed in amongst those configured for */
842 1.2.4.2 yamt /* that particular type. If the type is recognised then the function to */
843 1.2.4.3 yamt /* call to do the IP address search will be changed, regardless of whether */
844 1.2.4.2 yamt /* or not the "table" number exists. */
845 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
846 1.2.4.2 yamt void *
847 1.2.4.2 yamt ipf_lookup_res_name(ipf_main_softc_t *softc, int unit, u_int type, char *name,
848 1.2.4.2 yamt lookupfunc_t *funcptr)
849 1.2.4.2 yamt {
850 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
851 1.2.4.2 yamt ipf_lookup_t **l;
852 1.2.4.2 yamt void *ptr = NULL;
853 1.2.4.2 yamt int i;
854 1.2.4.2 yamt
855 1.2.4.2 yamt READ_ENTER(&softc->ipf_poolrw);
856 1.2.4.2 yamt
857 1.2.4.2 yamt for (i = 0, l = backends; i < MAX_BACKENDS; i++, l++) {
858 1.2.4.2 yamt if (type == (*l)->ipfl_type) {
859 1.2.4.2 yamt ptr = (*(*l)->ipfl_select_add_ref)(softl->ipf_back[i],
860 1.2.4.2 yamt unit, name);
861 1.2.4.2 yamt if (ptr != NULL && funcptr != NULL) {
862 1.2.4.2 yamt *funcptr = (*l)->ipfl_addr_find;
863 1.2.4.2 yamt }
864 1.2.4.2 yamt break;
865 1.2.4.2 yamt }
866 1.2.4.2 yamt }
867 1.2.4.2 yamt
868 1.2.4.2 yamt if (i == MAX_BACKENDS) {
869 1.2.4.2 yamt ptr = NULL;
870 1.2.4.2 yamt if (funcptr != NULL)
871 1.2.4.2 yamt *funcptr = NULL;
872 1.2.4.2 yamt }
873 1.2.4.2 yamt
874 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_poolrw);
875 1.2.4.2 yamt
876 1.2.4.2 yamt return ptr;
877 1.2.4.2 yamt }
878 1.2.4.2 yamt
879 1.2.4.2 yamt
880 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
881 1.2.4.2 yamt /* Function: ipf_lookup_find_htable */
882 1.2.4.2 yamt /* Returns: void * - NULL = failure, else success. */
883 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
884 1.2.4.2 yamt /* unit(I) - device for which this is for */
885 1.2.4.2 yamt /* name(I) - table name to use when searching */
886 1.2.4.2 yamt /* */
887 1.2.4.2 yamt /* To support the group-map feature, where a hash table maps address */
888 1.2.4.2 yamt /* networks to rule group numbers, we need to expose a function that uses */
889 1.2.4.2 yamt /* only the hash table backend. */
890 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
891 1.2.4.2 yamt void *
892 1.2.4.2 yamt ipf_lookup_find_htable(ipf_main_softc_t *softc, int unit, char *name)
893 1.2.4.2 yamt {
894 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
895 1.2.4.2 yamt ipf_lookup_t **l;
896 1.2.4.2 yamt void *tab = NULL;
897 1.2.4.2 yamt int i;
898 1.2.4.2 yamt
899 1.2.4.2 yamt READ_ENTER(&softc->ipf_poolrw);
900 1.2.4.2 yamt
901 1.2.4.2 yamt for (i = 0, l = backends; i < MAX_BACKENDS; i++, l++)
902 1.2.4.2 yamt if (IPLT_HASH == (*l)->ipfl_type) {
903 1.2.4.2 yamt tab = ipf_htable_find(softl->ipf_back[i], unit, name);
904 1.2.4.2 yamt break;
905 1.2.4.2 yamt }
906 1.2.4.2 yamt
907 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_poolrw);
908 1.2.4.2 yamt
909 1.2.4.2 yamt return tab;
910 1.2.4.2 yamt }
911 1.2.4.2 yamt
912 1.2.4.2 yamt
913 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
914 1.2.4.2 yamt /* Function: ipf_lookup_sync */
915 1.2.4.2 yamt /* Returns: void */
916 1.2.4.2 yamt /* Parameters: softc(I) - pointer to soft context main structure */
917 1.2.4.2 yamt /* */
918 1.2.4.2 yamt /* This function is the interface that the machine dependent sync functions */
919 1.2.4.2 yamt /* call when a network interface name change occurs. It then calls the sync */
920 1.2.4.2 yamt /* functions of the lookup implementations - if they have one. */
921 1.2.4.2 yamt /* ------------------------------------------------------------------------ */
922 1.2.4.2 yamt /*ARGSUSED*/
923 1.2.4.2 yamt void
924 1.2.4.2 yamt ipf_lookup_sync(ipf_main_softc_t *softc, void *ifp)
925 1.2.4.2 yamt {
926 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
927 1.2.4.2 yamt ipf_lookup_t **l;
928 1.2.4.2 yamt int i;
929 1.2.4.2 yamt
930 1.2.4.2 yamt READ_ENTER(&softc->ipf_poolrw);
931 1.2.4.2 yamt
932 1.2.4.2 yamt for (i = 0, l = backends; i < MAX_BACKENDS; i++, l++)
933 1.2.4.2 yamt if ((*l)->ipfl_sync != NULL)
934 1.2.4.2 yamt (*(*l)->ipfl_sync)(softc, softl->ipf_back[i]);
935 1.2.4.2 yamt
936 1.2.4.2 yamt RWLOCK_EXIT(&softc->ipf_poolrw);
937 1.2.4.2 yamt }
938 1.2.4.2 yamt
939 1.2.4.2 yamt
940 1.2.4.2 yamt #ifndef _KERNEL
941 1.2.4.2 yamt void
942 1.2.4.2 yamt ipf_lookup_dump(softc, arg)
943 1.2.4.2 yamt ipf_main_softc_t *softc;
944 1.2.4.2 yamt void *arg;
945 1.2.4.2 yamt {
946 1.2.4.2 yamt ipf_lookup_softc_t *softl = softc->ipf_lookup_soft;
947 1.2.4.2 yamt ipf_lookup_t **l;
948 1.2.4.2 yamt int i;
949 1.2.4.2 yamt
950 1.2.4.2 yamt for (i = 0, l = backends; i < MAX_BACKENDS; i++, l++)
951 1.2.4.2 yamt if (IPLT_POOL == (*l)->ipfl_type) {
952 1.2.4.2 yamt ipf_pool_dump(softc, softl->ipf_back[i]);
953 1.2.4.2 yamt break;
954 1.2.4.2 yamt }
955 1.2.4.2 yamt
956 1.2.4.2 yamt for (i = 0, l = backends; i < MAX_BACKENDS; i++, l++)
957 1.2.4.2 yamt if (IPLT_HASH == (*l)->ipfl_type) {
958 1.2.4.2 yamt ipf_htable_dump(softc, softl->ipf_back[i]);
959 1.2.4.2 yamt break;
960 1.2.4.2 yamt }
961 1.2.4.2 yamt }
962 1.2.4.2 yamt #endif
963