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