Skip to contentSkip to conversation

Use adapter index for add/delete_route_ipv6

PATCH Superseded Lev Stipakov 2 participants 4 messages Dec 11, 2015 – Dec 13, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use adapter index for add/delete_route_ipv6

Trac #637

---
 src/openvpn/route.c | 16 ++++++++++++----
 src/openvpn/tun.c   |  2 ++
 2 files changed, 14 insertions(+), 4 deletions(-)
src/openvpn/route.c +12 -4
index 4a60345..2012b5c 100644
@@ -1770,13 +1770,17 @@ add_route_ipv6 (struct route_ipv6 *r6, const struct tuntap *tt, unsigned int fla
 
 #elif defined (WIN32)
 
+  struct buffer out = alloc_buf_gc (64, &gc);
   if ( r6->adapter_index )		/* vpn server special route */
     {
-      struct buffer out = alloc_buf_gc (64, &gc);
       buf_printf (&out, "interface=%d", r6->adapter_index );
-      device = buf_bptr(&out);
       gateway_needed = true;
     }
+  else
+    {
+      buf_printf (&out, "interface=%d", tt->adapter_index );
+    }
+  device = buf_bptr(&out);
 
   /* netsh interface ipv6 add route 2001:db8::/32 MyTunDevice */
   argv_printf (&argv, "%s%sc interface ipv6 add route %s/%d %s",
@@ -2168,13 +2172,17 @@ delete_route_ipv6 (const struct route_ipv6 *r6, const struct tuntap *tt, unsigne
 
 #elif defined (WIN32)
 
+  struct buffer out = alloc_buf_gc (64, &gc);
   if ( r6->adapter_index )		/* vpn server special route */
     {
-      struct buffer out = alloc_buf_gc (64, &gc);
       buf_printf (&out, "interface=%d", r6->adapter_index );
-      device = buf_bptr(&out);
       gateway_needed = true;
     }
+  else
+    {
+      buf_printf (&out, "interface=%d", tt->adapter_index );
+    }
+  device = buf_bptr(&out);
 
   /* netsh interface ipv6 delete route 2001:db8::/32 MyTunDevice */
   argv_printf (&argv, "%s%sc interface ipv6 delete route %s/%d %s",
src/openvpn/tun.c +2 -0
index 014d988..aed5e75 100644
@@ -1328,6 +1328,8 @@ do_ifconfig (struct tuntap *tt,
 	 */
 	saved_actual = tt->actual_name;
 	tt->actual_name = (char*) actual;
+	/* we use adapter_index in add_route_ipv6 */
+	tt->adapter_index = idx;
 	add_route_connected_v6_net(tt, es);
 	tt->actual_name = saved_actual;
       }
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/1 Use adapter index for add/delete_route_ipv6

Trac #637

---
 src/openvpn/route.c | 16 ++++++++++++----
 src/openvpn/tun.c   |  6 +++++-
 2 files changed, 17 insertions(+), 5 deletions(-)
src/openvpn/route.c +12 -4
index 4a60345..2012b5c 100644
@@ -1770,13 +1770,17 @@ add_route_ipv6 (struct route_ipv6 *r6, const struct tuntap *tt, unsigned int fla
 
 #elif defined (WIN32)
 
+  struct buffer out = alloc_buf_gc (64, &gc);
   if ( r6->adapter_index )		/* vpn server special route */
     {
-      struct buffer out = alloc_buf_gc (64, &gc);
       buf_printf (&out, "interface=%d", r6->adapter_index );
-      device = buf_bptr(&out);
       gateway_needed = true;
     }
+  else
+    {
+      buf_printf (&out, "interface=%d", tt->adapter_index );
+    }
+  device = buf_bptr(&out);
 
   /* netsh interface ipv6 add route 2001:db8::/32 MyTunDevice */
   argv_printf (&argv, "%s%sc interface ipv6 add route %s/%d %s",
@@ -2168,13 +2172,17 @@ delete_route_ipv6 (const struct route_ipv6 *r6, const struct tuntap *tt, unsigne
 
 #elif defined (WIN32)
 
+  struct buffer out = alloc_buf_gc (64, &gc);
   if ( r6->adapter_index )		/* vpn server special route */
     {
-      struct buffer out = alloc_buf_gc (64, &gc);
       buf_printf (&out, "interface=%d", r6->adapter_index );
-      device = buf_bptr(&out);
       gateway_needed = true;
     }
+  else
+    {
+      buf_printf (&out, "interface=%d", tt->adapter_index );
+    }
+  device = buf_bptr(&out);
 
   /* netsh interface ipv6 delete route 2001:db8::/32 MyTunDevice */
   argv_printf (&argv, "%s%sc interface ipv6 delete route %s/%d %s",
src/openvpn/tun.c +5 -1
index 014d988..efcd225 100644
@@ -1306,11 +1306,13 @@ do_ifconfig (struct tuntap *tt,
       {
 	char * saved_actual;
 	char iface[64];
+	DWORD idx;
 
 	if (!strcmp (actual, "NULL"))
 	  msg (M_FATAL, "Error: When using --tun-ipv6, if you have more than one TAP-Windows adapter, you must also specify --dev-node");
 
-	openvpn_snprintf(iface, sizeof(iface), "interface=%lu", get_adapter_index_flexible(actual));
+	idx = get_adapter_index_flexible(actual);
+	openvpn_snprintf(iface, sizeof(iface), "interface=%lu", idx);
 
 	/* example: netsh interface ipv6 set address interface=42 2001:608:8003::d store=active */
 	argv_printf (&argv,
@@ -1328,6 +1330,8 @@ do_ifconfig (struct tuntap *tt,
 	 */
 	saved_actual = tt->actual_name;
 	tt->actual_name = (char*) actual;
+	/* we use adapter_index in add_route_ipv6 */
+	tt->adapter_index = idx;
 	add_route_connected_v6_net(tt, es);
 	tt->actual_name = saved_actual;
       }
Signature · 1 line
1.9.1
#2 lore raw

ACK, and thanks. Code looks good and I'm reasonably sure that it will do the right thing - waiting for buildbot now to produce a windows binary to actually test it :-) - then applying the 2.3 version to 2.3

Chances are good that this will break compilation with older MSVC versions, though (as the "struct buffer out = ..." part is now right in the middle of a block which wasn't allowed in earlier versions).

Your patch has been applied to the master branch.

commit 6417a6f8a01c702e7c8f19f01b696c3b0d2dc1f1 (master)

Author: Lev Stipakov
Date:   Sat Dec 12 00:37:52 2015 +0200
     Use adapter index for add/delete_route_ipv6

     Signed-off-by: Lev Stipakov <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/10759
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#3 lore raw

Hi,

Quoted 3 lines · Gert Doering

ACK, and thanks. Code looks good and I'm reasonably sure that it will do the right thing - waiting for buildbot now to produce a windows binary to actually test it :-) - then applying the 2.3 version to 2.3

Works! "ifconfig" and routes are both nicely added to "interface=16", which is "tap adapter v9" (and with overlapping routes, I see the /128 installed on "interface=10", so that is still working as well :) ).

Good :-)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...