1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * Copyright (C) 2002 by Darren Reed.
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * See the IPFILTER.LICENCE file for details on licencing.
5*7c478bd9Sstevel@tonic-gate *
6*7c478bd9Sstevel@tonic-gate * $Id: remove_hashnode.c,v 1.1 2003/04/13 06:40:14 darrenr Exp $
7*7c478bd9Sstevel@tonic-gate */
8*7c478bd9Sstevel@tonic-gate
9*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
10*7c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
11*7c478bd9Sstevel@tonic-gate #include "ipf.h"
12*7c478bd9Sstevel@tonic-gate #include "netinet/ip_lookup.h"
13*7c478bd9Sstevel@tonic-gate #include "netinet/ip_htable.h"
14*7c478bd9Sstevel@tonic-gate
15*7c478bd9Sstevel@tonic-gate static int hashfd = -1;
16*7c478bd9Sstevel@tonic-gate
17*7c478bd9Sstevel@tonic-gate
remove_hashnode(unit,name,node,iocfunc)18*7c478bd9Sstevel@tonic-gate int remove_hashnode(unit, name, node, iocfunc)
19*7c478bd9Sstevel@tonic-gate int unit;
20*7c478bd9Sstevel@tonic-gate char *name;
21*7c478bd9Sstevel@tonic-gate iphtent_t *node;
22*7c478bd9Sstevel@tonic-gate ioctlfunc_t iocfunc;
23*7c478bd9Sstevel@tonic-gate {
24*7c478bd9Sstevel@tonic-gate iplookupop_t op;
25*7c478bd9Sstevel@tonic-gate iphtent_t ipe;
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
28*7c478bd9Sstevel@tonic-gate hashfd = open(IPLOOKUP_NAME, O_RDWR);
29*7c478bd9Sstevel@tonic-gate if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
30*7c478bd9Sstevel@tonic-gate return -1;
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate op.iplo_type = IPLT_HASH;
33*7c478bd9Sstevel@tonic-gate op.iplo_unit = unit;
34*7c478bd9Sstevel@tonic-gate op.iplo_size = sizeof(ipe);
35*7c478bd9Sstevel@tonic-gate op.iplo_struct = &ipe;
36*7c478bd9Sstevel@tonic-gate op.iplo_arg = 0;
37*7c478bd9Sstevel@tonic-gate strncpy(op.iplo_name, name, sizeof(op.iplo_name));
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate bzero((char *)&ipe, sizeof(ipe));
40*7c478bd9Sstevel@tonic-gate bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
41*7c478bd9Sstevel@tonic-gate sizeof(ipe.ipe_addr));
42*7c478bd9Sstevel@tonic-gate bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
43*7c478bd9Sstevel@tonic-gate sizeof(ipe.ipe_mask));
44*7c478bd9Sstevel@tonic-gate
45*7c478bd9Sstevel@tonic-gate if (opts & OPT_DEBUG) {
46*7c478bd9Sstevel@tonic-gate printf("\t%s - ", inet_ntoa(ipe.ipe_addr.in4));
47*7c478bd9Sstevel@tonic-gate printf("%s\n", inet_ntoa(ipe.ipe_mask.in4));
48*7c478bd9Sstevel@tonic-gate }
49*7c478bd9Sstevel@tonic-gate
50*7c478bd9Sstevel@tonic-gate if ((*iocfunc)(hashfd, SIOCLOOKUPDELNODE, &op))
51*7c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING)) {
52*7c478bd9Sstevel@tonic-gate perror("remove_hash:SIOCLOOKUPDELNODE");
53*7c478bd9Sstevel@tonic-gate return -1;
54*7c478bd9Sstevel@tonic-gate }
55*7c478bd9Sstevel@tonic-gate return 0;
56*7c478bd9Sstevel@tonic-gate }
57