[Openvpn-devel,v102,6/7] dco-win: ensure the DCO API is not used when running on Windows

Message ID 20220813213920.18959-1-a@unstable.cc
State Changes Requested
Headers show
Series None | expand

Commit Message

Antonio Quartulli Aug. 13, 2022, 11:39 a.m. UTC
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>
---
Changes from v101:
* add defined(TARGET_FREEBSD) to the #if guard

Changes from v100:
* removed ASSERTs (moved to previous patch)
* improve comment text in forward.c
---
 src/openvpn/forward.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

Comments

Lev Stipakov Aug. 13, 2022, 10:18 p.m. UTC | #1
Hi,

> 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.

This is true.

>
> + *
> + * Windows DCO needs control packets to be sent via the normal
> + * Socket API.

This is a bit confusing IMHO. What does "Socket API" mean here?
To read/write control packets we use what Windows calls "Overlapped I/O",
basically asynchronous IO with Write/ReadFile and events. We do not use
Winsock API, even though the OpenVPN function we use is called
"link_socket_write_win32()".

I would change the above mentioned comment to "normal Overlapped I/O".
Maybe this could be done at commit.

Also, as mentioned in chat, this should be merged before 3/7
("dco-win: implement ovpn-dco support in P2P Windows code path").

Acked-by: Lev Stipakov <lstipakov@gmail.com>

-Lev

Patch

diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index f6d416a3..8b95af64 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -1601,6 +1601,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
+ * Socket API.
+ *
+ * Hide that complexity (...especially if more platforms show up
+ * in future...) in a small inline function.
+ */
+static 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
  */
@@ -1674,7 +1694,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,