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