summaryrefslogtreecommitdiff
path: root/sys/net
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/net
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/net')
-rw-r--r--sys/net/bpf.c10
1 files changed, 7 insertions, 3 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);