Skip to contentSkip to conversation

tun.c: do not add/remove routes on tun open/close

PATCH In review Lev Stipakov 3 participants 3 messages Dec 19, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tun.c: do not add/remove routes on tun open/close

From: Lev Stipakov <[email protected]...>

Commit 1c4a47f added route manipulation to open/close tun functions, which is not really needed:

- routes are added in check_add_routes(), triggered by timer

- routes are removed in delete_routes(), called by do_close_tun()

---
 src/openvpn/route.c |  2 +-
 src/openvpn/route.h |  3 ---
 src/openvpn/tun.c   | 17 -----------------
 3 files changed, 1 insertion(+), 21 deletions(-)
src/openvpn/route.c +1 -1
index cc6d5519..97e90e56 100644
@@ -3019,7 +3019,7 @@ out:
     return ret;
 }
 
-bool
+static bool
 do_route_ipv4_service(const bool add, const struct route_ipv4 *r, const struct tuntap *tt)
 {
     DWORD if_index = windows_route_find_if_index(r, tt);
src/openvpn/route.h +0 -3
index 27b652cd..7dd96091 100644
@@ -321,9 +321,6 @@ void setenv_routes(struct env_set *es, const struct route_list *rl);
 
 void setenv_routes_ipv6(struct env_set *es, const struct route_ipv6_list *rl6);
 
-bool do_route_ipv4_service(const bool add, const struct route_ipv4 *r,
-                           const struct tuntap *tt);
-
 bool is_special_addr(const char *addr_str);
 
 void get_default_gateway(struct route_gateway_info *rgi,
src/openvpn/tun.c +0 -17
index 8d87ac41..ad497a71 100644
@@ -860,21 +860,6 @@ delete_route_connected_v6_net(struct tuntap *tt,
 }
 #endif /* if defined(_WIN32) || defined(TARGET_DARWIN) || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD) */
 
-#if defined(_WIN32)
-void
-do_route_ipv4_service_tun(bool add, const struct tuntap *tt)
-{
-    struct route_ipv4 r4;
-    CLEAR(r4);
-    r4.network = tt->local & tt->remote_netmask;
-    r4.netmask = tt->remote_netmask;
-    r4.gateway = tt->local;
-    r4.metric = 0;                     /* connected route */
-    r4.flags = RT_DEFINED | RT_METRIC_DEFINED;
-    do_route_ipv4_service(add, &r4, tt);
-}
-#endif
-
 #if defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)  \
     || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD)
 /* we can't use true subnet mode on tun on all platforms, as that
@@ -1406,7 +1391,6 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
         if (tt->options.msg_channel && tt->wintun)
         {
             do_address_service(true, AF_INET, tt);
-            do_route_ipv4_service_tun(true, tt);
             do_dns_service(true, AF_INET, tt);
         }
         else
@@ -6489,7 +6473,6 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
     {
         if (tt->options.msg_channel)
         {
-            do_route_ipv4_service_tun(false, tt);
             do_address_service(false, AF_INET, tt);
             do_dns_service(false, AF_INET, tt);
         }
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw

Makes sense. I am pretty sure the interface network route is not required to be added explicitly.

Best regards,
Simon

Quoted 104 lines

-----Original Message-----
From: Lev Stipakov <[email protected]...>
Sent: Thursday, December 19, 2019 12:18 PM
To: [email protected]
Cc: Lev Stipakov <[email protected]...>
Subject: [Openvpn-devel] [PATCH] tun.c: do not add/remove routes on tun open/close

From: Lev Stipakov <[email protected]...>

Commit 1c4a47f added route manipulation to open/close tun functions, which is not really needed:

- routes are added in check_add_routes(), triggered by timer

- routes are removed in delete_routes(), called by do_close_tun()

---
 src/openvpn/route.c |  2 +-
 src/openvpn/route.h |  3 ---
 src/openvpn/tun.c   | 17 -----------------
 3 files changed, 1 insertion(+), 21 deletions(-)
src/openvpn/route.c index renamed from src/openvpn/route.c +0 -0

cc6d5519..97e90e56 100644

src/openvpn/route.c +1 -1
@@ -3019,7 +3019,7 @@ out:
     return ret;
 }
 
-bool
+static bool
 do_route_ipv4_service(const bool add, const struct route_ipv4 *r, const
 struct tuntap *tt)  {
     DWORD if_index = windows_route_find_if_index(r, tt); diff --git

a/src/openvpn/route.h b/src/openvpn/route.h index 27b652cd..7dd96091 100644

src/openvpn/route.h +0 -3
@@ -321,9 +321,6 @@ void setenv_routes(struct env_set *es, const struct
 route_list *rl);
 
 void setenv_routes_ipv6(struct env_set *es, const struct
 route_ipv6_list *rl6);
 
-bool do_route_ipv4_service(const bool add, const struct route_ipv4 *r,
-                           const struct tuntap *tt);
-
 bool is_special_addr(const char *addr_str);

void get_default_gateway(struct route_gateway_info *rgi, diff --git
a/src/openvpn/tun.c b/src/openvpn/tun.c index 8d87ac41..ad497a71 100644

src/openvpn/tun.c +0 -0
@@ -860,21 +860,6 @@ delete_route_connected_v6_net(struct tuntap *tt,  }
 #endif /* if defined(_WIN32) || defined(TARGET_DARWIN) ||

defined(TARGET_NETBSD) || defined(TARGET_OPENBSD) */

src/openvpn/tun.c +0 -14
-#if defined(_WIN32)
-void
-do_route_ipv4_service_tun(bool add, const struct tuntap *tt) -{
-    struct route_ipv4 r4;
-    CLEAR(r4);
-    r4.network = tt->local & tt->remote_netmask;
-    r4.netmask = tt->remote_netmask;
-    r4.gateway = tt->local;
-    r4.metric = 0;                     /* connected route */
-    r4.flags = RT_DEFINED | RT_METRIC_DEFINED;
-    do_route_ipv4_service(add, &r4, tt);
-}
-#endif
-
 #if defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)  \
     || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD)
 /* we can't use true subnet mode on tun on all platforms, as that @@ -

1406,7 +1391,6 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,

         if (tt->options.msg_channel && tt->wintun)
         {
             do_address_service(true, AF_INET, tt);
src/openvpn/tun.c +0 -2
-            do_route_ipv4_service_tun(true, tt);
             do_dns_service(true, AF_INET, tt);
         }
         else
@@ -6489,7 +6473,6 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t
 *ctx)
     {
         if (tt->options.msg_channel)
         {
-            do_route_ipv4_service_tun(false, tt);
             do_address_service(false, AF_INET, tt);
             do_dns_service(false, AF_INET, tt);
         }

--
2.17.1

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#2 lore raw
In reply to Lev Stipakov

Your patch has been applied to the master branch.

As discussed on the IRC meeting, I've amended the commit message to make it more clear what happened. See below.

(Test built on ubuntu 1604, and also stared-at-code and asked confused questions :-) )

commit 4f2289893d9d1d448e9654b00d18e13f8fb0936c

Author: Lev Stipakov
Date:   Thu Dec 19 13:18:21 2019 +0200
     tun.c: do not add/remove on-link IPv4 route on tun open/close
    
     Commit 1c4a47f added route manipulation to open/close tun functions
     (for the IPv4 on-link network), but it turns out to be not needed
     at all.

     Signed-off-by: Lev Stipakov <[email protected]...>
     Acked-by: Simon Rozman <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19256.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering