xref: /titanic_41/usr/src/cmd/ipf/lib/common/remove_hashnode.c (revision e11c3f44f531fdff80941ce57c065d2ae861cefc)
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 #include "netinet/ip_lookup.h"
13 #include "netinet/ip_htable.h"
14 
15 static int hashfd = -1;
16 
17 
18 int remove_hashnode(unit, name, node, iocfunc)
19 int unit;
20 char *name;
21 iphtent_t *node;
22 ioctlfunc_t iocfunc;
23 {
24 	iplookupop_t op;
25 	iphtent_t ipe;
26 
27 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
28 		hashfd = open(IPLOOKUP_NAME, O_RDWR);
29 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
30 		return -1;
31 
32 	op.iplo_type = IPLT_HASH;
33 	op.iplo_unit = unit;
34 	op.iplo_size = sizeof(ipe);
35 	op.iplo_struct = &ipe;
36 	op.iplo_arg = 0;
37 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
38 
39 	bzero((char *)&ipe, sizeof(ipe));
40 	bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
41 	      sizeof(ipe.ipe_addr));
42 	bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
43 	      sizeof(ipe.ipe_mask));
44 
45 	if (opts & OPT_DEBUG) {
46 		printf("\t%s - ", inet_ntoa(ipe.ipe_addr.in4));
47 		printf("%s\n", inet_ntoa(ipe.ipe_mask.in4));
48 	}
49 
50 	if ((*iocfunc)(hashfd, SIOCLOOKUPDELNODE, &op))
51 		if (!(opts & OPT_DONOTHING)) {
52 			perror("remove_hash:SIOCLOOKUPDELNODE");
53 			return -1;
54 		}
55 	return 0;
56 }
57