Move empty filter handling to MI source.

MFC after:	3 days
This commit is contained in:
Jung-uk Kim 2008-08-26 21:06:31 +00:00
parent bf2a220894
commit a2b12e3b23
3 changed files with 26 additions and 10 deletions

View File

@ -107,10 +107,6 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem)
*/
emit_func emitm;
/* Do not compile an empty filter. */
if (nins == 0)
return (NULL);
/* Allocate the reference table for the jumps */
#ifdef _KERNEL
stream.refs = (u_int *)malloc((nins + 1) * sizeof(u_int),

View File

@ -107,10 +107,6 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem)
*/
emit_func emitm;
/* Do not compile an empty filter. */
if (nins == 0)
return (NULL);
/* Allocate the reference table for the jumps */
#ifdef _KERNEL
stream.refs = (u_int *)malloc((nins + 1) * sizeof(u_int),

View File

@ -50,6 +50,8 @@ __FBSDID("$FreeBSD$");
bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, int *);
static u_int bpf_jit_accept_all(u_char *, u_int, u_int);
#ifdef _KERNEL
MALLOC_DEFINE(M_BPFJIT, "BPF_JIT", "BPF JIT compiler");
@ -69,6 +71,12 @@ bpf_jitter(struct bpf_insn *fp, int nins)
if (filter == NULL)
return (NULL);
/* No filter means accept all */
if (fp == NULL || nins == 0) {
filter->func = bpf_jit_accept_all;
return (filter);
}
/* Create the binary */
if ((filter->func = bpf_jit_compile(fp, nins, filter->mem)) == NULL) {
free(filter, M_BPFJIT);
@ -82,7 +90,8 @@ void
bpf_destroy_jit_filter(bpf_jit_filter *filter)
{
free(filter->func, M_BPFJIT);
if (filter->func != bpf_jit_accept_all)
free(filter->func, M_BPFJIT);
free(filter, M_BPFJIT);
}
#else
@ -96,6 +105,12 @@ bpf_jitter(struct bpf_insn *fp, int nins)
if (filter == NULL)
return (NULL);
/* No filter means accept all */
if (fp == NULL || nins == 0) {
filter->func = bpf_jit_accept_all;
return (filter);
}
/* Create the binary */
if ((filter->func = bpf_jit_compile(fp, nins, filter->mem)) == NULL) {
free(filter);
@ -109,7 +124,16 @@ void
bpf_destroy_jit_filter(bpf_jit_filter *filter)
{
free(filter->func);
if (filter->func != bpf_jit_accept_all)
free(filter->func);
free(filter);
}
#endif
static u_int
bpf_jit_accept_all(__unused u_char *p, __unused u_int wirelen,
__unused u_int buflen)
{
return ((u_int)-1);
}