summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorjkim <jkim@FreeBSD.org>2005-12-07 21:30:47 +0000
committerjkim <jkim@FreeBSD.org>2005-12-07 21:30:47 +0000
commit99ef252d151a0dde1dc3f64330213074bb08fd64 (patch)
treec66cee417d03fe8210d3f5e392c690ed20dee756 /sys
parentd12a77cb38481285a7a2411f5b64a31c10b9d89b (diff)
downloadFreeBSD-src-99ef252d151a0dde1dc3f64330213074bb08fd64.zip
FreeBSD-src-99ef252d151a0dde1dc3f64330213074bb08fd64.tar.gz
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.
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/files2
-rw-r--r--sys/conf/files.amd642
-rw-r--r--sys/conf/files.i3862
-rw-r--r--sys/conf/files.pc982
-rw-r--r--sys/modules/netgraph/bpf/Makefile2
-rw-r--r--sys/net/bpf.c6
-rw-r--r--sys/net/bpf_jitter.c6
-rw-r--r--sys/net/bpf_jitter.h2
-rw-r--r--sys/netgraph/ng_bpf.c30
9 files changed, 41 insertions, 13 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 014d269..ff23bc1 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -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
diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64
index 2a302ab..a4fe564 100644
--- a/sys/conf/files.amd64
+++ b/sys/conf/files.amd64
@@ -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
diff --git a/sys/conf/files.i386 b/sys/conf/files.i386
index 80cd43a..deee3f2 100644
--- a/sys/conf/files.i386
+++ b/sys/conf/files.i386
@@ -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
diff --git a/sys/conf/files.pc98 b/sys/conf/files.pc98
index 1540c94..ce86180 100644
--- a/sys/conf/files.pc98
+++ b/sys/conf/files.pc98
@@ -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
diff --git a/sys/modules/netgraph/bpf/Makefile b/sys/modules/netgraph/bpf/Makefile
index 0bde4f2..adef38f 100644
--- a/sys/modules/netgraph/bpf/Makefile
+++ b/sys/modules/netgraph/bpf/Makefile
@@ -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>
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 5ffcb00..a66bf69 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -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;
diff --git a/sys/net/bpf_jitter.c b/sys/net/bpf_jitter.c
index 2d0ee2e1..b1a61c5 100644
--- a/sys/net/bpf_jitter.c
+++ b/sys/net/bpf_jitter.c
@@ -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)
{
diff --git a/sys/net/bpf_jitter.h b/sys/net/bpf_jitter.h
index 0ae64f9..9eed2c9 100644
--- a/sys/net/bpf_jitter.h
+++ b/sys/net/bpf_jitter.h
@@ -36,6 +36,8 @@
MALLOC_DECLARE(M_BPFJIT);
+extern int bpf_jitter_enable;
+
/*
* Prototype of a filtering function created by the jitter.
*
diff --git a/sys/netgraph/ng_bpf.c b/sys/netgraph/ng_bpf.c
index ff3e76f..aba24a8 100644
--- a/sys/netgraph/ng_bpf.c
+++ b/sys/netgraph/ng_bpf.c
@@ -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);
}
-
OpenPOWER on IntegriCloud