1 | #include <machine/rtems-bsd-user-space.h> |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996 |
---|
5 | * The Regents of the University of California. All rights reserved. |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that: (1) source code distributions |
---|
9 | * retain the above copyright notice and this paragraph in its entirety, (2) |
---|
10 | * distributions including binary code include the above copyright notice and |
---|
11 | * this paragraph in its entirety in the documentation or other materials |
---|
12 | * provided with the distribution, and (3) all advertising materials mentioning |
---|
13 | * features or use of this software display the following acknowledgement: |
---|
14 | * ``This product includes software developed by the University of California, |
---|
15 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of |
---|
16 | * the University nor the names of its contributors may be used to endorse |
---|
17 | * or promote products derived from this software without specific prior |
---|
18 | * written permission. |
---|
19 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
---|
20 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
---|
21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
22 | */ |
---|
23 | |
---|
24 | #ifndef lint |
---|
25 | static const char rcsid[] _U_ = |
---|
26 | "@(#) $Header: /tcpdump/master/tcpdump/print-pflog.c,v 1.16 2007-09-12 19:36:18 guy Exp $ (LBL)"; |
---|
27 | #endif |
---|
28 | |
---|
29 | #ifdef HAVE_CONFIG_H |
---|
30 | #include "config.h" |
---|
31 | #endif |
---|
32 | |
---|
33 | #ifndef HAVE_NET_PFVAR_H |
---|
34 | #error "No pf headers available" |
---|
35 | #endif |
---|
36 | #include <rtems/bsd/sys/types.h> |
---|
37 | #include <sys/socket.h> |
---|
38 | #include <net/if.h> |
---|
39 | #include <net/pfvar.h> |
---|
40 | #include <net/if_pflog.h> |
---|
41 | |
---|
42 | #include <tcpdump-stdinc.h> |
---|
43 | |
---|
44 | #include <stdio.h> |
---|
45 | #include <pcap.h> |
---|
46 | |
---|
47 | #include "extract.h" |
---|
48 | #include "interface.h" |
---|
49 | #include "addrtoname.h" |
---|
50 | |
---|
51 | static struct tok pf_reasons[] = { |
---|
52 | { 0, "0(match)" }, |
---|
53 | { 1, "1(bad-offset)" }, |
---|
54 | { 2, "2(fragment)" }, |
---|
55 | { 3, "3(short)" }, |
---|
56 | { 4, "4(normalize)" }, |
---|
57 | { 5, "5(memory)" }, |
---|
58 | { 6, "6(bad-timestamp)" }, |
---|
59 | { 7, "7(congestion)" }, |
---|
60 | { 8, "8(ip-option)" }, |
---|
61 | { 9, "9(proto-cksum)" }, |
---|
62 | { 10, "10(state-mismatch)" }, |
---|
63 | { 11, "11(state-insert)" }, |
---|
64 | { 12, "12(state-limit)" }, |
---|
65 | { 13, "13(src-limit)" }, |
---|
66 | { 14, "14(synproxy)" }, |
---|
67 | { 0, NULL } |
---|
68 | }; |
---|
69 | |
---|
70 | static struct tok pf_actions[] = { |
---|
71 | { PF_PASS, "pass" }, |
---|
72 | { PF_DROP, "block" }, |
---|
73 | { PF_SCRUB, "scrub" }, |
---|
74 | { PF_NAT, "nat" }, |
---|
75 | { PF_NONAT, "nat" }, |
---|
76 | { PF_BINAT, "binat" }, |
---|
77 | { PF_NOBINAT, "binat" }, |
---|
78 | { PF_RDR, "rdr" }, |
---|
79 | { PF_NORDR, "rdr" }, |
---|
80 | { PF_SYNPROXY_DROP, "synproxy-drop" }, |
---|
81 | { 0, NULL } |
---|
82 | }; |
---|
83 | |
---|
84 | static struct tok pf_directions[] = { |
---|
85 | { PF_INOUT, "in/out" }, |
---|
86 | { PF_IN, "in" }, |
---|
87 | { PF_OUT, "out" }, |
---|
88 | { 0, NULL } |
---|
89 | }; |
---|
90 | |
---|
91 | /* For reading capture files on other systems */ |
---|
92 | #define OPENBSD_AF_INET 2 |
---|
93 | #define OPENBSD_AF_INET6 24 |
---|
94 | |
---|
95 | static void |
---|
96 | pflog_print(const struct pfloghdr *hdr) |
---|
97 | { |
---|
98 | u_int32_t rulenr, subrulenr; |
---|
99 | |
---|
100 | rulenr = EXTRACT_32BITS(&hdr->rulenr); |
---|
101 | subrulenr = EXTRACT_32BITS(&hdr->subrulenr); |
---|
102 | if (subrulenr == (u_int32_t)-1) |
---|
103 | printf("rule %u/", rulenr); |
---|
104 | else |
---|
105 | printf("rule %u.%s.%u/", rulenr, hdr->ruleset, subrulenr); |
---|
106 | |
---|
107 | printf("%s: %s %s on %s: ", |
---|
108 | tok2str(pf_reasons, "unkn(%u)", hdr->reason), |
---|
109 | tok2str(pf_actions, "unkn(%u)", hdr->action), |
---|
110 | tok2str(pf_directions, "unkn(%u)", hdr->dir), |
---|
111 | hdr->ifname); |
---|
112 | } |
---|
113 | |
---|
114 | u_int |
---|
115 | pflog_if_print(const struct pcap_pkthdr *h, register const u_char *p) |
---|
116 | { |
---|
117 | u_int length = h->len; |
---|
118 | u_int hdrlen; |
---|
119 | u_int caplen = h->caplen; |
---|
120 | const struct pfloghdr *hdr; |
---|
121 | u_int8_t af; |
---|
122 | |
---|
123 | /* check length */ |
---|
124 | if (caplen < sizeof(u_int8_t)) { |
---|
125 | printf("[|pflog]"); |
---|
126 | return (caplen); |
---|
127 | } |
---|
128 | |
---|
129 | #define MIN_PFLOG_HDRLEN 45 |
---|
130 | hdr = (struct pfloghdr *)p; |
---|
131 | if (hdr->length < MIN_PFLOG_HDRLEN) { |
---|
132 | printf("[pflog: invalid header length!]"); |
---|
133 | return (hdr->length); /* XXX: not really */ |
---|
134 | } |
---|
135 | hdrlen = BPF_WORDALIGN(hdr->length); |
---|
136 | |
---|
137 | if (caplen < hdrlen) { |
---|
138 | printf("[|pflog]"); |
---|
139 | return (hdrlen); /* XXX: true? */ |
---|
140 | } |
---|
141 | |
---|
142 | /* print what we know */ |
---|
143 | hdr = (struct pfloghdr *)p; |
---|
144 | TCHECK(*hdr); |
---|
145 | if (eflag) |
---|
146 | pflog_print(hdr); |
---|
147 | |
---|
148 | /* skip to the real packet */ |
---|
149 | af = hdr->af; |
---|
150 | length -= hdrlen; |
---|
151 | caplen -= hdrlen; |
---|
152 | p += hdrlen; |
---|
153 | switch (af) { |
---|
154 | |
---|
155 | case AF_INET: |
---|
156 | #if OPENBSD_AF_INET != AF_INET |
---|
157 | case OPENBSD_AF_INET: /* XXX: read pcap files */ |
---|
158 | #endif |
---|
159 | ip_print(gndo, p, length); |
---|
160 | break; |
---|
161 | |
---|
162 | #ifdef INET6 |
---|
163 | case AF_INET6: |
---|
164 | #if OPENBSD_AF_INET6 != AF_INET6 |
---|
165 | case OPENBSD_AF_INET6: /* XXX: read pcap files */ |
---|
166 | #endif |
---|
167 | ip6_print(gndo, p, length); |
---|
168 | break; |
---|
169 | #endif |
---|
170 | |
---|
171 | default: |
---|
172 | /* address family not handled, print raw packet */ |
---|
173 | if (!eflag) |
---|
174 | pflog_print(hdr); |
---|
175 | if (!suppress_default_print) |
---|
176 | default_print(p, caplen); |
---|
177 | } |
---|
178 | |
---|
179 | return (hdrlen); |
---|
180 | trunc: |
---|
181 | printf("[|pflog]"); |
---|
182 | return (hdrlen); |
---|
183 | } |
---|
184 | |
---|
185 | /* |
---|
186 | * Local Variables: |
---|
187 | * c-style: whitesmith |
---|
188 | * c-basic-offset: 8 |
---|
189 | * End: |
---|
190 | */ |
---|