1 /* $NetBSD: remove_hashnode.c,v 1.2 2012/07/22 14:27:37 darrenr Exp $ */
2
3 /*
4 * Copyright (C) 2012 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 * Id: remove_hashnode.c,v 1.1.1.2 2012/07/22 13:44:42 darrenr Exp $
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
remove_hashnode(unit,name,node,iocfunc)19 remove_hashnode(unit, name, node, iocfunc)
20 int unit;
21 char *name;
22 iphtent_t *node;
23 ioctlfunc_t iocfunc;
24 {
25 iplookupop_t op;
26 iphtent_t ipe;
27
28 if (pool_open() == -1)
29 return -1;
30
31 op.iplo_type = IPLT_HASH;
32 op.iplo_unit = unit;
33 op.iplo_size = sizeof(ipe);
34 op.iplo_struct = &ipe;
35 op.iplo_arg = 0;
36 strncpy(op.iplo_name, name, sizeof(op.iplo_name));
37
38 bzero((char *)&ipe, sizeof(ipe));
39 bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
40 sizeof(ipe.ipe_addr));
41 bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
42 sizeof(ipe.ipe_mask));
43
44 if (opts & OPT_DEBUG) {
45 printf("\t%s - ", inet_ntoa(ipe.ipe_addr.in4));
46 printf("%s\n", inet_ntoa(ipe.ipe_mask.in4));
47 }
48
49 if (pool_ioctl(iocfunc, SIOCLOOKUPDELNODE, &op)) {
50 if (!(opts & OPT_DONOTHING)) {
51 return ipf_perror_fd(pool_fd(), iocfunc,
52 "remove lookup hash node");
53 }
54 }
55 return 0;
56 }
57