xref: /titanic_41/usr/src/cmd/ipf/lib/common/remove_hashnode.c (revision 1ae0874509b6811fdde1dfd46f0d93fd09867a3f)
1 /*
2  * Copyright (C) 2002 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: remove_hashnode.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_hashnode(unit, name, node, iocfunc)
25 int unit;
26 char *name;
27 iphtent_t *node;
28 ioctlfunc_t iocfunc;
29 {
30 	iplookupop_t op;
31 	iphtent_t ipe;
32 
33 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
34 		hashfd = open(IPLOOKUP_NAME, O_RDWR);
35 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
36 		return -1;
37 
38 	op.iplo_type = IPLT_HASH;
39 	op.iplo_unit = unit;
40 	op.iplo_size = sizeof(ipe);
41 	op.iplo_struct = &ipe;
42 	op.iplo_arg = 0;
43 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
44 
45 	bzero((char *)&ipe, sizeof(ipe));
46 	bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
47 	      sizeof(ipe.ipe_addr));
48 	bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
49 	      sizeof(ipe.ipe_mask));
50 
51 	if (opts & OPT_DEBUG) {
52 		printf("\t%s - ", inet_ntoa(ipe.ipe_addr.in4));
53 		printf("%s\n", inet_ntoa(ipe.ipe_mask.in4));
54 	}
55 
56 	if ((*iocfunc)(hashfd, SIOCLOOKUPDELNODE, &op))
57 		if (!(opts & OPT_DONOTHING)) {
58 			perror("remove_hash:SIOCLOOKUPDELNODE");
59 			return -1;
60 		}
61 	return 0;
62 }
63