aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Reed <Darren.Reed@Sun.COM>2009-11-24 21:40:44 -0500
committerMichael Richardson <mcr@sandelman.ottawa.on.ca>2009-11-24 21:40:44 -0500
commitbdc25fca79411dbaed26989fb40bf3d8877662b6 (patch)
tree6f685805a1e1cbcde120ccef236a0a789ca99428
parent5aa0044891da5206cce168ff00f56340f7b01867 (diff)
To compile libpcap on OpenSolaris (or Solaris Express Community Edition)
build 125 and later to use the native BPF with both IPNET and traditional MAC (ethernet, etc) packet sniffing, the attached patches are required. The attached patches represent what's in our internal build tree for libpcap.
-rw-r--r--Makefile.in1
-rw-r--r--configure.in2
-rw-r--r--gencode.c50
-rw-r--r--pcap-bpf.c4
-rw-r--r--pcap/bpf.h9
-rw-r--r--savefile.c5
6 files changed, 69 insertions, 2 deletions
diff --git a/Makefile.in b/Makefile.in
index ce34c7a..24dc74d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -44,6 +44,7 @@ VPATH = @srcdir@
# You shouldn't need to edit anything below.
#
+LD = /usr/bin/ld
CC = @CC@
CCOPT = @V_CCOPT@
INCLS = -I. @V_INCLS@
diff --git a/configure.in b/configure.in
index 43cd323..e444291 100644
--- a/configure.in
+++ b/configure.in
@@ -295,7 +295,7 @@ AC_HELP_STRING([--with-pcap=TYPE],[use packet capture TYPE]))
AC_MSG_CHECKING(packet capture type)
if test ! -z "$with_pcap" ; then
V_PCAP="$withval"
-elif test -r /dev/bpf ; then
+elif test -r /dev/bpf -o -h /dev/bpf ; then
#
# Cloning BPF device.
#
diff --git a/gencode.c b/gencode.c
index 8d9a1c7..db35164 100644
--- a/gencode.c
+++ b/gencode.c
@@ -212,6 +212,7 @@ static struct block *gen_uncond(int);
static inline struct block *gen_true(void);
static inline struct block *gen_false(void);
static struct block *gen_ether_linktype(int);
+static struct block *gen_ipnet_linktype(int);
static struct block *gen_linux_sll_linktype(int);
static struct slist *gen_load_prism_llprefixlen(void);
static struct slist *gen_load_avs_llprefixlen(void);
@@ -1569,6 +1570,13 @@ init_linktype(p)
off_nl = -1;
off_nl_nosnap = -1;
return;
+
+ case DLT_IPNET:
+ off_linktype = 1;
+ off_macpl = 24; /* ipnet header length */
+ off_nl = 0;
+ off_nl_nosnap = -1;
+ return;
}
bpf_error("unknown data link type %d", linktype);
/* NOTREACHED */
@@ -2003,6 +2011,33 @@ gen_ether_linktype(proto)
}
/*
+ * "proto" is an Ethernet type value and for IPNET, if it is not IPv4
+ * or IPv6 then we have an error.
+ */
+static struct block *
+gen_ipnet_linktype(proto)
+ register int proto;
+{
+ struct block *b0, *b1;
+
+ switch (proto) {
+ case ETHERTYPE_IP:
+ return gen_cmp(OR_LINK, off_linktype, BPF_B,
+ (bpf_int32)AF_INET);
+ /* NOTREACHED */
+
+ case ETHERTYPE_IPV6:
+ return gen_cmp(OR_LINK, off_linktype, BPF_B,
+ (bpf_int32)AF_INET6);
+ /* NOTREACHED */
+ default :
+ break;
+ }
+
+ return gen_false();
+}
+
+/*
* Generate code to match a particular packet type.
*
* "proto" is an Ethernet type value, if > ETHERMTU, or an LLC SAP
@@ -3399,6 +3434,9 @@ gen_linktype(proto)
*/
return gen_mcmp(OR_LINK, 0, BPF_W, 0x4d474300, 0xffffff00); /* compare the magic number */
+ case DLT_IPNET:
+ return gen_ipnet_linktype(proto);
+
case DLT_LINUX_IRDA:
bpf_error("IrDA link-layer type filtering not implemented");
@@ -7329,6 +7367,18 @@ gen_inbound(dir)
dir);
break;
+#ifdef DL_IPNET
+ case DLT_IPNET:
+ if (dir) {
+ /* match outgoing packets */
+ b0 = gen_cmp(OR_LINK, 2, BPF_H, IPNET_OUTBOUND);
+ } else {
+ /* match incoming packets */
+ b0 = gen_cmp(OR_LINK, 2, BPF_H, IPNET_INBOUND);
+ }
+ break;
+#endif
+
case DLT_LINUX_SLL:
if (dir) {
/*
diff --git a/pcap-bpf.c b/pcap-bpf.c
index 86d1bee..3cb91de 100644
--- a/pcap-bpf.c
+++ b/pcap-bpf.c
@@ -51,6 +51,7 @@ static const char rcsid[] _U_ =
#include <sys/ioccom.h>
#endif
#include <sys/utsname.h>
+#include <fcntl.h>
#ifdef HAVE_ZEROCOPY_BPF
#include <machine/atomic.h>
@@ -542,7 +543,8 @@ get_dlt_list(int fd, int v, struct bpf_dltlist *bdlp, char *ebuf)
if (v == DLT_EN10MB) {
is_ethernet = 1;
for (i = 0; i < bdlp->bfl_len; i++) {
- if (bdlp->bfl_list[i] != DLT_EN10MB) {
+ if (bdlp->bfl_list[i] != DLT_EN10MB &&
+ bdlp->bfl_list[i] != DLT_IPNET) {
is_ethernet = 0;
break;
}
diff --git a/pcap/bpf.h b/pcap/bpf.h
index b5f5ed2..cd61f83 100644
--- a/pcap/bpf.h
+++ b/pcap/bpf.h
@@ -953,6 +953,15 @@ struct bpf_version {
*/
#define DLT_CAN_SOCKETCAN 227
+#define DLT_IPNET 226 /* Assigned by tcpdump.org */
+#define DLT_IPOIB 162 /* Private until we know what it is */
+
+/*
+ * IPNET
+ */
+#define IPNET_OUTBOUND 1
+#define IPNET_INBOUND 2
+
/*
* DLT and savefile link type values are split into a class and
diff --git a/savefile.c b/savefile.c
index 4832f34..1a2f2be 100644
--- a/savefile.c
+++ b/savefile.c
@@ -793,6 +793,8 @@ static const char rcsid[] _U_ =
*/
#define LINKTYPE_CAN_SOCKETCAN 227
+#define LINKTYPE_IPNET 226
+
static struct linktype_map {
int dlt;
@@ -1135,6 +1137,9 @@ static struct linktype_map {
/* CAN frames with SocketCAN headers */
{ DLT_CAN_SOCKETCAN, LINKTYPE_CAN_SOCKETCAN },
+ /* Solaris IPNET */
+ { DLT_IPNET, LINKTYPE_IPNET },
+
{ -1, -1 }
};