Development discussion of WireGuard
 help / color / mirror / Atom feed
* [PATCH wireguard-windows] Calculate the actual route metric by summing interface and route metric.
@ 2020-03-27 17:07 Philipp Czerner
  2020-03-30  5:31 ` Jason A. Donenfeld
  0 siblings, 1 reply; 5+ messages in thread
From: Philipp Czerner @ 2020-03-27 17:07 UTC (permalink / raw)
  To: wireguard; +Cc: Philipp Czerner

Signed-off-by: Philipp Czerner <suyjuris.gi@nicze.de>
---
Hi,

I had some issues setting up Wireguard behind another VPN. Curiously, it bound the physical interface instead of the other VPN, which was the default route. According to MSDN "the actual route metric used to compute the route preference is the summation of interface metric specified in the Metric member of the MIB_IPINTERFACE_ROW structure and the route metric offset specified in this member" (documentation for MIB_IPFORWARD_ROW2), but the code did not seem to consider this. After I changed the calculation, I got the expected behaviour.

Cheers,
Philipp

 tunnel/defaultroutemonitor.go | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tunnel/defaultroutemonitor.go b/tunnel/defaultroutemonitor.go
index c102b64..4b24e8e 100644
--- a/tunnel/defaultroutemonitor.go
+++ b/tunnel/defaultroutemonitor.go
@@ -33,8 +33,14 @@ func bindSocketRoute(family winipcfg.AddressFamily, device *device.Device, ourLU
 		if err != nil || ifrow.OperStatus != winipcfg.IfOperStatusUp {
 			continue
 		}
-		if r[i].Metric < lowestMetric {
-			lowestMetric = r[i].Metric
+
+		iface, err := r[i].InterfaceLUID.IPInterface(family)
+		if err != nil {
+			continue
+		}
+
+		if r[i].Metric + iface.Metric < lowestMetric {
+			lowestMetric = r[i].Metric + iface.Metric;
 			index = r[i].InterfaceIndex
 			luid = r[i].InterfaceLUID
 		}
-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH wireguard-windows] Calculate the actual route metric by summing interface and route metric.
  2020-03-27 17:07 [PATCH wireguard-windows] Calculate the actual route metric by summing interface and route metric Philipp Czerner
@ 2020-03-30  5:31 ` Jason A. Donenfeld
  2020-03-30  8:40   ` Ludwig Herzog
  2020-03-31 12:56   ` Philipp Czerner
  0 siblings, 2 replies; 5+ messages in thread
From: Jason A. Donenfeld @ 2020-03-30  5:31 UTC (permalink / raw)
  To: Philipp Czerner; +Cc: WireGuard mailing list, Simon Rozman

On Sun, Mar 29, 2020 at 8:29 PM Philipp Czerner <suyjuris.gi@nicze.de> wrote:
>
> Signed-off-by: Philipp Czerner <suyjuris.gi@nicze.de>
> ---
> Hi,
>
> I had some issues setting up Wireguard behind another VPN. Curiously, it bound the physical interface instead of the other VPN, which was the default route. According to MSDN "the actual route metric used to compute the route preference is the summation of interface metric specified in the Metric member of the MIB_IPINTERFACE_ROW structure and the route metric offset specified in this member" (documentation for MIB_IPFORWARD_ROW2), but the code did not seem to consider this. After I changed the calculation, I got the expected behaviour.
>
> Cheers,
> Philipp
>
>  tunnel/defaultroutemonitor.go | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/tunnel/defaultroutemonitor.go b/tunnel/defaultroutemonitor.go
> index c102b64..4b24e8e 100644
> --- a/tunnel/defaultroutemonitor.go
> +++ b/tunnel/defaultroutemonitor.go
> @@ -33,8 +33,14 @@ func bindSocketRoute(family winipcfg.AddressFamily, device *device.Device, ourLU
>                 if err != nil || ifrow.OperStatus != winipcfg.IfOperStatusUp {
>                         continue
>                 }
> -               if r[i].Metric < lowestMetric {
> -                       lowestMetric = r[i].Metric
> +
> +               iface, err := r[i].InterfaceLUID.IPInterface(family)
> +               if err != nil {
> +                       continue
> +               }
> +
> +               if r[i].Metric + iface.Metric < lowestMetric {
> +                       lowestMetric = r[i].Metric + iface.Metric;

Nice semicolon ;-).

Thanks a lot for this patch and triaging the issue. Nice to hear that
nested VPNs work. If you don't mind sharing, I'd be interested to
learn what software sets up its routes in this manner.

Anyway, applied here:
https://git.zx2c4.com/wireguard-windows/commit/?id=66ad537f4e2144112cb6686c4fc4856d70bf6a3d

Jason

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH wireguard-windows] Calculate the actual route metric by summing interface and route metric.
  2020-03-30  5:31 ` Jason A. Donenfeld
@ 2020-03-30  8:40   ` Ludwig Herzog
  2020-04-01  6:46     ` Simon Rozman
  2020-03-31 12:56   ` Philipp Czerner
  1 sibling, 1 reply; 5+ messages in thread
From: Ludwig Herzog @ 2020-03-30  8:40 UTC (permalink / raw)
  To: wireguard

Hi,

I'm reading this maillist since a longer time and was never brave enough
to mention my problem since I'm not a developer or programmer and don't
know if I can describe it properly. Now this windows/metric stuff came
up, so I take a heart ;-)

In short: I have windows 10 client softwares which only work properly
with manually set adapter and gateway metrics in the VPN network
adapter, what works for openVPN (even better for a logmein test setup)
but not for wireguard, since manual metric settings are not recognized /
overwritten by the windows wireguard app. Is it possible to set the
metrics somehow in the config file? Or prevent the windows wireguard app
from overwriting?

Regards

Ludwig


Am 30.03.2020 um 07:31 schrieb Jason A. Donenfeld:
> On Sun, Mar 29, 2020 at 8:29 PM Philipp Czerner <suyjuris.gi@nicze.de> wrote:
>> Signed-off-by: Philipp Czerner <suyjuris.gi@nicze.de>
>> ---
>> Hi,
>>
>> I had some issues setting up Wireguard behind another VPN. Curiously, it bound the physical interface instead of the other VPN, which was the default route. According to MSDN "the actual route metric used to compute the route preference is the summation of interface metric specified in the Metric member of the MIB_IPINTERFACE_ROW structure and the route metric offset specified in this member" (documentation for MIB_IPFORWARD_ROW2), but the code did not seem to consider this. After I changed the calculation, I got the expected behaviour.
>>
>> Cheers,
>> Philipp
>>
>>   tunnel/defaultroutemonitor.go | 10 ++++++++--
>>   1 file changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/tunnel/defaultroutemonitor.go b/tunnel/defaultroutemonitor.go
>> index c102b64..4b24e8e 100644
>> --- a/tunnel/defaultroutemonitor.go
>> +++ b/tunnel/defaultroutemonitor.go
>> @@ -33,8 +33,14 @@ func bindSocketRoute(family winipcfg.AddressFamily, device *device.Device, ourLU
>>                  if err != nil || ifrow.OperStatus != winipcfg.IfOperStatusUp {
>>                          continue
>>                  }
>> -               if r[i].Metric < lowestMetric {
>> -                       lowestMetric = r[i].Metric
>> +
>> +               iface, err := r[i].InterfaceLUID.IPInterface(family)
>> +               if err != nil {
>> +                       continue
>> +               }
>> +
>> +               if r[i].Metric + iface.Metric < lowestMetric {
>> +                       lowestMetric = r[i].Metric + iface.Metric;
> Nice semicolon ;-).
>
> Thanks a lot for this patch and triaging the issue. Nice to hear that
> nested VPNs work. If you don't mind sharing, I'd be interested to
> learn what software sets up its routes in this manner.
>
> Anyway, applied here:
> https://git.zx2c4.com/wireguard-windows/commit/?id=66ad537f4e2144112cb6686c4fc4856d70bf6a3d
>
> Jason

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH wireguard-windows] Calculate the actual route metric by summing interface and route metric.
  2020-03-30  5:31 ` Jason A. Donenfeld
  2020-03-30  8:40   ` Ludwig Herzog
@ 2020-03-31 12:56   ` Philipp Czerner
  1 sibling, 0 replies; 5+ messages in thread
From: Philipp Czerner @ 2020-03-31 12:56 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: wireguard



On 30/03/2020 07:31, Jason A. Donenfeld wrote:
> Nice semicolon ;-).

Oops! ;)

> Thanks a lot for this patch and triaging the issue. Nice to hear that
> nested VPNs work. If you don't mind sharing, I'd be interested to
> learn what software sets up its routes in this manner.

Cisco AnyConnect.

Philipp


> Anyway, applied here:
> https://git.zx2c4.com/wireguard-windows/commit/?id=66ad537f4e2144112cb6686c4fc4856d70bf6a3d
> 
> Jason
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH wireguard-windows] Calculate the actual route metric by summing interface and route metric.
  2020-03-30  8:40   ` Ludwig Herzog
@ 2020-04-01  6:46     ` Simon Rozman
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Rozman @ 2020-04-01  6:46 UTC (permalink / raw)
  To: Ludwig Herzog, wireguard

[-- Attachment #1: Type: text/plain, Size: 1245 bytes --]

Hi Ludwig,

Would a support for ExecPostUp/ExecPreDown satisfy your need?

Regards, Simon

-----Original Message-----
From: WireGuard <wireguard-bounces@lists.zx2c4.com> on behalf of Ludwig Herzog <ludwig.herzog@web.de>
Date: Tuesday, 31 March 2020 at 05:33
To: "wireguard@lists.zx2c4.com" <wireguard@lists.zx2c4.com>
Subject: Re: [PATCH wireguard-windows] Calculate the actual route metric by summing interface and route metric.

    Hi,
    
    I'm reading this maillist since a longer time and was never brave enough
    to mention my problem since I'm not a developer or programmer and don't
    know if I can describe it properly. Now this windows/metric stuff came
    up, so I take a heart ;-)
    
    In short: I have windows 10 client softwares which only work properly
    with manually set adapter and gateway metrics in the VPN network
    adapter, what works for openVPN (even better for a logmein test setup)
    but not for wireguard, since manual metric settings are not recognized /
    overwritten by the windows wireguard app. Is it possible to set the
    metrics somehow in the config file? Or prevent the windows wireguard app
    from overwriting?
    
    Regards
    
    Ludwig
    

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2965 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-01  6:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-27 17:07 [PATCH wireguard-windows] Calculate the actual route metric by summing interface and route metric Philipp Czerner
2020-03-30  5:31 ` Jason A. Donenfeld
2020-03-30  8:40   ` Ludwig Herzog
2020-04-01  6:46     ` Simon Rozman
2020-03-31 12:56   ` Philipp Czerner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).