]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Skip existing interfaces on opening the first available utun on macOS
authorArne Schwabe <arne@rfc2549.org>
Mon, 10 Aug 2020 14:37:04 +0000 (16:37 +0200)
committerGert Doering <gert@greenie.muc.de>
Mon, 10 Aug 2020 18:48:55 +0000 (20:48 +0200)
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>
src/openvpn/tun.c

index cc7b65cf495ddb84553e0299d043c6a59a0b781a..30454454780c3d78ebfe9b73e3c6e8de4bef918b 100644 (file)
@@ -3021,8 +3021,15 @@ open_darwin_utun(const char *dev, const char *dev_type, const char *dev_node, st
     /* try to open first available utun device if no specific utun is requested */
     if (utunnum == -1)
     {
-        for (utunnum = 0; utunnum<255; utunnum++)
+        for (utunnum = 0; utunnum < 255; utunnum++)
         {
+            char ifname[20];
+            /* if the interface exists silently skip it */
+            ASSERT(snprintf(ifname, sizeof(ifname), "utun%d", utunnum) > 0);
+            if (if_nametoindex(ifname))
+            {
+                continue;
+            }
             fd = utun_open_helper(ctlInfo, utunnum);
             /* Break if the fd is valid,
              * or if early initialization failed (-2) */