2 * Copyright (C) 2002 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 #if defined(__sgi) && (IRIX > 602)
7 # include <sys/ptimers.h>
10 #include <sys/param.h>
11 #include <sys/socket.h>
12 #include <sys/ioctl.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
15 #include <netinet/in_systm.h>
18 #if __FreeBSD_version >= 300000
19 # include <net/if_var.h>
22 #include "netinet/ip_compat.h"
24 #include "netinet/ip_fil.h"
25 #include "netinet/ip_state.h"
27 #define PRINTF (void)printf
28 #define FPRINTF (void)fprintf
30 ipstate_t *printstate(sp, opts)
36 if (kmemcpy((char *)&ips, (u_long)sp, sizeof(ips)))
39 PRINTF("%s -> ", hostname(ips.is_v, &ips.is_src.in4));
40 PRINTF("%s ttl %ld pass %#x pr %d state %d/%d\n",
41 hostname(ips.is_v, &ips.is_dst.in4),
42 ips.is_age, ips.is_pass, ips.is_p,
43 ips.is_state[0], ips.is_state[1]);
45 PRINTF("\tpkts %qu bytes %qu", (unsigned long long) ips.is_pkts,
46 (unsigned long long) ips.is_bytes);
48 PRINTF("\tpkts %ld bytes %ld", ips.is_pkts, ips.is_bytes);
50 if (ips.is_p == IPPROTO_TCP) {
51 #if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \
52 (__FreeBSD_version >= 220000) || defined(__OpenBSD__)
53 PRINTF("\t%hu -> %hu %x:%x (max %x:%x)\n",
54 ntohs(ips.is_sport), ntohs(ips.is_dport),
55 ips.is_send, ips.is_dend,
56 ips.is_maxsend, ips.is_maxdend);
57 PRINTF("\t%u<<%d:%u<<%d",
58 ips.is_maxswin>>ips.is_swscale, ips.is_swscale,
59 ips.is_maxdwin>>ips.is_dwscale, ips.is_dwscale);
61 PRINTF("\t%hu -> %hu %x:%x (max %x:%x)\n",
62 ntohs(ips.is_sport), ntohs(ips.is_dport),
63 ips.is_send, ips.is_dend,
64 ips.is_maxsend, ips.is_maxdend);
65 PRINTF("\t%u<<%d:%u<<%d",
66 ips.is_maxswin>>ips.is_swscale, ips.is_swscale,
67 ips.is_maxdwin>>ips.is_dwscale, ips.is_dwscale);
69 } else if (ips.is_p == IPPROTO_UDP)
70 PRINTF(" %hu -> %hu", ntohs(ips.is_sport),
72 else if (ips.is_p == IPPROTO_ICMP
74 || ips.is_p == IPPROTO_ICMPV6
77 PRINTF(" id %hu seq %hu type %d", ntohs(ips.is_icmp.ics_id),
78 ntohs(ips.is_icmp.ics_seq), ips.is_icmp.ics_type);
83 * Print out bits set in the result code for the state being
84 * kept as they would for a rule.
86 if (ips.is_pass & FR_PASS) {
88 } else if (ips.is_pass & FR_BLOCK) {
90 switch (ips.is_pass & FR_RETMASK)
93 PRINTF(" return-icmp");
96 PRINTF(" return-icmp-as-dest");
99 PRINTF(" return-rst");
104 } else if ((ips.is_pass & FR_LOGMASK) == FR_LOG) {
106 if (ips.is_pass & FR_LOGBODY)
108 if (ips.is_pass & FR_LOGFIRST)
110 } else if (ips.is_pass & FR_ACCOUNT)
113 if (ips.is_pass & FR_OUTQUE)
118 if ((ips.is_pass & FR_LOG) != 0) {
120 if (ips.is_pass & FR_LOGBODY)
122 if (ips.is_pass & FR_LOGFIRST)
124 if (ips.is_pass & FR_LOGORBLOCK)
127 if (ips.is_pass & FR_QUICK)
129 if (ips.is_pass & FR_KEEPFRAG)
130 PRINTF(" keep frags");
132 if (ips.is_pass & FR_KEEPSTATE)
133 PRINTF(" keep state");
134 PRINTF("\tIPv%d", ips.is_v);
137 PRINTF("\tpkt_flags & %x(%x) = %x,\t",
138 ips.is_flags & 0xf, ips.is_flags,
140 PRINTF("\tpkt_options & %x = %x\n", ips.is_optmsk,
142 PRINTF("\tpkt_security & %x = %x, pkt_auth & %x = %x\n",
143 ips.is_secmsk, ips.is_sec, ips.is_authmsk,
145 PRINTF("\tinterfaces: in %s", getifname(ips.is_ifp[0]));
146 PRINTF(",%s", getifname(ips.is_ifp[1]));
147 PRINTF(" out %s", getifname(ips.is_ifp[2]));
148 PRINTF(",%s\n", getifname(ips.is_ifp[3]));