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