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_hashnode(int unit,char * name,iphtent_t * node,ioctlfunc_t iocfunc)18efeb8bffSCy Schubert remove_hashnode(int unit, char *name, iphtent_t *node, ioctlfunc_t iocfunc)
1941edb306SCy Schubert {
2041edb306SCy Schubert iplookupop_t op;
2141edb306SCy Schubert iphtent_t ipe;
2241edb306SCy Schubert
2341edb306SCy Schubert if (pool_open() == -1)
24*2582ae57SCy Schubert return (-1);
2541edb306SCy Schubert
2641edb306SCy Schubert op.iplo_type = IPLT_HASH;
2741edb306SCy Schubert op.iplo_unit = unit;
2841edb306SCy Schubert op.iplo_size = sizeof(ipe);
2941edb306SCy Schubert op.iplo_struct = &ipe;
3041edb306SCy Schubert op.iplo_arg = 0;
3141edb306SCy Schubert strncpy(op.iplo_name, name, sizeof(op.iplo_name));
3241edb306SCy Schubert
3341edb306SCy Schubert bzero((char *)&ipe, sizeof(ipe));
3441edb306SCy Schubert bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
3541edb306SCy Schubert sizeof(ipe.ipe_addr));
3641edb306SCy Schubert bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
3741edb306SCy Schubert sizeof(ipe.ipe_mask));
3841edb306SCy Schubert
3941edb306SCy Schubert if (opts & OPT_DEBUG) {
4041edb306SCy Schubert printf("\t%s - ", inet_ntoa(ipe.ipe_addr.in4));
4141edb306SCy Schubert printf("%s\n", inet_ntoa(ipe.ipe_mask.in4));
4241edb306SCy Schubert }
4341edb306SCy Schubert
4441edb306SCy Schubert if (pool_ioctl(iocfunc, SIOCLOOKUPDELNODE, &op)) {
4541edb306SCy Schubert if (!(opts & OPT_DONOTHING)) {
46*2582ae57SCy Schubert return (ipf_perror_fd(pool_fd(), iocfunc,
47*2582ae57SCy Schubert "remove lookup hash node"));
4841edb306SCy Schubert }
4941edb306SCy Schubert }
50*2582ae57SCy Schubert return (0);
5141edb306SCy Schubert }
52