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 $
12 #include <sys/ioctl.h>
14 #include "netinet/ip_lookup.h"
15 #include "netinet/ip_pool.h"
17 static int poolfd = -1;
20 int load_pool(plp, iocfunc)
28 if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
29 poolfd = open(IPLOOKUP_NAME, O_RDWR);
30 if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
33 op.iplo_unit = plp->ipo_unit;
34 op.iplo_type = IPLT_POOL;
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");
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);
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");