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