diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-02-22 15:35:51 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-02-22 15:35:51 +0100 |
commit | 8eebce593da39f37620658772a00045ab18ac865 (patch) | |
tree | d8560442c7ff507d8a6623ccfffe6bff17a0d2fc | |
parent | tunnel: new bind object handling (diff) | |
download | wireguard-windows-8eebce593da39f37620658772a00045ab18ac865.tar.xz wireguard-windows-8eebce593da39f37620658772a00045ab18ac865.zip |
tunnel: fix sorting cascade in address config
Reported-by: Tbolp <tbolp@qq.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | tunnel/addressconfig.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/tunnel/addressconfig.go b/tunnel/addressconfig.go index a61905ea..44bfd8ae 100644 --- a/tunnel/addressconfig.go +++ b/tunnel/addressconfig.go @@ -114,10 +114,19 @@ func configureInterface(family winipcfg.AddressFamily, conf *conf.Config, tun *t deduplicatedRoutes := make([]*winipcfg.RouteData, 0, len(routes)) sort.Slice(routes, func(i, j int) bool { - return routes[i].Metric < routes[j].Metric || - bytes.Compare(routes[i].NextHop, routes[j].NextHop) == -1 || - bytes.Compare(routes[i].Destination.IP, routes[j].Destination.IP) == -1 || - bytes.Compare(routes[i].Destination.Mask, routes[j].Destination.Mask) == -1 + if routes[i].Metric != routes[j].Metric { + return routes[i].Metric < routes[j].Metric + } + if c := bytes.Compare(routes[i].NextHop, routes[j].NextHop); c != 0 { + return c < 0 + } + if c := bytes.Compare(routes[i].Destination.IP, routes[j].Destination.IP); c != 0 { + return c < 0 + } + if c := bytes.Compare(routes[i].Destination.Mask, routes[j].Destination.Mask); c != 0 { + return c < 0 + } + return false }) for i := 0; i < len(routes); i++ { if i > 0 && routes[i].Metric == routes[i-1].Metric && |