2008-05-20 10:43:46 +04:00
|
|
|
/* $NetBSD: printpool_live.c,v 1.1.1.2 2008/05/20 06:45:04 darrenr Exp $ */
|
2007-04-15 00:17:19 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2002 by Darren Reed.
|
|
|
|
*
|
|
|
|
* See the IPFILTER.LICENCE file for details on licencing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include "ipf.h"
|
2008-05-20 10:43:46 +04:00
|
|
|
#include "netinet/ipl.h"
|
2007-04-15 00:17:19 +04:00
|
|
|
|
|
|
|
#define PRINTF (void)printf
|
|
|
|
#define FPRINTF (void)fprintf
|
|
|
|
|
|
|
|
|
|
|
|
ip_pool_t *printpool_live(pool, fd, name, opts)
|
|
|
|
ip_pool_t *pool;
|
|
|
|
int fd;
|
|
|
|
char *name;
|
|
|
|
int opts;
|
|
|
|
{
|
|
|
|
ip_pool_node_t entry, *top, *node;
|
|
|
|
ipflookupiter_t iter;
|
|
|
|
int printed, last;
|
|
|
|
ipfobj_t obj;
|
|
|
|
|
|
|
|
if ((name != NULL) && strncmp(name, pool->ipo_name, FR_GROUPLEN))
|
|
|
|
return pool->ipo_next;
|
|
|
|
|
|
|
|
printpooldata(pool, opts);
|
|
|
|
|
|
|
|
if ((pool->ipo_flags & IPOOL_DELETE) != 0)
|
|
|
|
PRINTF("# ");
|
|
|
|
if ((opts & OPT_DEBUG) == 0)
|
|
|
|
PRINTF("\t{");
|
|
|
|
|
|
|
|
obj.ipfo_rev = IPFILTER_VERSION;
|
|
|
|
obj.ipfo_type = IPFOBJ_LOOKUPITER;
|
|
|
|
obj.ipfo_ptr = &iter;
|
|
|
|
obj.ipfo_size = sizeof(iter);
|
|
|
|
|
|
|
|
iter.ili_data = &entry;
|
|
|
|
iter.ili_type = IPLT_POOL;
|
|
|
|
iter.ili_otype = IPFLOOKUPITER_NODE;
|
|
|
|
iter.ili_ival = IPFGENITER_LOOKUP;
|
|
|
|
iter.ili_unit = pool->ipo_unit;
|
|
|
|
strncpy(iter.ili_name, pool->ipo_name, FR_GROUPLEN);
|
|
|
|
|
|
|
|
last = 0;
|
|
|
|
top = NULL;
|
|
|
|
printed = 0;
|
|
|
|
|
|
|
|
while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) {
|
|
|
|
if (entry.ipn_next == NULL)
|
|
|
|
last = 1;
|
2008-05-20 10:43:46 +04:00
|
|
|
node = malloc(sizeof(*top));
|
|
|
|
if (node == NULL)
|
2007-04-15 00:17:19 +04:00
|
|
|
break;
|
2008-05-20 10:43:46 +04:00
|
|
|
bcopy(&entry, node, sizeof(entry));
|
|
|
|
node->ipn_next = top;
|
|
|
|
top = node;
|
2007-04-15 00:17:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (top != NULL) {
|
|
|
|
node = top;
|
|
|
|
(void) printpoolnode(node, opts);
|
|
|
|
if ((opts & OPT_DEBUG) == 0)
|
|
|
|
putchar(';');
|
|
|
|
top = node->ipn_next;
|
|
|
|
free(node);
|
|
|
|
printed++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (printed == 0)
|
|
|
|
putchar(';');
|
|
|
|
|
|
|
|
if ((opts & OPT_DEBUG) == 0)
|
|
|
|
PRINTF(" };\n");
|
2008-05-20 10:43:46 +04:00
|
|
|
|
|
|
|
if (ioctl(fd, SIOCIPFDELTOK, &iter.ili_key) != 0)
|
|
|
|
perror("SIOCIPFDELTOK");
|
|
|
|
|
2007-04-15 00:17:19 +04:00
|
|
|
return pool->ipo_next;
|
|
|
|
}
|