xref: /onnv-gate/usr/src/cmd/ipf/lib/common/load_poolnode.c (revision 2393:76e0289ce525)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * Copyright (C) 2002 by Darren Reed.
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
50Sstevel@tonic-gate  *
6*2393Syz155240  * $Id: load_poolnode.c,v 1.3.2.1 2004/03/06 14:33:29 darrenr Exp $
70Sstevel@tonic-gate  */
80Sstevel@tonic-gate 
90Sstevel@tonic-gate #include <fcntl.h>
100Sstevel@tonic-gate #include <sys/ioctl.h>
110Sstevel@tonic-gate #include "ipf.h"
120Sstevel@tonic-gate #include "netinet/ip_lookup.h"
130Sstevel@tonic-gate #include "netinet/ip_pool.h"
140Sstevel@tonic-gate 
150Sstevel@tonic-gate static int poolfd = -1;
160Sstevel@tonic-gate 
170Sstevel@tonic-gate 
load_poolnode(role,name,node,iocfunc)180Sstevel@tonic-gate int load_poolnode(role, name, node, iocfunc)
190Sstevel@tonic-gate int role;
200Sstevel@tonic-gate char *name;
210Sstevel@tonic-gate ip_pool_node_t *node;
220Sstevel@tonic-gate ioctlfunc_t iocfunc;
230Sstevel@tonic-gate {
240Sstevel@tonic-gate 	ip_pool_node_t pn;
250Sstevel@tonic-gate 	iplookupop_t op;
26*2393Syz155240 	int err;
270Sstevel@tonic-gate 
280Sstevel@tonic-gate 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
290Sstevel@tonic-gate 		poolfd = open(IPLOOKUP_NAME, O_RDWR);
300Sstevel@tonic-gate 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
310Sstevel@tonic-gate 		return -1;
320Sstevel@tonic-gate 
330Sstevel@tonic-gate 	op.iplo_unit = role;
340Sstevel@tonic-gate 	op.iplo_type = IPLT_POOL;
350Sstevel@tonic-gate 	op.iplo_arg = 0;
360Sstevel@tonic-gate 	op.iplo_struct = &pn;
370Sstevel@tonic-gate 	op.iplo_size = sizeof(pn);
380Sstevel@tonic-gate 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
390Sstevel@tonic-gate 
400Sstevel@tonic-gate 	bzero((char *)&pn, sizeof(pn));
410Sstevel@tonic-gate 	bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr,
420Sstevel@tonic-gate 	      sizeof(pn.ipn_addr));
430Sstevel@tonic-gate 	bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask,
440Sstevel@tonic-gate 	      sizeof(pn.ipn_mask));
450Sstevel@tonic-gate 	pn.ipn_info = node->ipn_info;
460Sstevel@tonic-gate 	strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name));
470Sstevel@tonic-gate 
48*2393Syz155240 	if ((opts & OPT_REMOVE) == 0)
49*2393Syz155240 		err = (*iocfunc)(poolfd, SIOCLOOKUPADDNODE, &op);
50*2393Syz155240 	else
51*2393Syz155240 		err = (*iocfunc)(poolfd, SIOCLOOKUPDELNODE, &op);
52*2393Syz155240 
53*2393Syz155240 	if (err != 0) {
540Sstevel@tonic-gate 		if ((opts & OPT_DONOTHING) == 0) {
55*2393Syz155240 			perror("load_pool:SIOCLOOKUP*NODE");
560Sstevel@tonic-gate 			return -1;
570Sstevel@tonic-gate 		}
580Sstevel@tonic-gate 	}
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 	return 0;
610Sstevel@tonic-gate }
62