Skip to contentSkip to conversation

Skip existing interfaces on opening the first available utun on macOS

PATCH In review Arne Schwabe 3 participants 4 messages Jul 31, 2020 – Aug 19, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Skip existing interfaces on opening the first available utun on macOS

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

---
 src/openvpn/tun.c | 7 +++++++
 1 file changed, 7 insertions(+)
src/openvpn/tun.c +7 -0
index cc7b65cf..b9e444b6 100644
@@ -3023,6 +3023,13 @@ open_darwin_utun(const char *dev, const char *dev_type, const char *dev_node, st
     {
         for (utunnum = 0; utunnum<255; utunnum++)
         {
+            char ifname[20];
+            /* if the interface exists silently skip it */
+            ASSERT(snprintf(ifname, sizeof(ifname), "utun%d", utunnum));
+            if (if_nametoindex(ifname))
+            {
+                continue;
+            }
             fd = utun_open_helper(ctlInfo, utunnum);
             /* Break if the fd is valid,
              * or if early initialization failed (-2) */
Signature · 1 line
2.26.2
#1 lore raw

Hi,

Quoted 3 lines · Arne Schwabe

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

I think the code looks good, but I have no time right now to test it (I can build MacOS binaries but have no test environment set up "just now").

Jonathan, do you have time?

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#3 lore raw

Am 05.08.20 um 11:02 schrieb Lev Stipakov:

Quoted 11 lines

Hi,

+ ASSERT(snprintf(ifname, sizeof(ifname), "utun%d", utunnum));

Not sure about ASSERT here, because according to
https://linux.die.net/man/3/snprintf

Quoted 1 line

If an output error is encountered, a negative value is returned.

which won't trigger assert.

Quoted 8 lines

Otherwise looks good.

Compiled and tested on macOS.

Maybe Gert could remove ASSERT wrapping before commiting.

You are too late, there is already a v2 that fixed that problem and is merged :)

Arne