xref: /titanic_44/usr/src/cmd/ipf/lib/common/load_poolnode.c (revision f48205be61a214698b763ff550ab9e657525104c)
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.3.2.1 2004/03/06 14:33:29 darrenr Exp $
7  */
8 
9 #include <fcntl.h>
10 #include <sys/ioctl.h>
11 #include "ipf.h"
12 #include "netinet/ip_lookup.h"
13 #include "netinet/ip_pool.h"
14 
15 static int poolfd = -1;
16 
17 
18 int load_poolnode(role, name, node, iocfunc)
19 int role;
20 char *name;
21 ip_pool_node_t *node;
22 ioctlfunc_t iocfunc;
23 {
24 	ip_pool_node_t pn;
25 	iplookupop_t op;
26 	int err;
27 
28 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
29 		poolfd = open(IPLOOKUP_NAME, O_RDWR);
30 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
31 		return -1;
32 
33 	op.iplo_unit = role;
34 	op.iplo_type = IPLT_POOL;
35 	op.iplo_arg = 0;
36 	op.iplo_struct = &pn;
37 	op.iplo_size = sizeof(pn);
38 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
39 
40 	bzero((char *)&pn, sizeof(pn));
41 	bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr,
42 	      sizeof(pn.ipn_addr));
43 	bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask,
44 	      sizeof(pn.ipn_mask));
45 	pn.ipn_info = node->ipn_info;
46 	strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name));
47 
48 	if ((opts & OPT_REMOVE) == 0)
49 		err = (*iocfunc)(poolfd, SIOCLOOKUPADDNODE, &op);
50 	else
51 		err = (*iocfunc)(poolfd, SIOCLOOKUPDELNODE, &op);
52 
53 	if (err != 0) {
54 		if ((opts & OPT_DONOTHING) == 0) {
55 			perror("load_pool:SIOCLOOKUP*NODE");
56 			return -1;
57 		}
58 	}
59 
60 	return 0;
61 }
62