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