xref: /freebsd/sbin/ipf/libipf/remove_pool.c (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
141edb306SCy Schubert 
241edb306SCy Schubert /*
341edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
441edb306SCy Schubert  *
541edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert  *
741edb306SCy Schubert  * $Id$
841edb306SCy Schubert  */
941edb306SCy Schubert 
1041edb306SCy Schubert #include <fcntl.h>
1141edb306SCy Schubert #include <sys/ioctl.h>
1241edb306SCy Schubert #include "ipf.h"
1341edb306SCy Schubert #include "netinet/ip_lookup.h"
1441edb306SCy Schubert #include "netinet/ip_htable.h"
1541edb306SCy Schubert 
1641edb306SCy Schubert 
1741edb306SCy Schubert int
remove_pool(ip_pool_t * poolp,ioctlfunc_t iocfunc)18efeb8bffSCy Schubert remove_pool(ip_pool_t *poolp, ioctlfunc_t iocfunc)
1941edb306SCy Schubert {
2041edb306SCy Schubert 	iplookupop_t op;
2141edb306SCy Schubert 	ip_pool_t pool;
2241edb306SCy Schubert 
2341edb306SCy Schubert 	if (pool_open() == -1)
24*2582ae57SCy Schubert 		return (-1);
2541edb306SCy Schubert 
2641edb306SCy Schubert 	op.iplo_type = IPLT_POOL;
2741edb306SCy Schubert 	op.iplo_unit = poolp->ipo_unit;
2841edb306SCy Schubert 	strncpy(op.iplo_name, poolp->ipo_name, sizeof(op.iplo_name));
2941edb306SCy Schubert 	op.iplo_size = sizeof(pool);
3041edb306SCy Schubert 	op.iplo_struct = &pool;
3141edb306SCy Schubert 
3241edb306SCy Schubert 	bzero((char *)&pool, sizeof(pool));
3341edb306SCy Schubert 	pool.ipo_unit = poolp->ipo_unit;
3441edb306SCy Schubert 	strncpy(pool.ipo_name, poolp->ipo_name, sizeof(pool.ipo_name));
3541edb306SCy Schubert 	pool.ipo_flags = poolp->ipo_flags;
3641edb306SCy Schubert 
3741edb306SCy Schubert 	if (pool_ioctl(iocfunc, SIOCLOOKUPDELTABLE, &op)) {
3841edb306SCy Schubert 		if ((opts & OPT_DONOTHING) == 0) {
39*2582ae57SCy Schubert 			return (ipf_perror_fd(pool_fd(), iocfunc,
40*2582ae57SCy Schubert 					     "delete lookup pool"));
4141edb306SCy Schubert 		}
4241edb306SCy Schubert 	}
43*2582ae57SCy Schubert 	return (0);
4441edb306SCy Schubert }
45