summaryrefslogtreecommitdiff
path: root/usr/src/cmd/ipf/lib/common/printpool.c
blob: 59f5d727e7e0f6b58d79eb2514dc1c9336df563e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * Copyright (C) 2002 by Darren Reed.
 *
 * See the IPFILTER.LICENCE file for details on licencing.
 *
 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include "ipf.h"

#define	PRINTF	(void)printf
#define	FPRINTF	(void)fprintf

ip_pool_t *printpool(pp, copyfunc, opts)
ip_pool_t *pp;
copyfunc_t copyfunc;
int opts;
{
	ip_pool_node_t *ipnp, *ipnpn;
	ip_pool_t ipp;

	if ((*copyfunc)(pp, &ipp, sizeof(ipp)))
		return NULL;

	if ((opts & OPT_DEBUG) == 0) {
		if ((ipp.ipo_flags & IPOOL_ANON) != 0)
			PRINTF("# 'anonymous' tree %s\n", ipp.ipo_name);
		PRINTF("table role = ");
	} else {
		PRINTF("Name: %s", ipp.ipo_name);
		if ((ipp.ipo_flags & IPOOL_ANON) == IPOOL_ANON)
			PRINTF("(anon)");
		putchar(' ');
		PRINTF("Role: ");
	}

	switch (ipp.ipo_unit)
	{
	case IPL_LOGIPF :
		printf("ipf");
		break;
	case IPL_LOGNAT :
		printf("nat");
		break;
	case IPL_LOGSTATE :
		printf("state");
		break;
	case IPL_LOGAUTH :
		printf("auth");
		break;
	case IPL_LOGSYNC :
		printf("sync");
		break;
	case IPL_LOGSCAN :
		printf("scan");
		break;
	case IPL_LOGLOOKUP :
		printf("lookup");
		break;
	case IPL_LOGCOUNT :
		printf("count");
		break;
	default :
		printf("unknown(%d)", ipp.ipo_unit);
	}

	if ((opts & OPT_DEBUG) == 0) {
		PRINTF(" type = tree number = %s\n", ipp.ipo_name);
		PRINTF("\t{");
	} else {
		putchar(' ');

		PRINTF("\tReferences: %d\tHits: %lu\n", ipp.ipo_ref,
			ipp.ipo_hits);
		PRINTF("\tNodes Starting at %p\n", ipp.ipo_list);
	}

	ipnpn = ipp.ipo_list;
	ipp.ipo_list = NULL;
	while (ipnpn != NULL) {
		ipnp = (ip_pool_node_t *)malloc(sizeof(*ipnp));
		(*copyfunc)(ipnpn, ipnp, sizeof(*ipnp));
		ipnpn = ipnp->ipn_next;
		ipnp->ipn_next = ipp.ipo_list;
		ipp.ipo_list = ipnp;
	}

	for (ipnp = ipp.ipo_list; ipnp != NULL; ) {
		ipnp = printpoolnode(ipnp, opts);

		if ((opts & OPT_DEBUG) == 0)
			putchar(';');
	}

	if ((opts & OPT_DEBUG) == 0)
		PRINTF(" };\n");

	return ipp.ipo_next;
}