load_pool.c revision 145510
1/* $NetBSD$ */ 2 3/* 4 * Copyright (C) 2002 by Darren Reed. 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 * 8 * Id: load_pool.c,v 1.14.2.2 2005/02/01 02:44:06 darrenr Exp 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 17static int poolfd = -1; 18 19 20int load_pool(plp, iocfunc) 21ip_pool_t *plp; 22ioctlfunc_t iocfunc; 23{ 24 iplookupop_t op; 25 ip_pool_node_t *a; 26 ip_pool_t pool; 27 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; 32 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') 42 op.iplo_arg |= IPOOL_ANON; 43 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; 49 } 50 } 51 52 if ((opts & OPT_VERBOSE) != 0) { 53 pool.ipo_list = plp->ipo_list; 54 printpool(&pool, bcopywrap, pool.ipo_name, opts); 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, plp->ipo_name, a, iocfunc); 60 61 if ((opts & OPT_REMOVE) != 0) { 62 if ((*iocfunc)(poolfd, SIOCLOOKUPDELTABLE, &op)) 63 if ((opts & OPT_DONOTHING) == 0) { 64 perror("load_pool:SIOCLOOKUPDELTABLE"); 65 return -1; 66 } 67 } 68 return 0; 69} 70