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