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