summaryrefslogtreecommitdiffstats
path: root/sys/net/bpf.c
diff options
context:
space:
mode:
authormelifaro <melifaro@FreeBSD.org>2012-05-21 22:19:19 +0000
committermelifaro <melifaro@FreeBSD.org>2012-05-21 22:19:19 +0000
commite5f61c6580ea0a76e8c43d0fa98f33e5623b639c (patch)
treea1fde4fc9d51ecf611705c4c685d911eacba3bb4 /sys/net/bpf.c
parent34ec5c86502577f86de209389836d93646d78b9b (diff)
downloadFreeBSD-src-e5f61c6580ea0a76e8c43d0fa98f33e5623b639c.zip
FreeBSD-src-e5f61c6580ea0a76e8c43d0fa98f33e5623b639c.tar.gz
Call bpf_jitter() before acquiring BPF global lock due to malloc() being used inside bpf_jitter.
Eliminate bpf_buffer_alloc() and allocate BPF buffers on descriptor creation and BIOCSBLEN ioctl. This permits us not to allocate buffers inside bpf_attachd() which is protected by global lock. Approved by: kib(mentor) MFC in: 4 weeks
Diffstat (limited to 'sys/net/bpf.c')
-rw-r--r--sys/net/bpf.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index aa40cc4..88d69aa 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -804,7 +804,7 @@ static int
bpfopen(struct cdev *dev, int flags, int fmt, struct thread *td)
{
struct bpf_d *d;
- int error;
+ int error, size;
d = malloc(sizeof(*d), M_BPF, M_WAITOK | M_ZERO);
error = devfs_set_cdevpriv(d, bpf_dtor);
@@ -831,6 +831,10 @@ bpfopen(struct cdev *dev, int flags, int fmt, struct thread *td)
callout_init_mtx(&d->bd_callout, &d->bd_lock, 0);
knlist_init_mtx(&d->bd_sel.si_note, &d->bd_lock);
+ /* Allocate default buffers */
+ size = d->bd_bufsize;
+ bpf_buffer_ioctl_sblen(d, &size);
+
return (0);
}
@@ -1664,7 +1668,7 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd)
struct bpf_insn *fcode, *old;
u_int wfilter, flen, size;
#ifdef BPF_JITTER
- bpf_jit_filter *ofunc;
+ bpf_jit_filter *ofunc, *jfunc;
#endif
int need_upgrade;
#ifdef COMPAT_FREEBSD32
@@ -1695,6 +1699,13 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd)
else
fcode = NULL; /* Make compiler happy */
+#ifdef BPF_JITTER
+ if (fp->bf_insns != NULL)
+ jfunc = bpf_jitter(fcode, flen);
+ else
+ jfunc = NULL; /* Make compiler happy */
+#endif
+
BPF_LOCK();
if (cmd == BIOCSETWF) {
@@ -1755,7 +1766,7 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd)
else {
d->bd_rfilter = fcode;
#ifdef BPF_JITTER
- d->bd_bfilter = bpf_jitter(fcode, flen);
+ d->bd_bfilter = jfunc;
#endif
if (cmd == BIOCSETF)
reset_d(d);
@@ -1827,11 +1838,6 @@ bpf_setif(struct bpf_d *d, struct ifreq *ifr)
*/
switch (d->bd_bufmode) {
case BPF_BUFMODE_BUFFER:
- if (d->bd_sbuf == NULL)
- bpf_buffer_alloc(d);
- KASSERT(d->bd_sbuf != NULL, ("bpf_setif: bd_sbuf NULL"));
- break;
-
case BPF_BUFMODE_ZBUF:
if (d->bd_sbuf == NULL)
return (EINVAL);
OpenPOWER on IntegriCloud