141edb306SCy Schubert /*	$FreeBSD$	*/
241edb306SCy Schubert 
341edb306SCy Schubert /*
441edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
541edb306SCy Schubert  *
641edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
741edb306SCy Schubert  *
841edb306SCy Schubert  * $Id$
941edb306SCy Schubert  */
1041edb306SCy Schubert 
1141edb306SCy Schubert #include <fcntl.h>
1241edb306SCy Schubert #include <sys/ioctl.h>
1341edb306SCy Schubert #include "ipf.h"
1441edb306SCy Schubert #include "netinet/ip_lookup.h"
1541edb306SCy Schubert #include "netinet/ip_pool.h"
1641edb306SCy Schubert 
1741edb306SCy Schubert 
1841edb306SCy Schubert int
19efeb8bffSCy Schubert remove_poolnode(int unit, char *name, ip_pool_node_t *node,
20efeb8bffSCy Schubert 	ioctlfunc_t iocfunc)
2141edb306SCy Schubert {
2241edb306SCy Schubert 	ip_pool_node_t pn;
2341edb306SCy Schubert 	iplookupop_t op;
2441edb306SCy Schubert 
2541edb306SCy Schubert 	if (pool_open() == -1)
26*2582ae57SCy Schubert 		return(-1);
2741edb306SCy Schubert 
2841edb306SCy Schubert 	op.iplo_unit = unit;
2941edb306SCy Schubert 	op.iplo_type = IPLT_POOL;
3041edb306SCy Schubert 	op.iplo_arg = 0;
3141edb306SCy Schubert 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
3241edb306SCy Schubert 	op.iplo_struct = &pn;
3341edb306SCy Schubert 	op.iplo_size = sizeof(pn);
3441edb306SCy Schubert 
3541edb306SCy Schubert 	bzero((char *)&pn, sizeof(pn));
3641edb306SCy Schubert 	bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr,
3741edb306SCy Schubert 	      sizeof(pn.ipn_addr));
3841edb306SCy Schubert 	bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask,
3941edb306SCy Schubert 	      sizeof(pn.ipn_mask));
4041edb306SCy Schubert 	pn.ipn_info = node->ipn_info;
4141edb306SCy Schubert 	strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name));
4241edb306SCy Schubert 
4341edb306SCy Schubert 	if (pool_ioctl(iocfunc, SIOCLOOKUPDELNODE, &op)) {
4441edb306SCy Schubert 		if ((opts & OPT_DONOTHING) == 0) {
45*2582ae57SCy Schubert 			return(ipf_perror_fd(pool_fd(), iocfunc,
46*2582ae57SCy Schubert 					     "remove lookup pool node"));
4741edb306SCy Schubert 		}
4841edb306SCy Schubert 	}
4941edb306SCy Schubert 
50*2582ae57SCy Schubert 	return(0);
5141edb306SCy Schubert }
52