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_DEBUG) == 0) { 16 if ((hp->iph_type & IPHASH_ANON) == IPHASH_ANON) 17 PRINTF("# 'anonymous' table refs %d\n", hp->iph_ref); 18 if ((hp->iph_flags & IPHASH_DELETE) == IPHASH_DELETE) 19 PRINTF("# "); 20 switch (hp->iph_type & ~IPHASH_ANON) 21 { 22 case IPHASH_LOOKUP : 23 PRINTF("table"); 24 break; 25 case IPHASH_GROUPMAP : 26 PRINTF("group-map"); 27 if (hp->iph_flags & FR_INQUE) 28 PRINTF(" in"); 29 else if (hp->iph_flags & FR_OUTQUE) 30 PRINTF(" out"); 31 else 32 PRINTF(" ???"); 33 break; 34 default : 35 PRINTF("%#x", hp->iph_type); 36 break; 37 } 38 PRINTF(" role="); 39 } else { 40 PRINTF("Hash Table %s: %s", 41 ISDIGIT(*hp->iph_name) ? "Number" : "Name", 42 hp->iph_name); 43 if ((hp->iph_type & IPHASH_ANON) == IPHASH_ANON) 44 PRINTF("(anon)"); 45 putchar(' '); 46 PRINTF("Role: "); 47 } 48 49 printunit(hp->iph_unit); 50 51 if ((opts & OPT_DEBUG) == 0) { 52 if ((hp->iph_type & ~IPHASH_ANON) == IPHASH_LOOKUP) 53 PRINTF(" type=hash"); 54 PRINTF(" %s=%s size=%lu", 55 ISDIGIT(*hp->iph_name) ? "number" : "name", 56 hp->iph_name, (u_long)hp->iph_size); 57 if (hp->iph_seed != 0) 58 PRINTF(" seed=%lu", hp->iph_seed); 59 putchar('\n'); 60 } else { 61 PRINTF(" Type: "); 62 switch (hp->iph_type & ~IPHASH_ANON) 63 { 64 case IPHASH_LOOKUP : 65 PRINTF("lookup"); 66 break; 67 case IPHASH_GROUPMAP : 68 PRINTF("groupmap Group. %s", hp->iph_name); 69 break; 70 default : 71 break; 72 } 73 74 putchar('\n'); 75 PRINTF("\t\tSize: %lu\tSeed: %lu", 76 (u_long)hp->iph_size, hp->iph_seed); 77 PRINTF("\tRef. Count: %d\tMasks: %#x\n", hp->iph_ref, 78 hp->iph_maskset[0]); 79 } 80 81 if ((opts & OPT_DEBUG) != 0) { 82 struct in_addr m; 83 int i; 84 85 for (i = 0; i < 32; i++) { 86 if ((1 << i) & hp->iph_maskset[0]) { 87 ntomask(AF_INET, i, &m.s_addr); 88 PRINTF("\t\tMask: %s\n", inet_ntoa(m)); 89 } 90 } 91 } 92 } 93