diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2016-04-02 08:49:50 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2016-04-02 08:49:50 +0000 |
commit | e5a0d0d70b99ccd066229eef52ecb6861bdc7f8e (patch) | |
tree | 467c8ba025beabaae6fe3b4d2c4c3eed8c4a3523 /sys/net/bpf.h | |
parent | 1205b031a9ad9ffbd73b76f455e3bcf03051352d (diff) |
refactor bpf_filter a bit.
the code was confusing around how it dealt with packets in mbufs
vs plain memory buffers with a lenght.
this renames bpf_filter to _bpf_filter, and changes it so the packet
memory is referred to by an opaque pointer, and callers have to
provide a set of operations to extra values from that opaque pointer.
bpf_filter is now provided as a wrapper around _bpf_filter. it
provides a set of operators that work on a straight buffer with a
lenght.
this also adds a bpf_mfilter function which takes an mbuf instead
of a buffer, and it provides explicit operations for extracting
values from mbufs.
if we want to use bpf filters against other data structures (usb
or scsi packets maybe?) we are able to provide functions for
extracting payloads from them and use _bpf_filter as is.
ok canacar@
Diffstat (limited to 'sys/net/bpf.h')
-rw-r--r-- | sys/net/bpf.h | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/sys/net/bpf.h b/sys/net/bpf.h index aba57b72b8c..37887894867 100644 --- a/sys/net/bpf.h +++ b/sys/net/bpf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.h,v 1.52 2016/03/30 12:51:10 dlg Exp $ */ +/* $OpenBSD: bpf.h,v 1.53 2016/04/02 08:49:49 dlg Exp $ */ /* $NetBSD: bpf.h,v 1.15 1996/12/13 07:57:33 mikel Exp $ */ /* @@ -263,13 +263,28 @@ struct bpf_dltlist { }; /* + * Load operations for _bpf_filter to use against the packet pointer. + */ +struct bpf_ops { + u_int32_t (*ldw)(const void *, u_int32_t, int *); + u_int32_t (*ldh)(const void *, u_int32_t, int *); + u_int32_t (*ldb)(const void *, u_int32_t, int *); +}; + +/* * Macros for insn array initializers. */ #define BPF_STMT(code, k) { (u_int16_t)(code), 0, 0, k } #define BPF_JUMP(code, k, jt, jf) { (u_int16_t)(code), jt, jf, k } +u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int); + +u_int _bpf_filter(const struct bpf_insn *, const struct bpf_ops *, + const void *, u_int); + #ifdef _KERNEL struct ifnet; +struct mbuf; int bpf_validate(struct bpf_insn *, int); int bpf_tap(caddr_t, u_char *, u_int, u_int); @@ -281,7 +296,8 @@ int bpf_mtap_ether(caddr_t, struct mbuf *, u_int); void bpfattach(caddr_t *, struct ifnet *, u_int, u_int); void bpfdetach(struct ifnet *); void bpfilterattach(int); -u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int); + +u_int bpf_mfilter(const struct bpf_insn *, const struct mbuf *, u_int); #endif /* _KERNEL */ /* |