From e16f7e48a3f8eca4cdc55cc0fb41c51ef69760bc Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 9 May 2020 03:30:22 +0000 Subject: [PATCH] wgengine: simplify wgcfg.* to netaddr.* conversion. Signed-off-by: David Anderson --- wgengine/userspace.go | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/wgengine/userspace.go b/wgengine/userspace.go index 62dc165c5..53bb0b1dc 100644 --- a/wgengine/userspace.go +++ b/wgengine/userspace.go @@ -417,40 +417,22 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, dnsDomains []string, local func wgIPToNetaddr(ips []wgcfg.IP) (ret []netaddr.IP) { for _, ip := range ips { - stdip := ip.IP() - // Force IPv4 addresses into their 4-byte representation, - // because netaddr.FromStdIP will use whatever the underlying - // address encoding is - which can lead to creating a v6 - // mapped v4 address and breaking everything downstream that - // expects a regular IPv4. - if stdip4 := stdip.To4(); stdip4 != nil { - stdip = stdip4 - } - nip, ok := netaddr.FromStdIP(stdip) + nip, ok := netaddr.FromStdIP(ip.IP()) if !ok { panic(fmt.Sprintf("conversion of %s from wgcfg to netaddr IP failed", ip)) } - log.Println(nip) - ret = append(ret, nip) + ret = append(ret, nip.Unmap()) } return ret } func wgCIDRToNetaddr(cidrs []wgcfg.CIDR) (ret []netaddr.IPPrefix) { for _, cidr := range cidrs { - stdipnet := cidr.IPNet() - // Force IPv4 addresses into their 4-byte representation, - // because netaddr.FromStdIP will use whatever the underlying - // address encoding is - which can lead to creating a v6 - // mapped v4 address and breaking everything downstream that - // expects a regular IPv4. - if ip4 := stdipnet.IP.To4(); ip4 != nil { - stdipnet.IP = ip4 - } - ncidr, ok := netaddr.FromStdIPNet(stdipnet) + ncidr, ok := netaddr.FromStdIPNet(cidr.IPNet()) if !ok { panic(fmt.Sprintf("conversion of %s from wgcfg to netaddr IPNet failed", cidr)) } + ncidr.IP = ncidr.IP.Unmap() ret = append(ret, ncidr) } return ret