Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add bpf_filter_ext() to use with BPF COP, restore bpf_fi...
details: https://anonhg.NetBSD.org/src/rev/052cf2d40489
branches: trunk
changeset: 790098:052cf2d40489
user: rmind <rmind%NetBSD.org@localhost>
date: Wed Sep 18 23:34:55 2013 +0000
description:
Add bpf_filter_ext() to use with BPF COP, restore bpf_filter() as it was
originally to preserve compatibility. Similarly, add bpf_validate_ext()
which takes bpf_ctx_t.
diffstat:
sys/external/bsd/ipf/netinet/fil.c | 10 ++--------
sys/net/bpf.c | 7 +++----
sys/net/bpf.h | 11 ++++-------
sys/net/bpf_filter.c | 29 ++++++++++++++++++++++++-----
sys/net/if_ppp.c | 12 ++++++------
sys/net/npf/npf_ruleset.c | 7 +++----
6 files changed, 42 insertions(+), 34 deletions(-)
diffs (246 lines):
diff -r 2039d4530ab3 -r 052cf2d40489 sys/external/bsd/ipf/netinet/fil.c
--- a/sys/external/bsd/ipf/netinet/fil.c Wed Sep 18 23:27:38 2013 +0000
+++ b/sys/external/bsd/ipf/netinet/fil.c Wed Sep 18 23:34:55 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fil.c,v 1.11 2013/09/12 20:03:10 martin Exp $ */
+/* $NetBSD: fil.c,v 1.12 2013/09/18 23:34:55 rmind Exp $ */
/*
* Copyright (C) 2012 by Darren Reed.
@@ -138,7 +138,7 @@
#if !defined(lint)
#if defined(__NetBSD__)
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fil.c,v 1.11 2013/09/12 20:03:10 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fil.c,v 1.12 2013/09/18 23:34:55 rmind Exp $");
#else
static const char sccsid[] = "@(#)fil.c 1.36 6/5/96 (C) 1993-2000 Darren Reed";
static const char rcsid[] = "@(#)Id: fil.c,v 1.1.1.2 2012/07/22 13:45:07 darrenr Exp $";
@@ -2405,14 +2405,8 @@
continue;
mc = (u_char *)fin->fin_m;
wlen = fin->fin_dlen + fin->fin_hlen;
-#if defined(__NetBSD__)
- if (!bpf_filter(bpf_def_ctx, NULL,
- fr->fr_data, mc, wlen, 0))
- continue;
-#else
if (!bpf_filter(fr->fr_data, mc, wlen, 0))
continue;
-#endif
break;
}
#endif
diff -r 2039d4530ab3 -r 052cf2d40489 sys/net/bpf.c
--- a/sys/net/bpf.c Wed Sep 18 23:27:38 2013 +0000
+++ b/sys/net/bpf.c Wed Sep 18 23:34:55 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bpf.c,v 1.176 2013/09/09 20:53:51 christos Exp $ */
+/* $NetBSD: bpf.c,v 1.177 2013/09/18 23:34:55 rmind Exp $ */
/*
* Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.176 2013/09/09 20:53:51 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.177 2013/09/18 23:34:55 rmind Exp $");
#if defined(_KERNEL_OPT)
#include "opt_bpf.h"
@@ -1382,8 +1382,7 @@
if (d->bd_jitcode != NULL)
slen = d->bd_jitcode(pkt, pktlen, buflen);
else
- slen = bpf_filter(bpf_def_ctx, NULL, d->bd_filter,
- pkt, pktlen, buflen);
+ slen = bpf_filter(d->bd_filter, pkt, pktlen, buflen);
if (!slen) {
continue;
diff -r 2039d4530ab3 -r 052cf2d40489 sys/net/bpf.h
--- a/sys/net/bpf.h Wed Sep 18 23:27:38 2013 +0000
+++ b/sys/net/bpf.h Wed Sep 18 23:34:55 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bpf.h,v 1.61 2013/08/30 15:00:08 rmind Exp $ */
+/* $NetBSD: bpf.h,v 1.62 2013/09/18 23:34:55 rmind Exp $ */
/*
* Copyright (c) 1990, 1991, 1993
@@ -384,23 +384,20 @@
typedef struct bpf_ctx bpf_ctx_t;
typedef uint32_t (*bpf_copfunc_t)(const struct mbuf *, void *,
uint32_t, uint32_t *);
-extern bpf_ctx_t *bpf_def_ctx;
bpf_ctx_t *bpf_create(void);
void bpf_destroy(bpf_ctx_t *);
int bpf_set_cop(bpf_ctx_t *, const bpf_copfunc_t *, size_t);
-u_int bpf_filter(bpf_ctx_t *, void *, const struct bpf_insn *,
+u_int bpf_filter_ext(bpf_ctx_t *, void *, const struct bpf_insn *,
const u_char *, u_int, u_int);
-int bpf_validate(const struct bpf_insn *, int);
+int bpf_validate_ext(bpf_ctx_t *, const struct bpf_insn *, int);
-#else
+#endif
int bpf_validate(const struct bpf_insn *, int);
u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
-#endif
-
__END_DECLS
/*
diff -r 2039d4530ab3 -r 052cf2d40489 sys/net/bpf_filter.c
--- a/sys/net/bpf_filter.c Wed Sep 18 23:27:38 2013 +0000
+++ b/sys/net/bpf_filter.c Wed Sep 18 23:34:55 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bpf_filter.c,v 1.57 2013/08/30 15:00:08 rmind Exp $ */
+/* $NetBSD: bpf_filter.c,v 1.58 2013/09/18 23:34:55 rmind Exp $ */
/*-
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf_filter.c,v 1.57 2013/08/30 15:00:08 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf_filter.c,v 1.58 2013/09/18 23:34:55 rmind Exp $");
#if 0
#if !(defined(lint) || defined(KERNEL))
@@ -61,8 +61,7 @@
};
/* Default BPF context (zeroed). */
-static bpf_ctx_t bpf_def_ctx1;
-bpf_ctx_t * bpf_def_ctx = &bpf_def_ctx1;
+static bpf_ctx_t bpf_def_ctx;
bpf_ctx_t *
bpf_create(void)
@@ -179,8 +178,16 @@
* buflen is the amount of data present
*/
#ifdef _KERNEL
+
u_int
-bpf_filter(bpf_ctx_t *bc, void *arg, const struct bpf_insn *pc,
+bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
+ u_int buflen)
+{
+ return bpf_filter_ext(&bpf_def_ctx, NULL, pc, p, wirelen, buflen);
+}
+
+u_int
+bpf_filter_ext(bpf_ctx_t *bc, void *arg, const struct bpf_insn *pc,
const u_char *p, u_int wirelen, u_int buflen)
#else
u_int
@@ -547,9 +554,21 @@
*/
__CTASSERT(BPF_MEMWORDS == sizeof(uint16_t) * NBBY);
+#if defined(KERNEL) || defined(_KERNEL)
+
int
bpf_validate(const struct bpf_insn *f, int signed_len)
{
+ return bpf_validate_ext(&bpf_def_ctx, f, signed_len);
+}
+
+int
+bpf_validate_ext(bpf_ctx_t *bc, const struct bpf_insn *f, int signed_len)
+#else
+int
+bpf_validate(const struct bpf_insn *f, int signed_len)
+#endif
+{
u_int i, from, len, ok = 0;
const struct bpf_insn *p;
#if defined(KERNEL) || defined(_KERNEL)
diff -r 2039d4530ab3 -r 052cf2d40489 sys/net/if_ppp.c
--- a/sys/net/if_ppp.c Wed Sep 18 23:27:38 2013 +0000
+++ b/sys/net/if_ppp.c Wed Sep 18 23:34:55 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ppp.c,v 1.140 2013/08/30 15:00:08 rmind Exp $ */
+/* $NetBSD: if_ppp.c,v 1.141 2013/09/18 23:34:55 rmind Exp $ */
/* Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp */
/*
@@ -102,7 +102,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.140 2013/08/30 15:00:08 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.141 2013/09/18 23:34:55 rmind Exp $");
#include "ppp.h"
@@ -946,7 +946,7 @@
* but only if it is a data packet.
*/
if (sc->sc_pass_filt_out.bf_insns != 0
- && bpf_filter(bpf_def_ctx, NULL, sc->sc_pass_filt_out.bf_insns,
+ && bpf_filter(sc->sc_pass_filt_out.bf_insns,
(u_char *)m0, len, 0) == 0) {
error = 0; /* drop this packet */
goto bad;
@@ -956,7 +956,7 @@
* Update the time we sent the most recent packet.
*/
if (sc->sc_active_filt_out.bf_insns == 0
- || bpf_filter(bpf_def_ctx, NULL, sc->sc_active_filt_out.bf_insns,
+ || bpf_filter(sc->sc_active_filt_out.bf_insns,
(u_char *)m0, len, 0))
sc->sc_last_sent = time_second;
#else
@@ -1584,14 +1584,14 @@
* if it counts as link activity.
*/
if (sc->sc_pass_filt_in.bf_insns != 0
- && bpf_filter(bpf_def_ctx, NULL, sc->sc_pass_filt_in.bf_insns,
+ && bpf_filter(sc->sc_pass_filt_in.bf_insns,
(u_char *)m, ilen, 0) == 0) {
/* drop this packet */
m_freem(m);
return;
}
if (sc->sc_active_filt_in.bf_insns == 0
- || bpf_filter(bpf_def_ctx, NULL, sc->sc_active_filt_in.bf_insns,
+ || bpf_filter(sc->sc_active_filt_in.bf_insns,
(u_char *)m, ilen, 0))
sc->sc_last_recv = time_second;
#else
diff -r 2039d4530ab3 -r 052cf2d40489 sys/net/npf/npf_ruleset.c
--- a/sys/net/npf/npf_ruleset.c Wed Sep 18 23:27:38 2013 +0000
+++ b/sys/net/npf/npf_ruleset.c Wed Sep 18 23:34:55 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_ruleset.c,v 1.22 2013/08/30 15:00:08 rmind Exp $ */
+/* $NetBSD: npf_ruleset.c,v 1.23 2013/09/18 23:34:55 rmind Exp $ */
/*-
* Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_ruleset.c,v 1.22 2013/08/30 15:00:08 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_ruleset.c,v 1.23 2013/09/18 23:34:55 rmind Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -681,8 +681,7 @@
case NPF_CODE_BPF: {
struct mbuf *m = nbuf_head_mbuf(nbuf);
size_t pktlen = m_length(m);
- return bpf_filter(bpf_def_ctx, NULL, code,
- (unsigned char *)m, pktlen, 0) != 0;
+ return bpf_filter(code, (unsigned char *)m, pktlen, 0) != 0;
}
default:
KASSERT(false);
Home |
Main Index |
Thread Index |
Old Index