netsh: Specify interfaces by index rather than name
PATCH 1/3 netsh: Specify interfaces by index rather than name
This is more efficient and less error prone.
--- src/openvpn/route.c | 26 +++++++------- src/openvpn/tun.c | 88 +++++++++++++++++++++------------------------ 2 files changed, 53 insertions(+), 61 deletions(-)
src/openvpn/route.c +12 -14
@@ -1987,25 +1987,24 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, }else { -struct buffer out =alloc_buf_gc (64 , &gc); +DWORD adapter_index;if (r6->adapter_index)/* vpn server special route */ { -buf_printf (&out,"interface=%lu" , r6->adapter_index ); + adapter_index = r6->adapter_index; gateway_needed = true; }else { -buf_printf (&out,"interface=%lu" , tt->adapter_index ); + adapter_index = tt->adapter_index; } - device =buf_bptr (&out); -/* netsh interface ipv6 add route 2001:db8::/32 MyTunDevice */ -argv_printf (&argv,"%s%s interface ipv6 add route %s/%d %s" , +/* 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, - device); + adapter_index);/* next-hop depends on TUN or TAP mode: * - in TAP mode, we use the "real" next-hop
@@ -2431,25 +2430,24 @@ delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, }else { -struct buffer out =alloc_buf_gc (64 , &gc); +DWORD adapter_index;if (r6->adapter_index)/* vpn server special route */ { -buf_printf (&out,"interface=%lu" , r6->adapter_index ); + adapter_index = r6->adapter_index; gateway_needed = true; }else { -buf_printf (&out,"interface=%lu" , tt->adapter_index ); + adapter_index = tt->adapter_index; } - device =buf_bptr (&out); -/* netsh interface ipv6 delete route 2001:db8::/32 MyTunDevice */ -argv_printf (&argv,"%s%s interface ipv6 delete route %s/%d %s" , +/* 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, - device); + adapter_index);/* next-hop depends on TUN or TAP mode: * - in TAP mode, we use the "real" next-hop
src/openvpn/tun.c +41 -47
268 lines not on this page · raw message
Signature · 1 line
2.28.0.windows.1
PATCH 2/3 netsh: Clear existing IPv6 DNS servers before configuring new ones
When there are no IPv6 DNS published, the adapter state is not sanitized and might contain IPv6 DNS server from a previous session.
netsh_ifconfig_options() clears DNS servers for IPv4 already.
--- src/openvpn/tun.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
src/openvpn/tun.c +7 -1
@@ -5281,7 +5281,6 @@ ip_addr_member_of(const in_addr_t addr, const IP_ADDR_STRING *ias)* Set the ipv6 dns servers on the specified interface. * The list of dns servers currently set on the interface * are cleared first. -* No action is taken if number of addresses (addr_len) < 1. */ static void netsh_set_dns6_servers(const struct in6_addr *addr_list,
@@ -5291,6 +5290,13 @@ netsh_set_dns6_servers(const struct in6_addr *addr_list,struct gc_arena gc =gc_new ();struct argv argv =argv_new (); +/* delete existing DNS settings from TAP interface */ +argv_printf (&argv,"%s%s interface ipv6 delete dns %lu all" , +get_win_sys_path (), +NETSH_PATH_SUFFIX , + adapter_index); +netsh_command (&argv,2 ,M_FATAL ); +for (int i =0 ; i < addr_len; ++i) { const char *fmt = (i == 0) ?
Signature · 1 line
2.28.0.windows.1
Re: [Openvpn-devel] [PATCH 2/3] netsh: Clear existing IPv6 DNS servers before configuring new ones
Hi,
Quoted 2 lines
When there are no IPv6 DNS published, the adapter state is not sanitized and might contain IPv6 DNS server from a previous session.
In this case, shouldn't the "set dns" call below overwrite the previous value?
Quoted 1 line
netsh_ifconfig_options()clears DNS servers for IPv4 already.
Agreed, let's do it for consistency.
Quoted 2 lines
* The list of dns servers currently set on the interface
* are cleared first.
Either existing comment lied or "implicit clear" was assumed because of the "set dns" call.
But now it is fine, since we have real clearing.
Stared and the code, built and tested on MSVC/Win10.
Re: [Openvpn-devel] [PATCH 2/3] netsh: Clear existing IPv6 DNS servers before configuring new ones
Hi,
Quoted 11 lines · Lev Stipakov
Hi,
Quoted 2 lines
When there are no IPv6 DNS published, the adapter state is not sanitized and might contain IPv6 DNS server from a previous session.
In this case, shouldn't the "set dns" call below overwrite the previous value?
Quoted 1 line
netsh_ifconfig_options()clears DNS servers for IPv4 already.
Quoted 8 lines
Agreed, let's do it for consistency.
Quoted 2 lines
* The list of dns servers currently set on the interface
* are cleared first.Either existing comment lied or "implicit clear" was assumed because of the "set dns" call.
The clearing happened only if at least one DNS address was specified using --dhcp-option DNS.
Quoted 2 lines
But now it is fine, since we have real clearing.
Now that this has been merged, should we make DNS settings using iservice consistent with this? Currently, when using the service, we do not touch any existing dns servers if none are specified using --dhcp-option. Same approach was taken in my patch for setting the domain suffix. The original logic was that any statically set values should not be overwritten unless explicitly asked for. At the same time, we do delete all addresses for v4 (not v6) while closing tun.
But, if we want to ensure a clean state for the adapter, as argued here, we should be clearing current values regardless of whether new one's are being set or not.
Selva
Quoted 10 lines
Stared and the code, built and tested on MSVC/Win10.
Acked-by Lev Stipakov <[email protected]...>_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
[Openvpn-devel] [PATCH applied] Re: netsh: Clear existing IPv6 DNS servers before configuring new ones
In reply to Simon RozmanYour patch has been applied to the master and release/2.5 branch.
In my win7 tests this does not seem to be *needed* - I ran a test with an IPv6 DNS server, and then the same test without, and the "ipconfig /all" output showed "no more IPv6 DNS server" (before applying this patch) - but this might have an effect if no IPv4 servers are there.
I was a bit worried that this might break in the "ip-win32 netsh" case, so I tested that one as well. It seems to do the right thing, though, decoupling IPv4 DNS servers and IPv6 DNS servers (and not deleting "just all" with the delete command).
Incidentially I tested "netsh interface ip set address 17 dhcp" here as well (works).
commit dd754221024cf60226ebaa679ec65ccc23f4e402 (master) commit 77c62003c263304f8b411d664cf56179f8d4df08 (release/2.5)
Author: Simon Rozman via Openvpn-devel Date: Thu Sep 24 08:44:51 2020 +0200
netsh: Clear existing IPv6 DNS servers before configuring new ones
Signed-off-by: Simon Rozman <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21078.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 3/3 netsh: Delete WINS servers on TUN close
In reply to Simon Rozman--- src/openvpn/tun.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
src/openvpn/tun.c +10 -0
@@ -6706,6 +6706,16 @@ netsh_delete_address_dns(const struct tuntap *tt, bool ipv6, struct gc_arena *gcnetsh_command (&argv,1 ,M_WARN ); } +if (!ipv6 && tt->options.wins_len >0 ) + { +argv_printf (&argv, +"%s%s interface ipv4 delete winsservers %lu all" , +get_win_sys_path (), +NETSH_PATH_SUFFIX , + tt->adapter_index); +netsh_command (&argv,1 ,M_WARN ); + } +if (ipv6 && tt->type ==DEV_TYPE_TUN ) {delete_route_connected_v6_net (tt);
Signature · 1 line
2.28.0.windows.1
Re: [Openvpn-devel] [PATCH 3/3] netsh: Delete WINS servers on TUN close
Hi,
Quoted 1 line
+ "%s%s interface ipv4 delete winsservers %lu all",
For DNS we use "dns", so it would be nice to unify it - either use dnsservers/winsservers or dns/wins. But that could be done later.
Code makes sense, compiled/tested on MSVC/Win10.
[Openvpn-devel] [PATCH applied] Re: netsh: Delete WINS servers on TUN close
In reply to Simon RozmanYour patch has been applied to the master and release/2.5 branch.
I have not tested this at all (no WINS infra), but "it looks reasonable and compiles" (Ubuntu 18, mingw).
commit 370395b3348c4307cdea955abaa36ba315cc128e (master) commit b77fc7121003d988eaa3eaeef2ec46bff73202cf (release/2.5)
Author: Simon Rozman via Openvpn-devel Date: Thu Sep 24 08:44:52 2020 +0200
netsh: Delete WINS servers on TUN close
Signed-off-by: Simon Rozman <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21075.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Good old "name vs index" thing.
According to "man" of netsh, index indeed could be used for "set address" and "add route":
Quoted 4 lines
interface - Interface name or index.
src/openvpn/route.c +1
-0+DWORD adapter_index;if (r6->adapter_index)/* vpn server special route */
src/openvpn/route.c add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, · line 1999
Quoted 10 lines
src/openvpn/route.c +2
-2{ -buf_printf (&out,"interface=%lu" , r6->adapter_index ); + adapter_index = r6->adapter_index; gateway_needed = true; } else { -buf_printf (&out,"interface=%lu" , tt->adapter_index ); + adapter_index = tt->adapter_index; }
Here I would do something like
DWORD adapter_index = tt->adapter_index;
if (r6->adapter_index)
{
adapter_index = r6->adapter_index;
gateway_needed = true;
}to make code more concise, but I am fine with current implementation too.
Stared at the code, built and tested on MSVC/Win10. Works as expected.
This patch is good and a useful change (I have stared-at-code and it make sense, and Lev has reviewed and tested it on Win10/MSVC).
I have test compiled this in MinGW on Ubuntu 18.04 and tested IPv6 route installation/removal on Win7/64 with the GUI running as Administrator (= netsh commands used, not iservice) and it is also doing the right things. I have tested "ipv6 ifconfig", "ipv6 route" and "ipv6 DNS", but not "IPv4 configs" or "enable DHCP".
At this point in the release cycle I would normally have not included it into release/2.5 anymore - we're trying to eventually reach a release, and not merge refactoring things anymore - *but* since this is well-contained, and 2/3+3/3 are actual bugfixes that sort of need this as prerequisite, so be it.
Let's see if we beat the number of release candidates 2.1 had... :-)
Your patch has been applied to the master and release/2.5 branch.
commit 6020e94bcf9eda89aa6573cb2eb1faf6d267cb46 (master) commit 422343040f137cf970aea0cf8f1f248d5dc50b9d (release/2.5)
Author: Simon Rozman via Openvpn-devel Date: Thu Sep 24 08:44:50 2020 +0200
netsh: Specify interfaces by index rather than name
Signed-off-by: Simon Rozman <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21076.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering