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.
23 static const char rcsid
[] _U_
=
24 "@(#) $Header: /tcpdump/master/tcpdump/print-pflog.c,v 1.13.2.4 2007/09/13 17:18:10 gianluca Exp $ (LBL)";
31 #ifndef HAVE_NET_PFVAR_H
32 #error "No pf headers available"
35 #include <sys/types.h>
37 #include <sys/socket.h>
40 #include <net/pfvar.h>
41 #include <net/if_pflog.h>
45 #include <tcpdump-stdinc.h>
50 #include "interface.h"
51 #include "addrtoname.h"
53 static struct tok pf_reasons
[] = {
55 { 1, "1(bad-offset)" },
58 { 4, "4(normalize)" },
60 { 6, "6(bad-timestamp)" },
61 { 7, "7(congestion)" },
62 { 8, "8(ip-option)" },
63 { 9, "9(proto-cksum)" },
64 { 10, "10(state-mismatch)" },
65 { 11, "11(state-insert)" },
66 { 12, "12(state-limit)" },
67 { 13, "13(src-limit)" },
68 { 14, "14(synproxy)" },
72 static struct tok pf_actions
[] = {
75 { PF_SCRUB
, "scrub" },
78 { PF_BINAT
, "binat" },
79 { PF_NOBINAT
, "binat" },
82 { PF_SYNPROXY_DROP
, "synproxy-drop" },
86 static struct tok pf_directions
[] = {
87 { PF_INOUT
, "in/out" },
93 /* For reading capture files on other systems */
94 #define OPENBSD_AF_INET 2
95 #define OPENBSD_AF_INET6 24
98 pflog_print(const struct pfloghdr
*hdr
)
100 u_int32_t rulenr
, subrulenr
;
102 rulenr
= ntohl(hdr
->rulenr
);
103 subrulenr
= ntohl(hdr
->subrulenr
);
104 if (subrulenr
== (u_int32_t
)-1)
105 printf("rule %u/", rulenr
);
107 printf("rule %u.%s.%u/", rulenr
, hdr
->ruleset
, subrulenr
);
109 printf("%s: %s %s on %s: ",
110 tok2str(pf_reasons
, "unkn(%u)", hdr
->reason
),
111 tok2str(pf_actions
, "unkn(%u)", hdr
->action
),
112 tok2str(pf_directions
, "unkn(%u)", hdr
->dir
),
117 pflog_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
119 u_int length
= h
->len
;
121 u_int caplen
= h
->caplen
;
122 const struct pfloghdr
*hdr
;
126 if (caplen
< sizeof(u_int8_t
)) {
131 #define MIN_PFLOG_HDRLEN 45
132 hdr
= (struct pfloghdr
*)p
;
133 if (hdr
->length
< MIN_PFLOG_HDRLEN
) {
134 printf("[pflog: invalid header length!]");
135 return (hdr
->length
); /* XXX: not really */
137 hdrlen
= BPF_WORDALIGN(hdr
->length
);
139 if (caplen
< hdrlen
) {
141 return (hdrlen
); /* XXX: true? */
144 /* print what we know */
145 hdr
= (struct pfloghdr
*)p
;
150 /* skip to the real packet */
158 #if OPENBSD_AF_INET != AF_INET
159 case OPENBSD_AF_INET
: /* XXX: read pcap files */
161 ip_print(gndo
, p
, length
);
166 #if OPENBSD_AF_INET6 != AF_INET6
167 case OPENBSD_AF_INET6
: /* XXX: read pcap files */
169 ip6_print(p
, length
);
174 /* address family not handled, print raw packet */
177 if (!suppress_default_print
)
178 default_print(p
, caplen
);
189 * c-style: whitesmith