1 /* $NetBSD: load_pool.c,v 1.1.1.1 2012/03/23 21:20:09 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2010 by Darren Reed. 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 * 8 * Id 9 */ 10 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" 16 17 18 int 19 load_pool(plp, iocfunc) 20 ip_pool_t *plp; 21 ioctlfunc_t iocfunc; 22 { 23 iplookupop_t op; 24 ip_pool_node_t *a; 25 ip_pool_t pool; 26 27 if (pool_open() == -1) 28 return -1; 29 30 op.iplo_unit = plp->ipo_unit; 31 op.iplo_type = IPLT_POOL; 32 op.iplo_arg = 0; 33 strncpy(op.iplo_name, plp->ipo_name, sizeof(op.iplo_name)); 34 op.iplo_size = sizeof(pool); 35 op.iplo_struct = &pool; 36 bzero((char *)&pool, sizeof(pool)); 37 strncpy(pool.ipo_name, plp->ipo_name, sizeof(pool.ipo_name)); 38 if (plp->ipo_name[0] == '\0') 39 op.iplo_arg |= IPOOL_ANON; 40 41 if ((opts & OPT_REMOVE) == 0) { 42 if (pool_ioctl(iocfunc, SIOCLOOKUPADDTABLE, &op)) 43 if ((opts & OPT_DONOTHING) == 0) { 44 perror("load_pool:SIOCLOOKUPADDTABLE"); 45 return -1; 46 } 47 } 48 49 if (op.iplo_arg & IPOOL_ANON) 50 strncpy(pool.ipo_name, op.iplo_name, sizeof(pool.ipo_name)); 51 52 if ((opts & OPT_VERBOSE) != 0) { 53 pool.ipo_list = plp->ipo_list; 54 (void) printpool(&pool, bcopywrap, pool.ipo_name, opts, NULL); 55 pool.ipo_list = NULL; 56 } 57 58 for (a = plp->ipo_list; a != NULL; a = a->ipn_next) 59 load_poolnode(plp->ipo_unit, pool.ipo_name, 60 a, 0, iocfunc); 61 62 if ((opts & OPT_REMOVE) != 0) { 63 if (pool_ioctl(iocfunc, SIOCLOOKUPDELTABLE, &op)) 64 if ((opts & OPT_DONOTHING) == 0) { 65 perror("load_pool:SIOCLOOKUPDELTABLE"); 66 return -1; 67 } 68 } 69 return 0; 70 } 71