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