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