summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libpcap/gencode.c57
-rw-r--r--lib/libpcap/gencode.h5
-rw-r--r--lib/libpcap/grammar.y7
-rw-r--r--lib/libpcap/llc.h122
-rw-r--r--lib/libpcap/nametoaddr.c23
-rw-r--r--lib/libpcap/scanner.l5
-rw-r--r--lib/libpcap/shlib_version2
7 files changed, 209 insertions, 12 deletions
diff --git a/lib/libpcap/gencode.c b/lib/libpcap/gencode.c
index 2ac99ac4ca5..ca5106baecf 100644
--- a/lib/libpcap/gencode.c
+++ b/lib/libpcap/gencode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gencode.c,v 1.24 2005/06/04 18:00:45 joel Exp $ */
+/* $OpenBSD: gencode.c,v 1.25 2005/10/07 19:32:39 mpf Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
@@ -46,6 +46,7 @@ struct rtentry;
#include "pcap-int.h"
#include "ethertype.h"
+#include "llc.h"
#include "gencode.h"
#include "ppp.h"
#include <pcap-namedb.h>
@@ -119,6 +120,7 @@ static __inline void syntax(void);
static void backpatch(struct block *, struct block *);
static void merge(struct block *, struct block *);
static struct block *gen_cmp(u_int, u_int, bpf_int32);
+static struct block *gen_cmp_gt(u_int, u_int, bpf_int32);
static struct block *gen_mcmp(u_int, u_int, bpf_int32, bpf_u_int32);
static struct block *gen_bcmp(u_int, u_int, const u_char *);
static struct block *gen_uncond(int);
@@ -464,6 +466,24 @@ gen_cmp(offset, size, v)
}
static struct block *
+gen_cmp_gt(offset, size, v)
+ u_int offset, size;
+ bpf_int32 v;
+{
+ struct slist *s;
+ struct block *b;
+
+ s = new_stmt(BPF_LD|BPF_ABS|size);
+ s->s.k = offset;
+
+ b = new_block(JMP(BPF_JGT));
+ b->stmts = s;
+ b->s.k = v;
+
+ return b;
+}
+
+static struct block *
gen_mcmp(offset, size, v, mask)
u_int offset, size;
bpf_int32 v;
@@ -704,6 +724,20 @@ gen_linktype(proto)
switch (linktype) {
+ case DLT_EN10MB:
+ if (proto <= ETHERMTU) {
+ /* This is an LLC SAP value */
+ b0 = gen_cmp_gt(off_linktype, BPF_H, ETHERMTU);
+ gen_not(b0);
+ b1 = gen_cmp(off_linktype + 2, BPF_B, (bpf_int32)proto);
+ gen_and(b0, b1);
+ return b1;
+ } else {
+ /* This is an Ethernet type */
+ return gen_cmp(off_linktype, BPF_H, (bpf_int32)proto);
+ }
+ break;
+
case DLT_SLIP:
return gen_false();
@@ -1128,6 +1162,9 @@ gen_host(addr, mask, proto, dir)
case Q_PIM:
bpf_error("'pim' modifier applied to host");
+ case Q_STP:
+ bpf_error("'stp' modifier applied to host");
+
case Q_ATALK:
bpf_error("ATALK host filtering not implemented");
@@ -1206,6 +1243,9 @@ gen_host6(addr, mask, proto, dir)
case Q_PIM:
bpf_error("'pim' modifier applied to host");
+ case Q_STP:
+ bpf_error("'stp' modifier applied to host");
+
case Q_ATALK:
bpf_error("ATALK host filtering not implemented");
@@ -1379,6 +1419,10 @@ gen_proto_abbrev(proto)
b1 = gen_linktype(ETHERTYPE_MOPRC);
break;
+ case Q_STP:
+ b1 = gen_linktype(LLCSAP_8021D);
+ break;
+
#ifdef INET6
case Q_IPV6:
b1 = gen_linktype(ETHERTYPE_IPV6);
@@ -1629,8 +1673,11 @@ lookup_proto(name, proto)
case Q_LINK:
/* XXX should look up h/w protocol type based on linktype */
v = pcap_nametoeproto(name);
- if (v == PROTO_UNDEF)
- bpf_error("unknown ether proto '%s'", name);
+ if (v == PROTO_UNDEF) {
+ v = pcap_nametollc(name);
+ if (v == PROTO_UNDEF)
+ bpf_error("unknown ether proto '%s'", name);
+ }
break;
default:
@@ -2022,6 +2069,10 @@ gen_proto(v, proto, dir)
bpf_error("'pim proto' is bogus");
/* NOTREACHED */
+ case Q_STP:
+ bpf_error("'stp proto' is bogus");
+ /* NOTREACHED */
+
#ifdef INET6
case Q_IPV6:
b0 = gen_linktype(ETHERTYPE_IPV6);
diff --git a/lib/libpcap/gencode.h b/lib/libpcap/gencode.h
index 487ae35ad3e..39c5d568877 100644
--- a/lib/libpcap/gencode.h
+++ b/lib/libpcap/gencode.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: gencode.h,v 1.11 2003/05/14 08:50:37 canacar Exp $ */
+/* $OpenBSD: gencode.h,v 1.12 2005/10/07 19:32:39 mpf 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.11 2003/05/14 08:50:37 canacar Exp $ (LBL)
+ * @(#) $Header: /cvs/OpenBSD/src/lib/libpcap/gencode.h,v 1.12 2005/10/07 19:32:39 mpf Exp $ (LBL)
*/
/* Address qualifiers. */
@@ -59,6 +59,7 @@
#define Q_ESP 19
#define Q_PIM 20
+#define Q_STP 21
/* Directional qualifiers. */
diff --git a/lib/libpcap/grammar.y b/lib/libpcap/grammar.y
index 1f4997426b2..2102dd73bef 100644
--- a/lib/libpcap/grammar.y
+++ b/lib/libpcap/grammar.y
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: grammar.y,v 1.13 2005/05/26 17:58:25 camield Exp $ */
+/* $OpenBSD: grammar.y,v 1.14 2005/10/07 19:32:39 mpf 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.13 2005/05/26 17:58:25 camield Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/grammar.y,v 1.14 2005/10/07 19:32:39 mpf Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -106,7 +106,7 @@ pcap_parse()
%token DST SRC HOST GATEWAY
%token NET MASK PORT LESS GREATER PROTO PROTOCHAIN BYTE
%token ARP RARP IP TCP UDP ICMP IGMP IGRP PIM
-%token ATALK DECNET LAT SCA MOPRC MOPDL
+%token ATALK DECNET LAT SCA MOPRC MOPDL STP
%token TK_BROADCAST TK_MULTICAST
%token NUM INBOUND OUTBOUND
%token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
@@ -263,6 +263,7 @@ pname: LINK { $$ = Q_LINK; }
| ICMPV6 { $$ = Q_ICMPV6; }
| AH { $$ = Q_AH; }
| ESP { $$ = Q_ESP; }
+ | STP { $$ = Q_STP; }
;
other: pqual TK_BROADCAST { $$ = gen_broadcast($1); }
| pqual TK_MULTICAST { $$ = gen_multicast($1); }
diff --git a/lib/libpcap/llc.h b/lib/libpcap/llc.h
new file mode 100644
index 00000000000..0857fbb8528
--- /dev/null
+++ b/lib/libpcap/llc.h
@@ -0,0 +1,122 @@
+/* $OpenBSD: llc.h,v 1.1 2005/10/07 19:32:39 mpf Exp $ */
+
+/*
+ * Copyright (c) 1993, 1994, 1997
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that: (1) source code distributions
+ * retain the above copyright notice and this paragraph in its entirety, (2)
+ * distributions including binary code include the above copyright notice and
+ * this paragraph in its entirety in the documentation or other materials
+ * provided with the distribution, and (3) all advertising materials mentioning
+ * features or use of this software display the following acknowledgement:
+ * ``This product includes software developed by the University of California,
+ * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
+ * the University nor the names of its contributors may be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * @(#) $Header: /cvs/OpenBSD/src/lib/libpcap/llc.h,v 1.1 2005/10/07 19:32:39 mpf Exp $ (LBL)
+ */
+
+/*
+ * This stuff should come from a system header file, but there's no
+ * obviously portable way to do that and it's not really going
+ * to change from system to system.
+ */
+
+/*
+ * A somewhat abstracted view of the LLC header
+ */
+
+struct llc {
+ u_char dsap;
+ u_char ssap;
+ union {
+ u_char u_ctl;
+ u_short is_ctl;
+ struct {
+ u_char snap_ui;
+ u_char snap_pi[5];
+ } snap;
+ struct {
+ u_char snap_ui;
+ u_char snap_orgcode[3];
+ u_char snap_ethertype[2];
+ } snap_ether;
+ } ctl;
+};
+
+#define llcui ctl.snap.snap_ui
+#define llcpi ctl.snap.snap_pi
+#define orgcode ctl.snap_ether.snap_orgcode
+#define ethertype ctl.snap_ether.snap_ethertype
+#define llcis ctl.is_ctl
+#define llcu ctl.u_ctl
+
+#define LLC_U_FMT 3
+#define LLC_GSAP 1
+#define LLC_S_FMT 1
+
+#define LLC_U_POLL 0x10
+#define LLC_IS_POLL 0x0001
+#define LLC_XID_FI 0x81
+
+#define LLC_U_CMD(u) ((u) & 0xef)
+#define LLC_UI 0x03
+#define LLC_UA 0x63
+#define LLC_DISC 0x43
+#define LLC_DM 0x0f
+#define LLC_SABME 0x6f
+#define LLC_TEST 0xe3
+#define LLC_XID 0xaf
+#define LLC_FRMR 0x87
+
+#define LLC_S_CMD(is) (((is) >> 10) & 0x03)
+#define LLC_RR 0x0100
+#define LLC_RNR 0x0500
+#define LLC_REJ 0x0900
+
+#define LLC_IS_NR(is) (((is) >> 1) & 0x7f)
+#define LLC_I_NS(is) (((is) >> 9) & 0x7f)
+
+#ifndef LLCSAP_NULL
+#define LLCSAP_NULL 0x00
+#endif
+#ifndef LLCSAP_GLOBAL
+#define LLCSAP_GLOBAL 0xff
+#endif
+#ifndef LLCSAP_8021B
+#define LLCSAP_8021B_I 0x02
+#endif
+#ifndef LLCSAP_8021B
+#define LLCSAP_8021B_G 0x03
+#endif
+#ifndef LLCSAP_IP
+#define LLCSAP_IP 0x06
+#endif
+#ifndef LLCSAP_PROWAYNM
+#define LLCSAP_PROWAYNM 0x0e
+#endif
+#ifndef LLCSAP_8021D
+#define LLCSAP_8021D 0x42
+#endif
+#ifndef LLCSAP_RS511
+#define LLCSAP_RS511 0x4e
+#endif
+#ifndef LLCSAP_ISO8208
+#define LLCSAP_ISO8208 0x7e
+#endif
+#ifndef LLCSAP_PROWAY
+#define LLCSAP_PROWAY 0x8e
+#endif
+#ifndef LLCSAP_SNAP
+#define LLCSAP_SNAP 0xaa
+#endif
+#ifndef LLCSAP_ISONS
+#define LLCSAP_ISONS 0xfe
+#endif
diff --git a/lib/libpcap/nametoaddr.c b/lib/libpcap/nametoaddr.c
index 8c34a8b96c5..74b809b0c24 100644
--- a/lib/libpcap/nametoaddr.c
+++ b/lib/libpcap/nametoaddr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nametoaddr.c,v 1.11 2005/03/28 06:19:58 tedu Exp $ */
+/* $OpenBSD: nametoaddr.c,v 1.12 2005/10/07 19:32:39 mpf Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
@@ -236,6 +236,27 @@ pcap_nametoeproto(const char *s)
return PROTO_UNDEF;
}
+#include "llc.h"
+
+/* Static data base of LLC values. */
+static struct eproto llc_db[] = {
+ { "stp", LLCSAP_8021D },
+ { (char *)0, 0 }
+};
+
+int
+pcap_nametollc(const char *s)
+{
+ struct eproto *p = llc_db;
+
+ while (p->s != 0) {
+ if (strcmp(p->s, s) == 0)
+ return p->p;
+ p += 1;
+ }
+ return PROTO_UNDEF;
+}
+
/* Hex digit to integer. */
static __inline int
xdtoi(c)
diff --git a/lib/libpcap/scanner.l b/lib/libpcap/scanner.l
index 8b9e3f5cfcf..1f5ba302335 100644
--- a/lib/libpcap/scanner.l
+++ b/lib/libpcap/scanner.l
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: scanner.l,v 1.15 2005/09/27 18:26:57 deraadt Exp $ */
+/* $OpenBSD: scanner.l,v 1.16 2005/10/07 19:32:39 mpf 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.15 2005/09/27 18:26:57 deraadt Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/scanner.l,v 1.16 2005/10/07 19:32:39 mpf Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -196,6 +196,7 @@ lat return LAT;
sca return SCA;
moprc return MOPRC;
mopdl return MOPDL;
+stp return STP;
host return HOST;
net return NET;
diff --git a/lib/libpcap/shlib_version b/lib/libpcap/shlib_version
index 012c14171d3..3f0196ebf4a 100644
--- a/lib/libpcap/shlib_version
+++ b/lib/libpcap/shlib_version
@@ -1,2 +1,2 @@
major=3
-minor=0
+minor=1