1 /* 2 * Copyright (C) 2002 by Darren Reed. 3 * 4 * See the IPFILTER.LICENCE file for details on licencing. 5 * 6 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 7 * Use is subject to license terms. 8 */ 9 10 #pragma ident "%Z%%M% %I% %E% SMI" 11 12 #include "ipf.h" 13 14 #define PRINTF (void)printf 15 #define FPRINTF (void)fprintf 16 17 18 iphtable_t *printhash(hp, copyfunc, name, opts) 19 iphtable_t *hp; 20 copyfunc_t copyfunc; 21 char *name; 22 int opts; 23 { 24 iphtent_t *ipep, **table; 25 iphtable_t iph; 26 int i, printed; 27 size_t sz; 28 29 if ((*copyfunc)((char *)hp, (char *)&iph, sizeof(iph))) 30 return NULL; 31 32 if ((name != NULL) && strncmp(name, iph.iph_name, FR_GROUPLEN)) 33 return iph.iph_next; 34 35 if ((opts & OPT_DEBUG) == 0) { 36 if ((iph.iph_type & IPHASH_ANON) == IPHASH_ANON) 37 PRINTF("# 'anonymous' table\n"); 38 switch (iph.iph_type & ~IPHASH_ANON) 39 { 40 case IPHASH_LOOKUP : 41 PRINTF("table"); 42 break; 43 case IPHASH_GROUPMAP : 44 PRINTF("group-map"); 45 if (iph.iph_flags & FR_INQUE) 46 PRINTF(" in"); 47 else if (iph.iph_flags & FR_OUTQUE) 48 PRINTF(" out"); 49 else 50 PRINTF(" ???"); 51 break; 52 default : 53 PRINTF("%#x", iph.iph_type); 54 break; 55 } 56 PRINTF(" role = "); 57 } else { 58 PRINTF("Hash Table Number: %s", iph.iph_name); 59 if ((iph.iph_type & IPHASH_ANON) == IPHASH_ANON) 60 PRINTF("(anon)"); 61 putchar(' '); 62 PRINTF("Role: "); 63 } 64 65 switch (iph.iph_unit) 66 { 67 case IPL_LOGNAT : 68 PRINTF("nat"); 69 break; 70 case IPL_LOGIPF : 71 PRINTF("ipf"); 72 break; 73 case IPL_LOGAUTH : 74 PRINTF("auth"); 75 break; 76 case IPL_LOGCOUNT : 77 PRINTF("count"); 78 break; 79 default : 80 PRINTF("#%d", iph.iph_unit); 81 break; 82 } 83 84 if ((opts & OPT_DEBUG) == 0) { 85 if ((iph.iph_type & ~IPHASH_ANON) == IPHASH_LOOKUP) 86 PRINTF(" type = hash"); 87 PRINTF(" number = %s size = %lu", 88 iph.iph_name, (u_long)iph.iph_size); 89 if (iph.iph_seed != 0) 90 PRINTF(" seed = %lu", iph.iph_seed); 91 putchar('\n'); 92 } else { 93 PRINTF(" Type: "); 94 switch (iph.iph_type & ~IPHASH_ANON) 95 { 96 case IPHASH_LOOKUP : 97 PRINTF("lookup"); 98 break; 99 case IPHASH_GROUPMAP : 100 PRINTF("groupmap Group. %s", iph.iph_name); 101 break; 102 default : 103 break; 104 } 105 106 putchar('\n'); 107 PRINTF("\t\tSize: %lu\tSeed: %lu", 108 (u_long)iph.iph_size, iph.iph_seed); 109 PRINTF("\tRef. Count: %d\tMasks: %#x\n", iph.iph_ref, 110 iph.iph_masks[3]); 111 } 112 113 if ((opts & OPT_DEBUG) != 0) { 114 struct in_addr m; 115 116 for (i = 0; i < 32; i++) { 117 if ((1 << i) & iph.iph_masks[3]) { 118 ntomask(4, i, &m.s_addr); 119 PRINTF("\t\tMask: %s\n", inet_ntoa(m)); 120 } 121 } 122 } 123 124 if ((opts & OPT_DEBUG) == 0) 125 PRINTF("\t{"); 126 127 sz = iph.iph_size * sizeof(*table); 128 table = malloc(sz); 129 if ((*copyfunc)((char *)iph.iph_table, (char *)table, sz)) 130 return NULL; 131 132 for (i = 0, printed = 0; i < iph.iph_size; i++) { 133 for (ipep = table[i]; ipep != NULL; ) { 134 ipep = printhashnode(&iph, ipep, copyfunc, opts); 135 printed++; 136 } 137 } 138 if (printed == 0) 139 putchar(';'); 140 141 free(table); 142 143 if ((opts & OPT_DEBUG) == 0) 144 PRINTF(" };\n"); 145 146 return iph.iph_next; 147 } 148