Move empty filter handling to MI source.
MFC after: 3 days
This commit is contained in:
parent
bf2a220894
commit
a2b12e3b23
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=182220
@ -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),
|
||||
|
@ -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),
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user