xref: /freebsd/sbin/ipf/libipf/remove_hashnode.c (revision efeb8bffe34422937c7f8df836afb5b817366d16)
141edb306SCy Schubert /*	$FreeBSD$	*/
241edb306SCy Schubert 
341edb306SCy Schubert /*
441edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
541edb306SCy Schubert  *
641edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
741edb306SCy Schubert  *
841edb306SCy Schubert  * $Id$
941edb306SCy Schubert  */
1041edb306SCy Schubert 
1141edb306SCy Schubert #include <fcntl.h>
1241edb306SCy Schubert #include <sys/ioctl.h>
1341edb306SCy Schubert #include "ipf.h"
1441edb306SCy Schubert #include "netinet/ip_lookup.h"
1541edb306SCy Schubert #include "netinet/ip_htable.h"
1641edb306SCy Schubert 
1741edb306SCy Schubert 
1841edb306SCy Schubert int
19*efeb8bffSCy Schubert remove_hashnode(int unit, char *name, iphtent_t *node, ioctlfunc_t iocfunc)
2041edb306SCy Schubert {
2141edb306SCy Schubert 	iplookupop_t op;
2241edb306SCy Schubert 	iphtent_t ipe;
2341edb306SCy Schubert 
2441edb306SCy Schubert 	if (pool_open() == -1)
2541edb306SCy Schubert 		return -1;
2641edb306SCy Schubert 
2741edb306SCy Schubert 	op.iplo_type = IPLT_HASH;
2841edb306SCy Schubert 	op.iplo_unit = unit;
2941edb306SCy Schubert 	op.iplo_size = sizeof(ipe);
3041edb306SCy Schubert 	op.iplo_struct = &ipe;
3141edb306SCy Schubert 	op.iplo_arg = 0;
3241edb306SCy Schubert 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
3341edb306SCy Schubert 
3441edb306SCy Schubert 	bzero((char *)&ipe, sizeof(ipe));
3541edb306SCy Schubert 	bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
3641edb306SCy Schubert 	      sizeof(ipe.ipe_addr));
3741edb306SCy Schubert 	bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
3841edb306SCy Schubert 	      sizeof(ipe.ipe_mask));
3941edb306SCy Schubert 
4041edb306SCy Schubert 	if (opts & OPT_DEBUG) {
4141edb306SCy Schubert 		printf("\t%s - ", inet_ntoa(ipe.ipe_addr.in4));
4241edb306SCy Schubert 		printf("%s\n", inet_ntoa(ipe.ipe_mask.in4));
4341edb306SCy Schubert 	}
4441edb306SCy Schubert 
4541edb306SCy Schubert 	if (pool_ioctl(iocfunc, SIOCLOOKUPDELNODE, &op)) {
4641edb306SCy Schubert 		if (!(opts & OPT_DONOTHING)) {
4741edb306SCy Schubert 			return ipf_perror_fd(pool_fd(), iocfunc,
4841edb306SCy Schubert 					     "remove lookup hash node");
4941edb306SCy Schubert 		}
5041edb306SCy Schubert 	}
5141edb306SCy Schubert 	return 0;
5241edb306SCy Schubert }
53