From 99ef252d151a0dde1dc3f64330213074bb08fd64 Mon Sep 17 00:00:00 2001 From: jkim Date: Wed, 7 Dec 2005 21:30:47 +0000 Subject: 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. --- sys/netgraph/ng_bpf.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'sys/netgraph/ng_bpf.c') 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 #include #include @@ -62,6 +64,9 @@ #include #include +#ifdef BPF_JITTER +#include +#endif #include #include @@ -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); } - -- cgit v1.1