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