Re: [Openvpn-devel] [PATCH] Added environment variable for IPv6 route metric.

2020-09-23 Thread Gert Doering
Hi,

On Thu, Aug 20, 2020 at 03:49:46PM +0200, Jan Seeger wrote:
> --- a/src/openvpn/route.c
> +++ b/src/openvpn/route.c
> @@ -1463,6 +1463,7 @@ setenv_route_ipv6(struct env_set *es, const struct 
> route_ipv6 *r6, int i)
>  struct buffer name1 = alloc_buf_gc( 256, &gc );
>  struct buffer val = alloc_buf_gc( 256, &gc );
>  struct buffer name2 = alloc_buf_gc( 256, &gc );
> +struct buffer name3 = alloc_buf_gc( 256, &gc );
>  
>  buf_printf( &name1, "route_ipv6_network_%d", i );
>  buf_printf( &val, "%s/%d", print_in6_addr( r6->network, 0, &gc ),
> @@ -1471,6 +1472,11 @@ setenv_route_ipv6(struct env_set *es, const struct 
> route_ipv6 *r6, int i)
>  
>  buf_printf( &name2, "route_ipv6_gateway_%d", i );
>  setenv_str( es, BSTR(&name2), print_in6_addr( r6->gateway, 0, &gc ));
> +
> +if (r6->flags & RT_METRIC_DEFINED) {
> +buf_printf( &name3, "route_ipv6_metric_%d", i) ;
> +setenv_int( es, BSTR(&name3), r6->metric);
> +}

style guide demands "{" on a separate line, so

   if (r6->flags & RT_METRIC_DEFINED)
   {

also, I'd move the allocation of "name3" into this block.

   if (r6->flags & RT_METRIC_DEFINED)
   {
   struct buffer name3 = alloc_buf_gc( 256, &gc );
   ...

(no need to allocate memory if this is never used - also, with our
move towards C99, new code is encouraged to declare variables where
first needed, not "at the top of the function")

gert

-- 
"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 g...@greenie.muc.de


signature.asc
Description: PGP signature
___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


[Openvpn-devel] [PATCH] Added environment variable for IPv6 route metric.

2020-09-23 Thread Jan Seeger
---
 doc/man-sections/script-options.rst | 4 ++--
 src/openvpn/route.c | 7 +++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/doc/man-sections/script-options.rst 
b/doc/man-sections/script-options.rst
index a4df6732..0bf68c43 100644
--- a/doc/man-sections/script-options.rst
+++ b/doc/man-sections/script-options.rst
@@ -709,10 +709,10 @@ instances.
 A set of variables which define each IPv6 route to be added, and are
 set prior to **--up** script execution.
 
-``parm`` will be one of :code:`network` or :code:`gateway`
+``parm`` will be one of :code:`network`, :code:`gateway`
 (:code:`netmask` is contained as :code:`/nnn` in the
 ``route_ipv6_network_{n}``, unlike IPv4 where it is passed in a
-separate environment variable).
+separate environment variable) or :code:`metric`.
 
 ``n`` is the OpenVPN route number, starting from 1.
 
diff --git a/src/openvpn/route.c b/src/openvpn/route.c
index bd6b968b..bab9b8e9 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -1479,6 +1479,13 @@ setenv_route_ipv6(struct env_set *es, const struct 
route_ipv6 *r6, int i)
 
 buf_printf( &name2, "route_ipv6_gateway_%d", i );
 setenv_str( es, BSTR(&name2), print_in6_addr( r6->gateway, 0, &gc ));
+
+if (r6->flags & RT_METRIC_DEFINED)
+{
+struct buffer name3 = alloc_buf_gc( 256, &gc );
+buf_printf( &name3, "route_ipv6_metric_%d", i) ;
+setenv_int( es, BSTR(&name3), r6->metric);
+}
 }
 gc_free(&gc);
 }
-- 
2.26.2



___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


[Openvpn-devel] [PATCH] Added environment variable for IPv6 route metric.

2020-09-23 Thread Jan Seeger
Hello!

Thanks for your feedback. I've added the necessary changes.

Best regards,
Jan




___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


Re: [Openvpn-devel] [PATCH] Added environment variable for IPv6 route metric.

2020-09-23 Thread David Sommerseth
On 23/09/2020 14:58, Jan Seeger wrote:
> --- a/doc/man-sections/script-options.rst
> +++ b/doc/man-sections/script-options.rst
> @@ -709,10 +709,10 @@ instances.
>  A set of variables which define each IPv6 route to be added, and are
>  set prior to **--up** script execution.
>  
> -``parm`` will be one of :code:`network` or :code:`gateway`
> +``parm`` will be one of :code:`network`, :code:`gateway`
>  (:code:`netmask` is contained as :code:`/nnn` in the
>  ``route_ipv6_network_{n}``, unlike IPv4 where it is passed in a
> -separate environment variable).
> +separate environment variable) or :code:`metric`.

I would suggest to rewrite this slightly, to make it clearer.  The () sentence
should be incorporated as a normal sentence.

So the (text/plain) result will be something like:

  param will be one of network, code or metric.  The netmask is contained
  as /nnn in the route_ipv6_network_{n}, unlike IPv4 where it is passed in
  a separate environment variable.

Or maybe even (why do we highlight IPv4 differences so much?):

  param will be one of network, code or metric.  The netmask is
  not provided and is preserved as /nnn in the IPv6 range in
  route_ipv6_network_{n}.

(These examples needs the proper :code:`value` and ``value`` highlighting,
removed here for clarity)


-- 
kind regards,

David Sommerseth
OpenVPN Inc




signature.asc
Description: OpenPGP digital signature
___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


[Openvpn-devel] [PATCH 3/3] netsh: Delete WINS servers on TUN close

2020-09-23 Thread Simon Rozman via Openvpn-devel
Signed-off-by: Simon Rozman 
---
 src/openvpn/tun.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index b1cd7a1b..80ae6958 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -6706,6 +6706,16 @@ netsh_delete_address_dns(const struct tuntap *tt, bool 
ipv6, struct gc_arena *gc
 netsh_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);
-- 
2.28.0.windows.1



___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


[Openvpn-devel] [PATCH 1/3] netsh: Specify interfaces by index rather than name

2020-09-23 Thread Simon Rozman via Openvpn-devel
This is more efficient and less error prone.

Signed-off-by: Simon Rozman 
---
 src/openvpn/route.c | 26 +++---
 src/openvpn/tun.c   | 88 +
 2 files changed, 53 insertions(+), 61 deletions(-)

diff --git a/src/openvpn/route.c b/src/openvpn/route.c
index bd6b968b..d75aa5f4 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -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
diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index faa02504..8fd3229f 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -68,7 +68,7 @@ const static GUID GUID_DEVINTERFACE_NET = { 0xcac88484, 
0x7515, 0x4c03, { 0x82,
 #define NI_OPTIONS (1<<2)
 
 static void netsh_ifconfig(const struct tuntap_options *to,
-   const char *flex_name,
+   DWORD adapter_index,
const in_addr_t ip,
const in_addr_t netmask,
const unsigned int flags);
@@ -79,7 +79,7 @@ static void windows_set_mtu(const int iface_index,
 
 static void netsh_set_dns6_servers(const struct in6_addr *addr_list,
const int addr_len,
-   const char *flex_name);
+   DWORD adapter_index);
 
 static void netsh_command(const struct argv *a, int n, int msglevel);
 
@@ -1103,10 +1103,9 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, 
int tun_mtu,
 }
 else
 {
-/* example: netsh interface ipv6 set address interface=42
+/* example: netsh interface ipv6 set address 42
  *  2001:608:8003::d/bits store=active
  */
-char iface[64];
 
 /* in TUN mode, we only simulate a subnet, so the interface
  * is configured with /128 + a route to fe80::8.  In TAP mode,
@@ -1114,10 +1113,8 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, 
int tun_mtu,
  */
 int netbits = (tt->type == DEV_TYPE_TUN) ? 128 : tt->netbits_ipv6;
 
-openvpn_snprintf(iface, sizeof(iface), "interface=%lu",
- tt->adapter_index);
-argv_printf(&argv, "%s%s interface ipv6 set address %s %s/%d 
store=active",
-get_win_sys_path(), NETSH_PATH_SUFFIX, iface,
+argv_printf(&argv, "%s%s interface ipv6 set address %lu %s/%d 
store=active",
+get_win_sys_path(), NETSH_PATH_SUFFIX, tt->adapter_index,
 ifconfig_ipv6_local, netbits);
 netsh_command(&argv, 

[Openvpn-devel] [PATCH] openvpnmsica: Simplify find_adapters() to void return

2020-09-23 Thread Simon Rozman via Openvpn-devel
As the find_adapters() failure is not critical and FindSystemInfo()
should continue regardless, the find_adapters() has been simplified not
to return result code. It still logs any error thou.

Signed-off-by: Simon Rozman 
---
 src/openvpnmsica/openvpnmsica.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/openvpnmsica/openvpnmsica.c b/src/openvpnmsica/openvpnmsica.c
index f203f736..de1cf65c 100644
--- a/src/openvpnmsica/openvpnmsica.c
+++ b/src/openvpnmsica/openvpnmsica.c
@@ -248,7 +248,7 @@ cleanup_OpenSCManager:
 }
 
 
-static UINT
+static void
 find_adapters(
 _In_ MSIHANDLE hInstall,
 _In_z_ LPCTSTR szzHardwareIDs,
@@ -262,12 +262,12 @@ find_adapters(
 uiResult = tap_list_adapters(NULL, szzHardwareIDs, &pAdapterList);
 if (uiResult != ERROR_SUCCESS)
 {
-return uiResult;
+return;
 }
 else if (pAdapterList == NULL)
 {
 /* No adapters - no fun. */
-return ERROR_SUCCESS;
+return;
 }
 
 /* Get IPv4/v6 info for all network adapters. Actually, we're interested 
in link status only: up/down? */
@@ -394,7 +394,6 @@ cleanup_pAdapterAdresses:
 free(pAdapterAdresses);
 cleanup_pAdapterList:
 tap_free_adapter_list(pAdapterList);
-return uiResult;
 }
 
 
-- 
2.28.0.windows.1



___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


[Openvpn-devel] [PATCH 2/3] netsh: Clear existing IPv6 DNS servers before configuring new ones

2020-09-23 Thread Simon Rozman via Openvpn-devel
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.

Signed-off-by: Simon Rozman 
---
 src/openvpn/tun.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index 8fd3229f..b1cd7a1b 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -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) ?
-- 
2.28.0.windows.1



___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel