xref: /onnv-gate/usr/src/cmd/ipf/lib/common/load_pool.c (revision 3448:aaf16568054b)
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  *
62393Syz155240  * $Id: load_pool.c,v 1.14.2.2 2005/02/01 02:44:06 darrenr Exp $
7*3448Sdh155122  *
8*3448Sdh155122  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
9*3448Sdh155122  * Use is subject to license terms.
100Sstevel@tonic-gate  */
110Sstevel@tonic-gate 
12*3448Sdh155122 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13*3448Sdh155122 
140Sstevel@tonic-gate #include <fcntl.h>
150Sstevel@tonic-gate #include <sys/ioctl.h>
160Sstevel@tonic-gate #include "ipf.h"
170Sstevel@tonic-gate #include "netinet/ip_lookup.h"
180Sstevel@tonic-gate #include "netinet/ip_pool.h"
190Sstevel@tonic-gate 
200Sstevel@tonic-gate static int poolfd = -1;
210Sstevel@tonic-gate 
220Sstevel@tonic-gate 
load_pool(plp,iocfunc)230Sstevel@tonic-gate int load_pool(plp, iocfunc)
240Sstevel@tonic-gate ip_pool_t *plp;
250Sstevel@tonic-gate ioctlfunc_t iocfunc;
260Sstevel@tonic-gate {
270Sstevel@tonic-gate 	iplookupop_t op;
280Sstevel@tonic-gate 	ip_pool_node_t *a;
290Sstevel@tonic-gate 	ip_pool_t pool;
300Sstevel@tonic-gate 
310Sstevel@tonic-gate 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
320Sstevel@tonic-gate 		poolfd = open(IPLOOKUP_NAME, O_RDWR);
330Sstevel@tonic-gate 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
340Sstevel@tonic-gate 		return -1;
350Sstevel@tonic-gate 
360Sstevel@tonic-gate 	op.iplo_unit = plp->ipo_unit;
370Sstevel@tonic-gate 	op.iplo_type = IPLT_POOL;
380Sstevel@tonic-gate 	op.iplo_arg = 0;
390Sstevel@tonic-gate 	strncpy(op.iplo_name, plp->ipo_name, sizeof(op.iplo_name));
400Sstevel@tonic-gate 	op.iplo_size = sizeof(pool);
410Sstevel@tonic-gate 	op.iplo_struct = &pool;
420Sstevel@tonic-gate 	bzero((char *)&pool, sizeof(pool));
430Sstevel@tonic-gate 	strncpy(pool.ipo_name, plp->ipo_name, sizeof(pool.ipo_name));
440Sstevel@tonic-gate 	if (*plp->ipo_name == '\0')
450Sstevel@tonic-gate 		op.iplo_arg |= IPOOL_ANON;
460Sstevel@tonic-gate 
472393Syz155240 	if ((opts & OPT_REMOVE) == 0) {
482393Syz155240 		if ((*iocfunc)(poolfd, SIOCLOOKUPADDTABLE, &op))
492393Syz155240 			if ((opts & OPT_DONOTHING) == 0) {
502393Syz155240 				perror("load_pool:SIOCLOOKUPADDTABLE");
512393Syz155240 				return -1;
522393Syz155240 			}
532393Syz155240 	}
540Sstevel@tonic-gate 
550Sstevel@tonic-gate 	if ((opts & OPT_VERBOSE) != 0) {
560Sstevel@tonic-gate 		pool.ipo_list = plp->ipo_list;
572393Syz155240 		printpool(&pool, bcopywrap, pool.ipo_name, opts);
580Sstevel@tonic-gate 		pool.ipo_list = NULL;
590Sstevel@tonic-gate 	}
600Sstevel@tonic-gate 
610Sstevel@tonic-gate 	for (a = plp->ipo_list; a != NULL; a = a->ipn_next)
620Sstevel@tonic-gate 		load_poolnode(plp->ipo_unit, plp->ipo_name, a, iocfunc);
630Sstevel@tonic-gate 
642393Syz155240 	if ((opts & OPT_REMOVE) != 0) {
652393Syz155240 		if ((*iocfunc)(poolfd, SIOCLOOKUPDELTABLE, &op))
662393Syz155240 			if ((opts & OPT_DONOTHING) == 0) {
672393Syz155240 				perror("load_pool:SIOCLOOKUPDELTABLE");
682393Syz155240 				return -1;
692393Syz155240 			}
702393Syz155240 	}
710Sstevel@tonic-gate 	return 0;
720Sstevel@tonic-gate }
73