Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / load_pool.c
blob3f09bfedf17130d9e02ada9e30bdd6a0fcad9a50
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2002-2005 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: load_pool.c,v 1.14.2.4 2006/06/16 17:21:06 darrenr Exp
9 */
11 #include <fcntl.h>
12 #include <sys/ioctl.h>
13 #include "ipf.h"
14 #include "netinet/ip_lookup.h"
15 #include "netinet/ip_pool.h"
17 static int poolfd = -1;
20 int load_pool(plp, iocfunc)
21 ip_pool_t *plp;
22 ioctlfunc_t iocfunc;
24 iplookupop_t op;
25 ip_pool_node_t *a;
26 ip_pool_t pool;
28 if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
29 poolfd = open(IPLOOKUP_NAME, O_RDWR);
30 if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
31 return -1;
33 op.iplo_unit = plp->ipo_unit;
34 op.iplo_type = IPLT_POOL;
35 op.iplo_arg = 0;
36 strncpy(op.iplo_name, plp->ipo_name, sizeof(op.iplo_name));
37 op.iplo_size = sizeof(pool);
38 op.iplo_struct = &pool;
39 bzero((char *)&pool, sizeof(pool));
40 strncpy(pool.ipo_name, plp->ipo_name, sizeof(pool.ipo_name));
41 if (plp->ipo_name[0] == '\0')
42 op.iplo_arg |= IPOOL_ANON;
44 if ((opts & OPT_REMOVE) == 0) {
45 if ((*iocfunc)(poolfd, SIOCLOOKUPADDTABLE, &op))
46 if ((opts & OPT_DONOTHING) == 0) {
47 perror("load_pool:SIOCLOOKUPADDTABLE");
48 return -1;
52 if (op.iplo_arg & IPOOL_ANON)
53 strncpy(pool.ipo_name, op.iplo_name, sizeof(pool.ipo_name));
55 if ((opts & OPT_VERBOSE) != 0) {
56 pool.ipo_list = plp->ipo_list;
57 printpool(&pool, bcopywrap, pool.ipo_name, opts);
58 pool.ipo_list = NULL;
61 for (a = plp->ipo_list; a != NULL; a = a->ipn_next)
62 load_poolnode(plp->ipo_unit, pool.ipo_name, a, iocfunc);
64 if ((opts & OPT_REMOVE) != 0) {
65 if ((*iocfunc)(poolfd, SIOCLOOKUPDELTABLE, &op))
66 if ((opts & OPT_DONOTHING) == 0) {
67 perror("load_pool:SIOCLOOKUPDELTABLE");
68 return -1;
71 return 0;