load_pool.c revision 145519
11590Srgrimes/* $FreeBSD: head/contrib/ipfilter/lib/load_pool.c 145519 2005-04-25 18:20:15Z darrenr $ */ 21590Srgrimes 31590Srgrimes/* 41590Srgrimes * Copyright (C) 2002 by Darren Reed. 51590Srgrimes * 61590Srgrimes * See the IPFILTER.LICENCE file for details on licencing. 71590Srgrimes * 81590Srgrimes * Id: load_pool.c,v 1.14.2.2 2005/02/01 02:44:06 darrenr Exp 91590Srgrimes */ 101590Srgrimes 111590Srgrimes#include <fcntl.h> 121590Srgrimes#include <sys/ioctl.h> 131590Srgrimes#include "ipf.h" 141590Srgrimes#include "netinet/ip_lookup.h" 151590Srgrimes#include "netinet/ip_pool.h" 161590Srgrimes 171590Srgrimesstatic int poolfd = -1; 181590Srgrimes 191590Srgrimes 201590Srgrimesint load_pool(plp, iocfunc) 211590Srgrimesip_pool_t *plp; 221590Srgrimesioctlfunc_t iocfunc; 231590Srgrimes{ 241590Srgrimes iplookupop_t op; 251590Srgrimes ip_pool_node_t *a; 261590Srgrimes ip_pool_t pool; 271590Srgrimes 281590Srgrimes if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0)) 291590Srgrimes poolfd = open(IPLOOKUP_NAME, O_RDWR); 3087674Smarkm if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0)) 3187674Smarkm return -1; 3287674Smarkm 3387674Smarkm op.iplo_unit = plp->ipo_unit; 341590Srgrimes op.iplo_type = IPLT_POOL; 3587674Smarkm op.iplo_arg = 0; 3628694Scharnier strncpy(op.iplo_name, plp->ipo_name, sizeof(op.iplo_name)); 371590Srgrimes op.iplo_size = sizeof(pool); 381590Srgrimes op.iplo_struct = &pool; 391590Srgrimes bzero((char *)&pool, sizeof(pool)); 401590Srgrimes strncpy(pool.ipo_name, plp->ipo_name, sizeof(pool.ipo_name)); 411590Srgrimes if (*plp->ipo_name == '\0') 42200462Sdelphij op.iplo_arg |= IPOOL_ANON; 43181922Sache 441590Srgrimes if ((opts & OPT_REMOVE) == 0) { 451590Srgrimes if ((*iocfunc)(poolfd, SIOCLOOKUPADDTABLE, &op)) 461590Srgrimes if ((opts & OPT_DONOTHING) == 0) { 471590Srgrimes perror("load_pool:SIOCLOOKUPADDTABLE"); 481590Srgrimes return -1; 498874Srgrimes } 501590Srgrimes } 51196652Sume 5297981Sjmallett if ((opts & OPT_VERBOSE) != 0) { 531590Srgrimes pool.ipo_list = plp->ipo_list; 54196652Sume printpool(&pool, bcopywrap, pool.ipo_name, opts); 5553073Sdavidn pool.ipo_list = NULL; 561590Srgrimes } 57196956Sdelphij 58196652Sume for (a = plp->ipo_list; a != NULL; a = a->ipn_next) 591590Srgrimes load_poolnode(plp->ipo_unit, plp->ipo_name, a, iocfunc); 6053073Sdavidn 6153073Sdavidn if ((opts & OPT_REMOVE) != 0) { 621590Srgrimes if ((*iocfunc)(poolfd, SIOCLOOKUPDELTABLE, &op)) 631590Srgrimes if ((opts & OPT_DONOTHING) == 0) { 641590Srgrimes perror("load_pool:SIOCLOOKUPDELTABLE"); 659987Swollman return -1; 66196652Sume } 671590Srgrimes } 681590Srgrimes return 0; 6953073Sdavidn} 7053073Sdavidn