mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-23 03:17:43 +00:00
all: use various net/netip parse funcs directly
Mechanical change with perl+goimports. Changed {Must,}Parse{IP,IPPrefix,IPPort} to their netip variants, then goimports -d . Finally, removed the net/netaddr wrappers, to prevent future use. Updates #5162 Change-Id: I59c0e38b5fbca5a935d701645789cddf3d7863ad Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
730ca4203c
commit
6a396731eb
@@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net/netip"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -81,7 +82,7 @@ func testDirect(t *testing.T, fs wholeFileFS) {
|
||||
|
||||
m := directManager{logf: t.Logf, fs: fs}
|
||||
if err := m.SetDNS(OSConfig{
|
||||
Nameservers: []netaddr.IP{netaddr.MustParseIP("8.8.8.8"), netaddr.MustParseIP("8.8.4.4")},
|
||||
Nameservers: []netaddr.IP{netip.MustParseAddr("8.8.8.8"), netip.MustParseAddr("8.8.4.4")},
|
||||
SearchDomains: []dnsname.FQDN{"ts.net.", "ts-dns.test."},
|
||||
MatchDomains: []dnsname.FQDN{"ignored."},
|
||||
}); err != nil {
|
||||
@@ -108,7 +109,7 @@ search ts.net ts-dns.test
|
||||
assertBaseState(t)
|
||||
|
||||
// Test that Close cleans up resolv.conf.
|
||||
if err := m.SetDNS(OSConfig{Nameservers: []netaddr.IP{netaddr.MustParseIP("8.8.8.8")}}); err != nil {
|
||||
if err := m.SetDNS(OSConfig{Nameservers: []netaddr.IP{netip.MustParseAddr("8.8.8.8")}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := m.Close(); err != nil {
|
||||
@@ -150,21 +151,21 @@ func TestReadResolve(t *testing.T) {
|
||||
{in: `nameserver 192.168.0.100`,
|
||||
want: OSConfig{
|
||||
Nameservers: []netaddr.IP{
|
||||
netaddr.MustParseIP("192.168.0.100"),
|
||||
netip.MustParseAddr("192.168.0.100"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{in: `nameserver 192.168.0.100 # comment`,
|
||||
want: OSConfig{
|
||||
Nameservers: []netaddr.IP{
|
||||
netaddr.MustParseIP("192.168.0.100"),
|
||||
netip.MustParseAddr("192.168.0.100"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{in: `nameserver 192.168.0.100#`,
|
||||
want: OSConfig{
|
||||
Nameservers: []netaddr.IP{
|
||||
netaddr.MustParseIP("192.168.0.100"),
|
||||
netip.MustParseAddr("192.168.0.100"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@@ -5,6 +5,7 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -425,14 +426,14 @@ func TestManager(t *testing.T) {
|
||||
|
||||
func mustIPs(strs ...string) (ret []netaddr.IP) {
|
||||
for _, s := range strs {
|
||||
ret = append(ret, netaddr.MustParseIP(s))
|
||||
ret = append(ret, netip.MustParseAddr(s))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func mustIPPs(strs ...string) (ret []netaddr.IPPort) {
|
||||
for _, s := range strs {
|
||||
ret = append(ret, netaddr.MustParseIPPort(s))
|
||||
ret = append(ret, netip.MustParseAddrPort(s))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
@@ -459,7 +460,7 @@ func hosts(strs ...string) (ret map[dnsname.FQDN][]netaddr.IP) {
|
||||
var key dnsname.FQDN
|
||||
ret = map[dnsname.FQDN][]netaddr.IP{}
|
||||
for _, s := range strs {
|
||||
if ip, err := netaddr.ParseIP(s); err == nil {
|
||||
if ip, err := netip.ParseAddr(s); err == nil {
|
||||
if key == "" {
|
||||
panic("IP provided before name")
|
||||
}
|
||||
@@ -479,7 +480,7 @@ func hostsR(strs ...string) (ret map[dnsname.FQDN][]dnstype.Resolver) {
|
||||
var key dnsname.FQDN
|
||||
ret = map[dnsname.FQDN][]dnstype.Resolver{}
|
||||
for _, s := range strs {
|
||||
if ip, err := netaddr.ParseIP(s); err == nil {
|
||||
if ip, err := netip.ParseAddr(s); err == nil {
|
||||
if key == "" {
|
||||
panic("IP provided before name")
|
||||
}
|
||||
@@ -504,12 +505,12 @@ func upstreams(strs ...string) (ret map[dnsname.FQDN][]*dnstype.Resolver) {
|
||||
panic("IPPort provided before suffix")
|
||||
}
|
||||
ret[key] = nil
|
||||
} else if ipp, err := netaddr.ParseIPPort(s); err == nil {
|
||||
} else if ipp, err := netip.ParseAddrPort(s); err == nil {
|
||||
if key == "" {
|
||||
panic("IPPort provided before suffix")
|
||||
}
|
||||
ret[key] = append(ret[key], &dnstype.Resolver{Addr: ipp.String()})
|
||||
} else if _, err := netaddr.ParseIP(s); err == nil {
|
||||
} else if _, err := netip.ParseAddr(s); err == nil {
|
||||
if key == "" {
|
||||
panic("IPPort provided before suffix")
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ package dns
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"os/exec"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -422,9 +423,9 @@ func (m windowsManager) getBasePrimaryResolver() (resolvers []netaddr.IP, err er
|
||||
}
|
||||
|
||||
var siteLocalResolvers = []netaddr.IP{
|
||||
netaddr.MustParseIP("fec0:0:0:ffff::1"),
|
||||
netaddr.MustParseIP("fec0:0:0:ffff::2"),
|
||||
netaddr.MustParseIP("fec0:0:0:ffff::3"),
|
||||
netip.MustParseAddr("fec0:0:0:ffff::1"),
|
||||
netip.MustParseAddr("fec0:0:0:ffff::2"),
|
||||
netip.MustParseAddr("fec0:0:0:ffff::3"),
|
||||
}
|
||||
|
||||
func isWindows10OrBetter() bool {
|
||||
|
@@ -8,6 +8,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/netip"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -91,7 +92,7 @@ func TestManagerWindowsGPMove(t *testing.T) {
|
||||
// Upon initialization of cfg, we should not have any NRPT rules
|
||||
ensureNoRules(t)
|
||||
|
||||
resolvers := []netaddr.IP{netaddr.MustParseIP("1.1.1.1")}
|
||||
resolvers := []netaddr.IP{netip.MustParseAddr("1.1.1.1")}
|
||||
domains := genRandomSubdomains(t, 1)
|
||||
|
||||
// 1. Populate local NRPT
|
||||
@@ -215,7 +216,7 @@ func runTest(t *testing.T, isLocal bool) {
|
||||
// Upon initialization of cfg, we should not have any NRPT rules
|
||||
ensureNoRules(t)
|
||||
|
||||
resolvers := []netaddr.IP{netaddr.MustParseIP("1.1.1.1")}
|
||||
resolvers := []netaddr.IP{netip.MustParseAddr("1.1.1.1")}
|
||||
|
||||
domains := genRandomSubdomains(t, 2*nrptMaxDomainsPerRule+1)
|
||||
|
||||
|
@@ -10,6 +10,7 @@ package dns
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
@@ -312,7 +313,7 @@ func (m *nmManager) GetBaseConfig() (OSConfig, error) {
|
||||
if v, ok := cfg["nameservers"]; ok {
|
||||
if ips, ok := v.Value().([]string); ok {
|
||||
for _, s := range ips {
|
||||
ip, err := netaddr.ParseIP(s)
|
||||
ip, err := netip.ParseAddr(s)
|
||||
if err != nil {
|
||||
// hmm, what do? Shouldn't really happen.
|
||||
continue
|
||||
|
@@ -7,6 +7,7 @@
|
||||
package publicdns
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"sync"
|
||||
|
||||
"tailscale.com/net/netaddr"
|
||||
@@ -45,7 +46,7 @@ func DoHV6(base string) (ip netaddr.IP, ok bool) {
|
||||
// addDoH parses a given well-formed ip string into a netaddr.IP type and
|
||||
// adds it to both knownDoH and dohIPsOFBase maps.
|
||||
func addDoH(ipStr, base string) {
|
||||
ip := netaddr.MustParseIP(ipStr)
|
||||
ip := netip.MustParseAddr(ipStr)
|
||||
knownDoH[ip] = base
|
||||
dohIPsOfBase[base] = append(dohIPsOfBase[base], ip)
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@
|
||||
package publicdns
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/net/netaddr"
|
||||
@@ -26,8 +27,8 @@ func TestDohV6(t *testing.T) {
|
||||
firstIP netaddr.IP
|
||||
want bool
|
||||
}{
|
||||
{"https://cloudflare-dns.com/dns-query", netaddr.MustParseIP("2606:4700:4700::1111"), true},
|
||||
{"https://dns.google/dns-query", netaddr.MustParseIP("2001:4860:4860::8888"), true},
|
||||
{"https://cloudflare-dns.com/dns-query", netip.MustParseAddr("2606:4700:4700::1111"), true},
|
||||
{"https://dns.google/dns-query", netip.MustParseAddr("2001:4860:4860::8888"), true},
|
||||
{"bogus", netaddr.IP{}, false},
|
||||
}
|
||||
for _, test := range tests {
|
||||
|
@@ -16,6 +16,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/netip"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -74,7 +75,7 @@ func Parse(r io.Reader) (*Config, error) {
|
||||
if len(nameserver) == len(s) {
|
||||
return nil, fmt.Errorf("missing space after \"nameserver\" in %q", line)
|
||||
}
|
||||
ip, err := netaddr.ParseIP(nameserver)
|
||||
ip, err := netip.ParseAddr(nameserver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@
|
||||
package resolvconffile
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -22,21 +23,21 @@ func TestParse(t *testing.T) {
|
||||
{in: `nameserver 192.168.0.100`,
|
||||
want: &Config{
|
||||
Nameservers: []netaddr.IP{
|
||||
netaddr.MustParseIP("192.168.0.100"),
|
||||
netip.MustParseAddr("192.168.0.100"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{in: `nameserver 192.168.0.100 # comment`,
|
||||
want: &Config{
|
||||
Nameservers: []netaddr.IP{
|
||||
netaddr.MustParseIP("192.168.0.100"),
|
||||
netip.MustParseAddr("192.168.0.100"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{in: `nameserver 192.168.0.100#`,
|
||||
want: &Config{
|
||||
Nameservers: []netaddr.IP{
|
||||
netaddr.MustParseIP("192.168.0.100"),
|
||||
netip.MustParseAddr("192.168.0.100"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@@ -670,7 +670,7 @@ func (r *Resolver) parseViaDomain(domain dnsname.FQDN, typ dns.Type) (netaddr.IP
|
||||
ip4Str = fqdn[:lastDot]
|
||||
}
|
||||
|
||||
ip4, err := netaddr.ParseIP(ip4Str)
|
||||
ip4, err := netip.ParseAddr(ip4Str)
|
||||
if err != nil {
|
||||
return netaddr.IP{}, false // badly formed, dont respond
|
||||
}
|
||||
@@ -1068,7 +1068,7 @@ func rawNameToLower(name []byte) string {
|
||||
// 1.2.3.4
|
||||
func rdnsNameToIPv4(name dnsname.FQDN) (ip netaddr.IP, ok bool) {
|
||||
s := strings.TrimSuffix(name.WithTrailingDot(), rdnsv4Suffix)
|
||||
ip, err := netaddr.ParseIP(s)
|
||||
ip, err := netip.ParseAddr(s)
|
||||
if err != nil {
|
||||
return netaddr.IP{}, false
|
||||
}
|
||||
@@ -1196,7 +1196,7 @@ func unARPA(a string) (ipStr string, ok bool) {
|
||||
if strings.HasSuffix(a, suf4) {
|
||||
s := strings.TrimSuffix(a, suf4)
|
||||
// Parse and reverse octets.
|
||||
ip, err := netaddr.ParseIP(s)
|
||||
ip, err := netip.ParseAddr(s)
|
||||
if err != nil || !ip.Is4() {
|
||||
return "", false
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/netip"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@@ -32,13 +33,13 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
testipv4 = netaddr.MustParseIP("1.2.3.4")
|
||||
testipv6 = netaddr.MustParseIP("0001:0203:0405:0607:0809:0a0b:0c0d:0e0f")
|
||||
testipv4 = netip.MustParseAddr("1.2.3.4")
|
||||
testipv6 = netip.MustParseAddr("0001:0203:0405:0607:0809:0a0b:0c0d:0e0f")
|
||||
|
||||
testipv4Arpa = dnsname.FQDN("4.3.2.1.in-addr.arpa.")
|
||||
testipv6Arpa = dnsname.FQDN("f.0.e.0.d.0.c.0.b.0.a.0.9.0.8.0.7.0.6.0.5.0.4.0.3.0.2.0.1.0.0.0.ip6.arpa.")
|
||||
|
||||
magicDNSv4Port = netaddr.MustParseIPPort("100.100.100.100:53")
|
||||
magicDNSv4Port = netip.MustParseAddrPort("100.100.100.100:53")
|
||||
)
|
||||
|
||||
var dnsCfg = Config{
|
||||
@@ -237,7 +238,7 @@ func syncRespond(r *Resolver, query []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
func mustIP(str string) netaddr.IP {
|
||||
ip, err := netaddr.ParseIP(str)
|
||||
ip, err := netip.ParseAddr(str)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -342,11 +343,11 @@ func TestResolveLocal(t *testing.T) {
|
||||
{"mx-nxdomain", "test3.ipn.dev.", dns.TypeMX, netaddr.IP{}, dns.RCodeNameError},
|
||||
{"ns-nxdomain", "test3.ipn.dev.", dns.TypeNS, netaddr.IP{}, dns.RCodeNameError},
|
||||
{"onion-domain", "footest.onion.", dns.TypeA, netaddr.IP{}, dns.RCodeNameError},
|
||||
{"magicdns", dnsSymbolicFQDN, dns.TypeA, netaddr.MustParseIP("100.100.100.100"), dns.RCodeSuccess},
|
||||
{"via_hex", dnsname.FQDN("via-0xff.1.2.3.4."), dns.TypeAAAA, netaddr.MustParseIP("fd7a:115c:a1e0:b1a:0:ff:1.2.3.4"), dns.RCodeSuccess},
|
||||
{"via_dec", dnsname.FQDN("via-1.10.0.0.1."), dns.TypeAAAA, netaddr.MustParseIP("fd7a:115c:a1e0:b1a:0:1:10.0.0.1"), dns.RCodeSuccess},
|
||||
{"x_via_hex", dnsname.FQDN("4.3.2.1.via-0xff."), dns.TypeAAAA, netaddr.MustParseIP("fd7a:115c:a1e0:b1a:0:ff:4.3.2.1"), dns.RCodeSuccess},
|
||||
{"x_via_dec", dnsname.FQDN("1.0.0.10.via-1."), dns.TypeAAAA, netaddr.MustParseIP("fd7a:115c:a1e0:b1a:0:1:1.0.0.10"), dns.RCodeSuccess},
|
||||
{"magicdns", dnsSymbolicFQDN, dns.TypeA, netip.MustParseAddr("100.100.100.100"), dns.RCodeSuccess},
|
||||
{"via_hex", dnsname.FQDN("via-0xff.1.2.3.4."), dns.TypeAAAA, netip.MustParseAddr("fd7a:115c:a1e0:b1a:0:ff:1.2.3.4"), dns.RCodeSuccess},
|
||||
{"via_dec", dnsname.FQDN("via-1.10.0.0.1."), dns.TypeAAAA, netip.MustParseAddr("fd7a:115c:a1e0:b1a:0:1:10.0.0.1"), dns.RCodeSuccess},
|
||||
{"x_via_hex", dnsname.FQDN("4.3.2.1.via-0xff."), dns.TypeAAAA, netip.MustParseAddr("fd7a:115c:a1e0:b1a:0:ff:4.3.2.1"), dns.RCodeSuccess},
|
||||
{"x_via_dec", dnsname.FQDN("1.0.0.10.via-1."), dns.TypeAAAA, netip.MustParseAddr("fd7a:115c:a1e0:b1a:0:1:1.0.0.10"), dns.RCodeSuccess},
|
||||
{"via_invalid", dnsname.FQDN("via-."), dns.TypeAAAA, netaddr.IP{}, dns.RCodeRefused},
|
||||
{"via_invalid_2", dnsname.FQDN("2.3.4.5.via-."), dns.TypeAAAA, netaddr.IP{}, dns.RCodeRefused},
|
||||
}
|
||||
@@ -644,8 +645,8 @@ func TestDelegate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDelegateSplitRoute(t *testing.T) {
|
||||
test4 := netaddr.MustParseIP("2.3.4.5")
|
||||
test6 := netaddr.MustParseIP("ff::1")
|
||||
test4 := netip.MustParseAddr("2.3.4.5")
|
||||
test6 := netip.MustParseAddr("ff::1")
|
||||
|
||||
server1 := serveDNS(t, "127.0.0.1:0",
|
||||
"test.site.", resolveToIP(testipv4, testipv6, "dns.test.site."))
|
||||
@@ -1048,16 +1049,16 @@ func TestHandleExitNodeDNSQueryWithNetPkg(t *testing.T) {
|
||||
dnsHandler(),
|
||||
|
||||
"one-a.test.",
|
||||
dnsHandler(netaddr.MustParseIP("1.2.3.4")),
|
||||
dnsHandler(netip.MustParseAddr("1.2.3.4")),
|
||||
|
||||
"two-a.test.",
|
||||
dnsHandler(netaddr.MustParseIP("1.2.3.4"), netaddr.MustParseIP("5.6.7.8")),
|
||||
dnsHandler(netip.MustParseAddr("1.2.3.4"), netip.MustParseAddr("5.6.7.8")),
|
||||
|
||||
"one-aaaa.test.",
|
||||
dnsHandler(netaddr.MustParseIP("1::2")),
|
||||
dnsHandler(netip.MustParseAddr("1::2")),
|
||||
|
||||
"two-aaaa.test.",
|
||||
dnsHandler(netaddr.MustParseIP("1::2"), netaddr.MustParseIP("3::4")),
|
||||
dnsHandler(netip.MustParseAddr("1::2"), netip.MustParseAddr("3::4")),
|
||||
|
||||
"nx-domain.test.",
|
||||
resolveToNXDOMAIN,
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -42,7 +43,7 @@ func TestDialCall_DNSWasTrustworthy(t *testing.T) {
|
||||
ip netaddr.IP // IP we pretended to dial
|
||||
err error // the dial error or nil for success
|
||||
}
|
||||
mustIP := netaddr.MustParseIP
|
||||
mustIP := netip.MustParseAddr
|
||||
errFail := errors.New("some connect failure")
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -90,7 +91,7 @@ func TestDialCall_DNSWasTrustworthy(t *testing.T) {
|
||||
|
||||
func TestDialCall_uniqueIPs(t *testing.T) {
|
||||
dc := &dialCall{}
|
||||
mustIP := netaddr.MustParseIP
|
||||
mustIP := netip.MustParseAddr
|
||||
errFail := errors.New("some connect failure")
|
||||
dc.noteDialResult(mustIP("2003::1"), errFail)
|
||||
dc.noteDialResult(mustIP("2003::2"), errFail)
|
||||
@@ -116,10 +117,10 @@ func TestResolverAllHostStaticResult(t *testing.T) {
|
||||
r := &Resolver{
|
||||
SingleHost: "foo.bar",
|
||||
SingleHostStaticResult: []netaddr.IP{
|
||||
netaddr.MustParseIP("2001:4860:4860::8888"),
|
||||
netaddr.MustParseIP("2001:4860:4860::8844"),
|
||||
netaddr.MustParseIP("8.8.8.8"),
|
||||
netaddr.MustParseIP("8.8.4.4"),
|
||||
netip.MustParseAddr("2001:4860:4860::8888"),
|
||||
netip.MustParseAddr("2001:4860:4860::8844"),
|
||||
netip.MustParseAddr("8.8.8.8"),
|
||||
netip.MustParseAddr("8.8.4.4"),
|
||||
},
|
||||
}
|
||||
ip4, ip6, allIPs, err := r.LookupIP(context.Background(), "foo.bar")
|
||||
|
@@ -18,6 +18,7 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
@@ -29,7 +30,7 @@ import (
|
||||
)
|
||||
|
||||
func Lookup(ctx context.Context, host string) ([]netaddr.IP, error) {
|
||||
if ip, err := netaddr.ParseIP(host); err == nil && ip.IsValid() {
|
||||
if ip, err := netip.ParseAddr(host); err == nil && ip.IsValid() {
|
||||
return []netaddr.IP{ip}, nil
|
||||
}
|
||||
|
||||
@@ -42,10 +43,10 @@ func Lookup(ctx context.Context, host string) ([]netaddr.IP, error) {
|
||||
var cands4, cands6 []nameIP
|
||||
for _, dr := range dm.Regions {
|
||||
for _, n := range dr.Nodes {
|
||||
if ip, err := netaddr.ParseIP(n.IPv4); err == nil {
|
||||
if ip, err := netip.ParseAddr(n.IPv4); err == nil {
|
||||
cands4 = append(cands4, nameIP{n.HostName, ip})
|
||||
}
|
||||
if ip, err := netaddr.ParseIP(n.IPv6); err == nil {
|
||||
if ip, err := netip.ParseAddr(n.IPv6); err == nil {
|
||||
cands6 = append(cands6, nameIP{n.HostName, ip})
|
||||
}
|
||||
}
|
||||
|
@@ -5,19 +5,19 @@
|
||||
package flowtrack
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/net/netaddr"
|
||||
"tailscale.com/tstest"
|
||||
)
|
||||
|
||||
func TestCache(t *testing.T) {
|
||||
c := &Cache{MaxEntries: 2}
|
||||
|
||||
k1 := Tuple{Src: netaddr.MustParseIPPort("1.1.1.1:1"), Dst: netaddr.MustParseIPPort("1.1.1.1:1")}
|
||||
k2 := Tuple{Src: netaddr.MustParseIPPort("1.1.1.1:1"), Dst: netaddr.MustParseIPPort("2.2.2.2:2")}
|
||||
k3 := Tuple{Src: netaddr.MustParseIPPort("1.1.1.1:1"), Dst: netaddr.MustParseIPPort("3.3.3.3:3")}
|
||||
k4 := Tuple{Src: netaddr.MustParseIPPort("1.1.1.1:1"), Dst: netaddr.MustParseIPPort("4.4.4.4:4")}
|
||||
k1 := Tuple{Src: netip.MustParseAddrPort("1.1.1.1:1"), Dst: netip.MustParseAddrPort("1.1.1.1:1")}
|
||||
k2 := Tuple{Src: netip.MustParseAddrPort("1.1.1.1:1"), Dst: netip.MustParseAddrPort("2.2.2.2:2")}
|
||||
k3 := Tuple{Src: netip.MustParseAddrPort("1.1.1.1:1"), Dst: netip.MustParseAddrPort("3.3.3.3:3")}
|
||||
k4 := Tuple{Src: netip.MustParseAddrPort("1.1.1.1:1"), Dst: netip.MustParseAddrPort("4.4.4.4:4")}
|
||||
|
||||
wantLen := func(want int) {
|
||||
t.Helper()
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -630,7 +631,7 @@ func isUsableV6(ip netaddr.IP) bool {
|
||||
}
|
||||
|
||||
var (
|
||||
v6Global1 = netaddr.MustParseIPPrefix("2000::/3")
|
||||
v6Global1 = netip.MustParsePrefix("2000::/3")
|
||||
)
|
||||
|
||||
// anyInterestingIP reports whether pfxs contains any IP that matches
|
||||
|
@@ -6,6 +6,7 @@ package interfaces
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/netip"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
@@ -72,7 +73,7 @@ func likelyHomeRouterIPDarwinExec() (ret netaddr.IP, ok bool) {
|
||||
if !mem.Contains(flagsm, mem.S("G")) {
|
||||
return nil
|
||||
}
|
||||
ip, err := netaddr.ParseIP(string(mem.Append(nil, ipm)))
|
||||
ip, err := netip.ParseAddr(string(mem.Append(nil, ipm)))
|
||||
if err == nil && ip.IsPrivate() {
|
||||
ret = ip
|
||||
// We've found what we're looking for.
|
||||
|
@@ -12,6 +12,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
@@ -125,7 +126,7 @@ func likelyHomeRouterIPAndroid() (ret netaddr.IP, ok bool) {
|
||||
return nil
|
||||
}
|
||||
ipb := line[:sp]
|
||||
if ip, err := netaddr.ParseIP(string(ipb)); err == nil && ip.Is4() {
|
||||
if ip, err := netip.ParseAddr(string(ipb)); err == nil && ip.Is4() {
|
||||
ret = ip
|
||||
log.Printf("interfaces: found Android default route %v", ip)
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ package interfaces
|
||||
import (
|
||||
"encoding/json"
|
||||
"net"
|
||||
"net/netip"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/net/netaddr"
|
||||
@@ -64,7 +65,7 @@ func TestIsUsableV6(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if got := isUsableV6(netaddr.MustParseIP(test.ip)); got != test.want {
|
||||
if got := isUsableV6(netip.MustParseAddr(test.ip)); got != test.want {
|
||||
t.Errorf("isUsableV6(%s) = %v, want %v", test.name, got, test.want)
|
||||
}
|
||||
}
|
||||
@@ -76,17 +77,17 @@ func TestStateEqualFilteredIPFilter(t *testing.T) {
|
||||
|
||||
s1 := &State{
|
||||
InterfaceIPs: map[string][]netaddr.IPPrefix{"x": {
|
||||
netaddr.MustParseIPPrefix("42.0.0.0/8"),
|
||||
netaddr.MustParseIPPrefix("169.254.0.0/16"), // link local unicast
|
||||
netip.MustParsePrefix("42.0.0.0/8"),
|
||||
netip.MustParsePrefix("169.254.0.0/16"), // link local unicast
|
||||
}},
|
||||
Interface: map[string]Interface{"x": {Interface: &net.Interface{Name: "x"}}},
|
||||
}
|
||||
|
||||
s2 := &State{
|
||||
InterfaceIPs: map[string][]netaddr.IPPrefix{"x": {
|
||||
netaddr.MustParseIPPrefix("42.0.0.0/8"),
|
||||
netaddr.MustParseIPPrefix("169.254.0.0/16"), // link local unicast
|
||||
netaddr.MustParseIPPrefix("127.0.0.0/8"), // loopback (added)
|
||||
netip.MustParsePrefix("42.0.0.0/8"),
|
||||
netip.MustParsePrefix("169.254.0.0/16"), // link local unicast
|
||||
netip.MustParsePrefix("127.0.0.0/8"), // loopback (added)
|
||||
}},
|
||||
Interface: map[string]Interface{"x": {Interface: &net.Interface{Name: "x"}}},
|
||||
}
|
||||
@@ -127,7 +128,7 @@ func TestStateString(t *testing.T) {
|
||||
},
|
||||
InterfaceIPs: map[string][]netaddr.IPPrefix{
|
||||
"eth0": []netaddr.IPPrefix{
|
||||
netaddr.MustParseIPPrefix("10.0.0.2/8"),
|
||||
netip.MustParsePrefix("10.0.0.2/8"),
|
||||
},
|
||||
},
|
||||
HaveV4: true,
|
||||
|
@@ -125,11 +125,3 @@ func FromStdAddr(stdIP net.IP, port int, zone string) (_ IPPort, ok bool) {
|
||||
}
|
||||
return netip.AddrPortFrom(ip, uint16(port)), true
|
||||
}
|
||||
|
||||
func ParseIP(s string) (IP, error) { return netip.ParseAddr(s) }
|
||||
func ParseIPPrefix(s string) (IPPrefix, error) { return netip.ParsePrefix(s) }
|
||||
func ParseIPPort(s string) (IPPort, error) { return netip.ParseAddrPort(s) }
|
||||
|
||||
func MustParseIP(s string) IP { return netip.MustParseAddr(s) }
|
||||
func MustParseIPPrefix(s string) IPPrefix { return netip.MustParsePrefix(s) }
|
||||
func MustParseIPPort(s string) IPPort { return netip.MustParseAddrPort(s) }
|
||||
|
@@ -467,7 +467,7 @@ func nodeMight6(n *tailcfg.DERPNode) bool {
|
||||
if n.IPv6 == "" {
|
||||
return true
|
||||
}
|
||||
ip, _ := netaddr.ParseIP(n.IPv6)
|
||||
ip, _ := netip.ParseAddr(n.IPv6)
|
||||
return ip.Is6()
|
||||
|
||||
}
|
||||
@@ -479,7 +479,7 @@ func nodeMight4(n *tailcfg.DERPNode) bool {
|
||||
if n.IPv4 == "" {
|
||||
return true
|
||||
}
|
||||
ip, _ := netaddr.ParseIP(n.IPv4)
|
||||
ip, _ := netip.ParseAddr(n.IPv4)
|
||||
return ip.Is4()
|
||||
}
|
||||
|
||||
@@ -1290,7 +1290,7 @@ func (c *Client) nodeAddr(ctx context.Context, n *tailcfg.DERPNode, proto probeP
|
||||
return
|
||||
}
|
||||
if n.STUNTestIP != "" {
|
||||
ip, err := netaddr.ParseIP(n.STUNTestIP)
|
||||
ip, err := netip.ParseAddr(n.STUNTestIP)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -1306,7 +1306,7 @@ func (c *Client) nodeAddr(ctx context.Context, n *tailcfg.DERPNode, proto probeP
|
||||
switch proto {
|
||||
case probeIPv4:
|
||||
if n.IPv4 != "" {
|
||||
ip, _ := netaddr.ParseIP(n.IPv4)
|
||||
ip, _ := netip.ParseAddr(n.IPv4)
|
||||
if !ip.Is4() {
|
||||
return
|
||||
}
|
||||
@@ -1314,7 +1314,7 @@ func (c *Client) nodeAddr(ctx context.Context, n *tailcfg.DERPNode, proto probeP
|
||||
}
|
||||
case probeIPv6:
|
||||
if n.IPv6 != "" {
|
||||
ip, _ := netaddr.ParseIP(n.IPv6)
|
||||
ip, _ := netip.ParseAddr(n.IPv6)
|
||||
if !ip.Is6() {
|
||||
return
|
||||
}
|
||||
|
@@ -17,8 +17,8 @@ package netns
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/netip"
|
||||
|
||||
"tailscale.com/net/netaddr"
|
||||
"tailscale.com/net/netknob"
|
||||
"tailscale.com/syncs"
|
||||
"tailscale.com/types/logger"
|
||||
@@ -100,6 +100,6 @@ func isLocalhost(addr string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
ip, _ := netaddr.ParseIP(host)
|
||||
ip, _ := netip.ParseAddr(host)
|
||||
return ip.IsLoopback()
|
||||
}
|
||||
|
@@ -5,17 +5,17 @@
|
||||
package packet
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/net/netaddr"
|
||||
"tailscale.com/types/ipproto"
|
||||
)
|
||||
|
||||
func TestICMPv6PingResponse(t *testing.T) {
|
||||
pingHdr := ICMP6Header{
|
||||
IP6Header: IP6Header{
|
||||
Src: netaddr.MustParseIP("1::1"),
|
||||
Dst: netaddr.MustParseIP("2::2"),
|
||||
Src: netip.MustParseAddr("1::1"),
|
||||
Dst: netip.MustParseAddr("2::2"),
|
||||
IPProto: ipproto.ICMPv6,
|
||||
},
|
||||
Type: ICMP6EchoRequest,
|
||||
|
@@ -6,6 +6,7 @@ package packet
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/netip"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -27,7 +28,7 @@ const (
|
||||
)
|
||||
|
||||
func mustIPPort(s string) netaddr.IPPort {
|
||||
ipp, err := netaddr.ParseIPPort(s)
|
||||
ipp, err := netip.ParseAddrPort(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@@ -5,9 +5,8 @@
|
||||
package packet
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/net/netaddr"
|
||||
)
|
||||
|
||||
func TestTailscaleRejectedHeader(t *testing.T) {
|
||||
@@ -17,10 +16,10 @@ func TestTailscaleRejectedHeader(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
h: TailscaleRejectedHeader{
|
||||
IPSrc: netaddr.MustParseIP("5.5.5.5"),
|
||||
IPDst: netaddr.MustParseIP("1.2.3.4"),
|
||||
Src: netaddr.MustParseIPPort("1.2.3.4:567"),
|
||||
Dst: netaddr.MustParseIPPort("5.5.5.5:443"),
|
||||
IPSrc: netip.MustParseAddr("5.5.5.5"),
|
||||
IPDst: netip.MustParseAddr("1.2.3.4"),
|
||||
Src: netip.MustParseAddrPort("1.2.3.4:567"),
|
||||
Dst: netip.MustParseAddrPort("5.5.5.5:443"),
|
||||
Proto: TCP,
|
||||
Reason: RejectedDueToACLs,
|
||||
},
|
||||
@@ -28,10 +27,10 @@ func TestTailscaleRejectedHeader(t *testing.T) {
|
||||
},
|
||||
{
|
||||
h: TailscaleRejectedHeader{
|
||||
IPSrc: netaddr.MustParseIP("2::2"),
|
||||
IPDst: netaddr.MustParseIP("1::1"),
|
||||
Src: netaddr.MustParseIPPort("[1::1]:567"),
|
||||
Dst: netaddr.MustParseIPPort("[2::2]:443"),
|
||||
IPSrc: netip.MustParseAddr("2::2"),
|
||||
IPDst: netip.MustParseAddr("1::1"),
|
||||
Src: netip.MustParseAddrPort("[1::1]:567"),
|
||||
Dst: netip.MustParseAddrPort("[2::2]:443"),
|
||||
Proto: UDP,
|
||||
Reason: RejectedDueToShieldsUp,
|
||||
},
|
||||
@@ -39,10 +38,10 @@ func TestTailscaleRejectedHeader(t *testing.T) {
|
||||
},
|
||||
{
|
||||
h: TailscaleRejectedHeader{
|
||||
IPSrc: netaddr.MustParseIP("2::2"),
|
||||
IPDst: netaddr.MustParseIP("1::1"),
|
||||
Src: netaddr.MustParseIPPort("[1::1]:567"),
|
||||
Dst: netaddr.MustParseIPPort("[2::2]:443"),
|
||||
IPSrc: netip.MustParseAddr("2::2"),
|
||||
IPDst: netip.MustParseAddr("1::1"),
|
||||
Src: netip.MustParseAddrPort("[1::1]:567"),
|
||||
Dst: netip.MustParseAddrPort("[2::2]:443"),
|
||||
Proto: UDP,
|
||||
Reason: RejectedDueToIPForwarding,
|
||||
MaybeBroken: true,
|
||||
|
@@ -6,6 +6,7 @@ package portmapper
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"net/netip"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/net/netaddr"
|
||||
@@ -21,7 +22,7 @@ func TestParsePCPMapResponse(t *testing.T) {
|
||||
if mapping == nil {
|
||||
t.Fatalf("got nil mapping when expected non-nil")
|
||||
}
|
||||
expectedAddr := netaddr.MustParseIPPort("135.180.175.246:1234")
|
||||
expectedAddr := netip.MustParseAddrPort("135.180.175.246:1234")
|
||||
if mapping.external != expectedAddr {
|
||||
t.Errorf("mismatched external address, got: %v, want: %v", mapping.external, expectedAddr)
|
||||
}
|
||||
|
@@ -397,7 +397,7 @@ func (c *Client) createMapping() {
|
||||
}
|
||||
|
||||
// wildcardIP is used when the previous external IP is not known for PCP port mapping.
|
||||
var wildcardIP = netaddr.MustParseIP("0.0.0.0")
|
||||
var wildcardIP = netip.MustParseAddr("0.0.0.0")
|
||||
|
||||
// createOrGetMapping either creates a new mapping or returns a cached
|
||||
// valid one.
|
||||
|
@@ -16,6 +16,7 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -170,7 +171,7 @@ func getUPnPClient(ctx context.Context, logf logger.Logf, gw netaddr.IP, meta uP
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ipp, err := netaddr.ParseIPPort(u.Host)
|
||||
ipp, err := netip.ParseAddrPort(u.Host)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unexpected host %q in %q", u.Host, meta.Location)
|
||||
}
|
||||
@@ -292,7 +293,7 @@ func (c *Client) getUPnPPortMapping(
|
||||
// TODO this doesn't seem right
|
||||
return netaddr.IPPort{}, false
|
||||
}
|
||||
externalIP, err := netaddr.ParseIP(extIP)
|
||||
externalIP, err := netip.ParseAddr(extIP)
|
||||
if err != nil {
|
||||
return netaddr.IPPort{}, false
|
||||
}
|
||||
|
@@ -9,12 +9,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/net/netaddr"
|
||||
"tailscale.com/net/stun"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/nettype"
|
||||
@@ -106,7 +106,7 @@ func DERPMapOf(stun ...string) *tailcfg.DERPMap {
|
||||
panic(fmt.Sprintf("bogus port %q in %q", portStr, hostPortStr))
|
||||
}
|
||||
var ipv4, ipv6 string
|
||||
ip, err := netaddr.ParseIP(host)
|
||||
ip, err := netip.ParseAddr(host)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("bogus non-IP STUN host %q in %q", host, hostPortStr))
|
||||
}
|
||||
|
@@ -143,7 +143,7 @@ func Tailscale6to4(ipv6 netaddr.IP) (netaddr.IP, bool) {
|
||||
|
||||
func mustPrefix(v *netaddr.IPPrefix, prefix string) {
|
||||
var err error
|
||||
*v, err = netaddr.ParseIPPrefix(prefix)
|
||||
*v, err = netip.ParsePrefix(prefix)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -253,8 +253,8 @@ func ContainsExitRoutes(rr []netaddr.IPPrefix) bool {
|
||||
}
|
||||
|
||||
var (
|
||||
allIPv4 = netaddr.MustParseIPPrefix("0.0.0.0/0")
|
||||
allIPv6 = netaddr.MustParseIPPrefix("::/0")
|
||||
allIPv4 = netip.MustParsePrefix("0.0.0.0/0")
|
||||
allIPv6 = netip.MustParsePrefix("::/0")
|
||||
)
|
||||
|
||||
// AllIPv4 returns 0.0.0.0/0.
|
||||
|
@@ -5,6 +5,7 @@
|
||||
package tsaddr
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/net/netaddr"
|
||||
@@ -52,30 +53,30 @@ func TestCGNATRange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewContainsIPFunc(t *testing.T) {
|
||||
f := NewContainsIPFunc([]netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.0.0.0/8")})
|
||||
if f(netaddr.MustParseIP("8.8.8.8")) {
|
||||
f := NewContainsIPFunc([]netaddr.IPPrefix{netip.MustParsePrefix("10.0.0.0/8")})
|
||||
if f(netip.MustParseAddr("8.8.8.8")) {
|
||||
t.Fatal("bad")
|
||||
}
|
||||
if !f(netaddr.MustParseIP("10.1.2.3")) {
|
||||
if !f(netip.MustParseAddr("10.1.2.3")) {
|
||||
t.Fatal("bad")
|
||||
}
|
||||
f = NewContainsIPFunc([]netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.1.2.3/32")})
|
||||
if !f(netaddr.MustParseIP("10.1.2.3")) {
|
||||
f = NewContainsIPFunc([]netaddr.IPPrefix{netip.MustParsePrefix("10.1.2.3/32")})
|
||||
if !f(netip.MustParseAddr("10.1.2.3")) {
|
||||
t.Fatal("bad")
|
||||
}
|
||||
f = NewContainsIPFunc([]netaddr.IPPrefix{
|
||||
netaddr.MustParseIPPrefix("10.1.2.3/32"),
|
||||
netaddr.MustParseIPPrefix("::2/128"),
|
||||
netip.MustParsePrefix("10.1.2.3/32"),
|
||||
netip.MustParsePrefix("::2/128"),
|
||||
})
|
||||
if !f(netaddr.MustParseIP("::2")) {
|
||||
if !f(netip.MustParseAddr("::2")) {
|
||||
t.Fatal("bad")
|
||||
}
|
||||
f = NewContainsIPFunc([]netaddr.IPPrefix{
|
||||
netaddr.MustParseIPPrefix("10.1.2.3/32"),
|
||||
netaddr.MustParseIPPrefix("10.1.2.4/32"),
|
||||
netaddr.MustParseIPPrefix("::2/128"),
|
||||
netip.MustParsePrefix("10.1.2.3/32"),
|
||||
netip.MustParsePrefix("10.1.2.4/32"),
|
||||
netip.MustParsePrefix("::2/128"),
|
||||
})
|
||||
if !f(netaddr.MustParseIP("10.1.2.4")) {
|
||||
if !f(netip.MustParseAddr("10.1.2.4")) {
|
||||
t.Fatal("bad")
|
||||
}
|
||||
}
|
||||
@@ -99,7 +100,7 @@ func TestUnmapVia(t *testing.T) {
|
||||
{"fd7a:115c:a1e0:b1b::bb:10.2.1.4", "fd7a:115c:a1e0:b1b:0:bb:a02:104"}, // "b1b",not "bia"
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := UnmapVia(netaddr.MustParseIP(tt.ip)).String(); got != tt.want {
|
||||
if got := UnmapVia(netip.MustParseAddr(tt.ip)).String(); got != tt.want {
|
||||
t.Errorf("for %q: got %q, want %q", tt.ip, got, tt.want)
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -68,7 +69,7 @@ func dnsMapFromNetworkMap(nm *netmap.NetworkMap) dnsMap {
|
||||
if rec.Type != "" {
|
||||
continue
|
||||
}
|
||||
ip, err := netaddr.ParseIP(rec.Value)
|
||||
ip, err := netip.ParseAddr(rec.Value)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -103,7 +104,7 @@ func (m dnsMap) resolveMemory(ctx context.Context, network, addr string) (_ neta
|
||||
// addr malformed or invalid port.
|
||||
return netaddr.IPPort{}, err
|
||||
}
|
||||
if ip, err := netaddr.ParseIP(host); err == nil {
|
||||
if ip, err := netip.ParseAddr(host); err == nil {
|
||||
// addr was literal ip:port.
|
||||
return netaddr.IPPortFrom(ip, port), nil
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@
|
||||
package tsdial
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -14,8 +15,8 @@ import (
|
||||
)
|
||||
|
||||
func TestDNSMapFromNetworkMap(t *testing.T) {
|
||||
pfx := netaddr.MustParseIPPrefix
|
||||
ip := netaddr.MustParseIP
|
||||
pfx := netip.MustParsePrefix
|
||||
ip := netip.MustParseAddr
|
||||
tests := []struct {
|
||||
name string
|
||||
nm *netmap.NetworkMap
|
||||
|
@@ -11,6 +11,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -330,7 +331,7 @@ func (d *Dialer) dialPeerAPI(ctx context.Context, network, addr string) (net.Con
|
||||
default:
|
||||
return nil, fmt.Errorf("peerAPI dial requires tcp; %q not supported", network)
|
||||
}
|
||||
ipp, err := netaddr.ParseIPPort(addr)
|
||||
ipp, err := netip.ParseAddrPort(addr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("peerAPI dial requires ip:port, not name resolution: %w", err)
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -28,11 +29,11 @@ import (
|
||||
)
|
||||
|
||||
func udp4(src, dst string, sport, dport uint16) []byte {
|
||||
sip, err := netaddr.ParseIP(src)
|
||||
sip, err := netip.ParseAddr(src)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
dip, err := netaddr.ParseIP(dst)
|
||||
dip, err := netip.ParseAddr(dst)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -49,11 +50,11 @@ func udp4(src, dst string, sport, dport uint16) []byte {
|
||||
}
|
||||
|
||||
func tcp4syn(src, dst string, sport, dport uint16) []byte {
|
||||
sip, err := netaddr.ParseIP(src)
|
||||
sip, err := netip.ParseAddr(src)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
dip, err := netaddr.ParseIP(dst)
|
||||
dip, err := netip.ParseAddr(dst)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -79,7 +80,7 @@ func tcp4syn(src, dst string, sport, dport uint16) []byte {
|
||||
func nets(nets ...string) (ret []netaddr.IPPrefix) {
|
||||
for _, s := range nets {
|
||||
if i := strings.IndexByte(s, '/'); i == -1 {
|
||||
ip, err := netaddr.ParseIP(s)
|
||||
ip, err := netip.ParseAddr(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -89,7 +90,7 @@ func nets(nets ...string) (ret []netaddr.IPPrefix) {
|
||||
}
|
||||
ret = append(ret, netaddr.IPPrefixFrom(ip, bits))
|
||||
} else {
|
||||
pfx, err := netaddr.ParseIPPrefix(s)
|
||||
pfx, err := netip.ParsePrefix(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -150,7 +151,7 @@ func setfilter(logf logger.Logf, tun *Wrapper) {
|
||||
{IPProto: protos, Srcs: nets("1.2.3.4"), Dsts: netports("5.6.7.8:98")},
|
||||
}
|
||||
var sb netipx.IPSetBuilder
|
||||
sb.AddPrefix(netaddr.MustParseIPPrefix("1.2.0.0/16"))
|
||||
sb.AddPrefix(netip.MustParsePrefix("1.2.0.0/16"))
|
||||
ipSet, _ := sb.IPSet()
|
||||
tun.SetFilter(filter.New(matches, ipSet, ipSet, nil, logf))
|
||||
}
|
||||
@@ -428,7 +429,7 @@ func TestAtomic64Alignment(t *testing.T) {
|
||||
func TestPeerAPIBypass(t *testing.T) {
|
||||
wrapperWithPeerAPI := &Wrapper{
|
||||
PeerAPIPort: func(ip netaddr.IP) (port uint16, ok bool) {
|
||||
if ip == netaddr.MustParseIP("100.64.1.2") {
|
||||
if ip == netip.MustParseAddr("100.64.1.2") {
|
||||
return 60000, true
|
||||
}
|
||||
return
|
||||
|
Reference in New Issue
Block a user