17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Copyright (C) 2002 by Darren Reed. 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * See the IPFILTER.LICENCE file for details on licencing. 57663b816Sml37995 * 6*ab25eeb5Syz155240 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 77663b816Sml37995 * Use is subject to license terms. 87c478bd9Sstevel@tonic-gate */ 97c478bd9Sstevel@tonic-gate 107663b816Sml37995 #pragma ident "%Z%%M% %I% %E% SMI" 117663b816Sml37995 127c478bd9Sstevel@tonic-gate #include "ipf.h" 137c478bd9Sstevel@tonic-gate 147c478bd9Sstevel@tonic-gate #define PRINTF (void)printf 157c478bd9Sstevel@tonic-gate #define FPRINTF (void)fprintf 167c478bd9Sstevel@tonic-gate 17*ab25eeb5Syz155240 18*ab25eeb5Syz155240 iphtable_t *printhash(hp, copyfunc, name, opts) 197c478bd9Sstevel@tonic-gate iphtable_t *hp; 207c478bd9Sstevel@tonic-gate copyfunc_t copyfunc; 21*ab25eeb5Syz155240 char *name; 227c478bd9Sstevel@tonic-gate int opts; 237c478bd9Sstevel@tonic-gate { 247663b816Sml37995 iphtent_t *ipep, **table; 257c478bd9Sstevel@tonic-gate iphtable_t iph; 26*ab25eeb5Syz155240 int i, printed; 277663b816Sml37995 size_t sz; 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate if ((*copyfunc)((char *)hp, (char *)&iph, sizeof(iph))) 307c478bd9Sstevel@tonic-gate return NULL; 317c478bd9Sstevel@tonic-gate 32*ab25eeb5Syz155240 if ((name != NULL) && strncmp(name, iph.iph_name, FR_GROUPLEN)) 33*ab25eeb5Syz155240 return iph.iph_next; 34*ab25eeb5Syz155240 357c478bd9Sstevel@tonic-gate if ((opts & OPT_DEBUG) == 0) { 367c478bd9Sstevel@tonic-gate if ((iph.iph_type & IPHASH_ANON) == IPHASH_ANON) 377c478bd9Sstevel@tonic-gate PRINTF("# 'anonymous' table\n"); 387c478bd9Sstevel@tonic-gate switch (iph.iph_type & ~IPHASH_ANON) 397c478bd9Sstevel@tonic-gate { 407c478bd9Sstevel@tonic-gate case IPHASH_LOOKUP : 417c478bd9Sstevel@tonic-gate PRINTF("table"); 427c478bd9Sstevel@tonic-gate break; 437c478bd9Sstevel@tonic-gate case IPHASH_GROUPMAP : 447c478bd9Sstevel@tonic-gate PRINTF("group-map"); 457c478bd9Sstevel@tonic-gate if (iph.iph_flags & FR_INQUE) 467c478bd9Sstevel@tonic-gate PRINTF(" in"); 477c478bd9Sstevel@tonic-gate else if (iph.iph_flags & FR_OUTQUE) 487c478bd9Sstevel@tonic-gate PRINTF(" out"); 497c478bd9Sstevel@tonic-gate else 507c478bd9Sstevel@tonic-gate PRINTF(" ???"); 517c478bd9Sstevel@tonic-gate break; 527c478bd9Sstevel@tonic-gate default : 537c478bd9Sstevel@tonic-gate PRINTF("%#x", iph.iph_type); 547c478bd9Sstevel@tonic-gate break; 557c478bd9Sstevel@tonic-gate } 567c478bd9Sstevel@tonic-gate PRINTF(" role = "); 577c478bd9Sstevel@tonic-gate } else { 587c478bd9Sstevel@tonic-gate PRINTF("Hash Table Number: %s", iph.iph_name); 597c478bd9Sstevel@tonic-gate if ((iph.iph_type & IPHASH_ANON) == IPHASH_ANON) 607c478bd9Sstevel@tonic-gate PRINTF("(anon)"); 617c478bd9Sstevel@tonic-gate putchar(' '); 627c478bd9Sstevel@tonic-gate PRINTF("Role: "); 637c478bd9Sstevel@tonic-gate } 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate switch (iph.iph_unit) 667c478bd9Sstevel@tonic-gate { 677c478bd9Sstevel@tonic-gate case IPL_LOGNAT : 687c478bd9Sstevel@tonic-gate PRINTF("nat"); 697c478bd9Sstevel@tonic-gate break; 707c478bd9Sstevel@tonic-gate case IPL_LOGIPF : 717c478bd9Sstevel@tonic-gate PRINTF("ipf"); 727c478bd9Sstevel@tonic-gate break; 737c478bd9Sstevel@tonic-gate case IPL_LOGAUTH : 747c478bd9Sstevel@tonic-gate PRINTF("auth"); 757c478bd9Sstevel@tonic-gate break; 767c478bd9Sstevel@tonic-gate case IPL_LOGCOUNT : 777c478bd9Sstevel@tonic-gate PRINTF("count"); 787c478bd9Sstevel@tonic-gate break; 797c478bd9Sstevel@tonic-gate default : 807c478bd9Sstevel@tonic-gate PRINTF("#%d", iph.iph_unit); 817c478bd9Sstevel@tonic-gate break; 827c478bd9Sstevel@tonic-gate } 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate if ((opts & OPT_DEBUG) == 0) { 857c478bd9Sstevel@tonic-gate if ((iph.iph_type & ~IPHASH_ANON) == IPHASH_LOOKUP) 867c478bd9Sstevel@tonic-gate PRINTF(" type = hash"); 877663b816Sml37995 PRINTF(" number = %s size = %lu", 887663b816Sml37995 iph.iph_name, (u_long)iph.iph_size); 897c478bd9Sstevel@tonic-gate if (iph.iph_seed != 0) 907c478bd9Sstevel@tonic-gate PRINTF(" seed = %lu", iph.iph_seed); 917c478bd9Sstevel@tonic-gate putchar('\n'); 927c478bd9Sstevel@tonic-gate } else { 937c478bd9Sstevel@tonic-gate PRINTF(" Type: "); 947c478bd9Sstevel@tonic-gate switch (iph.iph_type & ~IPHASH_ANON) 957c478bd9Sstevel@tonic-gate { 967c478bd9Sstevel@tonic-gate case IPHASH_LOOKUP : 977c478bd9Sstevel@tonic-gate PRINTF("lookup"); 987c478bd9Sstevel@tonic-gate break; 997c478bd9Sstevel@tonic-gate case IPHASH_GROUPMAP : 1007c478bd9Sstevel@tonic-gate PRINTF("groupmap Group. %s", iph.iph_name); 1017c478bd9Sstevel@tonic-gate break; 1027c478bd9Sstevel@tonic-gate default : 1037c478bd9Sstevel@tonic-gate break; 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate putchar('\n'); 1077663b816Sml37995 PRINTF("\t\tSize: %lu\tSeed: %lu", 1087663b816Sml37995 (u_long)iph.iph_size, iph.iph_seed); 1097663b816Sml37995 PRINTF("\tRef. Count: %d\tMasks: %#x\n", iph.iph_ref, 1107663b816Sml37995 iph.iph_masks[3]); 1117c478bd9Sstevel@tonic-gate } 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate if ((opts & OPT_DEBUG) != 0) { 1147663b816Sml37995 struct in_addr m; 1157c478bd9Sstevel@tonic-gate 1167663b816Sml37995 for (i = 0; i < 32; i++) { 1177663b816Sml37995 if ((1 << i) & iph.iph_masks[3]) { 1187663b816Sml37995 ntomask(4, i, &m.s_addr); 1197663b816Sml37995 PRINTF("\t\tMask: %s\n", inet_ntoa(m)); 1207663b816Sml37995 } 1217c478bd9Sstevel@tonic-gate } 1227c478bd9Sstevel@tonic-gate } 1237c478bd9Sstevel@tonic-gate 1247663b816Sml37995 if ((opts & OPT_DEBUG) == 0) 1257c478bd9Sstevel@tonic-gate PRINTF("\t{"); 1267c478bd9Sstevel@tonic-gate 1277663b816Sml37995 sz = iph.iph_size * sizeof(*table); 1287663b816Sml37995 table = malloc(sz); 1297663b816Sml37995 if ((*copyfunc)((char *)iph.iph_table, (char *)table, sz)) 1307663b816Sml37995 return NULL; 1317c478bd9Sstevel@tonic-gate 132*ab25eeb5Syz155240 for (i = 0, printed = 0; i < iph.iph_size; i++) { 1337663b816Sml37995 for (ipep = table[i]; ipep != NULL; ) { 1347663b816Sml37995 ipep = printhashnode(&iph, ipep, copyfunc, opts); 135*ab25eeb5Syz155240 printed++; 1367663b816Sml37995 } 1377663b816Sml37995 } 138*ab25eeb5Syz155240 if (printed == 0) 139*ab25eeb5Syz155240 putchar(';'); 1407663b816Sml37995 1417663b816Sml37995 free(table); 1427663b816Sml37995 1437663b816Sml37995 if ((opts & OPT_DEBUG) == 0) 1447c478bd9Sstevel@tonic-gate PRINTF(" };\n"); 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate return iph.iph_next; 1477c478bd9Sstevel@tonic-gate } 148