remove_poolnode.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: remove_poolnode.c,v 1.3 2003/11/22 10:14:36 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 remove_poolnode(unit, name, node, iocfunc) 21int unit; 22char *name; 23ip_pool_node_t *node; 24ioctlfunc_t iocfunc; 25{ 26 ip_pool_node_t pn; 27 iplookupop_t op; 28 29 if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0)) 30 poolfd = open(IPLOOKUP_NAME, O_RDWR); 31 if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0)) 32 return -1; 33 34 op.iplo_unit = unit; 35 op.iplo_type = IPLT_POOL; 36 op.iplo_arg = 0; 37 strncpy(op.iplo_name, name, sizeof(op.iplo_name)); 38 op.iplo_struct = &pn; 39 op.iplo_size = sizeof(pn); 40 41 bzero((char *)&pn, sizeof(pn)); 42 bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr, 43 sizeof(pn.ipn_addr)); 44 bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask, 45 sizeof(pn.ipn_mask)); 46 pn.ipn_info = node->ipn_info; 47 strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name)); 48 49 if ((*iocfunc)(poolfd, SIOCLOOKUPDELNODE, &op)) { 50 if ((opts & OPT_DONOTHING) == 0) { 51 perror("remove_pool:SIOCLOOKUPDELNODE"); 52 return -1; 53 } 54 } 55 56 return 0; 57} 58