1 /* 2 * Copyright (C) 2002 by Darren Reed. 3 * 4 * See the IPFILTER.LICENCE file for details on licencing. 5 */ 6 7 #include "ipf.h" 8 9 #define PRINTF (void)printf 10 #define FPRINTF (void)fprintf 11 12 13 iphtable_t *printhash(hp, copyfunc, opts) 14 iphtable_t *hp; 15 copyfunc_t copyfunc; 16 int opts; 17 { 18 iphtent_t *ipep; 19 iphtable_t iph; 20 int i; 21 22 if ((*copyfunc)((char *)hp, (char *)&iph, sizeof(iph))) 23 return NULL; 24 25 if ((opts & OPT_DEBUG) == 0) { 26 if ((iph.iph_type & IPHASH_ANON) == IPHASH_ANON) 27 PRINTF("# 'anonymous' table\n"); 28 switch (iph.iph_type & ~IPHASH_ANON) 29 { 30 case IPHASH_LOOKUP : 31 PRINTF("table"); 32 break; 33 case IPHASH_GROUPMAP : 34 PRINTF("group-map"); 35 if (iph.iph_flags & FR_INQUE) 36 PRINTF(" in"); 37 else if (iph.iph_flags & FR_OUTQUE) 38 PRINTF(" out"); 39 else 40 PRINTF(" ???"); 41 break; 42 default : 43 PRINTF("%#x", iph.iph_type); 44 break; 45 } 46 PRINTF(" role = "); 47 } else { 48 PRINTF("Hash Table Number: %s", iph.iph_name); 49 if ((iph.iph_type & IPHASH_ANON) == IPHASH_ANON) 50 PRINTF("(anon)"); 51 putchar(' '); 52 PRINTF("Role: "); 53 } 54 55 switch (iph.iph_unit) 56 { 57 case IPL_LOGNAT : 58 PRINTF("nat"); 59 break; 60 case IPL_LOGIPF : 61 PRINTF("ipf"); 62 break; 63 case IPL_LOGAUTH : 64 PRINTF("auth"); 65 break; 66 case IPL_LOGCOUNT : 67 PRINTF("count"); 68 break; 69 default : 70 PRINTF("#%d", iph.iph_unit); 71 break; 72 } 73 74 if ((opts & OPT_DEBUG) == 0) { 75 if ((iph.iph_type & ~IPHASH_ANON) == IPHASH_LOOKUP) 76 PRINTF(" type = hash"); 77 PRINTF(" number = %s size = %u", 78 iph.iph_name, iph.iph_size); 79 if (iph.iph_seed != 0) 80 PRINTF(" seed = %lu", iph.iph_seed); 81 putchar('\n'); 82 } else { 83 PRINTF(" Type: "); 84 switch (iph.iph_type & ~IPHASH_ANON) 85 { 86 case IPHASH_LOOKUP : 87 PRINTF("lookup"); 88 break; 89 case IPHASH_GROUPMAP : 90 PRINTF("groupmap Group. %s", iph.iph_name); 91 break; 92 default : 93 break; 94 } 95 96 putchar('\n'); 97 PRINTF("\tSize: %d\tSeed: %lu", iph.iph_size, iph.iph_seed); 98 PRINTF("\tRef. Count: %d\tMasks: %d\n", iph.iph_ref, 99 iph.iph_masks); 100 } 101 102 if ((opts & OPT_DEBUG) != 0) { 103 u_32_t m; 104 105 for (i = 0; i < 33; i++) { 106 ntomask(4, i, &m); 107 if (m & iph.iph_masks) 108 PRINTF("Mask: %#x\n", m); 109 } 110 } 111 112 PRINTF("\t{"); 113 114 for (i = 0; i < iph.iph_size; i++) 115 for (ipep = iph.iph_table[i]; ipep != NULL; ) 116 ipep = printhashnode(&iph, ipep, copyfunc, opts); 117 118 PRINTF(" };\n"); 119 120 return iph.iph_next; 121 } 122