printpool.c revision 145511
1/*	$NetBSD$	*/
2
3/*
4 * Copyright (C) 2002 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 */
8
9#include "ipf.h"
10
11#define	PRINTF	(void)printf
12#define	FPRINTF	(void)fprintf
13
14ip_pool_t *printpool(pp, copyfunc, name, opts)
15ip_pool_t *pp;
16copyfunc_t copyfunc;
17char *name;
18int opts;
19{
20	ip_pool_node_t *ipnp, *ipnpn, ipn;
21	ip_pool_t ipp;
22
23	if ((*copyfunc)(pp, &ipp, sizeof(ipp)))
24		return NULL;
25
26	if ((name != NULL) && strncmp(name, ipp.ipo_name, FR_GROUPLEN))
27		return ipp.ipo_next;
28
29	if ((opts & OPT_DEBUG) == 0) {
30		if ((ipp.ipo_flags & IPOOL_ANON) != 0)
31			PRINTF("# 'anonymous' tree %s\n", ipp.ipo_name);
32		PRINTF("table role = ");
33	} else {
34		PRINTF("Name: %s", ipp.ipo_name);
35		if ((ipp.ipo_flags & IPOOL_ANON) == IPOOL_ANON)
36			PRINTF("(anon)");
37		putchar(' ');
38		PRINTF("Role: ");
39	}
40
41	switch (ipp.ipo_unit)
42	{
43	case IPL_LOGIPF :
44		printf("ipf");
45		break;
46	case IPL_LOGNAT :
47		printf("nat");
48		break;
49	case IPL_LOGSTATE :
50		printf("state");
51		break;
52	case IPL_LOGAUTH :
53		printf("auth");
54		break;
55	case IPL_LOGSYNC :
56		printf("sync");
57		break;
58	case IPL_LOGSCAN :
59		printf("scan");
60		break;
61	case IPL_LOGLOOKUP :
62		printf("lookup");
63		break;
64	case IPL_LOGCOUNT :
65		printf("count");
66		break;
67	default :
68		printf("unknown(%d)", ipp.ipo_unit);
69	}
70
71	if ((opts & OPT_DEBUG) == 0) {
72		PRINTF(" type = tree number = %s\n", ipp.ipo_name);
73		PRINTF("\t{");
74	} else {
75		putchar(' ');
76
77		PRINTF("\tReferences: %d\tHits: %lu\n", ipp.ipo_ref,
78			ipp.ipo_hits);
79		PRINTF("\tNodes Starting at %p\n", ipp.ipo_list);
80	}
81
82	ipnpn = ipp.ipo_list;
83	ipp.ipo_list = NULL;
84	while (ipnpn != NULL) {
85		ipnp = (ip_pool_node_t *)malloc(sizeof(*ipnp));
86		(*copyfunc)(ipnpn, ipnp, sizeof(ipn));
87		ipnpn = ipnp->ipn_next;
88		ipnp->ipn_next = ipp.ipo_list;
89		ipp.ipo_list = ipnp;
90	}
91
92	if (ipp.ipo_list == NULL) {
93		putchar(';');
94	} else {
95		for (ipnp = ipp.ipo_list; ipnp != NULL; ) {
96			ipnp = printpoolnode(ipnp, opts);
97
98			if ((opts & OPT_DEBUG) == 0) {
99				putchar(';');
100			}
101		}
102	}
103
104	if ((opts & OPT_DEBUG) == 0)
105		PRINTF(" };\n");
106
107	return ipp.ipo_next;
108}
109