Move /var/svc/log to /var/log/svc
[unleashed/lotheac.git] / usr / src / cmd / ipf / lib / common / load_poolnode.c
blob4203f0faa5a4b82f76e50a3c89107aa561348539
1 /*
2 * Copyright (C) 2002 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * $Id: load_poolnode.c,v 1.3.2.1 2004/03/06 14:33:29 darrenr Exp $
8 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
9 */
11 #include <fcntl.h>
12 #include <sys/ioctl.h>
13 #include "ipf.h"
14 #include "netinet/ip_lookup.h"
15 #include "netinet/ip_pool.h"
16 #include "ipfzone.h"
18 static int poolfd = -1;
21 int load_poolnode(role, name, node, iocfunc)
22 int role;
23 char *name;
24 ip_pool_node_t *node;
25 ioctlfunc_t iocfunc;
27 ip_pool_node_t pn;
28 iplookupop_t op;
29 int err;
31 if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
32 poolfd = open(IPLOOKUP_NAME, O_RDWR);
33 if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
34 return -1;
35 if (setzone(poolfd) != 0) {
36 close(poolfd);
37 return -1;
40 op.iplo_unit = role;
41 op.iplo_type = IPLT_POOL;
42 op.iplo_arg = 0;
43 op.iplo_struct = &pn;
44 op.iplo_size = sizeof(pn);
45 strncpy(op.iplo_name, name, sizeof(op.iplo_name));
47 bzero((char *)&pn, sizeof(pn));
48 bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr,
49 sizeof(pn.ipn_addr));
50 bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask,
51 sizeof(pn.ipn_mask));
52 pn.ipn_info = node->ipn_info;
53 strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name));
55 if ((opts & OPT_REMOVE) == 0)
56 err = (*iocfunc)(poolfd, SIOCLOOKUPADDNODE, &op);
57 else
58 err = (*iocfunc)(poolfd, SIOCLOOKUPDELNODE, &op);
60 if (err != 0) {
61 if ((opts & OPT_DONOTHING) == 0) {
62 perror("load_pool:SIOCLOOKUP*NODE");
63 return -1;
67 return 0;