xref: /titanic_41/usr/src/cmd/ipf/lib/common/load_hashnode.c (revision 70025d765b044c6d8594bb965a2247a61e991a99)
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  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
9  * Use is subject to license terms.
10  */
11 
12 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13 
14 #include <fcntl.h>
15 #include <sys/ioctl.h>
16 #include "ipf.h"
17 
18 #if SOLARIS2 >= 10
19 #include "ip_lookup.h"
20 #include "ip_htable.h"
21 #else
22 #include "netinet/ip_lookup.h"
23 #include "netinet/ip_htable.h"
24 #endif
25 
26 static int hashfd = -1;
27 
28 
29 int load_hashnode(unit, name, node, iocfunc)
30 int unit;
31 char *name;
32 iphtent_t *node;
33 ioctlfunc_t iocfunc;
34 {
35 	iplookupop_t op;
36 	iphtent_t ipe;
37 
38 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
39 		hashfd = open(IPLOOKUP_NAME, O_RDWR);
40 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
41 		return -1;
42 
43 	op.iplo_type = IPLT_HASH;
44 	op.iplo_unit = unit;
45 	op.iplo_arg = 0;
46 	op.iplo_size = sizeof(ipe);
47 	op.iplo_struct = &ipe;
48 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
49 
50 	bzero((char *)&ipe, sizeof(ipe));
51 	ipe.ipe_family = node->ipe_family;
52 	bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
53 	      sizeof(ipe.ipe_addr));
54 	bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
55 	      sizeof(ipe.ipe_mask));
56 	bcopy((char *)&node->ipe_group, (char *)&ipe.ipe_group,
57 	      sizeof(ipe.ipe_group));
58 
59 	if ((*iocfunc)(hashfd, SIOCLOOKUPADDNODE, &op))
60 		if (!(opts & OPT_DONOTHING)) {
61 			perror("load_hash:SIOCLOOKUPADDNODE");
62 			return -1;
63 		}
64 	return 0;
65 }
66