xref: /titanic_51/usr/src/cmd/ipf/lib/common/load_poolnode.c (revision ea8dc4b6d2251b437950c0056bc626b311c73c27)
1 /*
2  * Copyright (C) 2002 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: load_poolnode.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_pool.h"
16 #else
17 #include "netinet/ip_lookup.h"
18 #include "netinet/ip_pool.h"
19 #endif
20 
21 static int poolfd = -1;
22 
23 
24 int load_poolnode(role, name, node, iocfunc)
25 int role;
26 char *name;
27 ip_pool_node_t *node;
28 ioctlfunc_t iocfunc;
29 {
30 	ip_pool_node_t pn;
31 	iplookupop_t op;
32 
33 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
34 		poolfd = open(IPLOOKUP_NAME, O_RDWR);
35 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
36 		return -1;
37 
38 	op.iplo_unit = role;
39 	op.iplo_type = IPLT_POOL;
40 	op.iplo_arg = 0;
41 	op.iplo_struct = &pn;
42 	op.iplo_size = sizeof(pn);
43 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
44 
45 	bzero((char *)&pn, sizeof(pn));
46 	bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr,
47 	      sizeof(pn.ipn_addr));
48 	bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask,
49 	      sizeof(pn.ipn_mask));
50 	pn.ipn_info = node->ipn_info;
51 	strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name));
52 
53 	if ((*iocfunc)(poolfd, SIOCLOOKUPADDNODE, &op)) {
54 		if ((opts & OPT_DONOTHING) == 0) {
55 			perror("load_pool:SIOCLOOKUPADDNODE");
56 			return -1;
57 		}
58 	}
59 
60 	return 0;
61 }
62