xref: /freebsd/sbin/ipf/libipf/remove_poolnode.c (revision edf8578117e8844e02c0121147f45e4609b30680)
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_pool.h"
15 
16 
17 int
18 remove_poolnode(int unit, char *name, ip_pool_node_t *node,
19 	ioctlfunc_t iocfunc)
20 {
21 	ip_pool_node_t pn;
22 	iplookupop_t op;
23 
24 	if (pool_open() == -1)
25 		return (-1);
26 
27 	op.iplo_unit = unit;
28 	op.iplo_type = IPLT_POOL;
29 	op.iplo_arg = 0;
30 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
31 	op.iplo_struct = &pn;
32 	op.iplo_size = sizeof(pn);
33 
34 	bzero((char *)&pn, sizeof(pn));
35 	bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr,
36 	      sizeof(pn.ipn_addr));
37 	bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask,
38 	      sizeof(pn.ipn_mask));
39 	pn.ipn_info = node->ipn_info;
40 	strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name));
41 
42 	if (pool_ioctl(iocfunc, SIOCLOOKUPDELNODE, &op)) {
43 		if ((opts & OPT_DONOTHING) == 0) {
44 			return (ipf_perror_fd(pool_fd(), iocfunc,
45 					     "remove lookup pool node"));
46 		}
47 	}
48 
49 	return (0);
50 }
51