1 /* $NetBSD: print-pflog.c,v 1.6 2004/09/27 23:04:24 dyoung Exp $ */
2 /* $OpenBSD: print-pflog.c,v 1.14 2003/06/21 21:01:15 dhartmei Exp $ */
5 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that: (1) source code distributions
10 * retain the above copyright notice and this paragraph in its entirety, (2)
11 * distributions including binary code include the above copyright notice and
12 * this paragraph in its entirety in the documentation or other materials
13 * provided with the distribution, and (3) all advertising materials mentioning
14 * features or use of this software display the following acknowledgement:
15 * ``This product includes software developed by the University of California,
16 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
17 * the University nor the names of its contributors may be used to endorse
18 * or promote products derived from this software without specific prior
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25 #include <sys/cdefs.h>
28 static const char rcsid
[] _U_
=
29 "@(#) Header: /tcpdump/master/tcpdump/print-pflog.c,v 1.13.2.2 2006/10/25 22:13:30 guy Exp (LBL)";
31 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
39 #include <tcpdump-stdinc.h>
41 #include <sys/ioctl.h>
44 #include <netinet/in_systm.h>
45 #include <netinet/ip.h>
48 #include <net/pfvar.h>
49 #include <net/if_pflog.h>
57 #include "interface.h"
58 #include "addrtoname.h"
61 static struct tok pf_reasons
[] = {
63 { 1, "1(bad-offset)" },
66 { 4, "4(normalize)" },
68 { 6, "6(bad-timestamp)" },
69 { 7, "7(congestion)" },
70 { 8, "8(ip-option)" },
71 { 9, "9(proto-cksum)" },
72 { 10, "10(state-mismatch)" },
73 { 11, "11(state-insert)" },
74 { 12, "12(state-limit)" },
75 { 13, "13(src-limit)" },
76 { 14, "14(synproxy)" },
80 static struct tok pf_actions
[] = {
83 { PF_SCRUB
, "scrub" },
86 { PF_BINAT
, "binat" },
87 { PF_NOBINAT
, "binat" },
90 { PF_SYNPROXY_DROP
, "synproxy-drop" },
94 static struct tok pf_directions
[] = {
95 { PF_INOUT
, "in/out" },
101 /* For reading capture files on other systems */
102 #define OPENBSD_AF_INET 2
103 #define OPENBSD_AF_INET6 24
106 pflog_print(const struct pfloghdr
*hdr
)
108 u_int32_t rulenr
, subrulenr
;
110 rulenr
= ntohl(hdr
->rulenr
);
111 subrulenr
= ntohl(hdr
->subrulenr
);
112 if (subrulenr
== (u_int32_t
)-1)
113 printf("rule %u/", rulenr
);
115 printf("rule %u.%s.%u/", rulenr
, hdr
->ruleset
, subrulenr
);
117 printf("%s: %s %s on %s: ",
118 tok2str(pf_reasons
, "unkn(%u)", hdr
->reason
),
119 tok2str(pf_actions
, "unkn(%u)", hdr
->action
),
120 tok2str(pf_directions
, "unkn(%u)", hdr
->dir
),
125 pflog_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
127 u_int length
= h
->len
;
129 u_int caplen
= h
->caplen
;
130 const struct pfloghdr
*hdr
;
134 if (caplen
< sizeof(u_int8_t
)) {
139 #define MIN_PFLOG_HDRLEN 45
140 hdr
= (struct pfloghdr
*)p
;
141 if (hdr
->length
< MIN_PFLOG_HDRLEN
) {
142 printf("[pflog: invalid header length!]");
143 return (hdr
->length
); /* XXX: not really */
145 hdrlen
= BPF_WORDALIGN(hdr
->length
);
147 if (caplen
< hdrlen
) {
149 return (hdrlen
); /* XXX: true? */
152 /* print what we know */
153 hdr
= (struct pfloghdr
*)p
;
158 /* skip to the real packet */
166 #if OPENBSD_AF_INET != AF_INET
167 case OPENBSD_AF_INET
: /* XXX: read pcap files */
169 ip_print(gndo
, p
, length
);
174 #if OPENBSD_AF_INET6 != AF_INET6
175 case OPENBSD_AF_INET6
: /* XXX: read pcap files */
177 ip6_print(p
, length
);
182 /* address family not handled, print raw packet */
185 if (!suppress_default_print
)
186 default_print(p
, caplen
);
197 * c-style: whitesmith