printhashdata.c revision 255332
1239310Sdim/* 2239310Sdim * Copyright (C) 2012 by Darren Reed. 3353358Sdim * 4353358Sdim * See the IPFILTER.LICENCE file for details on licencing. 5353358Sdim */ 6239310Sdim 7239310Sdim#include "ipf.h" 8239310Sdim#include <ctype.h> 9239310Sdim 10239310Sdim 11239310Sdimvoid 12239310Sdimprinthashdata(hp, opts) 13239310Sdim iphtable_t *hp; 14239310Sdim int opts; 15239310Sdim{ 16239310Sdim 17239310Sdim if ((opts & OPT_DEBUG) == 0) { 18239310Sdim if ((hp->iph_type & IPHASH_ANON) == IPHASH_ANON) 19239310Sdim PRINTF("# 'anonymous' table refs %d\n", hp->iph_ref); 20239310Sdim if ((hp->iph_flags & IPHASH_DELETE) == IPHASH_DELETE) 21239310Sdim PRINTF("# "); 22239310Sdim switch (hp->iph_type & ~IPHASH_ANON) 23239310Sdim { 24239310Sdim case IPHASH_LOOKUP : 25239310Sdim PRINTF("table"); 26239310Sdim break; 27239310Sdim case IPHASH_GROUPMAP : 28239310Sdim PRINTF("group-map"); 29353358Sdim if (hp->iph_flags & FR_INQUE) 30353358Sdim PRINTF(" in"); 31353358Sdim else if (hp->iph_flags & FR_OUTQUE) 32353358Sdim PRINTF(" out"); 33353358Sdim else 34353358Sdim PRINTF(" ???"); 35353358Sdim break; 36353358Sdim default : 37353358Sdim PRINTF("%#x", hp->iph_type); 38353358Sdim break; 39353358Sdim } 40239310Sdim PRINTF(" role="); 41353358Sdim } else { 42353358Sdim PRINTF("Hash Table %s: %s", 43353358Sdim ISDIGIT(*hp->iph_name) ? "Number" : "Name", 44353358Sdim hp->iph_name); 45353358Sdim if ((hp->iph_type & IPHASH_ANON) == IPHASH_ANON) 46353358Sdim PRINTF("(anon)"); 47353358Sdim putchar(' '); 48353358Sdim PRINTF("Role: "); 49353358Sdim } 50239310Sdim 51353358Sdim printunit(hp->iph_unit); 52353358Sdim 53353358Sdim if ((opts & OPT_DEBUG) == 0) { 54353358Sdim if ((hp->iph_type & ~IPHASH_ANON) == IPHASH_LOOKUP) 55353358Sdim PRINTF(" type=hash"); 56353358Sdim PRINTF(" %s=%s size=%lu", 57353358Sdim ISDIGIT(*hp->iph_name) ? "number" : "name", 58353358Sdim hp->iph_name, (u_long)hp->iph_size); 59360784Sdim if (hp->iph_seed != 0) 60360784Sdim PRINTF(" seed=%lu", hp->iph_seed); 61360784Sdim putchar('\n'); 62360784Sdim } else { 63239310Sdim PRINTF(" Type: "); 64309124Sdim switch (hp->iph_type & ~IPHASH_ANON) 65239310Sdim { 66309124Sdim case IPHASH_LOOKUP : 67239310Sdim PRINTF("lookup"); 68239310Sdim break; 69239310Sdim case IPHASH_GROUPMAP : 70321369Sdim PRINTF("groupmap Group. %s", hp->iph_name); 71321369Sdim break; 72321369Sdim default : 73321369Sdim break; 74321369Sdim } 75321369Sdim 76239310Sdim putchar('\n'); 77239310Sdim PRINTF("\t\tSize: %lu\tSeed: %lu", 78321369Sdim (u_long)hp->iph_size, hp->iph_seed); 79321369Sdim PRINTF("\tRef. Count: %d\tMasks: %#x\n", hp->iph_ref, 80321369Sdim hp->iph_maskset[0]); 81321369Sdim } 82239310Sdim 83239310Sdim if ((opts & OPT_DEBUG) != 0) { 84239310Sdim struct in_addr m; 85321369Sdim int i; 86321369Sdim 87321369Sdim for (i = 0; i < 32; i++) { 88321369Sdim if ((1 << i) & hp->iph_maskset[0]) { 89321369Sdim ntomask(AF_INET, i, &m.s_addr); 90321369Sdim PRINTF("\t\tMask: %s\n", inet_ntoa(m)); 91239310Sdim } 92239310Sdim } 93239310Sdim } 94321369Sdim} 95321369Sdim