]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/lib/printstate.c
Import IPFilter 4.1.28
[FreeBSD/FreeBSD.git] / contrib / ipfilter / lib / printstate.c
1 /*
2  * Copyright (C) 2002-2005 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  */
6
7 #include "ipf.h"
8 #include "kmem.h"
9
10 #define PRINTF  (void)printf
11 #define FPRINTF (void)fprintf
12
13 ipstate_t *printstate(sp, opts, now)
14 ipstate_t *sp;
15 int opts;
16 u_long now;
17 {
18         synclist_t ipsync;
19
20         if (sp->is_phnext == NULL)
21                 PRINTF("ORPHAN ");
22         PRINTF("%s -> ", hostname(sp->is_v, &sp->is_src.in4));
23         PRINTF("%s pass %#x pr %d state %d/%d",
24                 hostname(sp->is_v, &sp->is_dst.in4), sp->is_pass, sp->is_p,
25                 sp->is_state[0], sp->is_state[1]);
26         if (opts & OPT_DEBUG)
27                 PRINTF(" bkt %d ref %d", sp->is_hv, sp->is_ref);
28         PRINTF("\n\ttag %u ttl %lu", sp->is_tag, sp->is_die - now);
29
30         if (sp->is_p == IPPROTO_TCP) {
31                 PRINTF("\n\t%hu -> %hu %x:%x %hu<<%d:%hu<<%d\n",
32                         ntohs(sp->is_sport), ntohs(sp->is_dport),
33                         sp->is_send, sp->is_dend,
34                         sp->is_maxswin, sp->is_swinscale,
35                         sp->is_maxdwin, sp->is_dwinscale);
36                 PRINTF("\tcmsk %04x smsk %04x s0 %08x/%08x\n",
37                         sp->is_smsk[0], sp->is_smsk[1],
38                         sp->is_s0[0], sp->is_s0[1]);
39                 PRINTF("\tFWD:ISN inc %x sumd %x\n",
40                         sp->is_isninc[0], sp->is_sumd[0]);
41                 PRINTF("\tREV:ISN inc %x sumd %x\n",
42                         sp->is_isninc[1], sp->is_sumd[1]);
43 #ifdef  IPFILTER_SCAN
44                 PRINTF("\tsbuf[0] [");
45                 printsbuf(sp->is_sbuf[0]);
46                 PRINTF("] sbuf[1] [");
47                 printsbuf(sp->is_sbuf[1]);
48                 PRINTF("]\n");
49 #endif
50         } else if (sp->is_p == IPPROTO_UDP) {
51                 PRINTF(" %hu -> %hu\n", ntohs(sp->is_sport),
52                         ntohs(sp->is_dport));
53         } else if (sp->is_p == IPPROTO_GRE) {
54                 PRINTF(" call %hx/%hx\n", ntohs(sp->is_gre.gs_call[0]),
55                        ntohs(sp->is_gre.gs_call[1]));
56         } else if (sp->is_p == IPPROTO_ICMP
57 #ifdef  USE_INET6
58                  || sp->is_p == IPPROTO_ICMPV6
59 #endif
60                 )
61                 PRINTF(" id %hu seq %hu type %d\n", sp->is_icmp.ici_id,
62                         sp->is_icmp.ici_seq, sp->is_icmp.ici_type);
63
64 #ifdef        USE_QUAD_T
65         PRINTF("\tforward: pkts in %qd bytes in %qd pkts out %qd bytes out %qd\n\tbackward: pkts in %qd bytes in %qd pkts out %qd bytes out %qd\n",
66                 sp->is_pkts[0], sp->is_bytes[0],
67                 sp->is_pkts[1], sp->is_bytes[1],
68                 sp->is_pkts[2], sp->is_bytes[2],
69                 sp->is_pkts[3], sp->is_bytes[3]);
70 #else
71         PRINTF("\tforward: pkts in %ld bytes in %ld pkts out %ld bytes out %ld\n\tbackward: pkts in %ld bytes in %ld pkts out %ld bytes out %ld\n",
72                 sp->is_pkts[0], sp->is_bytes[0],
73                 sp->is_pkts[1], sp->is_bytes[1],
74                 sp->is_pkts[2], sp->is_bytes[2],
75                 sp->is_pkts[3], sp->is_bytes[3]);
76 #endif
77
78         PRINTF("\t");
79
80         /*
81          * Print out bits set in the result code for the state being
82          * kept as they would for a rule.
83          */
84         if (FR_ISPASS(sp->is_pass)) {
85                 PRINTF("pass");
86         } else if (FR_ISBLOCK(sp->is_pass)) {
87                 PRINTF("block");
88                 switch (sp->is_pass & FR_RETMASK)
89                 {
90                 case FR_RETICMP :
91                         PRINTF(" return-icmp");
92                         break;
93                 case FR_FAKEICMP :
94                         PRINTF(" return-icmp-as-dest");
95                         break;
96                 case FR_RETRST :
97                         PRINTF(" return-rst");
98                         break;
99                 default :
100                         break;
101                 }
102         } else if ((sp->is_pass & FR_LOGMASK) == FR_LOG) {
103                         PRINTF("log");
104                 if (sp->is_pass & FR_LOGBODY)
105                         PRINTF(" body");
106                 if (sp->is_pass & FR_LOGFIRST)
107                         PRINTF(" first");
108         } else if (FR_ISACCOUNT(sp->is_pass)) {
109                 PRINTF("count");
110         } else if (FR_ISPREAUTH(sp->is_pass)) {
111                 PRINTF("preauth");
112         } else if (FR_ISAUTH(sp->is_pass))
113                 PRINTF("auth");
114
115         if (sp->is_pass & FR_OUTQUE)
116                 PRINTF(" out");
117         else
118                 PRINTF(" in");
119
120         if ((sp->is_pass & FR_LOG) != 0) {
121                 PRINTF(" log");
122                 if (sp->is_pass & FR_LOGBODY)
123                         PRINTF(" body");
124                 if (sp->is_pass & FR_LOGFIRST)
125                         PRINTF(" first");
126                 if (sp->is_pass & FR_LOGORBLOCK)
127                         PRINTF(" or-block");
128         }
129         if (sp->is_pass & FR_QUICK)
130                 PRINTF(" quick");
131         if (sp->is_pass & FR_KEEPFRAG)
132                 PRINTF(" keep frags");
133         /* a given; no? */
134         if (sp->is_pass & FR_KEEPSTATE) {
135                 PRINTF(" keep state");
136                 if (sp->is_pass & FR_STATESYNC) 
137                         PRINTF(" ( sync )");
138         }
139         PRINTF("\tIPv%d", sp->is_v);
140         PRINTF("\n");
141
142         PRINTF("\tpkt_flags & %x(%x) = %x,\t",
143                 sp->is_flags & 0xf, sp->is_flags,
144                 sp->is_flags >> 4);
145         PRINTF("\tpkt_options & %x = %x, %x = %x \n", sp->is_optmsk[0],
146                 sp->is_opt[0], sp->is_optmsk[1], sp->is_opt[1]);
147         PRINTF("\tpkt_security & %x = %x, pkt_auth & %x = %x\n",
148                 sp->is_secmsk, sp->is_sec, sp->is_authmsk,
149                 sp->is_auth);
150         PRINTF("\tis_flx %#x %#x %#x %#x\n", sp->is_flx[0][0], sp->is_flx[0][1],
151                sp->is_flx[1][0], sp->is_flx[1][1]);
152         PRINTF("\tinterfaces: in %s[%s", getifname(sp->is_ifp[0]),
153                 sp->is_ifname[0]);
154         if (opts & OPT_DEBUG)
155                 PRINTF("/%p", sp->is_ifp[0]);
156         putchar(']');
157         PRINTF(",%s[%s", getifname(sp->is_ifp[1]), sp->is_ifname[1]);
158         if (opts & OPT_DEBUG)
159                 PRINTF("/%p", sp->is_ifp[1]);
160         putchar(']');
161         PRINTF(" out %s[%s", getifname(sp->is_ifp[2]), sp->is_ifname[2]);
162         if (opts & OPT_DEBUG)
163                 PRINTF("/%p", sp->is_ifp[2]);
164         putchar(']');
165         PRINTF(",%s[%s", getifname(sp->is_ifp[3]), sp->is_ifname[3]);
166         if (opts & OPT_DEBUG)
167                 PRINTF("/%p", sp->is_ifp[3]);
168         PRINTF("]\n");
169
170         if (sp->is_sync != NULL) {
171
172                 if (kmemcpy((char *)&ipsync, (u_long)sp->is_sync, sizeof(ipsync))) {
173         
174                         PRINTF("\tSync status: status could not be retrieved\n");
175                         return NULL;
176                 }
177
178                 PRINTF("\tSync status: idx %d num %d v %d pr %d rev %d\n",
179                         ipsync.sl_idx, ipsync.sl_num, ipsync.sl_v,
180                         ipsync.sl_p, ipsync.sl_rev);
181                 
182         } else {
183                 PRINTF("\tSync status: not synchronized\n");
184         }
185
186         return sp->is_next;
187 }