-/* $OpenBSD: bpf.c,v 1.223 2024/08/05 23:56:10 dlg Exp $ */
+/* $OpenBSD: bpf.c,v 1.224 2024/08/12 17:02:58 mvs Exp $ */
/* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */
/*
#define PRINET 26 /* interruptible */
+/*
+ * Locks used to protect data:
+ * a atomic
+ */
+
/*
* The default read buffer size is patchable.
*/
-int bpf_bufsize = BPF_BUFSIZE;
-int bpf_maxbufsize = BPF_MAXBUFSIZE;
+int bpf_bufsize = BPF_BUFSIZE; /* [a] */
+int bpf_maxbufsize = BPF_MAXBUFSIZE; /* [a] */
/*
* bpf_iflist is the list of interfaces; each corresponds to an ifnet
int filt_bpfreadmodify(struct kevent *, struct knote *);
int filt_bpfreadprocess(struct knote *, struct kevent *);
-int bpf_sysctl_locked(int *, u_int, void *, size_t *, void *, size_t);
-
struct bpf_d *bpfilter_lookup(int);
/*
void bpf_get(struct bpf_d *);
void bpf_put(struct bpf_d *);
-
-struct rwlock bpf_sysctl_lk = RWLOCK_INITIALIZER("bpfsz");
-
int
bpf_movein(struct uio *uio, struct bpf_d *d, struct mbuf **mp,
struct sockaddr *sockp)
/* Mark "free" and do most initialization. */
bd->bd_unit = unit;
- bd->bd_bufsize = bpf_bufsize;
+ bd->bd_bufsize = atomic_load_int(&bpf_bufsize);
bd->bd_sig = SIGIO;
mtx_init(&bd->bd_mtx, IPL_NET);
task_set(&bd->bd_wake_task, bpf_wakeup_cb, bd);
error = EINVAL;
else {
u_int size = *(u_int *)addr;
+ int bpf_maxbufsize_local =
+ atomic_load_int(&bpf_maxbufsize);
- if (size > bpf_maxbufsize)
- *(u_int *)addr = size = bpf_maxbufsize;
+ if (size > bpf_maxbufsize_local)
+ *(u_int *)addr = size = bpf_maxbufsize_local;
else if (size < BPF_MINBUFSIZE)
*(u_int *)addr = size = BPF_MINBUFSIZE;
mtx_enter(&d->bd_mtx);
}
int
-bpf_sysctl_locked(int *name, u_int namelen, void *oldp, size_t *oldlenp,
- void *newp, size_t newlen)
+bpf_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
+ size_t newlen)
{
+ if (namelen != 1)
+ return (ENOTDIR);
+
switch (name[0]) {
case NET_BPF_BUFSIZE:
return sysctl_int_bounded(oldp, oldlenp, newp, newlen,
- &bpf_bufsize, BPF_MINBUFSIZE, bpf_maxbufsize);
+ &bpf_bufsize, BPF_MINBUFSIZE,
+ atomic_load_int(&bpf_maxbufsize));
case NET_BPF_MAXBUFSIZE:
return sysctl_int_bounded(oldp, oldlenp, newp, newlen,
&bpf_maxbufsize, BPF_MINBUFSIZE, INT_MAX);
default:
return (EOPNOTSUPP);
}
-}
-
-int
-bpf_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
- size_t newlen)
-{
- int flags = RW_INTR;
- int error;
- if (namelen != 1)
- return (ENOTDIR);
-
- flags |= (newp == NULL) ? RW_READ : RW_WRITE;
-
- error = rw_enter(&bpf_sysctl_lk, flags);
- if (error != 0)
- return (error);
-
- error = bpf_sysctl_locked(name, namelen, oldp, oldlenp, newp, newlen);
-
- rw_exit(&bpf_sysctl_lk);
-
- return (error);
+ /* NOTREACHED */
}
struct bpf_d *