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