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