diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-08-31 20:08:50 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-08-31 20:08:50 -0700 |
commit | 1131a7c26c6f4d4772e4a2beeaf7212f4dea74ac (patch) | |
tree | 5fb97fbab51bd838aed0219ecf71c72f4403897c /bpf_filter.c | |
parent | 9c3cc5e26f74c3259a3428cae034ac818ba56fd9 (diff) |
Clean up the declaration of the packet-filtering routines.
If net/bpf.h declares bpf_filter() one way and libpcap defines it
another way, even pcap-bpf.c needs a declaration that matches how
libpcap defines it, not how net/bpf.h (mistakenly) declares it.
("Mistakenly" because it should *not* be declaring the kernel's version
of bpf_filter() unless it's being used in a *kernel* build; other *BSDs,
and macOS, declare it only in kernel builds by testing for a #define
such as KERNEL or KERNEL_PRIVATE, but NetBSD doesn't - it *should*, but
it doesn't.)
So we rename the internal-to-pcap filtering routine as pcap_filter(),
which is not exported from libpcap, and have bpf_filter() be a wrapper
around pcap_filter() that is exported.
Use pcap_filter(), rather than bpf_filter(), for all filtering inside
libpcap (except for filtering that uses bpf_filter_with_aux_data(),
which we rename pcap_filter_with_aux_data()).
Do the same for bpf_validate(), which is *also* declared in net/bpf.h,
even for non-kernel builds, in NetBSD.
As we're not exporting pcap_filter_with_aux_data(), don't even *declare*
it in a public header; don't declare struct bpf_aux_data in a public
header, either. That way we can change it without worrying about
breaking APIs or ABIs; we may do that if, for example, we want to
support the "inbound" and "outbound" filters when reading pcapng files,
adding a direction indicator to that structure.
Declare bpf_filter() in pcap/bpf.h even on NetBSD and QNX; pcap-bpf.c
doesn't include pcap/bpf.h (it sets a #define to force pcap/pcap.h not
to include it), so we won't get any collisions if net/bpf.h (which it
does include) declares it. The only collisions will occur in programs
that include *both* pcap/pcap.h or pcap/bpf.h *and* net/bpf.h, and that
will occur only if net/bpf.h declares bpf_filter() even when building
userland code, and the correct fix for *that* is to fix net/bpf.h not to
declare them in non-kernel builds.
Diffstat (limited to 'bpf_filter.c')
-rw-r--r-- | bpf_filter.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/bpf_filter.c b/bpf_filter.c index 93c33764..e5c286b5 100644 --- a/bpf_filter.c +++ b/bpf_filter.c @@ -85,11 +85,11 @@ enum { */ #if defined(SKF_AD_VLAN_TAG_PRESENT) u_int -bpf_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p, +pcap_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p, u_int wirelen, u_int buflen, const struct bpf_aux_data *aux_data) #else u_int -bpf_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p, +pcap_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p, u_int wirelen, u_int buflen, const struct bpf_aux_data *aux_data _U_) #endif { @@ -370,10 +370,10 @@ bpf_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p, } u_int -bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen, +pcap_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen, u_int buflen) { - return bpf_filter_with_aux_data(pc, p, wirelen, buflen, NULL); + return pcap_filter_with_aux_data(pc, p, wirelen, buflen, NULL); } /* @@ -388,7 +388,7 @@ bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen, * Otherwise, a bogus program could easily crash the system. */ int -bpf_validate(const struct bpf_insn *f, int len) +pcap_validate_filter(const struct bpf_insn *f, int len) { u_int i, from; const struct bpf_insn *p; @@ -510,3 +510,19 @@ bpf_validate(const struct bpf_insn *f, int len) } return BPF_CLASS(f[len - 1].code) == BPF_RET; } + +/* + * Exported because older versions of libpcap exported them. + */ +u_int +bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen, + u_int buflen) +{ + return pcap_filter(pc, p, wirelen, buflen); +} + +int +bpf_validate(const struct bpf_insn *f, int len) +{ + return pcap_validate_filter(f, len); +} |