diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2016-09-30 12:32:32 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2016-09-30 12:32:32 +0000 |
commit | dbc699e593c2b7d995bb41866153ccfd4afb58f9 (patch) | |
tree | 98002c0715b39f9ce464852406b497730a9c7937 /usr.sbin | |
parent | 6d831659b08e7251f7631a8ec59a3c5caeb7cae1 (diff) |
Open next available tap(4) device instead of just tap0
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/switchd/switchd.c | 18 | ||||
-rw-r--r-- | usr.sbin/switchd/types.h | 5 |
2 files changed, 15 insertions, 8 deletions
diff --git a/usr.sbin/switchd/switchd.c b/usr.sbin/switchd/switchd.c index 8d228f73a59..72e62fb35da 100644 --- a/usr.sbin/switchd/switchd.c +++ b/usr.sbin/switchd/switchd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: switchd.c,v 1.12 2016/09/30 11:57:57 reyk Exp $ */ +/* $OpenBSD: switchd.c,v 1.13 2016/09/30 12:32:31 reyk Exp $ */ /* * Copyright (c) 2013-2016 Reyk Floeter <reyk@openbsd.org> @@ -289,12 +289,18 @@ switchd_listen(struct sockaddr *sock) int switchd_tap(void) { - int fd; - if ((fd = open("/dev/tap0", O_WRONLY)) == -1) - return (-1); - return (fd); -} + char path[PATH_MAX]; + int i, fd; + + for (i = 0; i < SWITCHD_MAX_TAP; i++) { + snprintf(path, PATH_MAX, "/dev/tap%d", i); + fd = open(path, O_RDWR | O_NONBLOCK); + if (fd != -1) + return (fd); + } + return (-1); +} struct switch_connection * switchd_connbyid(struct switchd *sc, unsigned int id, unsigned int instance) diff --git a/usr.sbin/switchd/types.h b/usr.sbin/switchd/types.h index 6bb1598dd2e..aab9f13588d 100644 --- a/usr.sbin/switchd/types.h +++ b/usr.sbin/switchd/types.h @@ -1,4 +1,4 @@ -/* $OpenBSD: types.h,v 1.4 2016/09/30 11:57:57 reyk Exp $ */ +/* $OpenBSD: types.h,v 1.5 2016/09/30 12:32:31 reyk Exp $ */ /* * Copyright (c) 2013-2016 Reyk Floeter <reyk@openbsd.org> @@ -30,11 +30,12 @@ #endif #define SWITCHD_SOCKET "/var/run/" SWITCHD_NAME "d.sock" -#define SWITCHD_MAX_SESSIONS 0xffff #define SWITCHD_FD_RESERVE 5 #define SWITCHD_CYCLE_BUFFERS 8 /* # of static buffers for mapping */ #define SWITCHD_READ_BUFFER 0xffff #define SWITCHD_MSGBUF_MAX 0xffff +#define SWITCHD_MAX_TAP 256 +#define SWITCHD_MAX_SESSIONS 0xffff #define SWITCHD_CTLR_PORT 6633 /* Previously used by OpenFlow */ #define SWITCHD_CTLR_IANA_PORT 6653 /* Assigned by IANA for OpenFlow */ |