]>
The Tcpdump Group git mirrors - tcpdump/blob - print-pflog.c
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.
26 #ifndef HAVE_NET_PFVAR_H
27 #error "No pf headers available"
29 #include <sys/types.h>
30 #include <sys/socket.h>
32 #include <net/pfvar.h>
33 #include <net/if_pflog.h>
35 #include <tcpdump-stdinc.h>
41 #include "interface.h"
43 static const char tstr
[] = "[|pflog]";
45 static const struct tok pf_reasons
[] = {
47 { 1, "1(bad-offset)" },
50 { 4, "4(normalize)" },
52 { 6, "6(bad-timestamp)" },
53 { 7, "7(congestion)" },
54 { 8, "8(ip-option)" },
55 { 9, "9(proto-cksum)" },
56 { 10, "10(state-mismatch)" },
57 { 11, "11(state-insert)" },
58 { 12, "12(state-limit)" },
59 { 13, "13(src-limit)" },
60 { 14, "14(synproxy)" },
64 static const struct tok pf_actions
[] = {
67 { PF_SCRUB
, "scrub" },
70 { PF_BINAT
, "binat" },
71 { PF_NOBINAT
, "binat" },
74 { PF_SYNPROXY_DROP
, "synproxy-drop" },
78 static const struct tok pf_directions
[] = {
79 { PF_INOUT
, "in/out" },
85 /* For reading capture files on other systems */
86 #define OPENBSD_AF_INET 2
87 #define OPENBSD_AF_INET6 24
90 pflog_print(const struct pfloghdr
*hdr
)
92 u_int32_t rulenr
, subrulenr
;
94 rulenr
= EXTRACT_32BITS(&hdr
->rulenr
);
95 subrulenr
= EXTRACT_32BITS(&hdr
->subrulenr
);
96 if (subrulenr
== (u_int32_t
)-1)
97 printf("rule %u/", rulenr
);
99 printf("rule %u.%s.%u/", rulenr
, hdr
->ruleset
, subrulenr
);
101 printf("%s: %s %s on %s: ",
102 tok2str(pf_reasons
, "unkn(%u)", hdr
->reason
),
103 tok2str(pf_actions
, "unkn(%u)", hdr
->action
),
104 tok2str(pf_directions
, "unkn(%u)", hdr
->dir
),
109 pflog_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
111 u_int length
= h
->len
;
113 u_int caplen
= h
->caplen
;
114 const struct pfloghdr
*hdr
;
118 if (caplen
< sizeof(u_int8_t
)) {
123 #define MIN_PFLOG_HDRLEN 45
124 hdr
= (struct pfloghdr
*)p
;
125 if (hdr
->length
< MIN_PFLOG_HDRLEN
) {
126 printf("[pflog: invalid header length!]");
127 return (hdr
->length
); /* XXX: not really */
129 hdrlen
= BPF_WORDALIGN(hdr
->length
);
131 if (caplen
< hdrlen
) {
133 return (hdrlen
); /* XXX: true? */
136 /* print what we know */
137 hdr
= (struct pfloghdr
*)p
;
142 /* skip to the real packet */
150 #if OPENBSD_AF_INET != AF_INET
151 case OPENBSD_AF_INET
: /* XXX: read pcap files */
153 ip_print(gndo
, p
, length
);
158 #if OPENBSD_AF_INET6 != AF_INET6
159 case OPENBSD_AF_INET6
: /* XXX: read pcap files */
161 ip6_print(gndo
, p
, length
);
166 /* address family not handled, print raw packet */
169 if (!suppress_default_print
)
170 default_print(p
, caplen
);
181 * c-style: whitesmith