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 73 printstatefield(sp, fieldnum) 74 ipstate_t *sp; 75 int fieldnum; 76 { 77 int i; 78 79 switch (fieldnum) 80 { 81 case -2 : 82 for (i = 1; statefields[i].w_word != NULL; i++) { 83 if (statefields[i].w_value > 0) { 84 printstatefield(sp, i); 85 if (statefields[i + 1].w_value > 0) 86 putchar('\t'); 87 } 88 } 89 break; 90 91 case 1: 92 PRINTF("%#lx", (u_long)sp->is_ifp[0]); 93 break; 94 95 case 2: 96 PRINTF("%#lx", (u_long)sp->is_ifp[1]); 97 break; 98 99 case 3: 100 PRINTF("%#lx", (u_long)sp->is_ifp[2]); 101 break; 102 103 case 4: 104 PRINTF("%#lx", (u_long)sp->is_ifp[3]); 105 break; 106 107 case 5: 108 PRINTF("%s", sp->is_ifname[0]); 109 break; 110 111 case 6: 112 PRINTF("%s", sp->is_ifname[1]); 113 break; 114 115 case 7: 116 PRINTF("%s", sp->is_ifname[2]); 117 break; 118 119 case 8: 120 PRINTF("%s", sp->is_ifname[3]); 121 break; 122 123 case 9: 124 #ifdef USE_QUAD_T 125 PRINTF("%"PRIu64"", sp->is_pkts[0]); 126 #else 127 PRINTF("%lu", sp->is_pkts[0]); 128 #endif 129 break; 130 131 case 10: 132 #ifdef USE_QUAD_T 133 PRINTF("%"PRIu64"", sp->is_pkts[1]); 134 #else 135 PRINTF("%lu", sp->is_pkts[1]); 136 #endif 137 break; 138 139 case 11: 140 #ifdef USE_QUAD_T 141 PRINTF("%"PRIu64"", sp->is_pkts[2]); 142 #else 143 PRINTF("%lu", sp->is_pkts[2]); 144 #endif 145 break; 146 147 case 12: 148 #ifdef USE_QUAD_T 149 PRINTF("%"PRIu64"", sp->is_pkts[3]); 150 #else 151 PRINTF("%lu", sp->is_pkts[3]); 152 #endif 153 break; 154 155 case 13: 156 #ifdef USE_QUAD_T 157 PRINTF("%"PRIu64"", sp->is_bytes[0]); 158 #else 159 PRINTF("%lu", sp->is_bytes[0]); 160 #endif 161 break; 162 163 case 14: 164 #ifdef USE_QUAD_T 165 PRINTF("%"PRIu64"", sp->is_bytes[1]); 166 #else 167 PRINTF("%lu", sp->is_bytes[1]); 168 #endif 169 break; 170 171 case 15: 172 #ifdef USE_QUAD_T 173 PRINTF("%"PRIu64"", sp->is_bytes[2]); 174 #else 175 PRINTF("%lu", sp->is_bytes[2]); 176 #endif 177 break; 178 179 case 16: 180 #ifdef USE_QUAD_T 181 PRINTF("%"PRIu64"", sp->is_bytes[3]); 182 #else 183 PRINTF("%lu", sp->is_bytes[3]); 184 #endif 185 break; 186 187 case 17: 188 PRINTF("%d", sp->is_state[0]); 189 break; 190 191 case 18: 192 PRINTF("%d", sp->is_state[1]); 193 break; 194 195 case 19: 196 PRINTF("%d", sp->is_frage[0]); 197 break; 198 199 case 20: 200 PRINTF("%d", sp->is_frage[1]); 201 break; 202 203 case 21: 204 PRINTF("%d", sp->is_ref); 205 break; 206 207 case 22: 208 PRINTF("%d", sp->is_isninc[0]); 209 break; 210 211 case 23: 212 PRINTF("%d", sp->is_isninc[1]); 213 break; 214 215 case 24: 216 PRINTF("%hd", sp->is_sumd[0]); 217 break; 218 219 case 25: 220 PRINTF("%hd", sp->is_sumd[1]); 221 break; 222 223 case 26: 224 PRINTF("%s", hostname(sp->is_v, &sp->is_src.in4)); 225 break; 226 227 case 27: 228 PRINTF("%s", hostname(sp->is_v, &sp->is_dst.in4)); 229 break; 230 231 case 28: 232 PRINTF("%hu", ntohs(sp->is_sport)); 233 break; 234 235 case 29: 236 PRINTF("%hu", ntohs(sp->is_dport)); 237 break; 238 239 case 30: 240 PRINTF("%d", sp->is_type); 241 break; 242 243 case 32: 244 PRINTF("%#x", sp->is_pass); 245 break; 246 247 case 33: 248 PRINTF("%d", sp->is_p); 249 break; 250 251 case 34: 252 PRINTF("%d", sp->is_v); 253 break; 254 255 case 35: 256 PRINTF("%d", sp->is_hv); 257 break; 258 259 case 36: 260 PRINTF("%d", sp->is_tag); 261 break; 262 263 case 37: 264 PRINTF("%#x", sp->is_flags); 265 break; 266 267 case 38: 268 PRINTF("%d", sp->is_rulen); 269 break; 270 271 case 39: 272 PRINTF("%s", sp->is_group); 273 break; 274 275 case 40: 276 PRINTF("%#x", sp->is_flx[0][0]); 277 break; 278 279 case 41: 280 PRINTF("%#x", sp->is_flx[0][1]); 281 break; 282 283 case 42: 284 PRINTF("%#x", sp->is_flx[1][0]); 285 break; 286 287 case 43: 288 PRINTF("%#x", sp->is_flx[1][1]); 289 break; 290 291 case 44: 292 PRINTF("%#x", sp->is_opt[0]); 293 break; 294 295 case 45: 296 PRINTF("%#x", sp->is_opt[1]); 297 break; 298 299 case 46: 300 PRINTF("%#x", sp->is_optmsk[0]); 301 break; 302 303 case 47: 304 PRINTF("%#x", sp->is_optmsk[1]); 305 break; 306 307 case 48: 308 PRINTF("%#x", sp->is_sec); 309 break; 310 311 case 49: 312 PRINTF("%#x", sp->is_secmsk); 313 break; 314 315 case 50: 316 PRINTF("%#x", sp->is_auth); 317 break; 318 319 case 51: 320 PRINTF("%#x", sp->is_authmsk); 321 break; 322 323 case 52: 324 #ifdef USE_QUAD_T 325 PRINTF("%"PRIu64"", sp->is_icmppkts[0]); 326 #else 327 PRINTF("%lu", sp->is_icmppkts[0]); 328 #endif 329 break; 330 331 case 53: 332 #ifdef USE_QUAD_T 333 PRINTF("%"PRIu64"", sp->is_icmppkts[1]); 334 #else 335 PRINTF("%lu", sp->is_icmppkts[1]); 336 #endif 337 break; 338 339 case 54: 340 #ifdef USE_QUAD_T 341 PRINTF("%"PRIu64"", sp->is_icmppkts[2]); 342 #else 343 PRINTF("%lu", sp->is_icmppkts[2]); 344 #endif 345 break; 346 347 case 55: 348 #ifdef USE_QUAD_T 349 PRINTF("%"PRIu64"", sp->is_icmppkts[3]); 350 #else 351 PRINTF("%lu", sp->is_icmppkts[3]); 352 #endif 353 break; 354 355 default: 356 break; 357 } 358 } 359