xref: /titanic_44/usr/src/cmd/ipf/lib/common/load_pool.c (revision fb3fb4f3d76d55b64440afd0af72775dfad3bd1d)
1 /*
2  * Copyright (C) 2002 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: load_pool.c,v 1.12 2003/04/26 04:55:11 darrenr Exp $
7  */
8 
9 #include <fcntl.h>
10 #include <sys/ioctl.h>
11 #include "ipf.h"
12 #if SOLARIS2 >= 10
13 #include "ip_lookup.h"
14 #include "ip_pool.h"
15 #else
16 #include "netinet/ip_lookup.h"
17 #include "netinet/ip_pool.h"
18 #endif
19 
20 static int poolfd = -1;
21 
22 
23 int load_pool(plp, iocfunc)
24 ip_pool_t *plp;
25 ioctlfunc_t iocfunc;
26 {
27 	iplookupop_t op;
28 	ip_pool_node_t *a;
29 	ip_pool_t pool;
30 
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 
36 	op.iplo_unit = plp->ipo_unit;
37 	op.iplo_type = IPLT_POOL;
38 	op.iplo_arg = 0;
39 	strncpy(op.iplo_name, plp->ipo_name, sizeof(op.iplo_name));
40 	op.iplo_size = sizeof(pool);
41 	op.iplo_struct = &pool;
42 	bzero((char *)&pool, sizeof(pool));
43 	strncpy(pool.ipo_name, plp->ipo_name, sizeof(pool.ipo_name));
44 	if (*plp->ipo_name == '\0')
45 		op.iplo_arg |= IPOOL_ANON;
46 
47 	if ((*iocfunc)(poolfd, SIOCLOOKUPADDTABLE, &op))
48 		if ((opts & OPT_DONOTHING) == 0) {
49 			perror("load_pool:SIOCLOOKUPADDTABLE");
50 			return -1;
51 		}
52 
53 	if ((opts & OPT_VERBOSE) != 0) {
54 		pool.ipo_list = plp->ipo_list;
55 		printpool(&pool, bcopywrap, opts);
56 		pool.ipo_list = NULL;
57 	}
58 
59 	for (a = plp->ipo_list; a != NULL; a = a->ipn_next)
60 		load_poolnode(plp->ipo_unit, plp->ipo_name, a, iocfunc);
61 
62 	return 0;
63 }
64