summaryrefslogtreecommitdiffstats
path: root/contrib/libpcap/bpf
diff options
context:
space:
mode:
authorfenner <fenner@FreeBSD.org>2001-04-03 04:18:09 +0000
committerfenner <fenner@FreeBSD.org>2001-04-03 04:18:09 +0000
commita6bce8883c0f9dd7fee0eb03667f57b40b1d9dab (patch)
tree3549230334d9c115b8db8b950fb89d69f7b23d16 /contrib/libpcap/bpf
parent6f08532b51656817ca97987b95e3b7422d6be2ae (diff)
downloadFreeBSD-src-a6bce8883c0f9dd7fee0eb03667f57b40b1d9dab.zip
FreeBSD-src-a6bce8883c0f9dd7fee0eb03667f57b40b1d9dab.tar.gz
Virgin import of tcpdump.org libpcap v0.6.2
Diffstat (limited to 'contrib/libpcap/bpf')
-rw-r--r--contrib/libpcap/bpf/net/bpf.h145
-rw-r--r--contrib/libpcap/bpf/net/bpf_filter.c130
2 files changed, 194 insertions, 81 deletions
diff --git a/contrib/libpcap/bpf/net/bpf.h b/contrib/libpcap/bpf/net/bpf.h
index 8a997aa..26abc79 100644
--- a/contrib/libpcap/bpf/net/bpf.h
+++ b/contrib/libpcap/bpf/net/bpf.h
@@ -37,7 +37,7 @@
*
* @(#)bpf.h 7.1 (Berkeley) 5/7/91
*
- * @(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf.h,v 1.37 1999/10/19 15:18:31 itojun Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf.h,v 1.44 2000/12/21 10:29:24 guy Exp $ (LBL)
*/
#ifndef BPF_MAJOR_VERSION
@@ -154,13 +154,24 @@ struct bpf_hdr {
* will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
* Only the kernel needs to know about it; applications use bh_hdrlen.
*/
-#ifdef KERNEL
+#if defined(KERNEL) || defined(_KERNEL)
#define SIZEOF_BPF_HDR 18
#endif
/*
* Data-link level type codes.
*/
+
+/*
+ * These are the types that are the same on all platforms; on other
+ * platforms, a <net/bpf.h> should be supplied that defines the additional
+ * DLT_* codes appropriately for that platform (the BSDs, for example,
+ * should not just pick up this version of "bpf.h"; they should also define
+ * the additional DLT_* codes used by their kernels, as well as the values
+ * defined here - and, if the values they use for particular DLT_ types
+ * differ from those here, they should use their values, not the ones
+ * here).
+ */
#define DLT_NULL 0 /* no link-layer encapsulation */
#define DLT_EN10MB 1 /* Ethernet (10Mb) */
#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
@@ -172,24 +183,100 @@ struct bpf_hdr {
#define DLT_SLIP 8 /* Serial Line IP */
#define DLT_PPP 9 /* Point-to-point Protocol */
#define DLT_FDDI 10 /* FDDI */
-#ifdef __FreeBSD__
-#define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */
-#endif
-#ifdef __OpenBSD__
+
+/*
+ * These are values from the traditional libpcap "bpf.h".
+ * Ports of this to particular platforms should replace these definitions
+ * with the ones appropriate to that platform, if the values are
+ * different on that platform.
+ */
#define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */
-#define DLT_LOOP 12 /* loopback */
-#endif
-/* offset to avoid collision with BSD/OS values */
-#ifndef DLT_ATM_RFC1483
-#define DLT_ATM_RFC1483 100 /* LLC/SNAP encapsulated atm */
-#endif
-#define DLT_RAW 101 /* raw IP */
-#define DLT_SLIP_BSDOS 102 /* BSD/OS Serial Line IP */
-#define DLT_PPP_BSDOS 103 /* BSD/OS Point-to-point Protocol */
-#define DLT_CHDLC 104 /* Cisco HDLC */
+#define DLT_RAW 12 /* raw IP */
+
+/*
+ * These are values from BSD/OS's "bpf.h".
+ * These are not the same as the values from the traditional libpcap
+ * "bpf.h"; however, these values shouldn't be generated by any
+ * OS other than BSD/OS, so the correct values to use here are the
+ * BSD/OS values.
+ *
+ * Platforms that have already assigned these values to other
+ * DLT_ codes, however, should give these codes the values
+ * from that platform, so that programs that use these codes will
+ * continue to compile - even though they won't correctly read
+ * files of these types.
+ */
+#define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */
+#define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */
+
+#define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */
+
+/*
+ * This value is defined by NetBSD; other platforms should refrain from
+ * using it for other purposes, so that NetBSD savefiles with a link
+ * type of 50 can be read as this type on all platforms.
+ */
+#define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */
+
+/*
+ * This value was defined by libpcap 0.5; platforms that have defined
+ * it with a different value should define it here with that value -
+ * a link type of 104 in a save file will be mapped to DLT_C_HDLC,
+ * whatever value that happens to be, so programs will correctly
+ * handle files with that link type regardless of the value of
+ * DLT_C_HDLC.
+ *
+ * The name DLT_C_HDLC was used by BSD/OS; we use that name for source
+ * compatibility with programs written for BSD/OS.
+ *
+ * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
+ * for source compatibility with programs written for libpcap 0.5.
+ */
+#define DLT_C_HDLC 104 /* Cisco HDLC */
+#define DLT_CHDLC DLT_C_HDLC
+
+/*
+ * Reserved for future use.
+ * Do not pick other numerical value for these unless you have also
+ * picked up the tcpdump.org top-of-CVS-tree version of "savefile.c",
+ * which will arrange that capture files for these DLT_ types have
+ * the same "network" value on all platforms, regardless of what
+ * value is chosen for their DLT_ type (thus allowing captures made
+ * on one platform to be read on other platforms, even if the two
+ * platforms don't use the same numerical values for all DLT_ types).
+ */
+#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */
+
+/*
+ * Values between 106 and 107 are used in capture file headers as
+ * link-layer types corresponding to DLT_ types that might differ
+ * between platforms; don't use those values for new DLT_ new types.
+ */
+
+/*
+ * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
+ * that the AF_ type in the link-layer header is in network byte order.
+ *
+ * OpenBSD defines it as 12, but that collides with DLT_RAW, so we
+ * define it as 108 here. If OpenBSD picks up this file, it should
+ * define DLT_LOOP as 12 in its version, as per the comment above -
+ * and should not use 108 for any purpose.
+ */
+#define DLT_LOOP 108
+
+/*
+ * Values between 109 and 112 are used in capture file headers as
+ * link-layer types corresponding to DLT_ types that might differ
+ * between platforms; don't use those values for new DLT_ new types.
+ */
/*
- * The instruction encondings.
+ * This is for Linux cooked sockets.
+ */
+#define DLT_LINUX_SLL 113
+
+/*
+ * The instruction encodings.
*/
/* instruction classes */
#define BPF_CLASS(code) ((code) & 0x07)
@@ -260,15 +347,29 @@ struct bpf_insn {
#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
-#ifdef KERNEL
-extern u_int bpf_filter();
-extern void bpfattach();
+#if defined(BSD) && (defined(KERNEL) || defined(_KERNEL))
+/*
+ * Systems based on non-BSD kernels don't have ifnet's (or they don't mean
+ * anything if it is in <net/if.h>) and won't work like this.
+ */
+# if __STDC__
+extern void bpf_tap(struct ifnet *, u_char *, u_int);
+extern void bpf_mtap(struct ifnet *, struct mbuf *);
+extern void bpfattach(struct ifnet *, u_int, u_int);
+extern void bpfilterattach(int);
+# else
extern void bpf_tap();
extern void bpf_mtap();
-#else
+extern void bpfattach();
+extern void bpfilterattach();
+# endif /* __STDC__ */
+#endif /* BSD && (_KERNEL || KERNEL) */
#if __STDC__
+extern int bpf_validate(struct bpf_insn *, int);
extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
-#endif
+#else
+extern int bpf_validate();
+extern u_int bpf_filter();
#endif
/*
diff --git a/contrib/libpcap/bpf/net/bpf_filter.c b/contrib/libpcap/bpf/net/bpf_filter.c
index f274542..d47503f 100644
--- a/contrib/libpcap/bpf/net/bpf_filter.c
+++ b/contrib/libpcap/bpf/net/bpf_filter.c
@@ -38,17 +38,30 @@
* @(#)bpf.c 7.5 (Berkeley) 7/15/91
*/
-#if !(defined(lint) || defined(KERNEL))
+#if !(defined(lint) || defined(KERNEL) || defined(_KERNEL))
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf_filter.c,v 1.33.1.1 1999/10/07 23:46:41 mcr Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf_filter.c,v 1.35 2000/10/23 19:32:21 fenner Exp $ (LBL)";
#endif
#include <sys/param.h>
#include <sys/types.h>
#include <sys/time.h>
+
+#define SOLARIS (defined(sun) && (defined(__SVR4) || defined(__svr4__)))
+#if defined(__hpux) || SOLARIS
+# include <sys/sysmacros.h>
+# include <sys/stream.h>
+# define mbuf msgb
+# define m_next b_cont
+# define MLEN(m) ((m)->b_wptr - (m)->b_rptr)
+# define mtod(m,t) ((t)(m)->b_rptr)
+#else
+# define MLEN(m) ((m)->m_len)
+#endif
+
#include <net/bpf.h>
-#ifndef KERNEL
+#if !defined(KERNEL) && !defined(_KERNEL)
#include <stdlib.h>
#endif
@@ -79,17 +92,19 @@ static const char rcsid[] =
(u_int32)*((u_char *)p+3)<<0)
#endif
-#ifdef KERNEL
+#if defined(KERNEL) || defined(_KERNEL)
+# if !defined(__hpux) && !SOLARIS
#include <sys/mbuf.h>
-#define MINDEX(len, m, k) \
+# endif
+#define MINDEX(len, _m, _k) \
{ \
- len = m->m_len; \
- while (k >= len) { \
- k -= len; \
- m = m->m_next; \
- if (m == 0) \
+ len = MLEN(m); \
+ while ((_k) >= len) { \
+ (_k) -= len; \
+ (_m) = (_m)->m_next; \
+ if ((_m) == 0) \
return 0; \
- len = m->m_len; \
+ len = MLEN(m); \
} \
}
@@ -109,7 +124,7 @@ m_xword(m, k, err)
return EXTRACT_LONG(cp);
}
m0 = m->m_next;
- if (m0 == 0 || m0->m_len + len - k < 4)
+ if (m0 == 0 || MLEN(m0) + len - k < 4)
goto bad;
*err = 0;
np = mtod(m0, u_char *);
@@ -159,6 +174,8 @@ m_xhalf(m, k, err)
* Execute the filter program starting at pc on the packet p
* wirelen is the length of the original packet
* buflen is the amount of data present
+ * For the kernel, p is assumed to be a pointer to an mbuf if buflen is 0,
+ * in all other cases, p is a pointer to a buffer and buflen is its size.
*/
u_int
bpf_filter(pc, p, wirelen, buflen)
@@ -170,6 +187,17 @@ bpf_filter(pc, p, wirelen, buflen)
register u_int32 A, X;
register int k;
int32 mem[BPF_MEMWORDS];
+#if defined(KERNEL) || defined(_KERNEL)
+ struct mbuf *m, *n;
+ int merr, len;
+
+ if (buflen == 0) {
+ m = (struct mbuf *)p;
+ p = mtod(m, u_char *);
+ buflen = MLEN(m);
+ } else
+ m = NULL;
+#endif
if (pc == 0)
/*
@@ -184,7 +212,7 @@ bpf_filter(pc, p, wirelen, buflen)
switch (pc->code) {
default:
-#ifdef KERNEL
+#if defined(KERNEL) || defined(_KERNEL)
return 0;
#else
abort();
@@ -198,12 +226,10 @@ bpf_filter(pc, p, wirelen, buflen)
case BPF_LD|BPF_W|BPF_ABS:
k = pc->k;
if (k + sizeof(int32) > buflen) {
-#ifdef KERNEL
- int merr;
-
- if (buflen != 0)
+#if defined(KERNEL) || defined(_KERNEL)
+ if (m == NULL)
return 0;
- A = m_xword((struct mbuf *)p, k, &merr);
+ A = m_xword(m, k, &merr);
if (merr != 0)
return 0;
continue;
@@ -217,12 +243,12 @@ bpf_filter(pc, p, wirelen, buflen)
case BPF_LD|BPF_H|BPF_ABS:
k = pc->k;
if (k + sizeof(short) > buflen) {
-#ifdef KERNEL
- int merr;
-
- if (buflen != 0)
+#if defined(KERNEL) || defined(_KERNEL)
+ if (m == NULL)
+ return 0;
+ A = m_xhalf(m, k, &merr);
+ if (merr != 0)
return 0;
- A = m_xhalf((struct mbuf *)p, k, &merr);
continue;
#else
return 0;
@@ -234,15 +260,12 @@ bpf_filter(pc, p, wirelen, buflen)
case BPF_LD|BPF_B|BPF_ABS:
k = pc->k;
if (k >= buflen) {
-#ifdef KERNEL
- register struct mbuf *m;
- register int len;
-
- if (buflen != 0)
+#if defined(KERNEL) || defined(_KERNEL)
+ if (m == NULL)
return 0;
- m = (struct mbuf *)p;
- MINDEX(len, m, k);
- A = mtod(m, u_char *)[k];
+ n = m;
+ MINDEX(len, n, k);
+ A = mtod(n, u_char *)[k];
continue;
#else
return 0;
@@ -262,12 +285,10 @@ bpf_filter(pc, p, wirelen, buflen)
case BPF_LD|BPF_W|BPF_IND:
k = X + pc->k;
if (k + sizeof(int32) > buflen) {
-#ifdef KERNEL
- int merr;
-
- if (buflen != 0)
+#if defined(KERNEL) || defined(_KERNEL)
+ if (m == NULL)
return 0;
- A = m_xword((struct mbuf *)p, k, &merr);
+ A = m_xword(m, k, &merr);
if (merr != 0)
return 0;
continue;
@@ -281,12 +302,10 @@ bpf_filter(pc, p, wirelen, buflen)
case BPF_LD|BPF_H|BPF_IND:
k = X + pc->k;
if (k + sizeof(short) > buflen) {
-#ifdef KERNEL
- int merr;
-
- if (buflen != 0)
+#if defined(KERNEL) || defined(_KERNEL)
+ if (m == NULL)
return 0;
- A = m_xhalf((struct mbuf *)p, k, &merr);
+ A = m_xhalf(m, k, &merr);
if (merr != 0)
return 0;
continue;
@@ -300,15 +319,12 @@ bpf_filter(pc, p, wirelen, buflen)
case BPF_LD|BPF_B|BPF_IND:
k = X + pc->k;
if (k >= buflen) {
-#ifdef KERNEL
- register struct mbuf *m;
- register int len;
-
- if (buflen != 0)
+#if defined(KERNEL) || defined(_KERNEL)
+ if (m == NULL)
return 0;
- m = (struct mbuf *)p;
- MINDEX(len, m, k);
- A = mtod(m, u_char *)[k];
+ n = m;
+ MINDEX(len, n, k);
+ A = mtod(n, u_char *)[k];
continue;
#else
return 0;
@@ -320,15 +336,12 @@ bpf_filter(pc, p, wirelen, buflen)
case BPF_LDX|BPF_MSH|BPF_B:
k = pc->k;
if (k >= buflen) {
-#ifdef KERNEL
- register struct mbuf *m;
- register int len;
-
- if (buflen != 0)
+#if defined(KERNEL) || defined(_KERNEL)
+ if (m == NULL)
return 0;
- m = (struct mbuf *)p;
- MINDEX(len, m, k);
- X = (mtod(m, char *)[k] & 0xf) << 2;
+ n = m;
+ MINDEX(len, n, k);
+ X = (mtod(n, char *)[k] & 0xf) << 2;
continue;
#else
return 0;
@@ -478,7 +491,7 @@ bpf_filter(pc, p, wirelen, buflen)
}
}
-#ifdef KERNEL
+
/*
* Return true if the 'fcode' is a valid filter program.
* The constraints are that each jump be forward and to a valid
@@ -529,4 +542,3 @@ bpf_validate(f, len)
}
return BPF_CLASS(f[len - 1].code) == BPF_RET;
}
-#endif
OpenPOWER on IntegriCloud