]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/lib/printhashnode.c
MFV r337218: 7261 nvlist code should enforce name length limit
[FreeBSD/FreeBSD.git] / contrib / ipfilter / lib / printhashnode.c
1 /*      $FreeBSD$       */
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
11
12 iphtent_t *
13 printhashnode(iph, ipep, copyfunc, opts, fields)
14         iphtable_t *iph;
15         iphtent_t *ipep;
16         copyfunc_t copyfunc;
17         int opts;
18         wordtab_t *fields;
19 {
20         iphtent_t ipe;
21         u_int hv;
22         int i;
23
24         if ((*copyfunc)(ipep, &ipe, sizeof(ipe)))
25                 return NULL;
26
27         hv = IPE_V4_HASH_FN(ipe.ipe_addr.i6[0], ipe.ipe_mask.i6[0],
28                             iph->iph_size);
29
30         if (fields != NULL) {
31                 for (i = 0; fields[i].w_value != 0; i++) {
32                         printpoolfield(&ipe, IPLT_HASH, i);
33                         if (fields[i + 1].w_value != 0)
34                                 printf("\t");
35                 }
36                 printf("\n");
37         } else if ((opts & OPT_DEBUG) != 0) {
38 #ifdef USE_INET6
39                 if (ipe.ipe_family == AF_INET6) {
40                         char buf[INET6_ADDRSTRLEN + 1];
41                         const char *str;
42
43                         buf[0] = '\0';
44                         str = inet_ntop(AF_INET6, &ipe.ipe_addr.in6,
45                                 buf, sizeof(buf) - 1);
46                         if (str == NULL)
47                                 str = "???";
48                         PRINTF("\t%d\tAddress: %s", hv, str);
49                         printmask(ipe.ipe_family, (u_32_t *)&ipe.ipe_mask.in4_addr);
50                         PRINTF("\tRef. Count: %d\tGroup: %s\n", ipe.ipe_ref,
51                                 ipe.ipe_group);
52 #ifdef USE_QUAD_T
53                         PRINTF("\tHits: %"PRIu64"\tBytes: %"PRIu64"\n",
54                                ipe.ipe_hits, ipe.ipe_bytes);
55 #else
56                         PRINTF("\tHits: %lu\tBytes: %lu\n",
57                                ipe.ipe_hits, ipe.ipe_bytes);
58 #endif /* USE_QUAD_T */
59                 } else if (ipe.ipe_family == AF_INET) {
60 #else
61                 if (ipe.ipe_family == AF_INET) {
62 #endif /* USE_INET6 */
63                         PRINTF("\t%d\tAddress: %s", hv,
64                                 inet_ntoa(ipe.ipe_addr.in4));
65                         printmask(ipe.ipe_family, (u_32_t *)&ipe.ipe_mask.in4_addr);
66                         PRINTF("\tRef. Count: %d\tGroup: %s\n", ipe.ipe_ref,
67                                 ipe.ipe_group);
68 #ifdef USE_QUAD_T
69                         PRINTF("\tHits: %"PRIu64"\tBytes: %"PRIu64"\n",
70                                ipe.ipe_hits, ipe.ipe_bytes);
71 #else
72                         PRINTF("\tHits: %lu\tBytes: %lu\n",
73                                ipe.ipe_hits, ipe.ipe_bytes);
74 #endif /* USE_QUAD_T */
75                 } else {
76                         PRINTF("\tAddress: family: %d\n",
77                                 ipe.ipe_family);
78                 }
79         } else {
80                 putchar(' ');
81                 printip(ipe.ipe_family, (u_32_t *)&ipe.ipe_addr.in4_addr);
82                 printmask(ipe.ipe_family, (u_32_t *)&ipe.ipe_mask.in4_addr);
83                 if (ipe.ipe_value != 0) {
84                         switch (iph->iph_type & ~IPHASH_ANON)
85                         {
86                         case IPHASH_GROUPMAP :
87                                 if (strncmp(ipe.ipe_group, iph->iph_name,
88                                             FR_GROUPLEN))
89                                         PRINTF(", group=%s", ipe.ipe_group);
90                                 break;
91                         }
92                 }
93                 putchar(';');
94         }
95
96         ipep = ipe.ipe_next;
97         return ipep;
98 }