From: Guy Harris Date: Mon, 25 Jan 2021 00:13:50 +0000 (-0800) Subject: If BPF_STMT or BPF_JUMP is defined, undefine them before redefining them. X-Git-Tag: libpcap-1.10.1~93 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/041fe47c6126400cf5453a91770c983b5a022aaf If BPF_STMT or BPF_JUMP is defined, undefine them before redefining them. Do that instead of just not defining the BPF stuff if __LINUX_FILTER_H__ is defined. That way, our definitions override the definitions. If those differ from our definitions, we want our definitions, at least when building the BPF code generator, so that, for example, we support the modulo and XOR operators. (If the kernel doesn't support them, the attempt to set the kernel filter will fail if we use BPF_MOD or BPF_XOR, and we'll fall back on doing userland filtering.) This should address GitHub issue #987. (cherry picked from commit 2abff2bc2dbd2be3888330e9ce0df298dd441d8a) --- diff --git a/pcap/bpf.h b/pcap/bpf.h index ccb93cc7..bfc60d2c 100644 --- a/pcap/bpf.h +++ b/pcap/bpf.h @@ -119,8 +119,6 @@ struct bpf_program { #include -#ifndef __LINUX_FILTER_H__ - /* * The instruction encodings. * @@ -241,8 +239,6 @@ struct bpf_program { /* 0xf0 reserved */ /* 0xf8 reserved */ -#endif /* __LINUX_FILTER_H__ */ - /* * The instruction data structure. */ @@ -253,16 +249,25 @@ struct bpf_insn { bpf_u_int32 k; }; -#ifndef __LINUX_FILTER_H__ - /* * Macros for insn array initializers. + * + * In case somebody's included , or something else that + * gives the kernel's definitions of BPF statements, get rid of its + * definitions, so we can supply ours instead. If some kernel's + * definitions aren't *binary-compatible* with what BPF has had + * since it first sprung from the brows of Van Jacobson and Steve + * McCanne, that kernel should be fixed. */ +#ifdef BPF_STMT +#undef BPF_STMT +#endif #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k } +#ifdef BPF_JUMP +#undef BPF_JUMP +#endif #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k } -#endif /* __LINUX_FILTER_H__ */ - PCAP_AVAILABLE_0_4 PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);