printhashdata.c revision 170263
1270866Simp/* 2270866Simp * Copyright (C) 2002 by Darren Reed. 3270866Simp * 4270866Simp * See the IPFILTER.LICENCE file for details on licencing. 5270866Simp */ 6270866Simp 7270866Simp#include "ipf.h" 8270866Simp 9270866Simp#define PRINTF (void)printf 10270866Simp#define FPRINTF (void)fprintf 11270866Simp 12270866Simp 13270866Simpvoid printhashdata(hp, opts) 14270866Simpiphtable_t *hp; 15270866Simpint opts; 16270866Simp{ 17270866Simp 18270866Simp if ((opts & OPT_DEBUG) == 0) { 19270866Simp if ((hp->iph_type & IPHASH_ANON) == IPHASH_ANON) 20270866Simp PRINTF("# 'anonymous' table\n"); 21270866Simp if ((hp->iph_flags & IPHASH_DELETE) == IPHASH_DELETE) 22270866Simp PRINTF("# "); 23270866Simp switch (hp->iph_type & ~IPHASH_ANON) 24270866Simp { 25270866Simp case IPHASH_LOOKUP : 26270866Simp PRINTF("table"); 27270866Simp break; 28270866Simp case IPHASH_GROUPMAP : 29270866Simp PRINTF("group-map"); 30270866Simp if (hp->iph_flags & FR_INQUE) 31270866Simp PRINTF(" in"); 32270866Simp else if (hp->iph_flags & FR_OUTQUE) 33270866Simp PRINTF(" out"); 34270866Simp else 35270866Simp PRINTF(" ???"); 36270866Simp break; 37270866Simp default : 38270866Simp PRINTF("%#x", hp->iph_type); 39270866Simp break; 40270866Simp } 41270866Simp PRINTF(" role = "); 42270866Simp } else { 43270866Simp PRINTF("Hash Table %s: %s", 44270866Simp isdigit(*hp->iph_name) ? "Number" : "Name", 45270866Simp hp->iph_name); 46270866Simp if ((hp->iph_type & IPHASH_ANON) == IPHASH_ANON) 47270866Simp PRINTF("(anon)"); 48270866Simp putchar(' '); 49270866Simp PRINTF("Role: "); 50270866Simp } 51270866Simp 52270866Simp switch (hp->iph_unit) 53270866Simp { 54270866Simp case IPL_LOGNAT : 55270866Simp PRINTF("nat"); 56270866Simp break; 57270866Simp case IPL_LOGIPF : 58270866Simp PRINTF("ipf"); 59270866Simp break; 60270866Simp case IPL_LOGAUTH : 61270866Simp PRINTF("auth"); 62270866Simp break; 63 case IPL_LOGCOUNT : 64 PRINTF("count"); 65 break; 66 default : 67 PRINTF("#%d", hp->iph_unit); 68 break; 69 } 70 71 if ((opts & OPT_DEBUG) == 0) { 72 if ((hp->iph_type & ~IPHASH_ANON) == IPHASH_LOOKUP) 73 PRINTF(" type = hash"); 74 PRINTF(" %s = %s size = %lu", 75 isdigit(*hp->iph_name) ? "number" : "name", 76 hp->iph_name, (u_long)hp->iph_size); 77 if (hp->iph_seed != 0) 78 PRINTF(" seed = %lu", hp->iph_seed); 79 putchar('\n'); 80 } else { 81 PRINTF(" Type: "); 82 switch (hp->iph_type & ~IPHASH_ANON) 83 { 84 case IPHASH_LOOKUP : 85 PRINTF("lookup"); 86 break; 87 case IPHASH_GROUPMAP : 88 PRINTF("groupmap Group. %s", hp->iph_name); 89 break; 90 default : 91 break; 92 } 93 94 putchar('\n'); 95 PRINTF("\t\tSize: %lu\tSeed: %lu", 96 (u_long)hp->iph_size, hp->iph_seed); 97 PRINTF("\tRef. Count: %d\tMasks: %#x\n", hp->iph_ref, 98 hp->iph_masks); 99 } 100 101 if ((opts & OPT_DEBUG) != 0) { 102 struct in_addr m; 103 int i; 104 105 for (i = 0; i < 32; i++) { 106 if ((1 << i) & hp->iph_masks) { 107 ntomask(4, i, &m.s_addr); 108 PRINTF("\t\tMask: %s\n", inet_ntoa(m)); 109 } 110 } 111 } 112} 113