1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (C) 2002 by Darren Reed.
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
5*7c478bd9Sstevel@tonic-gate  *
6*7c478bd9Sstevel@tonic-gate  * $Id: remove_hash.c,v 1.1 2003/04/13 06:40:14 darrenr Exp $
7*7c478bd9Sstevel@tonic-gate  */
8*7c478bd9Sstevel@tonic-gate 
9*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
10*7c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
11*7c478bd9Sstevel@tonic-gate #include "ipf.h"
12*7c478bd9Sstevel@tonic-gate #include "netinet/ip_lookup.h"
13*7c478bd9Sstevel@tonic-gate #include "netinet/ip_htable.h"
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate static int hashfd = -1;
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate 
remove_hash(iphp,iocfunc)18*7c478bd9Sstevel@tonic-gate int remove_hash(iphp, iocfunc)
19*7c478bd9Sstevel@tonic-gate iphtable_t *iphp;
20*7c478bd9Sstevel@tonic-gate ioctlfunc_t iocfunc;
21*7c478bd9Sstevel@tonic-gate {
22*7c478bd9Sstevel@tonic-gate 	iplookupop_t op;
23*7c478bd9Sstevel@tonic-gate 	iphtable_t iph;
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
26*7c478bd9Sstevel@tonic-gate 		hashfd = open(IPLOOKUP_NAME, O_RDWR);
27*7c478bd9Sstevel@tonic-gate 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
28*7c478bd9Sstevel@tonic-gate 		return -1;
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 	op.iplo_type = IPLT_HASH;
31*7c478bd9Sstevel@tonic-gate 	op.iplo_unit = iphp->iph_unit;
32*7c478bd9Sstevel@tonic-gate 	strncpy(op.iplo_name, iphp->iph_name, sizeof(op.iplo_name));
33*7c478bd9Sstevel@tonic-gate 	if (*op.iplo_name == '\0')
34*7c478bd9Sstevel@tonic-gate 		op.iplo_arg = IPHASH_ANON;
35*7c478bd9Sstevel@tonic-gate 	op.iplo_size = sizeof(iph);
36*7c478bd9Sstevel@tonic-gate 	op.iplo_struct = &iph;
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate 	bzero((char *)&iph, sizeof(iph));
39*7c478bd9Sstevel@tonic-gate 	iph.iph_unit = iphp->iph_unit;
40*7c478bd9Sstevel@tonic-gate 	iph.iph_type = iphp->iph_type;
41*7c478bd9Sstevel@tonic-gate 	strncpy(iph.iph_name, iphp->iph_name, sizeof(iph.iph_name));
42*7c478bd9Sstevel@tonic-gate 	iph.iph_flags = iphp->iph_flags;
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 	if ((*iocfunc)(hashfd, SIOCLOOKUPDELTABLE, &op))
45*7c478bd9Sstevel@tonic-gate 		if ((opts & OPT_DONOTHING) == 0) {
46*7c478bd9Sstevel@tonic-gate 			perror("remove_hash:SIOCLOOKUPDELTABLE");
47*7c478bd9Sstevel@tonic-gate 			return -1;
48*7c478bd9Sstevel@tonic-gate 		}
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate 	return 0;
51*7c478bd9Sstevel@tonic-gate }
52