xref: /titanic_50/usr/src/cmd/ipf/lib/common/remove_hash.c (revision 3895f3e681d42b8122c8084f114c0d2f88dd7979)
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 #include "netinet/ip_lookup.h"
13 #include "netinet/ip_htable.h"
14 
15 static int hashfd = -1;
16 
17 
18 int remove_hash(iphp, iocfunc)
19 iphtable_t *iphp;
20 ioctlfunc_t iocfunc;
21 {
22 	iplookupop_t op;
23 	iphtable_t iph;
24 
25 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
26 		hashfd = open(IPLOOKUP_NAME, O_RDWR);
27 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
28 		return -1;
29 
30 	op.iplo_type = IPLT_HASH;
31 	op.iplo_unit = iphp->iph_unit;
32 	strncpy(op.iplo_name, iphp->iph_name, sizeof(op.iplo_name));
33 	if (*op.iplo_name == '\0')
34 		op.iplo_arg = IPHASH_ANON;
35 	op.iplo_size = sizeof(iph);
36 	op.iplo_struct = &iph;
37 
38 	bzero((char *)&iph, sizeof(iph));
39 	iph.iph_unit = iphp->iph_unit;
40 	iph.iph_type = iphp->iph_type;
41 	strncpy(iph.iph_name, iphp->iph_name, sizeof(iph.iph_name));
42 	iph.iph_flags = iphp->iph_flags;
43 
44 	if ((*iocfunc)(hashfd, SIOCLOOKUPDELTABLE, &op))
45 		if ((opts & OPT_DONOTHING) == 0) {
46 			perror("remove_hash:SIOCLOOKUPDELTABLE");
47 			return -1;
48 		}
49 
50 	return 0;
51 }
52