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:
Brad Fitzpatrick
2022-07-25 20:55:44 -07:00
committed by Brad Fitzpatrick
parent 730ca4203c
commit 6a396731eb
84 changed files with 401 additions and 355 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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)
}

View File

@@ -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,