1 /* 2 * Copyright (C) 2012 by Darren Reed. 3 * 4 * See the IPFILTER.LICENCE file for details on licencing. 5 */ 6 7 #include "ipf.h" 8 #include <ctype.h> 9 10 11 void 12 printhashdata(iphtable_t *hp, int opts) 13 { 14 15 if (opts & OPT_SAVEOUT) { 16 if ((hp->iph_flags & IPHASH_DELETE) == IPHASH_DELETE) 17 PRINTF("# "); 18 PRINTF("pool "); 19 } else if ((opts & OPT_DEBUG) == 0) { 20 if ((hp->iph_type & IPHASH_ANON) == IPHASH_ANON) 21 PRINTF("# 'anonymous' table refs %d\n", hp->iph_ref); 22 if ((hp->iph_flags & IPHASH_DELETE) == IPHASH_DELETE) 23 PRINTF("# "); 24 switch (hp->iph_type & ~IPHASH_ANON) 25 { 26 case IPHASH_LOOKUP : 27 PRINTF("table"); 28 break; 29 case IPHASH_GROUPMAP : 30 PRINTF("group-map"); 31 if (hp->iph_flags & FR_INQUE) 32 PRINTF(" in"); 33 else if (hp->iph_flags & FR_OUTQUE) 34 PRINTF(" out"); 35 else 36 PRINTF(" ???"); 37 break; 38 default : 39 PRINTF("%#x", hp->iph_type); 40 break; 41 } 42 PRINTF(" role="); 43 } else { 44 if ((hp->iph_flags & IPHASH_DELETE) == IPHASH_DELETE) 45 PRINTF("# "); 46 PRINTF("Hash Table %s: %s", 47 ISDIGIT(*hp->iph_name) ? "Number" : "Name", 48 hp->iph_name); 49 if ((hp->iph_type & IPHASH_ANON) == IPHASH_ANON) 50 PRINTF("(anon)"); 51 putchar(' '); 52 PRINTF("Role: "); 53 } 54 55 printunit(hp->iph_unit); 56 57 if ((opts & OPT_SAVEOUT)) { 58 if ((hp->iph_type & ~IPHASH_ANON) == IPHASH_LOOKUP) 59 PRINTF("/hash"); 60 PRINTF("(%s \"%s\"; size %lu;", 61 ISDIGIT(*hp->iph_name) ? "number" : "name", 62 hp->iph_name, (u_long)hp->iph_size); 63 if (hp->iph_seed != 0) 64 PRINTF(" seed %lu;", hp->iph_seed); 65 PRINTF(")\n", hp->iph_seed); 66 } else if ((opts & OPT_DEBUG) == 0) { 67 if ((hp->iph_type & ~IPHASH_ANON) == IPHASH_LOOKUP) 68 PRINTF(" type=hash"); 69 PRINTF(" %s=%s size=%lu", 70 ISDIGIT(*hp->iph_name) ? "number" : "name", 71 hp->iph_name, (u_long)hp->iph_size); 72 if (hp->iph_seed != 0) 73 PRINTF(" seed=%lu", hp->iph_seed); 74 putchar('\n'); 75 } else { 76 PRINTF(" Type: "); 77 switch (hp->iph_type & ~IPHASH_ANON) 78 { 79 case IPHASH_LOOKUP : 80 PRINTF("lookup"); 81 break; 82 case IPHASH_GROUPMAP : 83 PRINTF("groupmap Group. %s", hp->iph_name); 84 break; 85 default : 86 break; 87 } 88 89 putchar('\n'); 90 PRINTF("\t\tSize: %lu\tSeed: %lu", 91 (u_long)hp->iph_size, hp->iph_seed); 92 PRINTF("\tRef. Count: %d\tMasks: %#x\n", hp->iph_ref, 93 hp->iph_maskset[0]); 94 } 95 96 if ((opts & OPT_DEBUG) != 0) { 97 struct in_addr m; 98 int i; 99 100 for (i = 0; i < 32; i++) { 101 if ((1 << i) & hp->iph_maskset[0]) { 102 ntomask(AF_INET, i, &m.s_addr); 103 PRINTF("\t\tMask: %s\n", inet_ntoa(m)); 104 } 105 } 106 } 107 } 108