1 /*
2 * Copyright (C) 2012 by Darren Reed.
3 *
4 * See the IPFILTER.LICENCE file for details on licencing.
5 *
6 * $Id: printpoolfield.c,v 1.1.2.4 2012/01/26 05:44:26 darren_r Exp $
7 */
8
9 #include "ipf.h"
10
11 wordtab_t poolfields[] = {
12 { "all", -2 },
13 { "address", 1 },
14 { "mask", 2 },
15 { "ifname", 3 },
16 { "pkts", 4 },
17 { "bytes", 5 },
18 { "family", 6 },
19 { NULL, 0 }
20 };
21
22
23 void
printpoolfield(p,ptype,fieldnum)24 printpoolfield(p, ptype, fieldnum)
25 void *p;
26 int ptype;
27 int fieldnum;
28 {
29 addrfamily_t *a;
30 char abuf[80];
31 int i;
32
33 switch (fieldnum)
34 {
35 case -2 :
36 for (i = 1; poolfields[i].w_word != NULL; i++) {
37 if (poolfields[i].w_value > 0) {
38 printpoolfield(p, ptype, i);
39 if (poolfields[i + 1].w_value > 0)
40 putchar('\t');
41 }
42 }
43 break;
44
45 case 1:
46 if (ptype == IPLT_POOL) {
47 ip_pool_node_t *node = (ip_pool_node_t *)p;
48
49 if (node->ipn_info)
50 PRINTF("!");
51 a = &node->ipn_addr;
52 PRINTF("%s", inet_ntop(a->adf_family, &a->adf_addr,
53 abuf, sizeof(abuf)));
54 } else if (ptype == IPLT_HASH) {
55 iphtent_t *node = (iphtent_t *)p;
56
57 PRINTF("%s", inet_ntop(node->ipe_family,
58 &node->ipe_addr,
59 abuf, sizeof(abuf)));
60 } else if (ptype == IPLT_DSTLIST) {
61 ipf_dstnode_t *node = (ipf_dstnode_t *)p;
62
63 a = &node->ipfd_dest.fd_addr;
64 PRINTF("%s", inet_ntop(a->adf_family, &a->adf_addr,
65 abuf, sizeof(abuf)));
66 }
67 break;
68
69 case 2:
70 if (ptype == IPLT_POOL) {
71 ip_pool_node_t *node = (ip_pool_node_t *)p;
72
73 a = &node->ipn_mask;
74 PRINTF("%s", inet_ntop(a->adf_family, &a->adf_addr,
75 abuf, sizeof(abuf)));
76 } else if (ptype == IPLT_HASH) {
77 iphtent_t *node = (iphtent_t *)p;
78
79 PRINTF("%s", inet_ntop(node->ipe_family,
80 &node->ipe_mask,
81 abuf, sizeof(abuf)));
82 } else if (ptype == IPLT_DSTLIST) {
83 PRINTF("%s", "");
84 }
85 break;
86
87 case 3:
88 if (ptype == IPLT_POOL) {
89 PRINTF("%s", "");
90 } else if (ptype == IPLT_HASH) {
91 PRINTF("%s", "");
92 } else if (ptype == IPLT_DSTLIST) {
93 ipf_dstnode_t *node = (ipf_dstnode_t *)p;
94
95 if (node->ipfd_dest.fd_name == -1) {
96 PRINTF("%s", "");
97 } else {
98 PRINTF("%s", node->ipfd_names +
99 node->ipfd_dest.fd_name);
100 }
101 }
102 break;
103
104 case 4:
105 if (ptype == IPLT_POOL) {
106 ip_pool_node_t *node = (ip_pool_node_t *)p;
107
108 #ifdef USE_QUAD_T
109 PRINTF("%"PRIu64"", node->ipn_hits);
110 #else
111 PRINTF("%lu", node->ipn_hits);
112 #endif
113 } else if (ptype == IPLT_HASH) {
114 iphtent_t *node = (iphtent_t *)p;
115
116 #ifdef USE_QUAD_T
117 PRINTF("%"PRIu64"", node->ipe_hits);
118 #else
119 PRINTF("%lu", node->ipe_hits);
120 #endif
121 } else if (ptype == IPLT_DSTLIST) {
122 printf("0");
123 }
124 break;
125
126 case 5:
127 if (ptype == IPLT_POOL) {
128 ip_pool_node_t *node = (ip_pool_node_t *)p;
129
130 #ifdef USE_QUAD_T
131 PRINTF("%"PRIu64"", node->ipn_bytes);
132 #else
133 PRINTF("%lu", node->ipn_bytes);
134 #endif
135 } else if (ptype == IPLT_HASH) {
136 iphtent_t *node = (iphtent_t *)p;
137
138 #ifdef USE_QUAD_T
139 PRINTF("%"PRIu64"", node->ipe_bytes);
140 #else
141 PRINTF("%lu", node->ipe_bytes);
142 #endif
143 } else if (ptype == IPLT_DSTLIST) {
144 printf("0");
145 }
146 break;
147
148 case 6:
149 if (ptype == IPLT_POOL) {
150 ip_pool_node_t *node = (ip_pool_node_t *)p;
151
152 PRINTF("%s", familyname(node->ipn_addr.adf_family));
153 } else if (ptype == IPLT_HASH) {
154 iphtent_t *node = (iphtent_t *)p;
155
156 PRINTF("%s", familyname(node->ipe_family));
157 } else if (ptype == IPLT_DSTLIST) {
158 ipf_dstnode_t *node = (ipf_dstnode_t *)p;
159
160 a = &node->ipfd_dest.fd_addr;
161 PRINTF("%s", familyname(a->adf_family));
162 }
163 break;
164
165 default :
166 break;
167 }
168 }
169