1 /*
2 * Copyright (C) 2012 by Darren Reed.
3 *
4 * See the IPFILTER.LICENCE file for details on licencing.
5 *
6 * $Id: printstatefields.c,v 1.4.2.2 2012/01/26 05:44:26 darren_r Exp $
7 */
8
9 #include "ipf.h"
10
11 wordtab_t statefields[] = {
12 { "all", -2 },
13 { "ifp0", 1 },
14 { "ifp1", 2 },
15 { "ifp2", 3 },
16 { "ifp3", 4 },
17 { "ifname0", 5 },
18 { "ifname1", 6 },
19 { "ifname2", 7 },
20 { "ifname3", 8 },
21 { "pkts0", 9 },
22 { "pkts1", 10 },
23 { "pkts2", 11 },
24 { "pkts3", 12 },
25 { "bytes0", 13 },
26 { "bytes1", 14 },
27 { "bytes2", 15 },
28 { "bytes3", 16 },
29 { "state0", 17 },
30 { "state1", 18 },
31 { "age0", 19 },
32 { "age1", 20 },
33 { "ref", 21 },
34 { "isn0", 22 },
35 { "isn1", 23 },
36 { "sumd0", 24 },
37 { "sumd1", 25 },
38 { "src", 26 },
39 { "dst", 27 },
40 { "sport", 28 },
41 { "dport", 29 },
42 { "icmptype", 30 },
43 { "-", 31 },
44 { "pass", 32 },
45 { "proto", 33 },
46 { "version", 34 },
47 { "hash", 35 },
48 { "tag", 36 },
49 { "flags", 37 },
50 { "rulen", 38 },
51 { "group", 39 },
52 { "flx0", 40 },
53 { "flx1", 41 },
54 { "flx2", 42 },
55 { "flx3", 43 },
56 { "opt0", 44 },
57 { "opt1", 45 },
58 { "optmsk0", 46 },
59 { "optmsk1", 47 },
60 { "sec", 48 },
61 { "secmsk", 49 },
62 { "auth", 50 },
63 { "authmsk", 51 },
64 { "icmppkts0", 52 },
65 { "icmppkts1", 53 },
66 { "icmppkts2", 54 },
67 { "icmppkts3", 55 },
68 { NULL, 0 }
69 };
70
71
72 void
printstatefield(ipstate_t * sp,int fieldnum)73 printstatefield(ipstate_t *sp, int fieldnum)
74 {
75 int i;
76
77 switch (fieldnum)
78 {
79 case -2 :
80 for (i = 1; statefields[i].w_word != NULL; i++) {
81 if (statefields[i].w_value > 0) {
82 printstatefield(sp, i);
83 if (statefields[i + 1].w_value > 0)
84 putchar('\t');
85 }
86 }
87 break;
88
89 case 1:
90 PRINTF("%#lx", (u_long)sp->is_ifp[0]);
91 break;
92
93 case 2:
94 PRINTF("%#lx", (u_long)sp->is_ifp[1]);
95 break;
96
97 case 3:
98 PRINTF("%#lx", (u_long)sp->is_ifp[2]);
99 break;
100
101 case 4:
102 PRINTF("%#lx", (u_long)sp->is_ifp[3]);
103 break;
104
105 case 5:
106 PRINTF("%s", sp->is_ifname[0]);
107 break;
108
109 case 6:
110 PRINTF("%s", sp->is_ifname[1]);
111 break;
112
113 case 7:
114 PRINTF("%s", sp->is_ifname[2]);
115 break;
116
117 case 8:
118 PRINTF("%s", sp->is_ifname[3]);
119 break;
120
121 case 9:
122 #ifdef USE_QUAD_T
123 PRINTF("%"PRIu64"", sp->is_pkts[0]);
124 #else
125 PRINTF("%lu", sp->is_pkts[0]);
126 #endif
127 break;
128
129 case 10:
130 #ifdef USE_QUAD_T
131 PRINTF("%"PRIu64"", sp->is_pkts[1]);
132 #else
133 PRINTF("%lu", sp->is_pkts[1]);
134 #endif
135 break;
136
137 case 11:
138 #ifdef USE_QUAD_T
139 PRINTF("%"PRIu64"", sp->is_pkts[2]);
140 #else
141 PRINTF("%lu", sp->is_pkts[2]);
142 #endif
143 break;
144
145 case 12:
146 #ifdef USE_QUAD_T
147 PRINTF("%"PRIu64"", sp->is_pkts[3]);
148 #else
149 PRINTF("%lu", sp->is_pkts[3]);
150 #endif
151 break;
152
153 case 13:
154 #ifdef USE_QUAD_T
155 PRINTF("%"PRIu64"", sp->is_bytes[0]);
156 #else
157 PRINTF("%lu", sp->is_bytes[0]);
158 #endif
159 break;
160
161 case 14:
162 #ifdef USE_QUAD_T
163 PRINTF("%"PRIu64"", sp->is_bytes[1]);
164 #else
165 PRINTF("%lu", sp->is_bytes[1]);
166 #endif
167 break;
168
169 case 15:
170 #ifdef USE_QUAD_T
171 PRINTF("%"PRIu64"", sp->is_bytes[2]);
172 #else
173 PRINTF("%lu", sp->is_bytes[2]);
174 #endif
175 break;
176
177 case 16:
178 #ifdef USE_QUAD_T
179 PRINTF("%"PRIu64"", sp->is_bytes[3]);
180 #else
181 PRINTF("%lu", sp->is_bytes[3]);
182 #endif
183 break;
184
185 case 17:
186 PRINTF("%d", sp->is_state[0]);
187 break;
188
189 case 18:
190 PRINTF("%d", sp->is_state[1]);
191 break;
192
193 case 19:
194 PRINTF("%d", sp->is_frage[0]);
195 break;
196
197 case 20:
198 PRINTF("%d", sp->is_frage[1]);
199 break;
200
201 case 21:
202 PRINTF("%d", sp->is_ref);
203 break;
204
205 case 22:
206 PRINTF("%d", sp->is_isninc[0]);
207 break;
208
209 case 23:
210 PRINTF("%d", sp->is_isninc[1]);
211 break;
212
213 case 24:
214 PRINTF("%hd", sp->is_sumd[0]);
215 break;
216
217 case 25:
218 PRINTF("%hd", sp->is_sumd[1]);
219 break;
220
221 case 26:
222 PRINTF("%s", hostname(sp->is_v, &sp->is_src.in4));
223 break;
224
225 case 27:
226 PRINTF("%s", hostname(sp->is_v, &sp->is_dst.in4));
227 break;
228
229 case 28:
230 PRINTF("%hu", ntohs(sp->is_sport));
231 break;
232
233 case 29:
234 PRINTF("%hu", ntohs(sp->is_dport));
235 break;
236
237 case 30:
238 PRINTF("%d", sp->is_type);
239 break;
240
241 case 32:
242 PRINTF("%#x", sp->is_pass);
243 break;
244
245 case 33:
246 PRINTF("%d", sp->is_p);
247 break;
248
249 case 34:
250 PRINTF("%d", sp->is_v);
251 break;
252
253 case 35:
254 PRINTF("%d", sp->is_hv);
255 break;
256
257 case 36:
258 PRINTF("%d", sp->is_tag);
259 break;
260
261 case 37:
262 PRINTF("%#x", sp->is_flags);
263 break;
264
265 case 38:
266 PRINTF("%d", sp->is_rulen);
267 break;
268
269 case 39:
270 PRINTF("%s", sp->is_group);
271 break;
272
273 case 40:
274 PRINTF("%#x", sp->is_flx[0][0]);
275 break;
276
277 case 41:
278 PRINTF("%#x", sp->is_flx[0][1]);
279 break;
280
281 case 42:
282 PRINTF("%#x", sp->is_flx[1][0]);
283 break;
284
285 case 43:
286 PRINTF("%#x", sp->is_flx[1][1]);
287 break;
288
289 case 44:
290 PRINTF("%#x", sp->is_opt[0]);
291 break;
292
293 case 45:
294 PRINTF("%#x", sp->is_opt[1]);
295 break;
296
297 case 46:
298 PRINTF("%#x", sp->is_optmsk[0]);
299 break;
300
301 case 47:
302 PRINTF("%#x", sp->is_optmsk[1]);
303 break;
304
305 case 48:
306 PRINTF("%#x", sp->is_sec);
307 break;
308
309 case 49:
310 PRINTF("%#x", sp->is_secmsk);
311 break;
312
313 case 50:
314 PRINTF("%#x", sp->is_auth);
315 break;
316
317 case 51:
318 PRINTF("%#x", sp->is_authmsk);
319 break;
320
321 case 52:
322 #ifdef USE_QUAD_T
323 PRINTF("%"PRIu64"", sp->is_icmppkts[0]);
324 #else
325 PRINTF("%lu", sp->is_icmppkts[0]);
326 #endif
327 break;
328
329 case 53:
330 #ifdef USE_QUAD_T
331 PRINTF("%"PRIu64"", sp->is_icmppkts[1]);
332 #else
333 PRINTF("%lu", sp->is_icmppkts[1]);
334 #endif
335 break;
336
337 case 54:
338 #ifdef USE_QUAD_T
339 PRINTF("%"PRIu64"", sp->is_icmppkts[2]);
340 #else
341 PRINTF("%lu", sp->is_icmppkts[2]);
342 #endif
343 break;
344
345 case 55:
346 #ifdef USE_QUAD_T
347 PRINTF("%"PRIu64"", sp->is_icmppkts[3]);
348 #else
349 PRINTF("%lu", sp->is_icmppkts[3]);
350 #endif
351 break;
352
353 default:
354 break;
355 }
356 }
357