1 /*
2  * Copyright (C) 2002 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: load_hashnode.c,v 1.2 2003/04/26 04:55:11 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 load_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_arg = 0;
41 	op.iplo_size = sizeof(ipe);
42 	op.iplo_struct = &ipe;
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 	bcopy((char *)&node->ipe_group, (char *)&ipe.ipe_group,
51 	      sizeof(ipe.ipe_group));
52 
53 	if ((*iocfunc)(hashfd, SIOCLOOKUPADDNODE, &op))
54 		if (!(opts & OPT_DONOTHING)) {
55 			perror("load_hash:SIOCLOOKUPADDNODE");
56 			return -1;
57 		}
58 	return 0;
59 }
60