summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@cvs.openbsd.org>2008-06-11 15:02:22 +0000
committerDarren Tucker <dtucker@cvs.openbsd.org>2008-06-11 15:02:22 +0000
commitcbe6215ebf7e4edd3afcdb290dd13cb107d71e0c (patch)
treec7715d6fbe2fe71fcaa28bd2f4bf88a5064597c8 /lib
parent855ad27fad0df12cf14b93cf23b8b9a05910bebb (diff)
Import vlan support from upstream libpcap. This allows, eg, "tcpdump vla 3"
to work on a vlan parent interface. ok mcbride@, "commit it" deraadt@
Diffstat (limited to 'lib')
-rw-r--r--lib/libpcap/ethertype.h7
-rw-r--r--lib/libpcap/gencode.c100
-rw-r--r--lib/libpcap/gencode.h6
-rw-r--r--lib/libpcap/grammar.y7
-rw-r--r--lib/libpcap/scanner.l6
-rw-r--r--lib/libpcap/shlib_version2
6 files changed, 118 insertions, 10 deletions
diff --git a/lib/libpcap/ethertype.h b/lib/libpcap/ethertype.h
index 898543d4519..ecd18b5a50f 100644
--- a/lib/libpcap/ethertype.h
+++ b/lib/libpcap/ethertype.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ethertype.h,v 1.6 2000/04/26 21:25:52 jakob Exp $ */
+/* $OpenBSD: ethertype.h,v 1.7 2008/06/11 15:02:21 dtucker Exp $ */
/* $NetBSD: ethertype.h,v 1.2 1995/03/06 11:38:17 mycroft Exp $ */
/*
@@ -21,7 +21,7 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * @(#) $Header: /cvs/OpenBSD/src/lib/libpcap/ethertype.h,v 1.6 2000/04/26 21:25:52 jakob Exp $ (LBL)
+ * @(#) $Header: /cvs/OpenBSD/src/lib/libpcap/ethertype.h,v 1.7 2008/06/11 15:02:21 dtucker Exp $ (LBL)
*/
/* Types missing from some systems */
@@ -74,6 +74,9 @@
#ifndef ETHERTYPE_AARP
#define ETHERTYPE_AARP 0x80f3
#endif
+#ifndef ETHERTYPE_8021Q
+#define ETHERTYPE_8021Q 0x8100
+#endif
#ifndef ETHERTYPE_IPV6
#define ETHERTYPE_IPV6 0x80f3
#endif
diff --git a/lib/libpcap/gencode.c b/lib/libpcap/gencode.c
index e07ac825efb..e416606e3f4 100644
--- a/lib/libpcap/gencode.c
+++ b/lib/libpcap/gencode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gencode.c,v 1.29 2007/11/06 10:22:29 chl Exp $ */
+/* $OpenBSD: gencode.c,v 1.30 2008/06/11 15:02:21 dtucker Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
@@ -67,6 +67,9 @@ struct rtentry;
static jmp_buf top_ctx;
static pcap_t *bpf_pcap;
+/* Hack for updating VLAN offsets. */
+static u_int orig_linktype = -1, orig_nl = -1, orig_nl_nosnap = -1;
+
/* XXX */
#ifdef PCAP_FDDIPAD
int pcap_fddipad = PCAP_FDDIPAD;
@@ -548,6 +551,8 @@ gen_bcmp(offset, size, v)
*/
static u_int off_linktype;
static u_int off_nl;
+static u_int off_nl_nosnap;
+
static int linktype;
static void
@@ -3138,6 +3143,99 @@ gen_p80211_type(int type, int mask)
}
struct block *
+gen_acode(eaddr, q)
+ register const u_char *eaddr;
+ struct qual q;
+{
+ if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) {
+ if (linktype == DLT_ARCNET)
+ return gen_ahostop(eaddr, (int)q.dir);
+ }
+ bpf_error("ARCnet address used in non-arc expression");
+ /* NOTREACHED */
+}
+
+static struct block *
+gen_ahostop(eaddr, dir)
+ register const u_char *eaddr;
+ register int dir;
+{
+ register struct block *b0, *b1;
+
+ switch (dir) {
+ /* src comes first, different from Ethernet */
+ case Q_SRC:
+ return gen_bcmp(0, 1, eaddr);
+
+ case Q_DST:
+ return gen_bcmp(1, 1, eaddr);
+
+ case Q_AND:
+ b0 = gen_ahostop(eaddr, Q_SRC);
+ b1 = gen_ahostop(eaddr, Q_DST);
+ gen_and(b0, b1);
+ return b1;
+
+ case Q_DEFAULT:
+ case Q_OR:
+ b0 = gen_ahostop(eaddr, Q_SRC);
+ b1 = gen_ahostop(eaddr, Q_DST);
+ gen_or(b0, b1);
+ return b1;
+ }
+ abort();
+ /* NOTREACHED */
+}
+
+/*
+ * support IEEE 802.1Q VLAN trunk over ethernet
+ */
+struct block *
+gen_vlan(vlan_num)
+ int vlan_num;
+{
+ struct block *b0;
+
+ /*
+ * Change the offsets to point to the type and data fields within
+ * the VLAN packet. This is somewhat of a kludge.
+ */
+ if (orig_nl == (u_int)-1) {
+ orig_linktype = off_linktype; /* save original values */
+ orig_nl = off_nl;
+ orig_nl_nosnap = off_nl_nosnap;
+
+ switch (linktype) {
+
+ case DLT_EN10MB:
+ off_linktype = 16;
+ off_nl_nosnap = 18;
+ off_nl = 18;
+ break;
+
+ default:
+ bpf_error("no VLAN support for data link type %d",
+ linktype);
+ /*NOTREACHED*/
+ }
+ }
+
+ /* check for VLAN */
+ b0 = gen_cmp(orig_linktype, BPF_H, (bpf_int32)ETHERTYPE_8021Q);
+
+ /* If a specific VLAN is requested, check VLAN id */
+ if (vlan_num >= 0) {
+ struct block *b1;
+
+ b1 = gen_cmp(orig_nl, BPF_H, (bpf_int32)vlan_num);
+ gen_and(b0, b1);
+ b0 = b1;
+ }
+
+ return (b0);
+}
+
+struct block *
gen_p80211_fcdir(int fcdir)
{
struct block *b0;
diff --git a/lib/libpcap/gencode.h b/lib/libpcap/gencode.h
index 030e99c4e44..7cdff46b5db 100644
--- a/lib/libpcap/gencode.h
+++ b/lib/libpcap/gencode.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: gencode.h,v 1.14 2007/01/02 18:31:21 reyk Exp $ */
+/* $OpenBSD: gencode.h,v 1.15 2008/06/11 15:02:21 dtucker Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
@@ -20,7 +20,7 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * @(#) $Header: /cvs/OpenBSD/src/lib/libpcap/gencode.h,v 1.14 2007/01/02 18:31:21 reyk Exp $ (LBL)
+ * @(#) $Header: /cvs/OpenBSD/src/lib/libpcap/gencode.h,v 1.15 2008/06/11 15:02:21 dtucker Exp $ (LBL)
*/
/* Address qualifiers. */
@@ -180,6 +180,8 @@ struct block *gen_broadcast(int);
struct block *gen_multicast(int);
struct block *gen_inbound(int);
+struct block *gen_vlan(int);
+
struct block *gen_pf_ifname(char *);
struct block *gen_pf_rnr(int);
struct block *gen_pf_srnr(int);
diff --git a/lib/libpcap/grammar.y b/lib/libpcap/grammar.y
index 2b167b7a649..e71de53ce61 100644
--- a/lib/libpcap/grammar.y
+++ b/lib/libpcap/grammar.y
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: grammar.y,v 1.16 2007/01/02 18:31:21 reyk Exp $ */
+/* $OpenBSD: grammar.y,v 1.17 2008/06/11 15:02:21 dtucker Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
@@ -24,7 +24,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/grammar.y,v 1.16 2007/01/02 18:31:21 reyk Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/grammar.y,v 1.17 2008/06/11 15:02:21 dtucker Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -119,6 +119,7 @@ pcap_parse()
%token LSH RSH
%token LEN
%token IPV6 ICMPV6 AH ESP
+%token VLAN
%type <s> ID
%type <e> EID
@@ -280,6 +281,8 @@ other: pqual TK_BROADCAST { $$ = gen_broadcast($1); }
| BYTE NUM byteop NUM { $$ = gen_byteop($3, $2, $4); }
| INBOUND { $$ = gen_inbound(0); }
| OUTBOUND { $$ = gen_inbound(1); }
+ | VLAN pnum { $$ = gen_vlan($2); }
+ | VLAN { $$ = gen_vlan(-1); }
| pfvar { $$ = $1; }
| pqual p80211 { $$ = $2; }
;
diff --git a/lib/libpcap/scanner.l b/lib/libpcap/scanner.l
index 6aa93c19c0a..ffb1de12934 100644
--- a/lib/libpcap/scanner.l
+++ b/lib/libpcap/scanner.l
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: scanner.l,v 1.19 2007/01/02 18:31:21 reyk Exp $ */
+/* $OpenBSD: scanner.l,v 1.20 2008/06/11 15:02:21 dtucker Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -24,7 +24,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/scanner.l,v 1.19 2007/01/02 18:31:21 reyk Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/scanner.l,v 1.20 2008/06/11 15:02:21 dtucker Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -228,6 +228,8 @@ len|length return LEN;
inbound return INBOUND;
outbound return OUTBOUND;
+vlan return VLAN;
+
on|ifname return PF_IFNAME;
rset|ruleset return PF_RSET;
rnr|rulenum return PF_RNR;
diff --git a/lib/libpcap/shlib_version b/lib/libpcap/shlib_version
index 3066b9771e7..9c1551636c5 100644
--- a/lib/libpcap/shlib_version
+++ b/lib/libpcap/shlib_version
@@ -1,2 +1,2 @@
-major=5
+major=6
minor=0