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