aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-01-24 20:26:43 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-01-24 20:29:02 +0100
commitef8d4f03bbb6e407bc4470b2134a9ab374155633 (patch)
treeac925174d69e2077ca166f938de2a5e397f29228
parentversion: bump (diff)
downloadwireguard-windows-ef8d4f03bbb6e407bc4470b2134a9ab374155633.tar.xz
wireguard-windows-ef8d4f03bbb6e407bc4470b2134a9ab374155633.zip
tunnel: deduplicate addresses from config
Windows doesn't like it when passing these off to its config. Reported-by: Jonathan Tooker <jonathan.tooker@netprotect.com>
-rw-r--r--conf/config.go43
-rw-r--r--tunnel/service.go1
2 files changed, 44 insertions, 0 deletions
diff --git a/conf/config.go b/conf/config.go
index 5b3496b6..a84dc418 100644
--- a/conf/config.go
+++ b/conf/config.go
@@ -196,3 +196,46 @@ func (b Bytes) String() string {
}
return fmt.Sprintf("%.2f TiB", float64(b)/(1024*1024*1024)/1024)
}
+
+func (conf *Config) DeduplicateNetworkEntries() {
+ m := make(map[string]bool, len(conf.Interface.Addresses))
+ i := 0
+ for _, addr := range conf.Interface.Addresses {
+ s := addr.String()
+ if m[s] {
+ continue
+ }
+ m[s] = true
+ conf.Interface.Addresses[i] = addr
+ i++
+ }
+ conf.Interface.Addresses = conf.Interface.Addresses[:i]
+
+ m = make(map[string]bool, len(conf.Interface.DNS))
+ i = 0
+ for _, addr := range conf.Interface.DNS {
+ s := addr.String()
+ if m[s] {
+ continue
+ }
+ m[s] = true
+ conf.Interface.DNS[i] = addr
+ i++
+ }
+ conf.Interface.DNS = conf.Interface.DNS[:i]
+
+ for _, peer := range conf.Peers {
+ m = make(map[string]bool, len(peer.AllowedIPs))
+ i = 0
+ for _, addr := range peer.AllowedIPs {
+ s := addr.String()
+ if m[s] {
+ continue
+ }
+ m[s] = true
+ peer.AllowedIPs[i] = addr
+ i++
+ }
+ peer.AllowedIPs = peer.AllowedIPs[:i]
+ }
+}
diff --git a/tunnel/service.go b/tunnel/service.go
index 8bd981d6..e535894b 100644
--- a/tunnel/service.go
+++ b/tunnel/service.go
@@ -118,6 +118,7 @@ func (service *tunnelService) Execute(args []string, r <-chan svc.ChangeRequest,
serviceError = services.ErrorLoadConfiguration
return
}
+ conf.DeduplicateNetworkEntries()
err = CopyConfigOwnerToIPCSecurityDescriptor(service.Path)
if err != nil {
serviceError = services.ErrorLoadConfiguration