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