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