xref: /onnv-gate/usr/src/cmd/ipf/lib/common/printpool_live.c (revision 3448:aaf16568054b)
1*3448Sdh155122 /*
2*3448Sdh155122  * Copyright (C) 2002 by Darren Reed.
3*3448Sdh155122  *
4*3448Sdh155122  * See the IPFILTER.LICENCE file for details on licencing.
5*3448Sdh155122  *
6*3448Sdh155122  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
7*3448Sdh155122  * Use is subject to license terms.
8*3448Sdh155122  */
9*3448Sdh155122 
10*3448Sdh155122 #pragma ident	"%Z%%M%	%I%	%E% SMI"
11*3448Sdh155122 
12*3448Sdh155122 #include <sys/ioctl.h>
13*3448Sdh155122 #include "ipf.h"
14*3448Sdh155122 #include "netinet/ipl.h"
15*3448Sdh155122 
16*3448Sdh155122 #define	PRINTF	(void)printf
17*3448Sdh155122 #define	FPRINTF	(void)fprintf
18*3448Sdh155122 
19*3448Sdh155122 
printpool_live(pool,fd,name,opts)20*3448Sdh155122 ip_pool_t *printpool_live(pool, fd, name, opts)
21*3448Sdh155122 ip_pool_t *pool;
22*3448Sdh155122 int fd;
23*3448Sdh155122 char *name;
24*3448Sdh155122 int opts;
25*3448Sdh155122 {
26*3448Sdh155122 	ip_pool_node_t entry, *top, *node;
27*3448Sdh155122 	ipflookupiter_t iter;
28*3448Sdh155122 	int i, printed, last;
29*3448Sdh155122 	ipfobj_t obj;
30*3448Sdh155122 
31*3448Sdh155122 	if ((name != NULL) && strncmp(name, pool->ipo_name, FR_GROUPLEN))
32*3448Sdh155122 		return pool->ipo_next;
33*3448Sdh155122 
34*3448Sdh155122 	printpooldata(pool, opts);
35*3448Sdh155122 
36*3448Sdh155122 	if ((opts & OPT_DEBUG) == 0)
37*3448Sdh155122 		PRINTF("\t{");
38*3448Sdh155122 
39*3448Sdh155122 	obj.ipfo_rev = IPFILTER_VERSION;
40*3448Sdh155122 	obj.ipfo_type = IPFOBJ_LOOKUPITER;
41*3448Sdh155122 	obj.ipfo_ptr = &iter;
42*3448Sdh155122 	obj.ipfo_size = sizeof(iter);
43*3448Sdh155122 
44*3448Sdh155122 	iter.ili_data = &entry;
45*3448Sdh155122 	iter.ili_type = IPLT_POOL;
46*3448Sdh155122 	iter.ili_otype = IPFLOOKUPITER_NODE;
47*3448Sdh155122 	iter.ili_ival = IPFGENITER_LOOKUP;
48*3448Sdh155122 	iter.ili_unit = pool->ipo_unit;
49*3448Sdh155122 	strncpy(iter.ili_name, pool->ipo_name, FR_GROUPLEN);
50*3448Sdh155122 
51*3448Sdh155122 	last = 0;
52*3448Sdh155122 	top = NULL;
53*3448Sdh155122 
54*3448Sdh155122 	while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) {
55*3448Sdh155122 		if (entry.ipn_next == NULL)
56*3448Sdh155122 			last = 1;
57*3448Sdh155122 		entry.ipn_next = top;
58*3448Sdh155122 		top = malloc(sizeof(*top));
59*3448Sdh155122 		if (top == NULL)
60*3448Sdh155122 			break;
61*3448Sdh155122 		bcopy(&entry, top, sizeof(entry));
62*3448Sdh155122 	}
63*3448Sdh155122 
64*3448Sdh155122 	while (top != NULL) {
65*3448Sdh155122 		node = top;
66*3448Sdh155122 		(void) printpoolnode(node, opts);
67*3448Sdh155122 		top = node->ipn_next;
68*3448Sdh155122 		free(node);
69*3448Sdh155122 		printed++;
70*3448Sdh155122 
71*3448Sdh155122 		if ((opts & OPT_DEBUG) == 0)
72*3448Sdh155122 			putchar(';');
73*3448Sdh155122 	}
74*3448Sdh155122 
75*3448Sdh155122 	if (printed == 0)
76*3448Sdh155122 		putchar(';');
77*3448Sdh155122 
78*3448Sdh155122 	if ((opts & OPT_DEBUG) == 0)
79*3448Sdh155122 		PRINTF(" };\n");
80*3448Sdh155122 	return pool->ipo_next;
81*3448Sdh155122 }
82