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