From 0015b7e71a4c9ab92a378347a35ecd0eabe2c211 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 24 Jan 2020 20:26:43 +0100 Subject: tunnel: deduplicate addresses from config Windows doesn't like it when passing these off to its config. Reported-by: Jonathan Tooker Signed-off-by: Jason A. Donenfeld --- conf/config.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'conf/config.go') 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] + } +} -- cgit v1.2.3-59-g8ed1b