Skip to contentSkip to conversation

Cleanup: get rid of 'dynamic' argument of open_tun_generic()

PATCH In review Gert Doering 2 participants 3 messages Aug 7, 2022 – Aug 8, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Cleanup: get rid of 'dynamic' argument of open_tun_generic()

All callers of open_tun_generic() always set dynamic=true - so just get rid of it. While at it, move "int i" into the for() loop.

---
 src/openvpn/tun.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
src/openvpn/tun.c +11 -12
index 659bd245..6e7c0197 100644
@@ -1736,7 +1736,7 @@ tun_dco_enabled(struct tuntap *tt)
 #if !(defined(_WIN32) || defined(TARGET_LINUX))
 static void
 open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
-                 bool dynamic, struct tuntap *tt)
+                 struct tuntap *tt)
 {
     char tunname[256];
     char dynamic_name[256];
@@ -1767,7 +1767,7 @@ open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
              * opening /dev/tap and then querying the system about the
              * actual device name (tap0, tap1, ...) assigned
              */
-            if (dynamic && strcmp( dev, "tap" ) == 0)
+            if (strcmp( dev, "tap" ) == 0)
             {
                 struct ifreq ifr;
                 if ((tt->fd = open( "/dev/tap", O_RDWR)) < 0)
@@ -1786,10 +1786,9 @@ open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
             else
 #endif
 
-            if (dynamic && !tun_name_is_fixed(dev))
+            if (!tun_name_is_fixed(dev))
             {
-                int i;
-                for (i = 0; i < 256; ++i)
+                for (int i = 0; i < 256; ++i)
                 {
                     openvpn_snprintf(tunname, sizeof(tunname),
                                      "/dev/%s%d", dev, i);
@@ -2682,7 +2681,7 @@ void
 open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt,
          openvpn_net_ctx_t *ctx)
 {
-    open_tun_generic(dev, dev_type, dev_node, true, tt);
+    open_tun_generic(dev, dev_type, dev_node, tt);
 
     /* Enable multicast on the interface */
     if (tt->fd >= 0)
@@ -2777,7 +2776,7 @@ void
 open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt,
          openvpn_net_ctx_t *ctx)
 {
-    open_tun_generic(dev, dev_type, dev_node, true, tt);
+    open_tun_generic(dev, dev_type, dev_node, tt);
 
     if (tt->fd >= 0)
     {
@@ -2918,7 +2917,7 @@ void
 open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt,
          openvpn_net_ctx_t *ctx)
 {
-    open_tun_generic(dev, dev_type, dev_node, true, tt);
+    open_tun_generic(dev, dev_type, dev_node, tt);
 
     if (tt->fd >= 0 && tt->type == DEV_TYPE_TUN)
     {
@@ -3047,7 +3046,7 @@ void
 open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt,
          openvpn_net_ctx_t *ctx)
 {
-    open_tun_generic(dev, dev_type, dev_node, true, tt);
+    open_tun_generic(dev, dev_type, dev_node, tt);
 
     if (tt->fd >= 0)
     {
@@ -3300,7 +3299,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
             {
                 /* No explicit utun and utun failed, try the generic way) */
                 msg(M_INFO, "Failed to open utun device. Falling back to /dev/tun device");
-                open_tun_generic(dev, dev_type, NULL, true, tt);
+                open_tun_generic(dev, dev_type, NULL, tt);
             }
             else
             {
@@ -3323,7 +3322,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
             dev_node = NULL;
         }
 
-        open_tun_generic(dev, dev_type, dev_node, true, tt);
+        open_tun_generic(dev, dev_type, dev_node, tt);
     }
 }
 
@@ -7004,7 +7003,7 @@ void
 open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt,
          openvpn_net_ctx_t *ctx)
 {
-    open_tun_generic(dev, dev_type, dev_node, true, tt);
+    open_tun_generic(dev, dev_type, dev_node, tt);
 }
 
 void
Signature · 1 line
2.35.1
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 4 lines · Gert Doering

All callers of open_tun_generic() always set dynamic=true - so just get rid of it. While at it, move "int i" into the for() loop.

Patch does what it says and it is easy to verify that all invocations of open_tun_generic() were simply passing "true" as dynamic argument.

Quoted 18 lines
---
  src/openvpn/tun.c | 23 +++++++++++------------
  1 file changed, 11 insertions(+), 12 deletions(-)
src/openvpn/tun.c +1 -1
index 659bd245..6e7c0197 100644
@@ -1736,7 +1736,7 @@ tun_dco_enabled(struct tuntap *tt)
  #if !(defined(_WIN32) || defined(TARGET_LINUX))
  static void
  open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
-                 bool dynamic, struct tuntap *tt)
+                 struct tuntap *tt)
  {
      char tunname[256];
      char dynamic_name[256];

src/openvpn/tun.c open_tun_generic(const char *dev, const char *dev_type, const char *dev_node, · line 1770

Quoted 5 lines
src/openvpn/tun.c +1 -1
@@ -1767,7 +1767,7 @@ open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
               * opening /dev/tap and then querying the system about the
               * actual device name (tap0, tap1, ...) assigned
               */
-            if (dynamic && strcmp( dev, "tap" ) == 0)
+            if (strcmp( dev, "tap" ) == 0)

While at it you could have removed the spaces next to the parenthesis... :)

Quoted 71 lines
src/openvpn/tun.c +8 -9
              {
                  struct ifreq ifr;
                  if ((tt->fd = open( "/dev/tap", O_RDWR)) < 0)
@@ -1786,10 +1786,9 @@ open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
              else
  #endif
 
-            if (dynamic && !tun_name_is_fixed(dev))
+            if (!tun_name_is_fixed(dev))
              {
-                int i;
-                for (i = 0; i < 256; ++i)
+                for (int i = 0; i < 256; ++i)
                  {
                      openvpn_snprintf(tunname, sizeof(tunname),
                                       "/dev/%s%d", dev, i);
@@ -2682,7 +2681,7 @@ void
  open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt,
           openvpn_net_ctx_t *ctx)
  {
-    open_tun_generic(dev, dev_type, dev_node, true, tt);
+    open_tun_generic(dev, dev_type, dev_node, tt);
 
      /* Enable multicast on the interface */
      if (tt->fd >= 0)
@@ -2777,7 +2776,7 @@ void
  open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt,
           openvpn_net_ctx_t *ctx)
  {
-    open_tun_generic(dev, dev_type, dev_node, true, tt);
+    open_tun_generic(dev, dev_type, dev_node, tt);
 
      if (tt->fd >= 0)
      {
@@ -2918,7 +2917,7 @@ void
  open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt,
           openvpn_net_ctx_t *ctx)
  {
-    open_tun_generic(dev, dev_type, dev_node, true, tt);
+    open_tun_generic(dev, dev_type, dev_node, tt);
 
      if (tt->fd >= 0 && tt->type == DEV_TYPE_TUN)
      {
@@ -3047,7 +3046,7 @@ void
  open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt,
           openvpn_net_ctx_t *ctx)
  {
-    open_tun_generic(dev, dev_type, dev_node, true, tt);
+    open_tun_generic(dev, dev_type, dev_node, tt);
 
      if (tt->fd >= 0)
      {
@@ -3300,7 +3299,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
              {
                  /* No explicit utun and utun failed, try the generic way) */
                  msg(M_INFO, "Failed to open utun device. Falling back to /dev/tun device");
-                open_tun_generic(dev, dev_type, NULL, true, tt);
+                open_tun_generic(dev, dev_type, NULL, tt);
              }
              else
              {
@@ -3323,7 +3322,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
              dev_node = NULL;
          }
 
-        open_tun_generic(dev, dev_type, dev_node, true, tt);
+        open_tun_generic(dev, dev_type, dev_node, tt);
      }
  }
 

src/openvpn/tun.c void · line 7009

Quoted 8 lines
src/openvpn/tun.c +1 -1
@@ -7004,7 +7003,7 @@ void
  open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt,
           openvpn_net_ctx_t *ctx)
  {
-    open_tun_generic(dev, dev_type, dev_node, true, tt);
+    open_tun_generic(dev, dev_type, dev_node, tt);
  }
 
  void

other than my nitpick above,

Cheers,

Signature · 1 line
Antonio Quartulli
#2 lore raw
In reply to Gert Doering

Whitespace in "strcmp()" adjusted as instructed :-)

Tested by feeding to the buildbot army, which did not complain.

Patch has been applied to the master branch.

commit 4c31a3ca0660e2693e18430d836957edf6e128ea

Author: Gert Doering
Date:   Sun Aug 7 21:35:35 2022 +0200
     Cleanup: get rid of 'dynamic' argument of open_tun_generic()

     Signed-off-by: Gert Doering <[email protected]...>
     Acked-by: Antonio Quartulli <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg24838.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering