From e5a0d0d70b99ccd066229eef52ecb6861bdc7f8e Mon Sep 17 00:00:00 2001 From: David Gwynne Date: Sat, 2 Apr 2016 08:49:50 +0000 Subject: 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@ --- sys/net/bpf.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'sys/net/bpf.h') 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 $ */ /* @@ -262,14 +262,29 @@ struct bpf_dltlist { u_int *bfl_list; /* array of DLTs */ }; +/* + * 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 */ /* -- cgit v1.2.3