]> The Tcpdump Group git mirrors - tcpdump/blob - print-pflog.c
Add support for Apple's IP-over-IEEE 1394 encapsulation.
[tcpdump] / print-pflog.c
1 /* $OpenBSD: print-pflog.c,v 1.9 2001/09/18 14:52:53 jakob Exp $ */
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.7.2.2 2003-11-16 08:51:38 guy Exp $ (LBL)";
27 #endif
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <tcpdump-stdinc.h>
34
35 #include <stdio.h>
36 #include <pcap.h>
37
38 #include "interface.h"
39 #include "addrtoname.h"
40
41 /* The header in OpenBSD pflog files. */
42
43 struct pfloghdr {
44 u_int32_t af;
45 char ifname[16];
46 int16_t rnr;
47 u_int16_t reason;
48 u_int16_t action;
49 u_int16_t dir;
50 };
51 #define PFLOG_HDRLEN sizeof(struct pfloghdr)
52
53 /* Actions */
54 #define PF_PASS 0
55 #define PF_DROP 1
56 #define PF_SCRUB 2
57
58 /* Directions */
59 #define PF_IN 0
60 #define PF_OUT 1
61
62 static struct tok pf_reasons[] = {
63 { 0, "match" },
64 { 1, "bad-offset" },
65 { 2, "fragment" },
66 { 3, "short" },
67 { 4, "normalize" },
68 { 5, "memory" },
69 { 0, NULL }
70 };
71
72 static struct tok pf_actions[] = {
73 { PF_PASS, "pass" },
74 { PF_DROP, "drop" },
75 { PF_SCRUB, "scrub" },
76 { 0, NULL }
77 };
78
79 static struct tok pf_directions[] = {
80 { PF_IN, "in" },
81 { PF_OUT, "out" },
82 { 0, NULL }
83 };
84
85 #define OPENBSD_AF_INET 2
86 #define OPENBSD_AF_INET6 24
87
88 static void
89 pflog_print(const struct pfloghdr *hdr)
90 {
91 printf("rule %d/%s: %s %s on %s: ",
92 (short)ntohs(hdr->rnr),
93 tok2str(pf_reasons, "unkn(%u)", ntohs(hdr->reason)),
94 tok2str(pf_actions, "unkn(%u)", ntohs(hdr->action)),
95 tok2str(pf_directions, "unkn(%u)", ntohs(hdr->dir)),
96 hdr->ifname);
97 }
98
99 u_int
100 pflog_if_print(const struct pcap_pkthdr *h, register const u_char *p)
101 {
102 u_int length = h->len;
103 u_int caplen = h->caplen;
104 const struct pfloghdr *hdr;
105 u_int8_t af;
106
107 if (caplen < PFLOG_HDRLEN) {
108 printf("[|pflog]");
109 return (caplen);
110 }
111
112 hdr = (const struct pfloghdr *)p;
113 if (eflag)
114 pflog_print(hdr);
115 af = ntohl(hdr->af);
116 length -= PFLOG_HDRLEN;
117 caplen -= PFLOG_HDRLEN;
118 p += PFLOG_HDRLEN;
119 switch (af) {
120
121 case OPENBSD_AF_INET:
122 ip_print(p, length);
123 break;
124
125 #ifdef INET6
126 case OPENBSD_AF_INET6:
127 ip6_print(p, length);
128 break;
129 #endif
130
131 default:
132 /* address family not handled, print raw packet */
133 if (!eflag)
134 pflog_print(hdr);
135 if (!xflag && !qflag)
136 default_print(p, caplen);
137 }
138
139 return (PFLOG_HDRLEN);
140 }