diff options
author | 2016-09-30 12:32:31 +0000 | |
---|---|---|
committer | 2016-09-30 12:32:31 +0000 | |
commit | aaa615556e5a379e7a68785d80cb63a285b30c56 (patch) | |
tree | 88f913651a75d4cefb9120fb838df0fd7c82075b /usr.sbin/switchd/switchd.c | |
parent | Use WSKBDIO_GETENCODINGS ioctl to generate a list of supported keyboard (diff) | |
download | wireguard-openbsd-aaa615556e5a379e7a68785d80cb63a285b30c56.tar.xz wireguard-openbsd-aaa615556e5a379e7a68785d80cb63a285b30c56.zip |
Open next available tap(4) device instead of just tap0
Diffstat (limited to 'usr.sbin/switchd/switchd.c')
-rw-r--r-- | usr.sbin/switchd/switchd.c | 18 |
1 files changed, 12 insertions, 6 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) |