diff options
authorPhilipp Czerner <suyjuris.gi@nicze.de>2020-03-27 18:07:50 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-03-29 23:30:47 -0600
commit66ad537f4e2144112cb6686c4fc4856d70bf6a3d (patch)
parentgo: bump (diff)
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>
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 {
- 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