[Openvpn-devel,S] Change in openvpn[master]: Refactor methods to use the actual state of tun rather the options st...

Message ID 6c122f07c357a8877ba5259f3f6f01df7199b788-HTML@gerrit.openvpn.net
State Changes Requested
Headers show
Series [Openvpn-devel,S] Change in openvpn[master]: Refactor methods to use the actual state of tun rather the options st... | expand

Commit Message

flichtenheld (Code Review) Sept. 18, 2024, 5:35 p.m. UTC
Attention is currently required from: flichtenheld.

Hello flichtenheld,

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

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

to review the following change.


Change subject: Refactor methods to use the actual state of tun rather the options struct
......................................................................

Refactor methods to use the actual state of tun rather the options struct

Change-Id: Ib8ba2b63ea9fd1944ff07f69c545a880e464680c
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
M src/openvpn/dco.c
M src/openvpn/forward.c
M src/openvpn/tun.c
M src/openvpn/tun.h
4 files changed, 13 insertions(+), 16 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/53/753/1

Patch

diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c
index 2f33973..384ffe6 100644
--- a/src/openvpn/dco.c
+++ b/src/openvpn/dco.c
@@ -476,7 +476,7 @@ 
 int
 dco_p2p_add_new_peer(struct context *c)
 {
-    if (!dco_enabled(&c->options))
+    if (!tun_dco_enabled(c->c1.tuntap))
     {
         return 0;
     }
@@ -511,7 +511,7 @@ 
 void
 dco_remove_peer(struct context *c)
 {
-    if (!dco_enabled(&c->options))
+    if (!tun_dco_enabled(c->c1.tuntap))
     {
         return;
     }
@@ -631,7 +631,7 @@ 
                    struct mroute_addr *addr)
 {
 #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
-    if (!dco_enabled(&m->top.options))
+    if (tun_dco_enabled(m->top.c1.tuntap))
     {
         return;
     }
@@ -668,7 +668,7 @@ 
 dco_delete_iroutes(struct multi_context *m, struct multi_instance *mi)
 {
 #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
-    if (!dco_enabled(&m->top.options))
+    if (!tun_dco_enabled(m->top.c1.tuntap))
     {
         return;
     }
diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index 9c78adf..4b620ea 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -145,7 +145,7 @@ 
 check_dco_key_status(struct context *c)
 {
     /* DCO context is not yet initialised or enabled */
-    if (!dco_enabled(&c->options))
+    if (!tun_dco_enabled(c->c1.tuntap))
     {
         return;
     }
@@ -483,7 +483,7 @@ 
 static void
 check_inactivity_timeout(struct context *c)
 {
-    if (dco_enabled(&c->options) && dco_get_peer_stats(c) == 0)
+    if (tun_dco_enabled(c->c1.tuntap) && dco_get_peer_stats(c) == 0)
     {
         int64_t tot_bytes = c->c2.tun_read_bytes + c->c2.tun_write_bytes;
         int64_t new_bytes = tot_bytes - c->c2.inactivity_bytes;
@@ -623,7 +623,7 @@ 
     const uint8_t *orig_buf = c->c2.buf.data;
     struct crypto_options *co = NULL;
 
-    if (dco_enabled(&c->options))
+    if (tun_dco_enabled(c->c1.tuntap))
     {
         msg(M_WARN, "Attempting to send data packet while data channel offload is in use. "
             "Dropping packet");
diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index ec63bff..e44f2f0 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -1872,15 +1872,6 @@ 
     return has_digit(dev);
 }
 
-#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
-static bool
-tun_dco_enabled(struct tuntap *tt)
-{
-    return tt->backend_driver == DRIVER_DCO;
-}
-#endif
-
-
 #if !(defined(_WIN32) || defined(TARGET_LINUX) || defined(TARGET_SOLARIS))
 static void
 open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h
index db0b5d7..7e4cb59 100644
--- a/src/openvpn/tun.h
+++ b/src/openvpn/tun.h
@@ -261,6 +261,12 @@ 
 #endif
 }
 
+inline static bool
+tun_dco_enabled(struct tuntap *tt)
+{
+    return tt && tt->backend_driver == DRIVER_DCO;
+}
+
 #ifdef _WIN32
 static inline bool
 tuntap_is_wintun(struct tuntap *tt)