1*c9d5dc6cSdarrenr /* $NetBSD: printpool_live.c,v 1.1.1.2 2012/07/22 13:44:42 darrenr Exp $ */
2bc4097aaSchristos
3bc4097aaSchristos /*
4*c9d5dc6cSdarrenr * Copyright (C) 2012 by Darren Reed.
5bc4097aaSchristos *
6bc4097aaSchristos * See the IPFILTER.LICENCE file for details on licencing.
7bc4097aaSchristos */
8bc4097aaSchristos
9bc4097aaSchristos #include <sys/ioctl.h>
10bc4097aaSchristos #include "ipf.h"
11bc4097aaSchristos #include "netinet/ipl.h"
12bc4097aaSchristos
13bc4097aaSchristos
14bc4097aaSchristos ip_pool_t *
printpool_live(pool,fd,name,opts,fields)15bc4097aaSchristos printpool_live(pool, fd, name, opts, fields)
16bc4097aaSchristos ip_pool_t *pool;
17bc4097aaSchristos int fd;
18bc4097aaSchristos char *name;
19bc4097aaSchristos int opts;
20bc4097aaSchristos wordtab_t *fields;
21bc4097aaSchristos {
22*c9d5dc6cSdarrenr ip_pool_node_t entry;
23bc4097aaSchristos ipflookupiter_t iter;
24bc4097aaSchristos int printed, last;
25bc4097aaSchristos ipfobj_t obj;
26bc4097aaSchristos
27bc4097aaSchristos if ((name != NULL) && strncmp(name, pool->ipo_name, FR_GROUPLEN))
28bc4097aaSchristos return pool->ipo_next;
29bc4097aaSchristos
30bc4097aaSchristos if (fields == NULL)
31bc4097aaSchristos printpooldata(pool, opts);
32bc4097aaSchristos
33bc4097aaSchristos if ((pool->ipo_flags & IPOOL_DELETE) != 0)
34bc4097aaSchristos PRINTF("# ");
35bc4097aaSchristos if ((opts & OPT_DEBUG) == 0)
36bc4097aaSchristos PRINTF("\t{");
37bc4097aaSchristos
38bc4097aaSchristos obj.ipfo_rev = IPFILTER_VERSION;
39bc4097aaSchristos obj.ipfo_type = IPFOBJ_LOOKUPITER;
40bc4097aaSchristos obj.ipfo_ptr = &iter;
41bc4097aaSchristos obj.ipfo_size = sizeof(iter);
42bc4097aaSchristos
43bc4097aaSchristos iter.ili_data = &entry;
44bc4097aaSchristos iter.ili_type = IPLT_POOL;
45bc4097aaSchristos iter.ili_otype = IPFLOOKUPITER_NODE;
46bc4097aaSchristos iter.ili_ival = IPFGENITER_LOOKUP;
47bc4097aaSchristos iter.ili_unit = pool->ipo_unit;
48bc4097aaSchristos strncpy(iter.ili_name, pool->ipo_name, FR_GROUPLEN);
49bc4097aaSchristos
50bc4097aaSchristos last = 0;
51bc4097aaSchristos printed = 0;
52bc4097aaSchristos
53bc4097aaSchristos if (pool->ipo_list != NULL) {
54bc4097aaSchristos while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) {
55bc4097aaSchristos if (entry.ipn_next == NULL)
56bc4097aaSchristos last = 1;
57*c9d5dc6cSdarrenr (void) printpoolnode(&entry, opts, fields);
58bc4097aaSchristos if ((opts & OPT_DEBUG) == 0)
59bc4097aaSchristos putchar(';');
60bc4097aaSchristos printed++;
61bc4097aaSchristos }
62*c9d5dc6cSdarrenr }
63bc4097aaSchristos
64bc4097aaSchristos if (printed == 0)
65bc4097aaSchristos putchar(';');
66bc4097aaSchristos
67bc4097aaSchristos if ((opts & OPT_DEBUG) == 0)
68bc4097aaSchristos PRINTF(" };\n");
69bc4097aaSchristos
70bc4097aaSchristos (void) ioctl(fd,SIOCIPFDELTOK, &iter.ili_key);
71bc4097aaSchristos
72bc4097aaSchristos return pool->ipo_next;
73bc4097aaSchristos }
74