This avoids the error messages trying to open already used utuns.

Signed-off-by: Arne Schwabe <a...@rfc2549.org>
---
 src/openvpn/tun.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index cc7b65cf..30454454 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -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) */
-- 
2.26.2



_______________________________________________
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to