xref: /netbsd-src/external/bsd/ipf/dist/lib/remove_pool.c (revision 13885a665959c62f13a82b3caedf986eaa17aa31)
1*13885a66Sdarrenr /*	$NetBSD: remove_pool.c,v 1.2 2012/07/22 14:27:37 darrenr Exp $	*/
2bc4097aaSchristos 
3bc4097aaSchristos /*
4c9d5dc6cSdarrenr  * Copyright (C) 2012 by Darren Reed.
5bc4097aaSchristos  *
6bc4097aaSchristos  * See the IPFILTER.LICENCE file for details on licencing.
7bc4097aaSchristos  *
8*13885a66Sdarrenr  * Id: remove_pool.c,v 1.1.1.2 2012/07/22 13:44:42 darrenr Exp $
9bc4097aaSchristos  */
10bc4097aaSchristos 
11bc4097aaSchristos #include <fcntl.h>
12bc4097aaSchristos #include <sys/ioctl.h>
13bc4097aaSchristos #include "ipf.h"
14bc4097aaSchristos #include "netinet/ip_lookup.h"
15bc4097aaSchristos #include "netinet/ip_htable.h"
16bc4097aaSchristos 
17bc4097aaSchristos 
18bc4097aaSchristos int
remove_pool(poolp,iocfunc)19bc4097aaSchristos remove_pool(poolp, iocfunc)
20bc4097aaSchristos 	ip_pool_t *poolp;
21bc4097aaSchristos 	ioctlfunc_t iocfunc;
22bc4097aaSchristos {
23bc4097aaSchristos 	iplookupop_t op;
24bc4097aaSchristos 	ip_pool_t pool;
25bc4097aaSchristos 
26bc4097aaSchristos 	if (pool_open() == -1)
27bc4097aaSchristos 		return -1;
28bc4097aaSchristos 
29bc4097aaSchristos 	op.iplo_type = IPLT_POOL;
30bc4097aaSchristos 	op.iplo_unit = poolp->ipo_unit;
31bc4097aaSchristos 	strncpy(op.iplo_name, poolp->ipo_name, sizeof(op.iplo_name));
32bc4097aaSchristos 	op.iplo_size = sizeof(pool);
33bc4097aaSchristos 	op.iplo_struct = &pool;
34bc4097aaSchristos 
35bc4097aaSchristos 	bzero((char *)&pool, sizeof(pool));
36bc4097aaSchristos 	pool.ipo_unit = poolp->ipo_unit;
37bc4097aaSchristos 	strncpy(pool.ipo_name, poolp->ipo_name, sizeof(pool.ipo_name));
38bc4097aaSchristos 	pool.ipo_flags = poolp->ipo_flags;
39bc4097aaSchristos 
40c9d5dc6cSdarrenr 	if (pool_ioctl(iocfunc, SIOCLOOKUPDELTABLE, &op)) {
41bc4097aaSchristos 		if ((opts & OPT_DONOTHING) == 0) {
42c9d5dc6cSdarrenr 			return ipf_perror_fd(pool_fd(), iocfunc,
43c9d5dc6cSdarrenr 					     "delete lookup pool");
44bc4097aaSchristos 		}
45c9d5dc6cSdarrenr 	}
46bc4097aaSchristos 	return 0;
47bc4097aaSchristos }
48