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