aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2020-05-16 22:33:35 -0700
committerGuy Harris <gharris@sonic.net>2020-05-16 22:33:35 -0700
commit0bb0b261a05bd0f396429bf99984343c9bade3b1 (patch)
tree50730a955dd49e290580f48014da0fec21bb26e9
parent83842505386fcb1b37308c8508f0078ca7c6081f (diff)
Avoid #define collisions with <linux/filter.h> or stuff it includes.
Some programs, e.g. pktgen-dpdk, include both <linux/filter.h> and <pcap/bpf.h> in the same source file; both of them have BPF-instruction Just as we protect against <net/bpf.h> and <pcap/bpf.h> colliding, we protect against <linux/filter.h> and <pcap/bpf.h> colliding, although we need to protect fewer things as <linux/filter.h> doesn't define everything we need. This should address GitHub pull request #933.
-rw-r--r--pcap/bpf.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/pcap/bpf.h b/pcap/bpf.h
index b37546bf..95ea2abc 100644
--- a/pcap/bpf.h
+++ b/pcap/bpf.h
@@ -58,10 +58,21 @@
* I don't have earlier versions available to check), or QNX-style
* multiple-include protection (as per GitHub pull request #394).
*
+ * We trust that they will define structures and macros and types in
+ * a fashion that's source-compatible and binary-compatible with our
+ * definitions.
+ *
* We do not check for BPF_MAJOR_VERSION, as that's defined by
* <linux/filter.h>, which is directly or indirectly included in some
* programs that also include pcap.h, and <linux/filter.h> doesn't
- * define stuff we need.
+ * define stuff we need. We *do* protect against <linux/filter.h>
+ * defining various macros for BPF code itself; <linux/filter.h> says
+ *
+ * Try and keep these values and structures similar to BSD, especially
+ * the BPF code definitions which need to match so you can share filters
+ *
+ * so we trust that it will define them in a fashion that's source-compatible
+ * and binary-compatible with our definitions.
*
* This also provides our own multiple-include protection.
*/
@@ -108,6 +119,8 @@ struct bpf_program {
#include <pcap/dlt.h>
+#ifndef __LINUX_FILTER_H__
+
/*
* The instruction encodings.
*
@@ -228,6 +241,8 @@ struct bpf_program {
/* 0xf0 reserved */
/* 0xf8 reserved */
+#endif /* __LINUX_FILTER_H__ */
+
/*
* The instruction data structure.
*/
@@ -238,12 +253,16 @@ struct bpf_insn {
bpf_u_int32 k;
};
+#ifndef __LINUX_FILTER_H__
+
/*
* Macros for insn array initializers.
*/
#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
+#endif /* __LINUX_FILTER_H__ */
+
PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
PCAP_API int bpf_validate(const struct bpf_insn *f, int len);
PCAP_API char *bpf_image(const struct bpf_insn *, int);