xref: /netbsd-src/external/bsd/ipf/dist/lib/printhashdata.c (revision c9d5dc6c77aa32fd07899a7a63638e95ffa433dd)
1 /*	$NetBSD: printhashdata.c,v 1.1.1.2 2012/07/22 13:44:40 darrenr Exp $	*/
2 
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  */
8 
9 #include "ipf.h"
10 #include <ctype.h>
11 
12 
13 void
printhashdata(hp,opts)14 printhashdata(hp, opts)
15 	iphtable_t *hp;
16 	int opts;
17 {
18 
19 	if ((opts & OPT_DEBUG) == 0) {
20 		if ((hp->iph_type & IPHASH_ANON) == IPHASH_ANON)
21 			PRINTF("# 'anonymous' table refs %d\n", hp->iph_ref);
22 		if ((hp->iph_flags & IPHASH_DELETE) == IPHASH_DELETE)
23 			PRINTF("# ");
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 %s: %s",
45 			ISDIGIT(*hp->iph_name) ? "Number" : "Name",
46 			hp->iph_name);
47 		if ((hp->iph_type & IPHASH_ANON) == IPHASH_ANON)
48 			PRINTF("(anon)");
49 		putchar(' ');
50 		PRINTF("Role: ");
51 	}
52 
53 	printunit(hp->iph_unit);
54 
55 	if ((opts & OPT_DEBUG) == 0) {
56 		if ((hp->iph_type & ~IPHASH_ANON) == IPHASH_LOOKUP)
57 			PRINTF(" type=hash");
58 		PRINTF(" %s=%s size=%lu",
59 			ISDIGIT(*hp->iph_name) ? "number" : "name",
60 			hp->iph_name, (u_long)hp->iph_size);
61 		if (hp->iph_seed != 0)
62 			PRINTF(" seed=%lu", hp->iph_seed);
63 		putchar('\n');
64 	} else {
65 		PRINTF(" Type: ");
66 		switch (hp->iph_type & ~IPHASH_ANON)
67 		{
68 		case IPHASH_LOOKUP :
69 			PRINTF("lookup");
70 			break;
71 		case IPHASH_GROUPMAP :
72 			PRINTF("groupmap Group. %s", hp->iph_name);
73 			break;
74 		default :
75 			break;
76 		}
77 
78 		putchar('\n');
79 		PRINTF("\t\tSize: %lu\tSeed: %lu",
80 			(u_long)hp->iph_size, hp->iph_seed);
81 		PRINTF("\tRef. Count: %d\tMasks: %#x\n", hp->iph_ref,
82 			hp->iph_maskset[0]);
83 	}
84 
85 	if ((opts & OPT_DEBUG) != 0) {
86 		struct in_addr m;
87 		int i;
88 
89 		for (i = 0; i < 32; i++) {
90 			if ((1 << i) & hp->iph_maskset[0]) {
91 				ntomask(AF_INET, i, &m.s_addr);
92 				PRINTF("\t\tMask: %s\n", inet_ntoa(m));
93 			}
94 		}
95 	}
96 }
97