1254219Scy/*
2254219Scy * Copyright (C) 2012 by Darren Reed.
3254219Scy *
4254219Scy * See the IPFILTER.LICENCE file for details on licencing.
5254219Scy *
6254219Scy * $Id: printpoolfield.c,v 1.1.2.4 2012/01/26 05:44:26 darren_r Exp $
7254219Scy */
8254219Scy
9254219Scy#include "ipf.h"
10254219Scy
11254219Scywordtab_t poolfields[] = {
12254219Scy	{ "all",	-2 },
13254219Scy	{ "address",	1 },
14254219Scy	{ "mask",	2 },
15254219Scy	{ "ifname",	3 },
16254219Scy	{ "pkts",	4 },
17254219Scy	{ "bytes",	5 },
18254219Scy	{ "family",	6 },
19254219Scy	{ NULL, 0 }
20254219Scy};
21254219Scy
22254219Scy
23254219Scyvoid
24254219Scyprintpoolfield(p, ptype, fieldnum)
25254219Scy	void *p;
26254219Scy	int ptype;
27254219Scy	int fieldnum;
28254219Scy{
29254219Scy	addrfamily_t *a;
30254219Scy	char abuf[80];
31254219Scy	int i;
32254219Scy
33254219Scy	switch (fieldnum)
34254219Scy	{
35254219Scy	case -2 :
36254219Scy		for (i = 1; poolfields[i].w_word != NULL; i++) {
37254219Scy			if (poolfields[i].w_value > 0) {
38254219Scy				printpoolfield(p, ptype, i);
39254219Scy				if (poolfields[i + 1].w_value > 0)
40254219Scy					putchar('\t');
41254219Scy			}
42254219Scy		}
43254219Scy		break;
44254219Scy
45254219Scy	case 1:
46254219Scy		if (ptype == IPLT_POOL) {
47254219Scy			ip_pool_node_t *node = (ip_pool_node_t *)p;
48254219Scy
49254219Scy			if (node->ipn_info)
50254219Scy				PRINTF("!");
51254219Scy			a = &node->ipn_addr;
52254219Scy			PRINTF("%s", inet_ntop(a->adf_family, &a->adf_addr,
53254219Scy					       abuf, sizeof(abuf)));
54254219Scy		} else if (ptype == IPLT_HASH) {
55254219Scy			iphtent_t *node = (iphtent_t *)p;
56254219Scy
57254219Scy			PRINTF("%s", inet_ntop(node->ipe_family,
58254219Scy					       &node->ipe_addr,
59254219Scy					       abuf, sizeof(abuf)));
60254219Scy		} else if (ptype == IPLT_DSTLIST) {
61254219Scy			ipf_dstnode_t *node = (ipf_dstnode_t *)p;
62254219Scy
63254219Scy			a = &node->ipfd_dest.fd_addr;
64254219Scy			PRINTF("%s", inet_ntop(a->adf_family, &a->adf_addr,
65254219Scy					       abuf, sizeof(abuf)));
66254219Scy		}
67254219Scy		break;
68254219Scy
69254219Scy	case 2:
70254219Scy		if (ptype == IPLT_POOL) {
71254219Scy			ip_pool_node_t *node = (ip_pool_node_t *)p;
72254219Scy
73254219Scy			a = &node->ipn_mask;
74254219Scy			PRINTF("%s", inet_ntop(a->adf_family, &a->adf_addr,
75254219Scy					       abuf, sizeof(abuf)));
76254219Scy		} else if (ptype == IPLT_HASH) {
77254219Scy			iphtent_t *node = (iphtent_t *)p;
78254219Scy
79254219Scy			PRINTF("%s", inet_ntop(node->ipe_family,
80254219Scy					       &node->ipe_mask,
81254219Scy					       abuf, sizeof(abuf)));
82254219Scy		} else if (ptype == IPLT_DSTLIST) {
83254219Scy			PRINTF("%s", "");
84254219Scy		}
85254219Scy		break;
86254219Scy
87254219Scy	case 3:
88254219Scy		if (ptype == IPLT_POOL) {
89254219Scy			PRINTF("%s", "");
90254219Scy		} else if (ptype == IPLT_HASH) {
91254219Scy			PRINTF("%s", "");
92254219Scy		} else if (ptype == IPLT_DSTLIST) {
93254219Scy			ipf_dstnode_t *node = (ipf_dstnode_t *)p;
94254219Scy
95254219Scy			if (node->ipfd_dest.fd_name == -1) {
96254219Scy				PRINTF("%s", "");
97254219Scy			} else {
98254219Scy				PRINTF("%s", node->ipfd_names +
99254219Scy				       node->ipfd_dest.fd_name);
100254219Scy			}
101254219Scy		}
102254219Scy		break;
103254219Scy
104254219Scy	case 4:
105254219Scy		if (ptype == IPLT_POOL) {
106254219Scy			ip_pool_node_t *node = (ip_pool_node_t *)p;
107254219Scy
108254219Scy#ifdef USE_QUAD_T
109254219Scy			PRINTF("%"PRIu64"", node->ipn_hits);
110254219Scy#else
111254219Scy			PRINTF("%lu", node->ipn_hits);
112254219Scy#endif
113254219Scy		} else if (ptype == IPLT_HASH) {
114254219Scy			iphtent_t *node = (iphtent_t *)p;
115254219Scy
116254219Scy#ifdef USE_QUAD_T
117254219Scy			PRINTF("%"PRIu64"", node->ipe_hits);
118254219Scy#else
119254219Scy			PRINTF("%lu", node->ipe_hits);
120254219Scy#endif
121254219Scy		} else if (ptype == IPLT_DSTLIST) {
122254219Scy			printf("0");
123254219Scy		}
124254219Scy		break;
125254219Scy
126254219Scy	case 5:
127254219Scy		if (ptype == IPLT_POOL) {
128254219Scy			ip_pool_node_t *node = (ip_pool_node_t *)p;
129254219Scy
130254219Scy#ifdef USE_QUAD_T
131254219Scy			PRINTF("%"PRIu64"", node->ipn_bytes);
132254219Scy#else
133254219Scy			PRINTF("%lu", node->ipn_bytes);
134254219Scy#endif
135254219Scy		} else if (ptype == IPLT_HASH) {
136254219Scy			iphtent_t *node = (iphtent_t *)p;
137254219Scy
138254219Scy#ifdef USE_QUAD_T
139254219Scy			PRINTF("%"PRIu64"", node->ipe_bytes);
140254219Scy#else
141254219Scy			PRINTF("%lu", node->ipe_bytes);
142254219Scy#endif
143254219Scy		} else if (ptype == IPLT_DSTLIST) {
144254219Scy			printf("0");
145254219Scy		}
146254219Scy		break;
147254219Scy
148254219Scy	case 6:
149254219Scy		if (ptype == IPLT_POOL) {
150254219Scy			ip_pool_node_t *node = (ip_pool_node_t *)p;
151254219Scy
152254219Scy			PRINTF("%s", familyname(node->ipn_addr.adf_family));
153254219Scy		} else if (ptype == IPLT_HASH) {
154254219Scy			iphtent_t *node = (iphtent_t *)p;
155254219Scy
156254219Scy			PRINTF("%s", familyname(node->ipe_family));
157254219Scy		} else if (ptype == IPLT_DSTLIST) {
158254219Scy			ipf_dstnode_t *node = (ipf_dstnode_t *)p;
159254219Scy
160254219Scy			a = &node->ipfd_dest.fd_addr;
161254219Scy			PRINTF("%s", familyname(a->adf_family));
162254219Scy		}
163254219Scy		break;
164254219Scy
165254219Scy	default :
166254219Scy		break;
167254219Scy	}
168254219Scy}
169