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_pool.h"
1541edb306SCy Schubert
1641edb306SCy Schubert
1741edb306SCy Schubert int
remove_poolnode(int unit,char * name,ip_pool_node_t * node,ioctlfunc_t iocfunc)18efeb8bffSCy Schubert remove_poolnode(int unit, char *name, ip_pool_node_t *node,
19efeb8bffSCy Schubert ioctlfunc_t iocfunc)
2041edb306SCy Schubert {
2141edb306SCy Schubert ip_pool_node_t pn;
2241edb306SCy Schubert iplookupop_t op;
2341edb306SCy Schubert
2441edb306SCy Schubert if (pool_open() == -1)
25*2582ae57SCy Schubert return (-1);
2641edb306SCy Schubert
2741edb306SCy Schubert op.iplo_unit = unit;
2841edb306SCy Schubert op.iplo_type = IPLT_POOL;
2941edb306SCy Schubert op.iplo_arg = 0;
3041edb306SCy Schubert strncpy(op.iplo_name, name, sizeof(op.iplo_name));
3141edb306SCy Schubert op.iplo_struct = &pn;
3241edb306SCy Schubert op.iplo_size = sizeof(pn);
3341edb306SCy Schubert
3441edb306SCy Schubert bzero((char *)&pn, sizeof(pn));
3541edb306SCy Schubert bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr,
3641edb306SCy Schubert sizeof(pn.ipn_addr));
3741edb306SCy Schubert bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask,
3841edb306SCy Schubert sizeof(pn.ipn_mask));
3941edb306SCy Schubert pn.ipn_info = node->ipn_info;
4041edb306SCy Schubert strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name));
4141edb306SCy Schubert
4241edb306SCy Schubert if (pool_ioctl(iocfunc, SIOCLOOKUPDELNODE, &op)) {
4341edb306SCy Schubert if ((opts & OPT_DONOTHING) == 0) {
44*2582ae57SCy Schubert return (ipf_perror_fd(pool_fd(), iocfunc,
45*2582ae57SCy Schubert "remove lookup pool node"));
4641edb306SCy Schubert }
4741edb306SCy Schubert }
4841edb306SCy Schubert
49*2582ae57SCy Schubert return (0);
5041edb306SCy Schubert }
51