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