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