diff options
author | 2020-03-27 18:07:50 +0100 | |
---|---|---|
committer | 2020-03-29 23:30:47 -0600 | |
commit | 66ad537f4e2144112cb6686c4fc4856d70bf6a3d (patch) | |
tree | d9563bcbd164507fffaa03cb9686c1917a6add0c | |
parent | go: bump (diff) | |
download | wireguard-windows-66ad537f4e2144112cb6686c4fc4856d70bf6a3d.tar.xz wireguard-windows-66ad537f4e2144112cb6686c4fc4856d70bf6a3d.zip |
tunnel: calculate the actual route metric by summing interface and route metric
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.
Signed-off-by: Philipp Czerner <suyjuris.gi@nicze.de>
Link: https://docs.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-mib_ipforward_row2
[zx2c4: fixed up commit message, removed semicolon]
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | tunnel/defaultroutemonitor.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/tunnel/defaultroutemonitor.go b/tunnel/defaultroutemonitor.go index c102b644..68853fd1 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 } |