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