From: Philipp Czerner <suyjuris.gi@nicze.de>
To: wireguard@lists.zx2c4.com
Cc: Philipp Czerner <suyjuris.gi@nicze.de>
Subject: [PATCH wireguard-windows] Calculate the actual route metric by summing interface and route metric.
Date: Fri, 27 Mar 2020 18:07:50 +0100 [thread overview]
Message-ID: <20200327170750.5285-1-suyjuris.gi@nicze.de> (raw)
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
next reply other threads:[~2020-03-30 2:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-27 17:07 Philipp Czerner [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200327170750.5285-1-suyjuris.gi@nicze.de \
--to=suyjuris.gi@nicze.de \
--cc=wireguard@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).