17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (C) 2002 by Darren Reed.
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
57c478bd9Sstevel@tonic-gate  *
6ab25eeb5Syz  * $Id: remove_poolnode.c,v 1.3 2003/11/22 10:14:36 darrenr Exp $
77c478bd9Sstevel@tonic-gate  */
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate #include <fcntl.h>
107c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
117c478bd9Sstevel@tonic-gate #include "ipf.h"
127c478bd9Sstevel@tonic-gate #include "netinet/ip_lookup.h"
13ab25eeb5Syz #include "netinet/ip_pool.h"
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate static int poolfd = -1;
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate 
remove_poolnode(unit,name,node,iocfunc)187c478bd9Sstevel@tonic-gate int remove_poolnode(unit, name, node, iocfunc)
197c478bd9Sstevel@tonic-gate int unit;
207c478bd9Sstevel@tonic-gate char *name;
217c478bd9Sstevel@tonic-gate ip_pool_node_t *node;
227c478bd9Sstevel@tonic-gate ioctlfunc_t iocfunc;
237c478bd9Sstevel@tonic-gate {
247c478bd9Sstevel@tonic-gate 	ip_pool_node_t pn;
257c478bd9Sstevel@tonic-gate 	iplookupop_t op;
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
287c478bd9Sstevel@tonic-gate 		poolfd = open(IPLOOKUP_NAME, O_RDWR);
297c478bd9Sstevel@tonic-gate 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
307c478bd9Sstevel@tonic-gate 		return -1;
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate 	op.iplo_unit = unit;
337c478bd9Sstevel@tonic-gate 	op.iplo_type = IPLT_POOL;
347c478bd9Sstevel@tonic-gate 	op.iplo_arg = 0;
357c478bd9Sstevel@tonic-gate 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
367c478bd9Sstevel@tonic-gate 	op.iplo_struct = &pn;
377c478bd9Sstevel@tonic-gate 	op.iplo_size = sizeof(pn);
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate 	bzero((char *)&pn, sizeof(pn));
407c478bd9Sstevel@tonic-gate 	bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr,
417c478bd9Sstevel@tonic-gate 	      sizeof(pn.ipn_addr));
427c478bd9Sstevel@tonic-gate 	bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask,
437c478bd9Sstevel@tonic-gate 	      sizeof(pn.ipn_mask));
447c478bd9Sstevel@tonic-gate 	pn.ipn_info = node->ipn_info;
457c478bd9Sstevel@tonic-gate 	strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name));
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate 	if ((*iocfunc)(poolfd, SIOCLOOKUPDELNODE, &op)) {
487c478bd9Sstevel@tonic-gate 		if ((opts & OPT_DONOTHING) == 0) {
497c478bd9Sstevel@tonic-gate 			perror("remove_pool:SIOCLOOKUPDELNODE");
507c478bd9Sstevel@tonic-gate 			return -1;
517c478bd9Sstevel@tonic-gate 		}
527c478bd9Sstevel@tonic-gate 	}
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate 	return 0;
557c478bd9Sstevel@tonic-gate }
56