[Openvpn-devel,v2,03/25] dco: use specific metric when installing routes

Message ID 20220628185623.1734-1-a@unstable.cc
State Accepted
Headers show
Series None | expand

Commit Message

Antonio Quartulli June 28, 2022, 6:56 p.m. UTC
When using DCO iroutes and routes all live in the same routing table,
However, the latter should always come after the former.

for this reason assign a default metric of 200 to routes. iroutes will
later get a metric of 100.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
---

Changes from v1:
* added comments before "(if (dco_enabled(c))" to explain why we need
  a different metric


 src/openvpn/dco.h  |  2 ++
 src/openvpn/init.c | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

Comments

Gert Doering June 28, 2022, 8:52 p.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

Arne has already ACKed the functionality (and I'm fine with that), and
I ACK the extra comments.  We could spend days on perfect wordsmithing
here, but I think they are good enough.

Please do not forget to include the metric thing in the "overall
documentation" patch that was mentioned :-)

Your patch has been applied to the master branch.

commit 90d9c38b116b8c816596d71a5cf6db7fd068d61a
Author: Antonio Quartulli
Date:   Tue Jun 28 20:56:23 2022 +0200

     dco: use specific metric when installing routes

     Signed-off-by: Antonio Quartulli <a@unstable.cc>
     Acked-by: Arne Schwabe <arne@rfc2549.org>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20220628185623.1734-1-a@unstable.cc>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24599.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/dco.h b/src/openvpn/dco.h
index dcadba78..063e5028 100644
--- a/src/openvpn/dco.h
+++ b/src/openvpn/dco.h
@@ -38,6 +38,8 @@  struct event_set;
 struct options;
 struct tuntap;
 
+#define DCO_DEFAULT_METRIC  200
+
 #if defined(ENABLE_DCO)
 
 /**
diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index 638fd10c..03221cbb 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -1385,6 +1385,15 @@  do_init_route_list(const struct options *options,
     int dev = dev_type_enum(options->dev, options->dev_type);
     int metric = 0;
 
+    /* if DCO is enabled we have both regular routes and iroutes in the system
+     * routing table, and normal routes must have a higher metric for that to
+     * work so that iroutes are always matched first
+     */
+    if (dco_enabled(options))
+    {
+        metric = DCO_DEFAULT_METRIC;
+    }
+
     if (dev == DEV_TYPE_TUN && (options->topology == TOP_NET30 || options->topology == TOP_P2P))
     {
         gw = options->ifconfig_remote_netmask;
@@ -1421,6 +1430,12 @@  do_init_route_ipv6_list(const struct options *options,
     const char *gw = NULL;
     int metric = -1;            /* no metric set */
 
+    /* see explanation in do_init_route_list() */
+    if (dco_enabled(options))
+    {
+        metric = DCO_DEFAULT_METRIC;
+    }
+
     gw = options->ifconfig_ipv6_remote;         /* default GW = remote end */
     if (options->route_ipv6_default_gateway)
     {