bpf_filter: add a custom argument which can be passed to coprocessor routine.
This commit is contained in:
parent
36c915dd13
commit
4c45c55542
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: fil.c,v 1.9 2013/08/29 14:25:40 rmind Exp $ */
|
||||
/* $NetBSD: fil.c,v 1.10 2013/08/30 15:00:08 rmind Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012 by Darren Reed.
|
||||
|
@ -138,7 +138,7 @@ extern struct timeout ipf_slowtimer_ch;
|
|||
#if !defined(lint)
|
||||
#if defined(__NetBSD__)
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: fil.c,v 1.9 2013/08/29 14:25:40 rmind Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: fil.c,v 1.10 2013/08/30 15:00:08 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 $";
|
||||
|
@ -2406,7 +2406,8 @@ ipf_scanlist(fr_info_t *fin, u_32_t pass)
|
|||
mc = (u_char *)fin->fin_m;
|
||||
wlen = fin->fin_dlen + fin->fin_hlen;
|
||||
#if defined(__NetBSD__)
|
||||
if (!bpf_filter(bpf_def_ctx, fr->fr_data, mc, wlen, 0))
|
||||
if (!bpf_filter(bpf_def_ctx, NULL,
|
||||
fr->fr_data, mc, wlen, 0))
|
||||
continue;
|
||||
#else
|
||||
if (!bpf_filter(fr->fr_data, mc, wlen, 0))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bpf.c,v 1.174 2013/08/29 14:25:41 rmind Exp $ */
|
||||
/* $NetBSD: bpf.c,v 1.175 2013/08/30 15:00:08 rmind Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1993
|
||||
|
@ -39,7 +39,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.174 2013/08/29 14:25:41 rmind Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.175 2013/08/30 15:00:08 rmind Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_bpf.h"
|
||||
|
@ -1382,7 +1382,7 @@ bpf_deliver(struct bpf_if *bp, void *(*cpfn)(void *, const void *, size_t),
|
|||
if (d->bd_jitcode != NULL)
|
||||
slen = d->bd_jitcode(pkt, pktlen, buflen);
|
||||
else
|
||||
slen = bpf_filter(bpf_def_ctx, d->bd_filter,
|
||||
slen = bpf_filter(bpf_def_ctx, NULL, d->bd_filter,
|
||||
pkt, pktlen, buflen);
|
||||
|
||||
if (!slen) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bpf.h,v 1.60 2013/08/29 14:25:41 rmind Exp $ */
|
||||
/* $NetBSD: bpf.h,v 1.61 2013/08/30 15:00:08 rmind Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1993
|
||||
|
@ -382,14 +382,15 @@ void bpfilterattach(int);
|
|||
|
||||
struct bpf_ctx;
|
||||
typedef struct bpf_ctx bpf_ctx_t;
|
||||
typedef uint32_t (*bpf_copfunc_t)(const struct mbuf *, uint32_t, uint32_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 *, const struct bpf_insn *,
|
||||
u_int bpf_filter(bpf_ctx_t *, void *, const struct bpf_insn *,
|
||||
const u_char *, u_int, u_int);
|
||||
int bpf_validate(const struct bpf_insn *, int);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bpf_filter.c,v 1.56 2013/08/29 14:25:41 rmind Exp $ */
|
||||
/* $NetBSD: bpf_filter.c,v 1.57 2013/08/30 15:00:08 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.56 2013/08/29 14:25:41 rmind Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: bpf_filter.c,v 1.57 2013/08/30 15:00:08 rmind Exp $");
|
||||
|
||||
#if 0
|
||||
#if !(defined(lint) || defined(KERNEL))
|
||||
|
@ -180,8 +180,8 @@ m_xbyte(const struct mbuf *m, uint32_t k, int *err)
|
|||
*/
|
||||
#ifdef _KERNEL
|
||||
u_int
|
||||
bpf_filter(bpf_ctx_t *bc, const struct bpf_insn *pc, const u_char *p,
|
||||
u_int wirelen, u_int buflen)
|
||||
bpf_filter(bpf_ctx_t *bc, void *arg, const struct bpf_insn *pc,
|
||||
const u_char *p, u_int wirelen, u_int buflen)
|
||||
#else
|
||||
u_int
|
||||
bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
|
||||
|
@ -515,7 +515,7 @@ bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
|
|||
#ifdef _KERNEL
|
||||
if (pc->k < bc->nfuncs) {
|
||||
const bpf_copfunc_t fn = bc->copfuncs[pc->k];
|
||||
A = fn((const struct mbuf *)p, A, mem);
|
||||
A = fn((const struct mbuf *)p, arg, A, mem);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
@ -525,7 +525,7 @@ bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
|
|||
#ifdef _KERNEL
|
||||
if (X < bc->nfuncs) {
|
||||
const bpf_copfunc_t fn = bc->copfuncs[X];
|
||||
A = fn((const struct mbuf *)p, A, mem);
|
||||
A = fn((const struct mbuf *)p, arg, A, mem);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_ppp.c,v 1.139 2013/08/29 14:25:41 rmind Exp $ */
|
||||
/* $NetBSD: if_ppp.c,v 1.140 2013/08/30 15:00:08 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.139 2013/08/29 14:25:41 rmind Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.140 2013/08/30 15:00:08 rmind Exp $");
|
||||
|
||||
#include "ppp.h"
|
||||
|
||||
|
@ -946,7 +946,7 @@ pppoutput(struct ifnet *ifp, struct mbuf *m0, const struct sockaddr *dst,
|
|||
* but only if it is a data packet.
|
||||
*/
|
||||
if (sc->sc_pass_filt_out.bf_insns != 0
|
||||
&& bpf_filter(bpf_def_ctx, sc->sc_pass_filt_out.bf_insns,
|
||||
&& bpf_filter(bpf_def_ctx, NULL, sc->sc_pass_filt_out.bf_insns,
|
||||
(u_char *)m0, len, 0) == 0) {
|
||||
error = 0; /* drop this packet */
|
||||
goto bad;
|
||||
|
@ -956,7 +956,7 @@ pppoutput(struct ifnet *ifp, struct mbuf *m0, const struct sockaddr *dst,
|
|||
* Update the time we sent the most recent packet.
|
||||
*/
|
||||
if (sc->sc_active_filt_out.bf_insns == 0
|
||||
|| bpf_filter(bpf_def_ctx, sc->sc_active_filt_out.bf_insns,
|
||||
|| bpf_filter(bpf_def_ctx, NULL, sc->sc_active_filt_out.bf_insns,
|
||||
(u_char *)m0, len, 0))
|
||||
sc->sc_last_sent = time_second;
|
||||
#else
|
||||
|
@ -1584,14 +1584,14 @@ ppp_inproc(struct ppp_softc *sc, struct mbuf *m)
|
|||
* if it counts as link activity.
|
||||
*/
|
||||
if (sc->sc_pass_filt_in.bf_insns != 0
|
||||
&& bpf_filter(bpf_def_ctx, sc->sc_pass_filt_in.bf_insns,
|
||||
&& bpf_filter(bpf_def_ctx, NULL, 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, sc->sc_active_filt_in.bf_insns,
|
||||
|| bpf_filter(bpf_def_ctx, NULL, sc->sc_active_filt_in.bf_insns,
|
||||
(u_char *)m, ilen, 0))
|
||||
sc->sc_last_recv = time_second;
|
||||
#else
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: npf_ruleset.c,v 1.21 2013/08/29 14:25:41 rmind Exp $ */
|
||||
/* $NetBSD: npf_ruleset.c,v 1.22 2013/08/30 15:00:08 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.21 2013/08/29 14:25:41 rmind Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: npf_ruleset.c,v 1.22 2013/08/30 15:00:08 rmind Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -681,8 +681,8 @@ npf_rule_inspect(npf_cache_t *npc, nbuf_t *nbuf, const npf_rule_t *rl,
|
|||
case NPF_CODE_BPF: {
|
||||
struct mbuf *m = nbuf_head_mbuf(nbuf);
|
||||
size_t pktlen = m_length(m);
|
||||
return bpf_filter(bpf_def_ctx, code, (unsigned char *)m,
|
||||
pktlen, 0) != 0;
|
||||
return bpf_filter(bpf_def_ctx, NULL, code,
|
||||
(unsigned char *)m, pktlen, 0) != 0;
|
||||
}
|
||||
default:
|
||||
KASSERT(false);
|
||||
|
|
Loading…
Reference in New Issue