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