summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMartin Natano <natano@cvs.openbsd.org>2016-04-14 08:27:25 +0000
committerMartin Natano <natano@cvs.openbsd.org>2016-04-14 08:27:25 +0000
commit4e812c23f1adbf6ec614ba000334efa7978d50bd (patch)
tree3ed7155aa40cf9b2f95e9f86007facede56d2e84 /sys
parenta57625b601b491a37f0ea42e7f7e63032a268d23 (diff)
Enable device cloning for bpf. This allows to have just one bpf device
node in /dev, that services all bpf consumers (up to 1024). Also, disallow the usage of all but the first minor device, so accidental use of another minor device will attract attention. Cloning bpf offers some advantages: - Users with high bpf usage won't have to clutter their /dev with device nodes. - A lot of programs in base use a pattern like this to acces bpf: int fd, n = 0; do { (void)snprintf(device, sizeof device, "/dev/bpf%d", n++); fd = open(device, mode); } while (fd < 0 && errno == EBUSY); Those can now be replaced by a simple open(), without loop. ok mikeb "right time in the cycle to try" deraadt
Diffstat (limited to 'sys')
-rw-r--r--sys/net/bpf.c10
-rw-r--r--sys/sys/conf.h4
2 files changed, 9 insertions, 5 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 6842dfe4ca7..db871b31756 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.138 2016/04/02 08:49:49 dlg Exp $ */
+/* $OpenBSD: bpf.c,v 1.139 2016/04/14 08:27:24 natano Exp $ */
/* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */
/*
@@ -56,6 +56,7 @@
#include <sys/rwlock.h>
#include <sys/atomic.h>
#include <sys/srp.h>
+#include <sys/specdev.h>
#include <net/if.h>
#include <net/bpf.h>
@@ -333,6 +334,9 @@ bpfopen(dev_t dev, int flag, int mode, struct proc *p)
{
struct bpf_d *d;
+ if (minor(dev) & ((1 << CLONE_SHIFT) - 1))
+ return (ENXIO);
+
/* create on demand */
if ((d = bpfilter_create(minor(dev))) == NULL)
return (EBUSY);
@@ -1644,8 +1648,8 @@ bpfilter_create(int unit)
{
struct bpf_d *bd;
- if ((bd = bpfilter_lookup(unit)) != NULL)
- return (NULL);
+ KASSERT(bpfilter_lookup(unit) == NULL);
+
if ((bd = malloc(sizeof(*bd), M_DEVBUF, M_NOWAIT|M_ZERO)) != NULL) {
bd->bd_unit = unit;
LIST_INSERT_HEAD(&bpf_d_list, bd, bd_list);
diff --git a/sys/sys/conf.h b/sys/sys/conf.h
index 4880f83eaab..569946dd619 100644
--- a/sys/sys/conf.h
+++ b/sys/sys/conf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: conf.h,v 1.139 2016/02/25 16:48:50 uebayasi Exp $ */
+/* $OpenBSD: conf.h,v 1.140 2016/04/14 08:27:24 natano Exp $ */
/* $NetBSD: conf.h,v 1.33 1996/05/03 20:03:32 christos Exp $ */
/*-
@@ -296,7 +296,7 @@ extern struct cdevsw cdevsw[];
dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
- 0, 0, dev_init(c,n,kqfilter) }
+ 0, D_CLONE, dev_init(c,n,kqfilter) }
/* open, close, ioctl */
#define cdev_ch_init(c,n) { \