[S] Change in openvpn[master]: init: create and destroy Linux DCO devices with --mktun/--rmtun

"ralf_lici \(Code Review\) via Openvpn-devel" <[email protected]>
Newsgroups gmane.network.openvpn.devel
Message-ID <[email protected]>
Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1735?usp=email

to review the following change.


Change subject: init: create and destroy Linux DCO devices with --mktun/--rmtun
......................................................................

init: create and destroy Linux DCO devices with --mktun/--rmtun

When DCO is enabled on Linux, make --mktun create an ovpn interface
instead of falling back to a TUN device. Set the ovpn interface mode
from --mode, using MP for server mode and P2P otherwise. Handle --rmtun
in the same branch by deleting the ovpn interface through the networking
backend.

Users can still request the old userspace TUN behavior with
--disable-dco.

Change-Id: Ic8c83132a4de64f27e6453ddb90ebcf137500db2
Signed-off-by: Ralf Lici <[email protected]>
---
M src/openvpn/init.c
1 file changed, 32 insertions(+), 8 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/35/1735/1

diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index caaa769..c71081f 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -1109,19 +1109,43 @@
     }
 
 #if defined(ENABLE_DCO)
-    if (dco_enabled(options))
+    if (dco_enabled(options) && dev_type_enum(options->dev, options->dev_type) == DEV_TYPE_TUN)
     {
-        /* creating a DCO interface via --mktun is not supported as it does not
-         * make much sense. Since DCO is enabled by default, people may run into
-         * this without knowing, therefore this case should be properly handled.
+#if defined(TARGET_LINUX)
+        if (options->persist_mode)
+        {
+            struct tuntap *tt;
+
+            ALLOC_OBJ_CLEAR(tt, struct tuntap);
+            tt->type = DEV_TYPE_TUN;
+            tt->backend_driver = DRIVER_DCO;
+            tt->dco.ifmode = options->mode == MODE_SERVER ? OVPN_MODE_MP : OVPN_MODE_P2P;
+
+            open_tun(options->dev, options->dev_type, options->dev_node, tt, ctx);
+            free(tt->actual_name);
+            free(tt);
+            msg(M_INFO, "Created DCO device %s in %s mode", options->dev, options->mode == MODE_SERVER ? "server" : "p2p");
+        }
+        else
+        {
+            int ret = net_iface_del(ctx, options->dev);
+            if (ret < 0)
+            {
+                msg(M_FATAL, "Cannot remove DCO device %s: %s (%d)", options->dev, strerror(-ret), ret);
+            }
+            msg(M_INFO, "Deleted DCO device %s", options->dev);
+        }
+        return true;
+#endif /* defined(TARGET_LINUX) */
+        /* creating a non-Linux DCO interface via --mktun is not supported as it
+         * does not make much sense. Since DCO is enabled by default, people may
+         * run into this without knowing, therefore this case should be properly
+         * handled.
          *
          * Disable DCO if --mktun was provided and print a message to let
          * user know.
          */
-        if (dev_type_enum(options->dev, options->dev_type) == DEV_TYPE_TUN)
-        {
-            msg(M_WARN, "Note: --mktun does not support DCO. Creating TUN interface.");
-        }
+        msg(M_WARN, "Note: --mktun does not support DCO. Creating TUN interface.");
 
         options->disable_dco = true;
     }

-- 
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1735?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic8c83132a4de64f27e6453ddb90ebcf137500db2
Gerrit-Change-Number: 1735
Gerrit-PatchSet: 1
Gerrit-Owner: ralf_lici <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.