xref: /freebsd/sbin/ipf/libipf/remove_hash.c (revision 315ee00f)
1 
2 /*
3  * Copyright (C) 2012 by Darren Reed.
4  *
5  * See the IPFILTER.LICENCE file for details on licencing.
6  *
7  * $Id$
8  */
9 
10 #include <fcntl.h>
11 #include <sys/ioctl.h>
12 #include "ipf.h"
13 #include "netinet/ip_lookup.h"
14 #include "netinet/ip_htable.h"
15 
16 
17 int
18 remove_hash(iphtable_t *iphp, ioctlfunc_t iocfunc)
19 {
20 	iplookupop_t op;
21 	iphtable_t iph;
22 
23 	if (pool_open() == -1)
24 		return (-1);
25 
26 	op.iplo_type = IPLT_HASH;
27 	op.iplo_unit = iphp->iph_unit;
28 	strncpy(op.iplo_name, iphp->iph_name, sizeof(op.iplo_name));
29 	if (*op.iplo_name == '\0')
30 		op.iplo_arg = IPHASH_ANON;
31 	op.iplo_size = sizeof(iph);
32 	op.iplo_struct = &iph;
33 
34 	bzero((char *)&iph, sizeof(iph));
35 	iph.iph_unit = iphp->iph_unit;
36 	iph.iph_type = iphp->iph_type;
37 	strncpy(iph.iph_name, iphp->iph_name, sizeof(iph.iph_name));
38 	iph.iph_flags = iphp->iph_flags;
39 
40 	if (pool_ioctl(iocfunc, SIOCLOOKUPDELTABLE, &op)) {
41 		if ((opts & OPT_DONOTHING) == 0) {
42 			return (ipf_perror_fd(pool_fd(), iocfunc,
43 					     "remove lookup hash table"));
44 		}
45 	}
46 	return (0);
47 }
48