Re: [Openvpn-devel] [PATCH v3] Use adapter index instead of name
Hi, On Wed, Nov 11, 2015 at 08:40:06PM +0100, Gert Doering wrote: > ... but wouldn't > > argv_printf (, > "%s%sc interface ipv6 set address interface=%lu %s > store=active", >get_win_sys_path(), >NETSH_PATH_SUFFIX, >get_adapter_index_flexible(actual), >ifconfig_ipv6_local); > > (without storing into a temp variable) work "just fine"? Turns out this does not work, as argv_printf() does not implement a generic printf() parser, but splits up the string at whitespace boundaries and then handles each element explicitly - and '%-parsing' is only done for known cases, and then the % part has to stand on its own, with some special exceptions... else if (!strcmp (term, "%s/%d")) ... else if (!strcmp (term, "%s%sc")) ... given that, I think the v3 patch is as good as it's going to get without extending argv_printf() - IOW, ACK, and I'll merge later. Thanks. (I'll add a comment to the commit message to explain why a temporary string has to be used, in case I forget and start wondering a year from now...) gert -- USENET is *not* the non-clickable part of WWW! //www.muc.de/~gert/ Gert Doering - Munich, Germany g...@greenie.muc.de fax: +49-89-35655025g...@net.informatik.tu-muenchen.de signature.asc Description: PGP signature
Re: [Openvpn-devel] [PATCH v3] Use adapter index instead of name
Hi, On Wed, Nov 11, 2015 at 01:48:07PM +0200, Lev Stipakov wrote: > @@ -1301,18 +1303,20 @@ do_ifconfig (struct tuntap *tt, > if ( do_ipv6 ) >{ > char * saved_actual; > + char iface[64]; > > 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"); > > - /* example: netsh interface ipv6 set address MyTap 2001:608:8003::d > store=active */ > + openvpn_snprintf(iface, sizeof(iface), "interface=%lu", > get_adapter_index_flexible(actual)); Uh. I'm afraid if I speak up once more, you'll stop talking to me... (or not give me any beer next time we meet :) ) > + /* example: netsh interface ipv6 set address interface=42 > 2001:608:8003::d store=active */ > argv_printf (, > - "%s%sc interface ipv6 set address %s %s store=active", > + "%s%sc interface ipv6 set address %s %s store=active", >get_win_sys_path(), >NETSH_PATH_SUFFIX, > - actual, > - ifconfig_ipv6_local ); > - ... but wouldn't argv_printf (, "%s%sc interface ipv6 set address interface=%lu %s store=active", get_win_sys_path(), NETSH_PATH_SUFFIX, get_adapter_index_flexible(actual), ifconfig_ipv6_local); (without storing into a temp variable) work "just fine"? gert -- USENET is *not* the non-clickable part of WWW! //www.muc.de/~gert/ Gert Doering - Munich, Germany g...@greenie.muc.de fax: +49-89-35655025g...@net.informatik.tu-muenchen.de signature.asc Description: PGP signature
[Openvpn-devel] [PATCH v3] Use adapter index instead of name
v3: * Use interface= syntax. * Add forward declaration of get_adapter_index_flexible to get rid of warning. v2: * Remove netsh call which uses adapter name. After thoughtful testing turns out that "adapter name" code branch is never used. Some windows machines get weird issues with netsh when using adapter name on "netsh.exe interface ipv6 set address" command. Changed logic to get adapter index and use it instead of adapter name for netsh set address command. if unable to get adapter index, try with adapter name. Signed-off-by: Olli MannistoSigned-off-by: Lev Stipakov --- src/openvpn/tun.c | 14 +- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 24a61ec..070fd18 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -67,6 +67,8 @@ static void netsh_command (const struct argv *a, int n); static const char *netsh_get_id (const char *dev_node, struct gc_arena *gc); +static DWORD get_adapter_index_flexible (const char *name); + #endif #ifdef TARGET_SOLARIS @@ -1301,18 +1303,20 @@ do_ifconfig (struct tuntap *tt, if ( do_ipv6 ) { char * saved_actual; + char iface[64]; 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"); - /* example: netsh interface ipv6 set address MyTap 2001:608:8003::d store=active */ + openvpn_snprintf(iface, sizeof(iface), "interface=%lu", get_adapter_index_flexible(actual)); + + /* example: netsh interface ipv6 set address interface=42 2001:608:8003::d store=active */ argv_printf (, - "%s%sc interface ipv6 set address %s %s store=active", +"%s%sc interface ipv6 set address %s %s store=active", get_win_sys_path(), NETSH_PATH_SUFFIX, -actual, -ifconfig_ipv6_local ); - +iface, +ifconfig_ipv6_local); netsh_command (, 4); /* explicit route needed */ -- 1.9.1