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