Add BPF Just-In-Time compiler support for ng_bpf(4).
The sysctl is changed from net.bpf.jitter.enable to net.bpf_jitter.enable and this controls both bpf(4) and ng_bpf(4) now.
This commit is contained in:
parent
081ff8ace3
commit
848c454cc1
@ -1401,7 +1401,7 @@ libkern/strtoul.c standard
|
||||
libkern/strtouq.c standard
|
||||
libkern/strvalid.c standard
|
||||
net/bpf.c standard
|
||||
net/bpf_jitter.c optional bpf bpf_jitter
|
||||
net/bpf_jitter.c optional bpf_jitter
|
||||
net/bpf_filter.c optional bpf | netgraph_bpf
|
||||
net/bridgestp.c optional if_bridge
|
||||
net/bsd_comp.c optional ppp_bsdcomp
|
||||
|
@ -82,7 +82,7 @@ amd64/amd64/amd64_mem.c optional mem
|
||||
amd64/amd64/atomic.c standard
|
||||
amd64/amd64/autoconf.c standard
|
||||
amd64/amd64/bios.c standard
|
||||
amd64/amd64/bpf_jit_machdep.c optional bpf bpf_jitter
|
||||
amd64/amd64/bpf_jit_machdep.c optional bpf_jitter
|
||||
amd64/amd64/busdma_machdep.c standard
|
||||
amd64/amd64/cpu_switch.S standard
|
||||
amd64/amd64/db_disasm.c optional ddb
|
||||
|
@ -241,7 +241,7 @@ i386/i386/atomic.c standard \
|
||||
i386/i386/autoconf.c standard
|
||||
i386/i386/bios.c standard
|
||||
i386/i386/bioscall.s standard
|
||||
i386/i386/bpf_jit_machdep.c optional bpf bpf_jitter
|
||||
i386/i386/bpf_jit_machdep.c optional bpf_jitter
|
||||
i386/i386/busdma_machdep.c standard
|
||||
i386/i386/db_disasm.c optional ddb
|
||||
i386/i386/db_interface.c optional ddb
|
||||
|
@ -136,7 +136,7 @@ i386/i386/atomic.c standard \
|
||||
i386/i386/autoconf.c standard
|
||||
i386/i386/bios.c standard
|
||||
i386/i386/bioscall.s standard
|
||||
i386/i386/bpf_jit_machdep.c optional bpf bpf_jitter
|
||||
i386/i386/bpf_jit_machdep.c optional bpf_jitter
|
||||
i386/i386/busdma_machdep.c standard
|
||||
i386/i386/db_disasm.c optional ddb
|
||||
i386/i386/db_interface.c optional ddb
|
||||
|
@ -4,6 +4,6 @@
|
||||
.PATH: ${.CURDIR}/../../../net
|
||||
|
||||
KMOD= ng_bpf
|
||||
SRCS= ng_bpf.c bpf_filter.c
|
||||
SRCS= opt_bpf.h ng_bpf.c bpf_filter.c
|
||||
|
||||
.include <bsd.kmod.mk>
|
||||
|
@ -129,12 +129,6 @@ SYSCTL_INT(_net_bpf, OID_AUTO, maxinsns, CTLFLAG_RW,
|
||||
&bpf_maxinsns, 0, "Maximum bpf program instructions");
|
||||
SYSCTL_NODE(_net_bpf, OID_AUTO, stats, CTLFLAG_RW,
|
||||
bpf_stats_sysctl, "bpf statistics portal");
|
||||
#ifdef BPF_JITTER
|
||||
SYSCTL_NODE(_net_bpf, OID_AUTO, jitter, CTLFLAG_RW, 0, "bpf jitter sysctl");
|
||||
static int bpf_jitter_enable = 1;
|
||||
SYSCTL_INT(_net_bpf_jitter, OID_AUTO, enable, CTLFLAG_RW,
|
||||
&bpf_jitter_enable, 0, "bpf JIT compiler");
|
||||
#endif
|
||||
|
||||
static d_open_t bpfopen;
|
||||
static d_close_t bpfclose;
|
||||
|
@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <net/bpf.h>
|
||||
#include <net/bpf_jitter.h>
|
||||
@ -46,6 +47,11 @@ MALLOC_DEFINE(M_BPFJIT, "BPF_JIT", "BPF JIT compiler");
|
||||
|
||||
bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, int *);
|
||||
|
||||
SYSCTL_NODE(_net, OID_AUTO, bpf_jitter, CTLFLAG_RW, 0, "BPF JIT compiler");
|
||||
int bpf_jitter_enable = 1;
|
||||
SYSCTL_INT(_net_bpf_jitter, OID_AUTO, enable, CTLFLAG_RW,
|
||||
&bpf_jitter_enable, 0, "enable BPF JIT compiler");
|
||||
|
||||
bpf_jit_filter *
|
||||
bpf_jitter(struct bpf_insn *fp, int nins)
|
||||
{
|
||||
|
@ -36,6 +36,8 @@
|
||||
|
||||
MALLOC_DECLARE(M_BPFJIT);
|
||||
|
||||
extern int bpf_jitter_enable;
|
||||
|
||||
/*
|
||||
* Prototype of a filtering function created by the jitter.
|
||||
*
|
||||
|
@ -54,6 +54,8 @@
|
||||
* Each hook also keeps statistics about how many packets have matched, etc.
|
||||
*/
|
||||
|
||||
#include "opt_bpf.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/errno.h>
|
||||
@ -62,6 +64,9 @@
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
#include <net/bpf.h>
|
||||
#ifdef BPF_JITTER
|
||||
#include <net/bpf_jitter.h>
|
||||
#endif
|
||||
|
||||
#include <netgraph/ng_message.h>
|
||||
#include <netgraph/netgraph.h>
|
||||
@ -83,6 +88,9 @@ struct ng_bpf_hookinfo {
|
||||
node_p node;
|
||||
hook_p hook;
|
||||
struct ng_bpf_hookprog *prog;
|
||||
#ifdef BPF_JITTER
|
||||
bpf_jit_filter *jit_prog;
|
||||
#endif
|
||||
struct ng_bpf_hookstat stats;
|
||||
};
|
||||
typedef struct ng_bpf_hookinfo *hinfo_p;
|
||||
@ -406,8 +414,14 @@ ng_bpf_rcvdata(hook_p hook, item_p item)
|
||||
/* Run packet through filter */
|
||||
if (totlen == 0)
|
||||
len = 0; /* don't call bpf_filter() with totlen == 0! */
|
||||
else
|
||||
else {
|
||||
#ifdef BPF_JITTER
|
||||
if (bpf_jitter_enable != 0 && hip->jit_prog != NULL)
|
||||
len = (*(hip->jit_prog->func))(data, totlen, totlen);
|
||||
else
|
||||
#endif
|
||||
len = bpf_filter(hip->prog->bpf_prog, data, totlen, totlen);
|
||||
}
|
||||
if (needfree)
|
||||
FREE(data, M_NETGRAPH_BPF);
|
||||
|
||||
@ -461,6 +475,10 @@ ng_bpf_disconnect(hook_p hook)
|
||||
|
||||
KASSERT(hip != NULL, ("%s: null info", __func__));
|
||||
FREE(hip->prog, M_NETGRAPH_BPF);
|
||||
#ifdef BPF_JITTER
|
||||
if (hip->jit_prog != NULL)
|
||||
bpf_destroy_jit_filter(hip->jit_prog);
|
||||
#endif
|
||||
bzero(hip, sizeof(*hip));
|
||||
FREE(hip, M_NETGRAPH_BPF);
|
||||
NG_HOOK_SET_PRIVATE(hook, NULL); /* for good measure */
|
||||
@ -483,6 +501,7 @@ ng_bpf_setprog(hook_p hook, const struct ng_bpf_hookprog *hp0)
|
||||
{
|
||||
const hinfo_p hip = NG_HOOK_PRIVATE(hook);
|
||||
struct ng_bpf_hookprog *hp;
|
||||
bpf_jit_filter *jit_prog;
|
||||
int size;
|
||||
|
||||
/* Check program for validity */
|
||||
@ -495,11 +514,18 @@ ng_bpf_setprog(hook_p hook, const struct ng_bpf_hookprog *hp0)
|
||||
if (hp == NULL)
|
||||
return (ENOMEM);
|
||||
bcopy(hp0, hp, size);
|
||||
#ifdef BPF_JITTER
|
||||
jit_prog = bpf_jitter(hp->bpf_prog, hp->bpf_prog_len);
|
||||
#endif
|
||||
|
||||
/* Free previous program, if any, and assign new one */
|
||||
if (hip->prog != NULL)
|
||||
FREE(hip->prog, M_NETGRAPH_BPF);
|
||||
hip->prog = hp;
|
||||
#ifdef BPF_JITTER
|
||||
if (hip->jit_prog != NULL)
|
||||
bpf_destroy_jit_filter(hip->jit_prog);
|
||||
#endif
|
||||
hip->jit_prog = jit_prog;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user