2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 /* \summary: OpenBSD packet filter log file printer */
28 #ifndef HAVE_NET_PFVAR_H
29 #error "No pf headers available"
31 #include <sys/types.h>
32 #include <sys/socket.h>
34 #include <net/pfvar.h>
35 #include <net/if_pflog.h>
37 #include "netdissect-stdinc.h"
39 #include "netdissect.h"
43 static const struct tok pf_reasons[] = {
45 { 1, "1(bad-offset)" },
48 { 4, "4(normalize)" },
50 { 6, "6(bad-timestamp)" },
51 { 7, "7(congestion)" },
52 { 8, "8(ip-option)" },
53 { 9, "9(proto-cksum)" },
54 { 10, "10(state-mismatch)" },
55 { 11, "11(state-insert)" },
56 { 12, "12(state-limit)" },
57 { 13, "13(src-limit)" },
58 { 14, "14(synproxy)" },
62 static const struct tok pf_actions[] = {
65 { PF_SCRUB, "scrub" },
68 { PF_BINAT, "binat" },
69 { PF_NOBINAT, "binat" },
72 { PF_SYNPROXY_DROP, "synproxy-drop" },
76 static const struct tok pf_directions[] = {
77 { PF_INOUT, "in/out" },
83 /* For reading capture files on other systems */
84 #define OPENBSD_AF_INET 2
85 #define OPENBSD_AF_INET6 24
88 pflog_print(netdissect_options *ndo, const struct pfloghdr *hdr)
90 uint32_t rulenr, subrulenr;
92 ndo->ndo_protocol = "pflog";
93 rulenr = GET_BE_U_4(&hdr->rulenr);
94 subrulenr = GET_BE_U_4(&hdr->subrulenr);
95 if (subrulenr == (uint32_t)-1)
96 ND_PRINT("rule %u/", rulenr);
98 ND_PRINT("rule %u.", rulenr);
99 nd_printjnp(ndo, (const u_char*)hdr->ruleset, PFLOG_RULESET_NAME_SIZE);
100 ND_PRINT(".%u/", subrulenr);
103 ND_PRINT("%s: %s %s on ",
104 tok2str(pf_reasons, "unkn(%u)", GET_U_1(&hdr->reason)),
105 tok2str(pf_actions, "unkn(%u)", GET_U_1(&hdr->action)),
106 tok2str(pf_directions, "unkn(%u)", GET_U_1(&hdr->dir)));
107 nd_printjnp(ndo, (const u_char*)hdr->ifname, IFNAMSIZ);
112 pflog_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
115 u_int length = h->len;
117 u_int caplen = h->caplen;
118 const struct pfloghdr *hdr;
121 ndo->ndo_protocol = "pflog";
123 if (caplen < sizeof(uint8_t)) {
125 ndo->ndo_ll_hdr_len += h->caplen;
129 #define MIN_PFLOG_HDRLEN 45
130 hdr = (const struct pfloghdr *)p;
131 if (GET_U_1(&hdr->length) < MIN_PFLOG_HDRLEN) {
132 ND_PRINT("[pflog: invalid header length!]");
133 ndo->ndo_ll_hdr_len += GET_U_1(&hdr->length); /* XXX: not really */
136 hdrlen = BPF_WORDALIGN(hdr->length);
138 if (caplen < hdrlen) {
140 ndo->ndo_ll_hdr_len += hdrlen; /* XXX: true? */
144 /* print what we know */
147 pflog_print(ndo, hdr);
149 /* skip to the real packet */
150 af = GET_U_1(&hdr->af);
157 #if OPENBSD_AF_INET != AF_INET
158 case OPENBSD_AF_INET: /* XXX: read pcap files */
160 ip_print(ndo, p, length);
163 #if defined(AF_INET6) || defined(OPENBSD_AF_INET6)
166 #endif /* AF_INET6 */
167 #if !defined(AF_INET6) || OPENBSD_AF_INET6 != AF_INET6
168 case OPENBSD_AF_INET6: /* XXX: read pcap files */
169 #endif /* !defined(AF_INET6) || OPENBSD_AF_INET6 != AF_INET6 */
170 ip6_print(ndo, p, length);
172 #endif /* defined(AF_INET6) || defined(OPENBSD_AF_INET6) */
175 /* address family not handled, print raw packet */
177 pflog_print(ndo, hdr);
178 if (!ndo->ndo_suppress_default_print)
179 ND_DEFAULTPRINT(p, caplen);
182 ndo->ndo_ll_hdr_len += hdrlen;
186 ndo->ndo_ll_hdr_len += hdrlen;