Use IPAPI for setting ipv6 routes when iservice not available
PATCH 1/3 Use IPAPI for setting ipv6 routes when iservice not available
From: Selva Nair <[email protected]...>
Currently we use netsh for this. The new code closely follows what interactive service does.
--- src/openvpn/route.c | 175 ++++++++++++++++++-------------------------- 1 file changed, 71 insertions(+), 104 deletions(-)
src/openvpn/route.c +71 -104
@@ -65,6 +65,8 @@ static bool add_route_ipv6_service(const struct route_ipv6 *, const struct tuntastatic bool del_route_ipv6_service (const struct route_ipv6 *,const struct tuntap *); +static bool route_ipv6_ipapi (bool add,const struct route_ipv6 *,const struct tuntap *); +#endif static void delete_route (struct route_ipv4 *r,const struct tuntap *tt,unsigned int flags,const struct route_gateway_info *rgi,const struct env_set *es,openvpn_net_ctx_t *ctx);
@@ -1975,58 +1977,8 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, }else { -DWORD adapter_index; -if (r6->adapter_index)/* vpn server special route */ - { - adapter_index = r6->adapter_index; - gateway_needed = true; - } -else - { - adapter_index = tt->adapter_index; - } - -/* netsh interface ipv6 add route 2001:db8::/32 42 */ -argv_printf (&argv,"%s%s interface ipv6 add route %s/%d %lu" , -get_win_sys_path (), -NETSH_PATH_SUFFIX , - network, - r6->netbits, - adapter_index); - -/* next-hop depends on TUN or TAP mode: -* - in TAP mode, we use the "real" next-hop -* - in TUN mode we use a special-case link-local address that the tapdrvr -* knows about and will answer ND (neighbor discovery) packets for -*/ -if (tt->type ==DEV_TYPE_TUN && !gateway_needed) - { -argv_printf_cat ( &argv," %s" ,"fe80::8" ); - } -else if (!IN6_IS_ADDR_UNSPECIFIED (&r6->gateway) ) - { -argv_printf_cat ( &argv," %s" , gateway ); - } - -#if 0 -if (r6->flags &RT_METRIC_DEFINED ) - { -argv_printf_cat (&argv," METRIC %d" , r->metric); - } -#endif - -/* in some versions of Windows, routes are persistent across reboots by -* default, unless "store=active" is set (pointed out by Tony Lim, thanks) -*/ -argv_printf_cat ( &argv," store=active" ); - -argv_msg (D_ROUTE , &argv); - -netcmd_semaphore_lock (); - status =openvpn_execve_check (&argv, es,0 ,"ERROR: Windows route add ipv6 command failed" ); -netcmd_semaphore_release (); + status =route_ipv6_ipapi (true, r6, tt); } -#elif defined (TARGET_SOLARIS)/* example: route add -inet6 2001:db8::/32 somegateway 0 */
@@ -2416,60 +2368,8 @@ delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, }else { -DWORD adapter_index; -if (r6->adapter_index)/* vpn server special route */ - { - adapter_index = r6->adapter_index; - gateway_needed = true; - } -else - { - adapter_index = tt->adapter_index; - } - -/* netsh interface ipv6 delete route 2001:db8::/32 42 */ -argv_printf (&argv,"%s%s interface ipv6 delete route %s/%d %lu" , -get_win_sys_path (), -NETSH_PATH_SUFFIX , - network, - r6->netbits, - adapter_index); - -/* next-hop depends on TUN or TAP mode: -* - in TAP mode, we use the "real" next-hop -* - in TUN mode we use a special-case link-local address that the tapdrvr -* knows about and will answer ND (neighbor discovery) packets for -* (and "route deletion without specifying next-hop" does not work...) -*/ -if (tt->type ==DEV_TYPE_TUN && !gateway_needed) - { -argv_printf_cat ( &argv," %s" ,"fe80::8" ); - } -else if (!IN6_IS_ADDR_UNSPECIFIED (&r6->gateway) ) - { -argv_printf_cat ( &argv," %s" , gateway ); - } - -#if 0 -if (r6->flags &RT_METRIC_DEFINED ) - { -argv_printf_cat (&argv,"METRIC %d" , r->metric); - } -#endif - -/* Windows XP to 7 "just delete" routes, wherever they came from, but -* in Windows 8(.1?), if you create them with "store=active", this is -* how you should delete them as well (pointed out by Cedric Tabary) -*/ -argv_printf_cat ( &argv," store=active" ); - -argv_msg (D_ROUTE , &argv); - -netcmd_semaphore_lock (); -openvpn_execve_check (&argv, es,0 ,"ERROR: Windows route delete ipv6 command failed" ); -netcmd_semaphore_release (); +route_ipv6_ipapi (false, r6, tt); } -#elif defined (TARGET_SOLARIS)/* example: route delete -inet6 2001:db8::/32 somegateway */
@@ -3049,6 +2949,73 @@ do_route_ipv4_service(const bool add, const struct route_ipv4 *r, const struct treturn do_route_service (add, &msg,sizeof (msg), tt->options.msg_channel); } +/* Add or delete an ipv6 route */ +static bool +route_ipv6_ipapi (const bool add,const struct route_ipv6 *r,const struct tuntap *tt) +{ +DWORD err; +PMIB_IPFORWARD_ROW2 fwd_row; +struct gc_arena gc =gc_new (); + + fwd_row =gc_malloc (sizeof (*fwd_row), true, &gc); + + fwd_row->ValidLifetime =0xffffffff ; + fwd_row->PreferredLifetime =0xffffffff ; + fwd_row->Protocol =MIB_IPPROTO_NETMGMT ; + fwd_row->Metric = ((r->flags &RT_METRIC_DEFINED ) ? r->metric :-1 ); + fwd_row->DestinationPrefix.Prefix.si_family =AF_INET6 ; + fwd_row->DestinationPrefix.Prefix.Ipv6.sin6_addr = r->network; + fwd_row->DestinationPrefix.PrefixLength = (UINT8 ) r->netbits; + fwd_row->NextHop.si_family =AF_INET6 ; + fwd_row->NextHop.Ipv6.sin6_addr = r->gateway; + fwd_row->InterfaceIndex = r->adapter_index ? r->adapter_index : tt->adapter_index; + +/* In TUN mode we use a special link-local address as the next hop. +* The tapdrvr knows about it and will answer neighbor discovery packets. +* (only do this for routes actually using the tun/tap device) +*/ +if (tt->type ==DEV_TYPE_TUN && !r->adapter_index) + { +inet_pton (AF_INET6 ,"fe80::8" , &fwd_row->NextHop.Ipv6.sin6_addr); + } + +/* Use LUID if interface index not available */ +if (fwd_row->InterfaceIndex ==TUN_ADAPTER_INDEX_INVALID &&strlen (tt->actual_name)) + { +NET_LUID luid; + err =ConvertInterfaceAliasToLuid (wide_string (tt->actual_name, &gc), &luid); +if (err !=NO_ERROR ) + { + goto out; + } + fwd_row->InterfaceLuid = luid; + fwd_row->InterfaceIndex =0 ; + } + +if (add) + { + err =CreateIpForwardEntry2 (fwd_row); + } +else + { + err =DeleteIpForwardEntry2 (fwd_row); + } + +out: +if (err !=NO_ERROR ) + { +msg (M_WARN ,"ROUTE: route %s failed using ipapi: %s [status=%lu if_index=%lu]" , + (add ?"addition" :"deletion" ),strerror_win32 (err, &gc), err, fwd_row->InterfaceIndex); + } +else + { +msg (D_ROUTE ,"IPv6 route %s using ipapi" , add ?"added" :"deleted" ); + } +gc_free (&gc); + +return (err ==NO_ERROR ); +} +static bool do_route_ipv6_service (const bool add,const struct route_ipv6 *r,const struct tuntap *tt) {
Signature · 1 line
2.34.1
PATCH 2/3 Distinguish route addition errors from route already exists
From: Selva Nair <[email protected]...>
When possible, functions that add a route now return 1 on success, or 2 if route already exists or 0 on other errors instead of true/false.
Note:
net_route_v4/v6_add using netlink filters out EEXIST before returning this looks like a bug as add_route() and add_route_ipv6() should set RT_ADDED only if route was really added.
---
net_route_v4/v6_add when using iproute2 always returns 0 (meaning success) making it impossible to respect RT_ADDED flag or propagate errors. I think these should be fixed.
src/openvpn/route.c | 91 ++++++++++++++++++++++++++++----------------- src/openvpn/route.h | 4 -- 2 files changed, 57 insertions(+), 38 deletions(-)
src/openvpn/route.c +57 -34
@@ -57,15 +57,20 @@#include "openvpn-msg.h" #define METRIC_NOT_USED ((DWORD)-1) -static bool add_route_service (const struct route_ipv4 *,const struct tuntap *); +static int add_route_service (const struct route_ipv4 *,const struct tuntap *);static bool del_route_service (const struct route_ipv4 *,const struct tuntap *); -static bool add_route_ipv6_service (const struct route_ipv6 *,const struct tuntap *); +static int add_route_ipv6_service (const struct route_ipv6 *,const struct tuntap *);static bool del_route_ipv6_service (const struct route_ipv6 *,const struct tuntap *); -static bool route_ipv6_ipapi (bool add,const struct route_ipv6 *,const struct tuntap *); +static int route_ipv6_ipapi (bool add,const struct route_ipv6 *,const struct tuntap *); + +static int add_route_ipapi (const struct route_ipv4 *r,const struct tuntap *tt,DWORD adapter_index); + +static bool del_route_ipapi (const struct route_ipv4 *r,const struct tuntap *tt); +#endif
@@ -1572,7 +1577,7 @@ add_route(struct route_ipv4 *r,const struct env_set *es, openvpn_net_ctx_t *ctx) { - bool status = false; + int status = 0;int is_local_route;if (!(r->flags &RT_DEFINED ))
@@ -1611,12 +1616,12 @@ add_route(struct route_ipv4 *r, metric = r->metric; } - status = true; + status =1 ;if (net_route_v4_add (ctx, &r->network,netmask_to_netbits2 (r->netmask), &r->gateway, iface,0 , metric) <0 ) {msg (M_WARN ,"ERROR: Linux route add command failed" ); - status = false; + status =0 ; }#elif defined (TARGET_ANDROID)
@@ -1656,12 +1661,12 @@ add_route(struct route_ipv4 *r,if ((flags &ROUTE_METHOD_MASK ) ==ROUTE_METHOD_SERVICE ) { status =add_route_service (r, tt); -msg (D_ROUTE ,"Route addition via service %s" , status ?"succeeded" :"failed" ); +msg (D_ROUTE ,"Route addition via service %s" , (status ==1 ) ?"succeeded" :"failed" ); }else if ((flags &ROUTE_METHOD_MASK ) ==ROUTE_METHOD_IPAPI ) { status =add_route_ipapi (r, tt, ai); -msg (D_ROUTE ,"Route addition via IPAPI %s" , status ?"succeeded" :"failed" ); +msg (D_ROUTE ,"Route addition via IPAPI %s" , (status ==1 ) ?"succeeded/skipped" :"failed" ); }else if ((flags &ROUTE_METHOD_MASK ) ==ROUTE_METHOD_EXE ) {
@@ -1672,8 +1677,8 @@ add_route(struct route_ipv4 *r,else if ((flags &ROUTE_METHOD_MASK ) ==ROUTE_METHOD_ADAPTIVE ) { status =add_route_ipapi (r, tt, ai); -msg (D_ROUTE ,"Route addition via IPAPI %s [adaptive]" , status ?"succeeded" :"failed" ); -if (!status) +msg (D_ROUTE ,"Route addition via IPAPI %s [adaptive]" , (status ==1 ) ?"succeeded/skipped" :"failed" ); +if (status ==0 ) {msg (D_ROUTE ,"Route addition fallback to route.exe" );netcmd_semaphore_lock ();
@@ -1828,7 +1833,7 @@ add_route(struct route_ipv4 *r,#endif /* if defined(TARGET_LINUX) */ done: -if (status) +if (status ==1 ) { r->flags |=RT_ADDED ; }
@@ -1871,7 +1876,7 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx) { - bool status = false; + int status = 0;const char *device = tt->actual_name;bool gateway_needed = false;
@@ -1942,7 +1947,7 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt,"parameter for a --route-ipv6 option and no default was set via " "--ifconfig-ipv6 or --route-ipv6-gateway option. Not installing " "IPv6 route to %s/%d.", network, r6->netbits); - status = false; + status =0 ; goto done; }
@@ -1953,13 +1958,13 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, metric = r6->metric; } - status = true; + status =1 ;if (net_route_v6_add (ctx, &r6->network, r6->netbits, gateway_needed ? &r6->gateway :NULL , device,0 , metric) <0 ) {msg (M_WARN ,"ERROR: Linux IPv6 route can't be added" ); - status = false; + status =0 ; }#elif defined (TARGET_ANDROID)
@@ -2075,7 +2080,7 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt,#endif /* if defined(TARGET_LINUX) */ done: -if (status) +if (status ==1 ) { r6->flags |=RT_ADDED ; }
@@ -2773,11 +2778,11 @@ done:gc_free (&gc); } -bool +static int add_route_ipapi (const struct route_ipv4 *r,const struct tuntap *tt,DWORD adapter_index) {struct gc_arena gc =gc_new (); -bool ret = false; +int ret =0 ;DWORD status;const DWORD if_index = (adapter_index ==TUN_ADAPTER_INDEX_INVALID ) ?windows_route_find_if_index (r, tt) : adapter_index;
@@ -2811,7 +2816,11 @@ add_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt, DWORD adaptif (status ==NO_ERROR ) { - ret = true; + ret =1 ; + } +else if (status ==ERROR_OBJECT_ALREADY_EXISTS ) + { + ret =2 ; }else {
@@ -2830,7 +2839,7 @@ add_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt, DWORD adaptmsg (D_ROUTE ,"ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=%u and dwForwardType=%u" , (unsigned int )fr.dwForwardMetric1, (unsigned int )fr.dwForwardType); - ret = true; + ret =1 ; goto doublebreak; }else if (status !=ERROR_BAD_ARGUMENTS )
@@ -2847,6 +2856,10 @@ doublebreak:strerror_win32 (status, &gc), (unsigned int )status, (unsigned int)if_index); +if (status ==ERROR_OBJECT_ALREADY_EXISTS ) + { + ret =2 ; + } } } }
@@ -2855,7 +2868,7 @@ doublebreak:return ret; } -bool +static bool del_route_ipapi (const struct route_ipv4 *r,const struct tuntap *tt) {struct gc_arena gc =gc_new ();
@@ -2891,10 +2904,11 @@ del_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt)return ret; } -static bool +/* Returns 1 on success, 2 if route exists, 0 on error */ +static int do_route_service (const bool add,const route_message_t *rt,const size_t size,HANDLE pipe) { -bool ret = false; +int ret =0 ;ack_message_t ack;struct gc_arena gc =gc_new ();
@@ -2908,23 +2922,25 @@ do_route_service(const bool add, const route_message_t *rt, const size_t size, Hmsg (M_WARN ,"ROUTE: route %s failed using service: %s [status=%u if_index=%d]" , (add ?"addition" :"deletion" ),strerror_win32 (ack.error_number, &gc), ack.error_number, rt->iface.index); + ret = (ack.error_number ==ERROR_OBJECT_ALREADY_EXISTS ) ?2 :0 ; goto out; } - ret = true; + ret =1 ; out:gc_free (&gc);return ret; } -static bool +/* Returns 1 on success, 2 if route exists, 0 on error */ +static int 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);if (if_index == ~0 ) { -return false; +return 0 ; }route_message_t msg = {
@@ -2949,11 +2965,14 @@ do_route_ipv4_service(const bool add, const struct route_ipv4 *r, const struct treturn do_route_service (add, &msg,sizeof (msg), tt->options.msg_channel); } -/* Add or delete an ipv6 route */ -static bool +/* Add or delete an ipv6 route +* Returns 1 on success, 2 if route exists, 0 on error +*/ +static int route_ipv6_ipapi (const bool add,const struct route_ipv6 *r,const struct tuntap *tt) {DWORD err; +int ret =0 ;PMIB_IPFORWARD_ROW2 fwd_row;struct gc_arena gc =gc_new ();
@@ -3006,20 +3025,22 @@ out: {msg (M_WARN ,"ROUTE: route %s failed using ipapi: %s [status=%lu if_index=%lu]" , (add ?"addition" :"deletion" ),strerror_win32 (err, &gc), err, fwd_row->InterfaceIndex); + ret = (err ==ERROR_OBJECT_ALREADY_EXISTS ) ?2 :0 ; } else {msg (D_ROUTE ,"IPv6 route %s using ipapi" , add ?"added" :"deleted" ); + ret =1 ; }gc_free (&gc); - -return (err ==NO_ERROR ); +return ret; } -static bool +/* Returns 1 on success, 2 if route exists, 0 on error */ +static int do_route_ipv6_service (const bool add,const struct route_ipv6 *r,const struct tuntap *tt) { -bool status; +int status;route_message_t msg = { .header = { (add ? msg_add_route : msg_del_route),
@@ -3062,7 +3083,8 @@ do_route_ipv6_service(const bool add, const struct route_ipv6 *r, const struct treturn status; } -static bool +/* Returns 1 on success, 2 if route exists, 0 on error */ +static int add_route_service (const struct route_ipv4 *r,const struct tuntap *tt) {return do_route_ipv4_service (true, r, tt);
@@ -3074,7 +3096,8 @@ del_route_service(const struct route_ipv4 *r, const struct tuntap *tt)return do_route_ipv4_service (false, r, tt); } -static bool +/* Returns 1 on success, 2 if route exists, 0 on error */ +static int add_route_ipv6_service (const struct route_ipv6 *r,const struct tuntap *tt) {return do_route_ipv6_service (true, r, tt);
src/openvpn/route.h +0 -4
@@ -357,10 +357,6 @@ void show_routes(int msglev);bool test_routes (const struct route_list *rl,const struct tuntap *tt); -bool add_route_ipapi (const struct route_ipv4 *r,const struct tuntap *tt,DWORD adapter_index); - -bool del_route_ipapi (const struct route_ipv4 *r,const struct tuntap *tt); -#else /* ifdef _WIN32 */ static inline bool test_routes (const struct route_list *rl,const struct tuntap *tt)
Signature · 1 line
2.34.1
Re: [Openvpn-devel] [PATCH 2/3] Distinguish route addition errors from route already exists
Hi,
src/openvpn/route.c add_route(struct route_ipv4 *r, · line 1670
Quoted 6 lines
else if ((flags & ROUTE_METHOD_MASK) == ROUTE_METHOD_IPAPI) { status = add_route_ipapi(r, tt, ai);src/openvpn/route.c +1
-1-msg (D_ROUTE ,"Route addition via IPAPI %s" , status ?"succeeded" :"failed" ); +msg (D_ROUTE ,"Route addition via IPAPI %s" , (status ==1 ) ?"succeeded/skipped" :"failed" ); }
Under what conditions we might get "skipped"?
-Lev
Re: [Openvpn-devel] [PATCH 2/3] Distinguish route addition errors from route already exists
Quoted 6 lines · Lev Stipakov
Hi,
Quoted 4 lines
else if ((flags & ROUTE_METHOD_MASK) == ROUTE_METHOD_IPAPI) { status = add_route_ipapi(r, tt, ai);- msg(D_ROUTE, "Route addition via IPAPI %s", status ?
Quoted 7 lines
"succeeded" : "failed");
Quoted 1 line
+ msg(D_ROUTE, "Route addition via IPAPI %s", (status == 1) ?
"succeeded/skipped" : "failed");
Quoted 1 line
}Under what conditions we might get "skipped"?
My mistake -- I had initially left it at "status ?" which would now include already exists, but then the logs looked odd as it first prints "failed" with M_WARN in add_route_ipapi, and then "succeeded/skipped" here. On changing to "status==1", I missed to remove "skipped".
I'm assuming we want to continue printing a warning when route addition fails due to "already exists" though we wont pass that as an error to initialization_completed (next commit).
Time for v2.
Selva
PATCH v2 2/3 Distinguish route addition errors from route already exists
In reply to [email protected]...From: Selva Nair <[email protected]...>
When possible, functions that add a route now return 1 on success, or 2 if route already exists or 0 on other errors instead of true/false.
Note:
net_route_v4/v6_add using netlink filters out EEXIST before returning this looks like a bug as add_route() and add_route_ipv6() should set RT_ADDED only if route was really added.
v2: "succeeded/skipped" --> "succeeded" in log.
---
net_route_v4/v6_add when using iproute2 always returns 0 (meaning success) making it impossible to respect RT_ADDED flag or propagate errors. I think these should be fixed.
src/openvpn/route.c | 91 ++++++++++++++++++++++++++++----------------- src/openvpn/route.h | 4 -- 2 files changed, 57 insertions(+), 38 deletions(-)
src/openvpn/route.c +57 -34
@@ -57,15 +57,20 @@#include "openvpn-msg.h" #define METRIC_NOT_USED ((DWORD)-1) -static bool add_route_service (const struct route_ipv4 *,const struct tuntap *); +static int add_route_service (const struct route_ipv4 *,const struct tuntap *);static bool del_route_service (const struct route_ipv4 *,const struct tuntap *); -static bool add_route_ipv6_service (const struct route_ipv6 *,const struct tuntap *); +static int add_route_ipv6_service (const struct route_ipv6 *,const struct tuntap *);static bool del_route_ipv6_service (const struct route_ipv6 *,const struct tuntap *); -static bool route_ipv6_ipapi (bool add,const struct route_ipv6 *,const struct tuntap *); +static int route_ipv6_ipapi (bool add,const struct route_ipv6 *,const struct tuntap *); + +static int add_route_ipapi (const struct route_ipv4 *r,const struct tuntap *tt,DWORD adapter_index); + +static bool del_route_ipapi (const struct route_ipv4 *r,const struct tuntap *tt); +#endif
@@ -1572,7 +1577,7 @@ add_route(struct route_ipv4 *r,const struct env_set *es, openvpn_net_ctx_t *ctx) { - bool status = false; + int status = 0;int is_local_route;if (!(r->flags &RT_DEFINED ))
@@ -1611,12 +1616,12 @@ add_route(struct route_ipv4 *r, metric = r->metric; } - status = true; + status =1 ;if (net_route_v4_add (ctx, &r->network,netmask_to_netbits2 (r->netmask), &r->gateway, iface,0 , metric) <0 ) {msg (M_WARN ,"ERROR: Linux route add command failed" ); - status = false; + status =0 ; }#elif defined (TARGET_ANDROID)
@@ -1656,12 +1661,12 @@ add_route(struct route_ipv4 *r,if ((flags &ROUTE_METHOD_MASK ) ==ROUTE_METHOD_SERVICE ) { status =add_route_service (r, tt); -msg (D_ROUTE ,"Route addition via service %s" , status ?"succeeded" :"failed" ); +msg (D_ROUTE ,"Route addition via service %s" , (status ==1 ) ?"succeeded" :"failed" ); }else if ((flags &ROUTE_METHOD_MASK ) ==ROUTE_METHOD_IPAPI ) { status =add_route_ipapi (r, tt, ai); -msg (D_ROUTE ,"Route addition via IPAPI %s" , status ?"succeeded" :"failed" ); +msg (D_ROUTE ,"Route addition via IPAPI %s" , (status ==1 ) ?"succeeded" :"failed" ); }else if ((flags &ROUTE_METHOD_MASK ) ==ROUTE_METHOD_EXE ) {
@@ -1672,8 +1677,8 @@ add_route(struct route_ipv4 *r,else if ((flags &ROUTE_METHOD_MASK ) ==ROUTE_METHOD_ADAPTIVE ) { status =add_route_ipapi (r, tt, ai); -msg (D_ROUTE ,"Route addition via IPAPI %s [adaptive]" , status ?"succeeded" :"failed" ); -if (!status) +msg (D_ROUTE ,"Route addition via IPAPI %s [adaptive]" , (status ==1 ) ?"succeeded" :"failed" ); +if (status ==0 ) {msg (D_ROUTE ,"Route addition fallback to route.exe" );netcmd_semaphore_lock ();
@@ -1828,7 +1833,7 @@ add_route(struct route_ipv4 *r,#endif /* if defined(TARGET_LINUX) */ done: -if (status) +if (status ==1 ) { r->flags |=RT_ADDED ; }
@@ -1871,7 +1876,7 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx) { - bool status = false; + int status = 0;const char *device = tt->actual_name;bool gateway_needed = false;
@@ -1942,7 +1947,7 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt,"parameter for a --route-ipv6 option and no default was set via " "--ifconfig-ipv6 or --route-ipv6-gateway option. Not installing " "IPv6 route to %s/%d.", network, r6->netbits); - status = false; + status =0 ; goto done; }
@@ -1953,13 +1958,13 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, metric = r6->metric; } - status = true; + status =1 ;if (net_route_v6_add (ctx, &r6->network, r6->netbits, gateway_needed ? &r6->gateway :NULL , device,0 , metric) <0 ) {msg (M_WARN ,"ERROR: Linux IPv6 route can't be added" ); - status = false; + status =0 ; }#elif defined (TARGET_ANDROID)
@@ -2075,7 +2080,7 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt,#endif /* if defined(TARGET_LINUX) */ done: -if (status) +if (status ==1 ) { r6->flags |=RT_ADDED ; }
@@ -2773,11 +2778,11 @@ done:gc_free (&gc); } -bool +static int add_route_ipapi (const struct route_ipv4 *r,const struct tuntap *tt,DWORD adapter_index) {struct gc_arena gc =gc_new (); -bool ret = false; +int ret =0 ;DWORD status;const DWORD if_index = (adapter_index ==TUN_ADAPTER_INDEX_INVALID ) ?windows_route_find_if_index (r, tt) : adapter_index;
@@ -2811,7 +2816,11 @@ add_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt, DWORD adaptif (status ==NO_ERROR ) { - ret = true; + ret =1 ; + } +else if (status ==ERROR_OBJECT_ALREADY_EXISTS ) + { + ret =2 ; }else {
@@ -2830,7 +2839,7 @@ add_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt, DWORD adaptmsg (D_ROUTE ,"ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=%u and dwForwardType=%u" , (unsigned int )fr.dwForwardMetric1, (unsigned int )fr.dwForwardType); - ret = true; + ret =1 ; goto doublebreak; }else if (status !=ERROR_BAD_ARGUMENTS )
@@ -2847,6 +2856,10 @@ doublebreak:strerror_win32 (status, &gc), (unsigned int )status, (unsigned int)if_index); +if (status ==ERROR_OBJECT_ALREADY_EXISTS ) + { + ret =2 ; + } } } }
@@ -2855,7 +2868,7 @@ doublebreak:return ret; } -bool +static bool del_route_ipapi (const struct route_ipv4 *r,const struct tuntap *tt) {struct gc_arena gc =gc_new ();
@@ -2891,10 +2904,11 @@ del_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt)return ret; } -static bool +/* Returns 1 on success, 2 if route exists, 0 on error */ +static int do_route_service (const bool add,const route_message_t *rt,const size_t size,HANDLE pipe) { -bool ret = false; +int ret =0 ;ack_message_t ack;struct gc_arena gc =gc_new ();
@@ -2908,23 +2922,25 @@ do_route_service(const bool add, const route_message_t *rt, const size_t size, Hmsg (M_WARN ,"ROUTE: route %s failed using service: %s [status=%u if_index=%d]" , (add ?"addition" :"deletion" ),strerror_win32 (ack.error_number, &gc), ack.error_number, rt->iface.index); + ret = (ack.error_number ==ERROR_OBJECT_ALREADY_EXISTS ) ?2 :0 ; goto out; } - ret = true; + ret =1 ; out:gc_free (&gc);return ret; } -static bool +/* Returns 1 on success, 2 if route exists, 0 on error */ +static int 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);if (if_index == ~0 ) { -return false; +return 0 ; }route_message_t msg = {
@@ -2949,11 +2965,14 @@ do_route_ipv4_service(const bool add, const struct route_ipv4 *r, const struct treturn do_route_service (add, &msg,sizeof (msg), tt->options.msg_channel); } -/* Add or delete an ipv6 route */ -static bool +/* Add or delete an ipv6 route +* Returns 1 on success, 2 if route exists, 0 on error +*/ +static int route_ipv6_ipapi (const bool add,const struct route_ipv6 *r,const struct tuntap *tt) {DWORD err; +int ret =0 ;PMIB_IPFORWARD_ROW2 fwd_row;struct gc_arena gc =gc_new ();
@@ -3006,20 +3025,22 @@ out: {msg (M_WARN ,"ROUTE: route %s failed using ipapi: %s [status=%lu if_index=%lu]" , (add ?"addition" :"deletion" ),strerror_win32 (err, &gc), err, fwd_row->InterfaceIndex); + ret = (err ==ERROR_OBJECT_ALREADY_EXISTS ) ?2 :0 ; } else {msg (D_ROUTE ,"IPv6 route %s using ipapi" , add ?"added" :"deleted" ); + ret =1 ; }gc_free (&gc); - -return (err ==NO_ERROR ); +return ret; } -static bool +/* Returns 1 on success, 2 if route exists, 0 on error */ +static int do_route_ipv6_service (const bool add,const struct route_ipv6 *r,const struct tuntap *tt) { -bool status; +int status;route_message_t msg = { .header = { (add ? msg_add_route : msg_del_route),
@@ -3062,7 +3083,8 @@ do_route_ipv6_service(const bool add, const struct route_ipv6 *r, const struct treturn status; } -static bool +/* Returns 1 on success, 2 if route exists, 0 on error */ +static int add_route_service (const struct route_ipv4 *r,const struct tuntap *tt) {return do_route_ipv4_service (true, r, tt);
@@ -3074,7 +3096,8 @@ del_route_service(const struct route_ipv4 *r, const struct tuntap *tt)return do_route_ipv4_service (false, r, tt); } -static bool +/* Returns 1 on success, 2 if route exists, 0 on error */ +static int add_route_ipv6_service (const struct route_ipv6 *r,const struct tuntap *tt) {return do_route_ipv6_service (true, r, tt);
src/openvpn/route.h +0 -4
@@ -357,10 +357,6 @@ void show_routes(int msglev);bool test_routes (const struct route_list *rl,const struct tuntap *tt); -bool add_route_ipapi (const struct route_ipv4 *r,const struct tuntap *tt,DWORD adapter_index); - -bool del_route_ipapi (const struct route_ipv4 *r,const struct tuntap *tt); -#else /* ifdef _WIN32 */ static inline bool test_routes (const struct route_list *rl,const struct tuntap *tt)
Signature · 1 line
2.34.1
Re: [Openvpn-devel] [PATCH v2 2/3] Distinguish route addition errors from route already exists
I reviewed v1, checked that true/false has been replaced with 0/1/2. Checked that the only change in v2 is that "succeeded/skipped" is replaced with "succeeded".
Compiled and tested, looks good.
Re: [Openvpn-devel] [PATCH v2 2/3] Distinguish route addition errors from route already exists
In reply to [email protected]...Hi,
Quoted 4 lines · On Fri, Jan 06, 2023 at 10:04:12AM -0500, [email protected]... wrote:
Note:
net_route_v4/v6_add using netlink filters out EEXIST before returning this looks like a bug asadd_route()andadd_route_ipv6()should setRT_ADDEDonly if route was really added.
Actually we do have a Trac ticket that might be related to this somewhere, about multiple instances of OpenVPN messing each other's routing that way... maybe it's that very issue, maybe not. But worth having a very close look.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...[Openvpn-devel] [PATCH applied] Re: Distinguish route addition errors from route already exists
In reply to [email protected]...Lev has also ACKed, but since I did some previous digging into the code, I gave it an extra-hard stare and can confirm that it looks very reasonable.
That said, I have a dislike for magic "0", "1" and "2" constants appearing with no explanation - can we have a followup patch that documents the expected behaviour (maybe in route.h?) and also introduces some helpful constants? Like, we have ISC_ERROR, maybe RTA_ERROR, RTA_SUCCESS, RTA_EEXISTS or so? I do not care much about the actual naming, but I'm sure that I'll wonder in a year "why '2'? what is '2' here?".
I also notice that there is quite a bit of imbalance between IPv4 and IPv6 route addition on Windows - for IPv6, add_route_ipv6() will not print any messages (so, no diff here), while IPv4 has all that... maybe something to clean up in 2.7.
We *also* might want to get rid of that obscure
/* failed, try increasing the metric to work around Vista issue */
code bit, which looks extremely scary ("increasing metric with +1 in a tight loop until we reach 2048") and Vista is out of support anyway...
Last not least, a 'status ? "succeeded"...' msg() escaped your attention, in do_route_ipv6_service()...
I have compile-tested this for Windows, and client-side tested on Linux (netlink). Unsurprisingly nothing really interesting happened, as there is no real new code, my test rig has no "EEXIST" yet, and nothing uses the new status values yet.
Your patch has been applied to the master and release/2.6 branch.
commit 9c6d72c783f4212f965e1e855b4fdb0ea34b595b (master) commit 93da80eaa1548197b173537bb74bf6db7e10912e (release/2.6)
Author: Selva Nair Date: Fri Jan 6 10:04:12 2023 -0500
Distinguish route addition errors from route already exists
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg25903.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH applied] Re: Distinguish route addition errors from route already exists
Hi
Quoted 6 lines · Gert Doering
I also notice that there is quite a bit of imbalance between IPv4 and IPv6 route addition on Windows - for IPv6,
add_route_ipv6()will not print any messages (so, no diff here), while IPv4 has all that... maybe something to clean up in 2.7.
Quoted 7 lines
We *also* might want to get rid of that obscure
/* failed, try increasing the metric to work around Vista issue */
code bit, which looks extremely scary ("increasing metric with +1 in a tight loop until we reach 2048") and Vista is out of support anyway...
In fact the issue worked around is not a Vista thing but Vista+ including Win10 and results from wrong use of the API. The old API used here requires the metric parameter to be the route metric + interface metric starting Vista+. So metric = 0 or any value < interface-metric fails. If we want a metric of 5 on an interface that has a metric of 20, we have to pass in 25.
Looks like someone (I won't say who) added that obnoxious loop trying metric from 0 to 2048 to work around this. Probably the idea was to support pre-vista and vista without needing a run-time check.
That said, in Vista+ one should use CreateIpForwardEntry2() which is much easier. As we do for IPv6 and for both v4 and v6 in the service.
Let's rewrite this function in 2.7.
Selva
PATCH 3/3 Propagate route error to initialization_completed()
In reply to [email protected]...From: Selva Nair <[email protected]...>
Makes it possible to report management state as CONNECTED,ROUTE_ERROR instead of CONNECTED,SUCCESS in case of routing errors.
This depends on treating "route already exists" as not an error which right now works when using netlink on Linux and IPAPI or iservice on Windows.
For route set via command line there is no easy way to get this information and current behaviour is unchanged: i.e., the management state continues to be reported as CONNECTED,SUCCESS.
Status notification to systemd is not affected.
To test on Linux, build with netlink and use a --route option with an unreachable gateway like:
"--route 192.168.122.0 255.255.255.0 1.1.1.1"
Notes:
On windows, if the route method is "exe", setting a route that exists *may* get logged as error and this patch will lead to a slightly misleading CONNECTED,ROUTE_ERROR state message. This is considered tolerable as no one should be using "exe" (i.e. route.exe) as the route method.
--- src/openvpn/forward.c | 10 +++-- src/openvpn/init.c | 42 +++++++++++++------ src/openvpn/init.h | 10 ++--- src/openvpn/route.c | 97 +++++++++++++++++-------------------------- src/openvpn/route.h | 18 +++----- 5 files changed, 85 insertions(+), 92 deletions(-)
src/openvpn/forward.c +7 -3
@@ -405,12 +405,16 @@ send_control_channel_string(struct context *c, const char *str, int msglevel)static void check_add_routes_action (struct context *c,const bool errors) { -do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool route_status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + +int flags = (errors ?ISC_ERRORS :0 ); + flags |= (!route_status ?ISC_ROUTE_ERRORS :0 ); +update_time ();event_timeout_clear (&c->c2.route_wakeup);event_timeout_clear (&c->c2.route_wakeup_expire); -initialization_sequence_completed (c, errors ?ISC_ERRORS :0 );/* client/p2p --route-delay was defined */ +initialization_sequence_completed (c, flags);/* client/p2p --route-delay was defined */ } static void
src/openvpn/init.c +29 -13
123 lines not on this page · raw message
src/openvpn/init.h +4 -6
@@ -71,12 +71,9 @@ void init_instance(struct context *c, const struct env_set *env, const unsigned*/ void init_query_passwords (const struct context *c); -void do_route (const struct options *options, -struct route_list *route_list, -struct route_ipv6_list *route_ipv6_list, -const struct tuntap *tt, -const struct plugin_list *plugins, -struct env_set *es, +bool do_route (const struct options *options,struct route_list *route_list, +struct route_ipv6_list *route_ipv6_list,const struct tuntap *tt, +const struct plugin_list *plugins,struct env_set *es,openvpn_net_ctx_t *ctx);void close_instance (struct context *c);
@@ -116,6 +113,7 @@ void free_context_buffers(struct context_buffers *b);#define ISC_ERRORS (1<<0)#define ISC_SERVER (1<<1) +#define ISC_ROUTE_ERRORS (1<<2)void initialization_sequence_completed (struct context *c,const unsigned int flags);#ifdef ENABLE_MANAGEMENT
src/openvpn/route.c +39 -58
254 lines not on this page · raw message
src/openvpn/route.h +6 -12
@@ -259,15 +259,12 @@ void copy_route_ipv6_option_list(struct route_ipv6_option_list *dest,void route_ipv6_clear_host_bits (struct route_ipv6 *r6 ); -void add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); +bool add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx);void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); -void add_route (struct route_ipv4 *r, -const struct tuntap *tt, -unsigned int flags, -const struct route_gateway_info *rgi, -const struct env_set *es, +bool add_route (struct route_ipv4 *r,const struct tuntap *tt,unsigned int flags, +const struct route_gateway_info *rgi,const struct env_set *es,openvpn_net_ctx_t *ctx); void add_route_to_option_list(struct route_option_list *l,
@@ -301,12 +298,9 @@ void route_list_add_vpn_gateway(struct route_list *rl,struct env_set *es, const in_addr_t addr); -void add_routes (struct route_list *rl, -struct route_ipv6_list *rl6, -const struct tuntap *tt, -unsigned int flags, -const struct env_set *es, -openvpn_net_ctx_t *ctx); +bool add_routes (struct route_list *rl,struct route_ipv6_list *rl6, +const struct tuntap *tt,unsigned int flags, +const struct env_set *es,openvpn_net_ctx_t *ctx); void delete_routes(struct route_list *rl, struct route_ipv6_list *rl6,
Signature · 1 line
2.34.1
[Openvpn-devel] [PATCH applied] Re: Propagate route error to initialization_completed()
We discussed this previously, and it makes sense to take "route addition errors" into account, even if we consciously decided (long before I got involved...) that we consider these non-fatal, unlike ifconfig errors.
I have stared at the code, and it looks reasonable (we discussed the approach before).
Some of the lines are now longer than 80 characters, with "short continuation lines", like this
+ ret = add_bypass_routes(&rl->spec.bypass, rl->rgi.gateway.addr, tt, flags,
+ &rl->rgi, es, ctx);
.. while our style guide permits "longer lines if the alternativ is more ugly", in this case actually rewrapping would be nicer (not a showstopper), like this:
+ ret = add_bypass_routes(&rl->spec.bypass, rl->rgi.gateway.addr,
+ tt, flags &rl->rgi, es, ctx);
.. so two similarily-long lines, not one very long and one quite short.
The rewrappings of the add_route3() calls are welcome :-)
That it's only available for Windows and Linux/SITNL today is non-ideal, but I can see the motivation - for platforms where we can't distinguish "genuine errors" and "EEXIST errors", err on the side of "keep old behaviour, no new warnings". We did want a major "routing glue rewrite" for 2.6, which did not happen, so let's try again for 2.7...
I have tested "things still work" by subjecting this to the full client/server test on Linux (with SITNL, with and without DCO), and run manual tests, as suggested
openvpn --config base.ovpn --route 192.168.122.0 255.255.255.0 1.1.1.1
.. which ended unexpected...
2023-01-10 13:05:15 sitnl_send: rtnl: generic error (-101): Network is unreachable
2023-01-10 13:05:15 ERROR: Linux route add command failed
2023-01-10 13:05:15 Initialization Sequence Completed.. I did expect something about "with errors" here - and I think we *should* print something, given that many (most?) *Linux* users will not have a management-client-GUI running.
On the management interface, it does work fine:
state
1673352459,CONNECTED,ROUTE_ERROR,10.194.2.170,199.102.77.82,51194,,,fd00:abcd:194:2::1029(and if there are no errors, it will display "CONNECTED,SUCCESS,")
I have not tested what the Windows GUI will do or display in this case.
Also, the EEXIST suppression of SITNL is really a bug that needs to be fixed. If I have duplicate routes...
2023-01-10 13:11:40 net_route_v4_add: 10.194.0.0/16 via 10.194.2.169 dev [NULL] table 0 metric -1
2023-01-10 13:11:40 net_route_v4_add: 10.194.0.0/16 via 10.194.2.169 dev [NULL] table 0 metric -1.. installation just works fine, but...
2023-01-10 13:12:00 net_route_v4_del: 10.194.0.0/16 via 10.194.2.169 dev [NULL] table 0 metric -1
2023-01-10 13:12:00 net_route_v4_del: 10.194.0.0/16 via 10.194.2.169 dev [NULL] table 0 metric -1
2023-01-10 13:12:00 sitnl_send: rtnl: generic error (-3): No such process
2023-01-10 13:12:00 ERROR: Linux route delete command failed.. it does not understand that the 2nd addition actually *failed*, so tries to remove it, which creates an error that is in the wrong place, and fully avoidable. Antonio, you listening?
Your patch has been applied to the master and release/2.6 branch.
commit e04c253618ce2a1bb0996a67b81af891e8607fa9 (master) commit 705a08ee5adcc74d51bc096592d561f35dc8661a (release/2.6)
Author: Selva Nair Date: Wed Jan 4 21:27:18 2023 -0500
Propagate route error to initialization_completed()
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg25884.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Hi,
Compiled and slightly tested - pinged server's tunnel IPv6 address.
Hi,
Quoted 1 line · Lev Stipakov
Compiled and slightly tested - pinged server's tunnel IPv6 address.
Do we call "route" for connect networks on Windows? We do on some of the platforms, but for those where we do not, this is not a good test for "route add" functionality - as tunnel IP + subnet gets setup via the "ifconfig-ipv6" part (implicit route for connected net).
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Quoted 10 lines · Gert Doering
Hi,
Quoted 1 line · Lev Stipakov
Compiled and slightly tested - pinged server's tunnel IPv6 address.
Do we call "route" for connect networks on Windows? We do on some of the platforms, but for those where we do not, this is not a good test for "route add" functionality - as tunnel IP + subnet gets setup via the "ifconfig-ipv6" part (implicit route for connected net).
Yes we do call add_route_connected_v6_net() on windows, so add_route_ipv6() should always get exercised.
Though I vaguely understand why we set the address with /128 and then set the route for the vpn subnet with fe80::8 as the gateway for tap-windows6, wonder why we do this for dco as well.
Selva
Hi,
Quoted 10 lines · Selva Nair
Quoted 7 lines · Lev Stipakov
Quoted 1 line
Compiled and slightly tested - pinged server's tunnel IPv6 address.
Do we call "route" for connect networks on Windows? We do on some of the platforms, but for those where we do not, this is not a good test for "route add" functionality - as tunnel IP + subnet gets setup via the "ifconfig-ipv6" part (implicit route for connected net).
Yes we do call
add_route_connected_v6_net()on windows, soadd_route_ipv6()should always get exercised.
Thanks for reminding me :-)
Quoted 3 lines
Though I vaguely understand why we set the address with /128 and then set the route for the vpn subnet with fe80::8 as the gateway for tap-windows6, wonder why we do this for dco as well.
Let me recap why we do this for tap-windows - for windows, this is always an Ethernet adapter, so it wants to always do neighbour discovery (ND), IPv6's equivalent of ARP for all "on this interface" addresses.
For "--dev tun" setups, OpenVPN does not want to deal with "Ethernet things", so the TAP driver replies to ARP requests for "special addresses" - for net30, OpenVPN ioctl()'s the "peer" address (which is also the gateway address) into the TAP driver, and only this address is replied to - admittedly, I do not know how "topology subnet" works wrt virtual ARP, need to read up on this again.
For IPv6, I decided that having to deal with ND is easier if I could just look at a magic number, namely fe80::8, in the tap driver code - so, we use /128 for the ifconfig bit ("no network here, everything is behind the gateway") and point all routing to "on this interface, fe80::8" - so for whatever IPv6 destination, windows will only do ND for fe80::8, and the TAP driver will reply to it, without any further help (ioctl()) from OpenVPN.
This said, I have no idea why we do it that way for wintun and DCO - most likely because it avoids having to add even more windows-driver- specific special case handling in places where we are nicely generic today.
We are not really losing anything this way, though - even though we pretend "the interface is a multiaccess interface", it is really only point-to-point from the OS view, including win-dco. So whatever helps to convince windows "send the packet down this pipe" with the least amount of code and debugging is good :-)
On a "real" multiaccess network, different neighbours would have different MAC addresses, and more ND activity would happen - but "--dev tun" mode never is (--dev tap on a --server would be).
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Quoted 19 lines · Gert Doering
Quoted 4 lines
Though I vaguely understand why we set the address with /128 and then set the route for the vpn subnet with fe80::8 as the gateway for
tap-windows6,
Quoted 1 line
wonder why we do this for dco as well.
Let me recap why we do this for tap-windows - for windows, this is always an Ethernet adapter, so it wants to always do neighbour discovery (ND), IPv6's equivalent of ARP for all "on this interface" addresses.
For "--dev tun" setups, OpenVPN does not want to deal with "Ethernet things",
so the TAP driver replies to ARP requests for "special addresses" - for net30, OpenVPN ioctl()'s the "peer" address (which is also the gateway address) into the TAP driver, and only this address is replied to - admittedly, I do not know how "topology subnet" works wrt virtual ARP, need to read up on this again.
Quoted 8 lines
For IPv6, I decided that having to deal with ND is easier if I could just look at a magic number, namely fe80::8, in the tap driver code - so, we use /128 for the ifconfig bit ("no network here, everything is behind the gateway") and point all routing to "on this interface, fe80::8" - so for whatever IPv6 destination, windows will only do ND for fe80::8, and the TAP driver will reply to it, without any further help (
ioctl()) from OpenVPN.
Thanks for the explanation. I had a vague idea that this is done for ND.
Quoted 7 lines
This said, I have no idea why we do it that way for wintun and DCO - most likely because it avoids having to add even more windows-driver- specific special case handling in places where we are nicely generic today.
I guess it works because nexthop is ignored[*] for tun adapters and we could have just set an onlink route omitting the gateway parameter.
Selva
[*] Any bogus gateway seems to work, but still, "netsh int ipv6 show neighbours"
lists any such gateway set for dco as initially "Probe" and then "Unreachable",
so not totally ignored?
Stared-at-code ("looks reasonable"). Getting rid of netsh.exe calls is a good thing.
Actually tested! MinGW builds, on a Win10 system, running openvpn.exe from a "cmd.exe run as administrator" window, so no iservice involved - OpenVPN tells me "IPv6 route added using ipapi", and "route print -6" looks good.
There is something incorrect in the log, though - I connect via IPv6, and OpenVPN needs to install a redirect host route due to "gateway and pushed route overlaps". It is installed correctly, that is, the /128 route points to the LAN interface and that IPv6 default route (fe80::1), but the log says
add_route_ipv6(2001:608:8003::200/128 -> fe80::1 metric 1) dev LAN-Verbindung 2 IPv6 route added using ipapiadd_route_ipv6(2001:608:8003::/48 -> 2001:608:8003:f:98::1 metric -1) dev LAN-Verbindung 2 IPv6 route added using ipapi
In "route show -6", the first route ends up on "If 8 ... Intel Pro/100" and the second route on "If 2 ... TAP-Windows Adapter V9 #2" - which is both correct, but only the second is "dev LAN-Verbindung 2". So it seems to always print the name of the TAP adapter here - which is misleading at best.
I have also tested "not run as administrator", and it will correctly error out with
"ROUTE: route addition failed using ipapi: Zugriff verweigert [status=5 if_index=2]"
(if it gets there at all :-) - without --ifconfig-noexec, it fails IPv6 ifconfig/netsh already, and never proceeds to route addition - which actually brings up the observation that there's netsh.exe calls left, "netsh.exe interface ipv6 set address 2 2001:608:..." :-) )
Your patch has been applied to the master and release/2.6 branch.
commit dd66958198f7c4dcf7fca0db82ca72996100b3bd (master) commit 66a3dc3a007c13e7a8d48ef793e046b09d8e6d30 (release/2.6)
Author: Selva Nair Date: Wed Jan 4 21:27:16 2023 -0500
Use IPAPI for setting ipv6 routes when iservice not available
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg25886.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Hi
which actually brings up the observation that there's netsh.exe calls
Quoted 2 lines
left, "netsh.exe interface ipv6 set address 2 2001:608:..." :-) )
Yes, it's on my radar :)
Selva