This avoids the error messages trying to open already used utuns.
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20200810143707.5834-15-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg20665.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
| ... | ... |
@@ -3021,8 +3021,15 @@ open_darwin_utun(const char *dev, const char *dev_type, const char *dev_node, st |
| 3021 | 3021 |
/* try to open first available utun device if no specific utun is requested */ |
| 3022 | 3022 |
if (utunnum == -1) |
| 3023 | 3023 |
{
|
| 3024 |
- for (utunnum = 0; utunnum<255; utunnum++) |
|
| 3024 |
+ for (utunnum = 0; utunnum < 255; utunnum++) |
|
| 3025 | 3025 |
{
|
| 3026 |
+ char ifname[20]; |
|
| 3027 |
+ /* if the interface exists silently skip it */ |
|
| 3028 |
+ ASSERT(snprintf(ifname, sizeof(ifname), "utun%d", utunnum) > 0); |
|
| 3029 |
+ if (if_nametoindex(ifname)) |
|
| 3030 |
+ {
|
|
| 3031 |
+ continue; |
|
| 3032 |
+ } |
|
| 3026 | 3033 |
fd = utun_open_helper(ctlInfo, utunnum); |
| 3027 | 3034 |
/* Break if the fd is valid, |
| 3028 | 3035 |
* or if early initialization failed (-2) */ |