1*13885a66Sdarrenr /* $NetBSD: remove_hash.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_hash.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_hash(iphp,iocfunc)19bc4097aaSchristos remove_hash(iphp, iocfunc)
20bc4097aaSchristos iphtable_t *iphp;
21bc4097aaSchristos ioctlfunc_t iocfunc;
22bc4097aaSchristos {
23bc4097aaSchristos iplookupop_t op;
24bc4097aaSchristos iphtable_t iph;
25bc4097aaSchristos
26bc4097aaSchristos if (pool_open() == -1)
27bc4097aaSchristos return -1;
28bc4097aaSchristos
29bc4097aaSchristos op.iplo_type = IPLT_HASH;
30bc4097aaSchristos op.iplo_unit = iphp->iph_unit;
31bc4097aaSchristos strncpy(op.iplo_name, iphp->iph_name, sizeof(op.iplo_name));
32bc4097aaSchristos if (*op.iplo_name == '\0')
33bc4097aaSchristos op.iplo_arg = IPHASH_ANON;
34bc4097aaSchristos op.iplo_size = sizeof(iph);
35bc4097aaSchristos op.iplo_struct = &iph;
36bc4097aaSchristos
37bc4097aaSchristos bzero((char *)&iph, sizeof(iph));
38bc4097aaSchristos iph.iph_unit = iphp->iph_unit;
39bc4097aaSchristos iph.iph_type = iphp->iph_type;
40bc4097aaSchristos strncpy(iph.iph_name, iphp->iph_name, sizeof(iph.iph_name));
41bc4097aaSchristos iph.iph_flags = iphp->iph_flags;
42bc4097aaSchristos
43c9d5dc6cSdarrenr if (pool_ioctl(iocfunc, SIOCLOOKUPDELTABLE, &op)) {
44bc4097aaSchristos if ((opts & OPT_DONOTHING) == 0) {
45c9d5dc6cSdarrenr return ipf_perror_fd(pool_fd(), iocfunc,
46c9d5dc6cSdarrenr "remove lookup hash table");
47bc4097aaSchristos }
48c9d5dc6cSdarrenr }
49bc4097aaSchristos return 0;
50bc4097aaSchristos }
51