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: load_hashnode.c,v 1.2 2003/04/26 04:55:11 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 
13*0Sstevel@tonic-gate #if SOLARIS2 >= 10
14*0Sstevel@tonic-gate #include "ip_lookup.h"
15*0Sstevel@tonic-gate #include "ip_htable.h"
16*0Sstevel@tonic-gate #else
17*0Sstevel@tonic-gate #include "netinet/ip_lookup.h"
18*0Sstevel@tonic-gate #include "netinet/ip_htable.h"
19*0Sstevel@tonic-gate #endif
20*0Sstevel@tonic-gate 
21*0Sstevel@tonic-gate static int hashfd = -1;
22*0Sstevel@tonic-gate 
23*0Sstevel@tonic-gate 
24*0Sstevel@tonic-gate int load_hashnode(unit, name, node, iocfunc)
25*0Sstevel@tonic-gate int unit;
26*0Sstevel@tonic-gate char *name;
27*0Sstevel@tonic-gate iphtent_t *node;
28*0Sstevel@tonic-gate ioctlfunc_t iocfunc;
29*0Sstevel@tonic-gate {
30*0Sstevel@tonic-gate 	iplookupop_t op;
31*0Sstevel@tonic-gate 	iphtent_t ipe;
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
34*0Sstevel@tonic-gate 		hashfd = open(IPLOOKUP_NAME, O_RDWR);
35*0Sstevel@tonic-gate 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
36*0Sstevel@tonic-gate 		return -1;
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate 	op.iplo_type = IPLT_HASH;
39*0Sstevel@tonic-gate 	op.iplo_unit = unit;
40*0Sstevel@tonic-gate 	op.iplo_arg = 0;
41*0Sstevel@tonic-gate 	op.iplo_size = sizeof(ipe);
42*0Sstevel@tonic-gate 	op.iplo_struct = &ipe;
43*0Sstevel@tonic-gate 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate 	bzero((char *)&ipe, sizeof(ipe));
46*0Sstevel@tonic-gate 	bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
47*0Sstevel@tonic-gate 	      sizeof(ipe.ipe_addr));
48*0Sstevel@tonic-gate 	bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
49*0Sstevel@tonic-gate 	      sizeof(ipe.ipe_mask));
50*0Sstevel@tonic-gate 	bcopy((char *)&node->ipe_group, (char *)&ipe.ipe_group,
51*0Sstevel@tonic-gate 	      sizeof(ipe.ipe_group));
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate 	if ((*iocfunc)(hashfd, SIOCLOOKUPADDNODE, &op))
54*0Sstevel@tonic-gate 		if (!(opts & OPT_DONOTHING)) {
55*0Sstevel@tonic-gate 			perror("load_hash:SIOCLOOKUPADDNODE");
56*0Sstevel@tonic-gate 			return -1;
57*0Sstevel@tonic-gate 		}
58*0Sstevel@tonic-gate 	return 0;
59*0Sstevel@tonic-gate }
60