xref: /freebsd-src/sbin/ipf/libipf/remove_hash.c (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
141edb306SCy Schubert 
241edb306SCy Schubert /*
341edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
441edb306SCy Schubert  *
541edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert  *
741edb306SCy Schubert  * $Id$
841edb306SCy Schubert  */
941edb306SCy Schubert 
1041edb306SCy Schubert #include <fcntl.h>
1141edb306SCy Schubert #include <sys/ioctl.h>
1241edb306SCy Schubert #include "ipf.h"
1341edb306SCy Schubert #include "netinet/ip_lookup.h"
1441edb306SCy Schubert #include "netinet/ip_htable.h"
1541edb306SCy Schubert 
1641edb306SCy Schubert 
1741edb306SCy Schubert int
remove_hash(iphtable_t * iphp,ioctlfunc_t iocfunc)18efeb8bffSCy Schubert remove_hash(iphtable_t *iphp, ioctlfunc_t iocfunc)
1941edb306SCy Schubert {
2041edb306SCy Schubert 	iplookupop_t op;
2141edb306SCy Schubert 	iphtable_t iph;
2241edb306SCy Schubert 
2341edb306SCy Schubert 	if (pool_open() == -1)
24*2582ae57SCy Schubert 		return (-1);
2541edb306SCy Schubert 
2641edb306SCy Schubert 	op.iplo_type = IPLT_HASH;
2741edb306SCy Schubert 	op.iplo_unit = iphp->iph_unit;
2841edb306SCy Schubert 	strncpy(op.iplo_name, iphp->iph_name, sizeof(op.iplo_name));
2941edb306SCy Schubert 	if (*op.iplo_name == '\0')
3041edb306SCy Schubert 		op.iplo_arg = IPHASH_ANON;
3141edb306SCy Schubert 	op.iplo_size = sizeof(iph);
3241edb306SCy Schubert 	op.iplo_struct = &iph;
3341edb306SCy Schubert 
3441edb306SCy Schubert 	bzero((char *)&iph, sizeof(iph));
3541edb306SCy Schubert 	iph.iph_unit = iphp->iph_unit;
3641edb306SCy Schubert 	iph.iph_type = iphp->iph_type;
3741edb306SCy Schubert 	strncpy(iph.iph_name, iphp->iph_name, sizeof(iph.iph_name));
3841edb306SCy Schubert 	iph.iph_flags = iphp->iph_flags;
3941edb306SCy Schubert 
4041edb306SCy Schubert 	if (pool_ioctl(iocfunc, SIOCLOOKUPDELTABLE, &op)) {
4141edb306SCy Schubert 		if ((opts & OPT_DONOTHING) == 0) {
42*2582ae57SCy Schubert 			return (ipf_perror_fd(pool_fd(), iocfunc,
43*2582ae57SCy Schubert 					     "remove lookup hash table"));
4441edb306SCy Schubert 		}
4541edb306SCy Schubert 	}
46*2582ae57SCy Schubert 	return (0);
4741edb306SCy Schubert }
48