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