From 54d7070121d8d696d06a63594c64cc80f82bbc6b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 24 Feb 2021 20:06:49 -0800 Subject: [PATCH] wgengine/router: correctly read IPv6 routes when diffing. Fixes #1185. Signed-off-by: David Anderson --- wgengine/router/ifconfig_windows.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/wgengine/router/ifconfig_windows.go b/wgengine/router/ifconfig_windows.go index 486915e6e..9e7f4be3b 100644 --- a/wgengine/router/ifconfig_windows.go +++ b/wgengine/router/ifconfig_windows.go @@ -662,13 +662,26 @@ func getInterfaceRoutes(ifc *winipcfg.IPAdapterAddresses, family winipcfg.Addres // syncRoutes incrementally sets multiples routes on an interface. // This avoids a full ifc.FlushRoutes call. func syncRoutes(ifc *winipcfg.IPAdapterAddresses, want []*winipcfg.RouteData) error { - routes, err := getInterfaceRoutes(ifc, windows.AF_INET) + routes4, err := getInterfaceRoutes(ifc, windows.AF_INET) if err != nil { return err } - got := make([]*winipcfg.RouteData, 0, len(routes)) - for _, r := range routes { + routes6, err := getInterfaceRoutes(ifc, windows.AF_INET6) + if err != nil { + // TODO: what if v6 unavailable? + return err + } + + got := make([]*winipcfg.RouteData, 0, len(routes4)) + for _, r := range routes4 { + got = append(got, &winipcfg.RouteData{ + Destination: r.DestinationPrefix.IPNet(), + NextHop: r.NextHop.IP(), + Metric: r.Metric, + }) + } + for _, r := range routes6 { got = append(got, &winipcfg.RouteData{ Destination: r.DestinationPrefix.IPNet(), NextHop: r.NextHop.IP(),