xref: /freebsd/sbin/ipf/libipf/remove_hashnode.c (revision 41edb306f05651fcaf6c74f9e3557f59f80292e1)
1*41edb306SCy Schubert /*	$FreeBSD$	*/
2*41edb306SCy Schubert 
3*41edb306SCy Schubert /*
4*41edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
5*41edb306SCy Schubert  *
6*41edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
7*41edb306SCy Schubert  *
8*41edb306SCy Schubert  * $Id$
9*41edb306SCy Schubert  */
10*41edb306SCy Schubert 
11*41edb306SCy Schubert #include <fcntl.h>
12*41edb306SCy Schubert #include <sys/ioctl.h>
13*41edb306SCy Schubert #include "ipf.h"
14*41edb306SCy Schubert #include "netinet/ip_lookup.h"
15*41edb306SCy Schubert #include "netinet/ip_htable.h"
16*41edb306SCy Schubert 
17*41edb306SCy Schubert 
18*41edb306SCy Schubert int
19*41edb306SCy Schubert remove_hashnode(unit, name, node, iocfunc)
20*41edb306SCy Schubert 	int unit;
21*41edb306SCy Schubert 	char *name;
22*41edb306SCy Schubert 	iphtent_t *node;
23*41edb306SCy Schubert 	ioctlfunc_t iocfunc;
24*41edb306SCy Schubert {
25*41edb306SCy Schubert 	iplookupop_t op;
26*41edb306SCy Schubert 	iphtent_t ipe;
27*41edb306SCy Schubert 
28*41edb306SCy Schubert 	if (pool_open() == -1)
29*41edb306SCy Schubert 		return -1;
30*41edb306SCy Schubert 
31*41edb306SCy Schubert 	op.iplo_type = IPLT_HASH;
32*41edb306SCy Schubert 	op.iplo_unit = unit;
33*41edb306SCy Schubert 	op.iplo_size = sizeof(ipe);
34*41edb306SCy Schubert 	op.iplo_struct = &ipe;
35*41edb306SCy Schubert 	op.iplo_arg = 0;
36*41edb306SCy Schubert 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
37*41edb306SCy Schubert 
38*41edb306SCy Schubert 	bzero((char *)&ipe, sizeof(ipe));
39*41edb306SCy Schubert 	bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
40*41edb306SCy Schubert 	      sizeof(ipe.ipe_addr));
41*41edb306SCy Schubert 	bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
42*41edb306SCy Schubert 	      sizeof(ipe.ipe_mask));
43*41edb306SCy Schubert 
44*41edb306SCy Schubert 	if (opts & OPT_DEBUG) {
45*41edb306SCy Schubert 		printf("\t%s - ", inet_ntoa(ipe.ipe_addr.in4));
46*41edb306SCy Schubert 		printf("%s\n", inet_ntoa(ipe.ipe_mask.in4));
47*41edb306SCy Schubert 	}
48*41edb306SCy Schubert 
49*41edb306SCy Schubert 	if (pool_ioctl(iocfunc, SIOCLOOKUPDELNODE, &op)) {
50*41edb306SCy Schubert 		if (!(opts & OPT_DONOTHING)) {
51*41edb306SCy Schubert 			return ipf_perror_fd(pool_fd(), iocfunc,
52*41edb306SCy Schubert 					     "remove lookup hash node");
53*41edb306SCy Schubert 		}
54*41edb306SCy Schubert 	}
55*41edb306SCy Schubert 	return 0;
56*41edb306SCy Schubert }
57