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