[Openvpn-devel] Added environment variable for IPv6 route metric.

Message ID 20200930064845.28022-1-jan.seeger@thenybble.de
State Accepted
Headers show
Series [Openvpn-devel] Added environment variable for IPv6 route metric. | expand

Commit Message

Jan Seeger Sept. 29, 2020, 8:48 p.m. UTC
---
 doc/man-sections/script-options.rst | 8 ++++----
 src/openvpn/route.c                 | 7 +++++++
 2 files changed, 11 insertions(+), 4 deletions(-)

Comments

Gert Doering Oct. 4, 2020, 2:53 a.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

I have not actually tested this (I have no testbed with IPv6 route
metrics, and I do not feel like creating one).  So I have only test-
compiled this, and "stared at code", which looks good.

Your patch has been applied to the master and release/2.5 branch.

I have slightly reworded the commit message (as Antonio remarked) to
mention the actual *name* of the added environment variable.

commit bfb288454aa43f8c2d0131bc87b48a37e4ab01b4 (master)
commit 956c5af148d0f6d9b70d0498a499f6b70c8e8035 (HEAD -> release/2.5)
Author: Jan Seeger
Date:   Wed Sep 30 08:48:45 2020 +0200

     Added 'route_ipv6_metric_NN' environment variable for IPv6 route metric.

     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20200930064845.28022-1-jan.seeger@thenybble.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21110.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/doc/man-sections/script-options.rst b/doc/man-sections/script-options.rst
index a4df6732..03b3dd77 100644
--- a/doc/man-sections/script-options.rst
+++ b/doc/man-sections/script-options.rst
@@ -709,10 +709,10 @@  instances.
     A set of variables which define each IPv6 route to be added, and are
     set prior to **--up** script execution.
 
-    ``parm`` will be one of :code:`network` or :code:`gateway`
-    (:code:`netmask` is contained as :code:`/nnn` in the
-    ``route_ipv6_network_{n}``, unlike IPv4 where it is passed in a
-    separate environment variable).
+    ``parm`` will be one of :code:`network`, :code:`gateway` or
+    :code:`metric`. ``route_ipv6_network_{n}`` contains :code:`netmask`
+    as :code:`/nnn`, unlike IPv4 where it is passed in a separate environment
+    variable.
 
     ``n`` is the OpenVPN route number, starting from 1.
 
diff --git a/src/openvpn/route.c b/src/openvpn/route.c
index d75aa5f4..30cdabba 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -1479,6 +1479,13 @@  setenv_route_ipv6(struct env_set *es, const struct route_ipv6 *r6, int i)
 
         buf_printf( &name2, "route_ipv6_gateway_%d", i );
         setenv_str( es, BSTR(&name2), print_in6_addr( r6->gateway, 0, &gc ));
+
+        if (r6->flags & RT_METRIC_DEFINED)
+        {
+            struct buffer name3 = alloc_buf_gc( 256, &gc );
+            buf_printf( &name3, "route_ipv6_metric_%d", i) ;
+            setenv_int( es, BSTR(&name3), r6->metric);
+        }
     }
     gc_free(&gc);
 }