]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
dco-win: ensure the DCO API is not used when running on Windows
authorAntonio Quartulli <a@unstable.cc>
Sun, 14 Aug 2022 08:51:17 +0000 (10:51 +0200)
committerGert Doering <gert@greenie.muc.de>
Thu, 18 Aug 2022 06:31:44 +0000 (08:31 +0200)
On Windows the high level API should still use the link_socket object to
read and write packets. For this reason, even if dco_installed is true,
we still need to rely on the classic link_socket object.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20220814085117.7128-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24929.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/forward.c

index 14ad24fad61d06c538b9ab07168d9fdb58bbc424..d70b4f52e81d7a6ead7baed4c797629dfab1a1b2 100644 (file)
@@ -1593,6 +1593,26 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf)
     }
 }
 
+/* Linux-like DCO implementations pass the socket to the kernel and
+ * disallow usage of it from userland, so (control) packets sent and
+ * received by OpenVPN need to go through the DCO interface.
+ *
+ * Windows DCO needs control packets to be sent via the normal
+ * standard Overlapped I/O.
+ *
+ * Hide that complexity (...especially if more platforms show up
+ * in future...) in a small inline function.
+ */
+static inline bool
+should_use_dco_socket(struct link_socket *sock)
+{
+#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
+    return sock->info.dco_installed;
+#else
+    return false;
+#endif
+}
+
 /*
  * Input: c->c2.to_link
  */
@@ -1666,7 +1686,7 @@ process_outgoing_link(struct context *c)
                 socks_preprocess_outgoing_link(c, &to_addr, &size_delta);
 
                 /* Send packet */
-                if (c->c2.link_socket->info.dco_installed)
+                if (should_use_dco_socket(c->c2.link_socket))
                 {
                     size = dco_do_write(&c->c1.tuntap->dco,
                                         c->c2.tls_multi->peer_id,