summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/ng_bpf.c
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/netgraph/ng_bpf.c
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/netgraph/ng_bpf.c')
-rw-r--r--sys/netgraph/ng_bpf.c30
1 files changed, 28 insertions, 2 deletions
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