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>
pull/4637/merge
Brad Fitzpatrick 2 years ago committed by Brad Fitzpatrick
parent 730ca4203c
commit 6a396731eb

@ -60,7 +60,7 @@ type postRoutesParams struct {
} }
// SetRoutes updates the list of subnets that are enabled for a device. // SetRoutes updates the list of subnets that are enabled for a device.
// Subnets must be parsable by tailscale.com/net/netaddr.ParseIPPrefix. // Subnets must be parsable by net/netip.ParsePrefix.
// Subnets do not have to be currently advertised by a device, they may be pre-enabled. // Subnets do not have to be currently advertised by a device, they may be pre-enabled.
// Returns the updated list of enabled and advertised subnet routes in a *Routes object. // Returns the updated list of enabled and advertised subnet routes in a *Routes object.
func (c *Client) SetRoutes(ctx context.Context, deviceID string, subnets []netaddr.IPPrefix) (routes *Routes, err error) { func (c *Client) SetRoutes(ctx context.Context, deviceID string, subnets []netaddr.IPPrefix) (routes *Routes, err error) {

@ -9,6 +9,7 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"net/netip"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -153,9 +154,9 @@ func TestCheckForAccidentalSettingReverts(t *testing.T) {
CorpDNS: true, CorpDNS: true,
NetfilterMode: preftype.NetfilterOn, NetfilterMode: preftype.NetfilterOn,
AdvertiseRoutes: []netaddr.IPPrefix{ AdvertiseRoutes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.0.42.0/24"), netip.MustParsePrefix("10.0.42.0/24"),
netaddr.MustParseIPPrefix("0.0.0.0/0"), netip.MustParsePrefix("0.0.0.0/0"),
netaddr.MustParseIPPrefix("::/0"), netip.MustParsePrefix("::/0"),
}, },
}, },
want: accidentalUpPrefix + " --advertise-routes=10.0.42.0/24 --advertise-exit-node", want: accidentalUpPrefix + " --advertise-routes=10.0.42.0/24 --advertise-exit-node",
@ -169,9 +170,9 @@ func TestCheckForAccidentalSettingReverts(t *testing.T) {
CorpDNS: true, CorpDNS: true,
NetfilterMode: preftype.NetfilterOn, NetfilterMode: preftype.NetfilterOn,
AdvertiseRoutes: []netaddr.IPPrefix{ AdvertiseRoutes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.0.42.0/24"), netip.MustParsePrefix("10.0.42.0/24"),
netaddr.MustParseIPPrefix("0.0.0.0/0"), netip.MustParsePrefix("0.0.0.0/0"),
netaddr.MustParseIPPrefix("::/0"), netip.MustParsePrefix("::/0"),
}, },
}, },
want: "", want: "",
@ -185,9 +186,9 @@ func TestCheckForAccidentalSettingReverts(t *testing.T) {
CorpDNS: true, CorpDNS: true,
NetfilterMode: preftype.NetfilterOn, NetfilterMode: preftype.NetfilterOn,
AdvertiseRoutes: []netaddr.IPPrefix{ AdvertiseRoutes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.0.42.0/24"), netip.MustParsePrefix("10.0.42.0/24"),
netaddr.MustParseIPPrefix("0.0.0.0/0"), netip.MustParsePrefix("0.0.0.0/0"),
netaddr.MustParseIPPrefix("::/0"), netip.MustParsePrefix("::/0"),
}, },
}, },
want: "", want: "",
@ -213,7 +214,7 @@ func TestCheckForAccidentalSettingReverts(t *testing.T) {
NetfilterMode: preftype.NetfilterOn, NetfilterMode: preftype.NetfilterOn,
AdvertiseRoutes: []netaddr.IPPrefix{ AdvertiseRoutes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("1.2.0.0/16"), netip.MustParsePrefix("1.2.0.0/16"),
}, },
}, },
want: accidentalUpPrefix + " --advertise-exit-node --advertise-routes=1.2.0.0/16", want: accidentalUpPrefix + " --advertise-exit-node --advertise-routes=1.2.0.0/16",
@ -227,9 +228,9 @@ func TestCheckForAccidentalSettingReverts(t *testing.T) {
CorpDNS: true, CorpDNS: true,
NetfilterMode: preftype.NetfilterOn, NetfilterMode: preftype.NetfilterOn,
AdvertiseRoutes: []netaddr.IPPrefix{ AdvertiseRoutes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("0.0.0.0/0"), netip.MustParsePrefix("0.0.0.0/0"),
netaddr.MustParseIPPrefix("::/0"), netip.MustParsePrefix("::/0"),
netaddr.MustParseIPPrefix("1.2.0.0/16"), netip.MustParsePrefix("1.2.0.0/16"),
}, },
}, },
want: accidentalUpPrefix + " --advertise-exit-node --advertise-routes=1.2.0.0/16", want: accidentalUpPrefix + " --advertise-exit-node --advertise-routes=1.2.0.0/16",
@ -255,16 +256,16 @@ func TestCheckForAccidentalSettingReverts(t *testing.T) {
ControlURL: ipn.DefaultControlURL, ControlURL: ipn.DefaultControlURL,
RouteAll: true, RouteAll: true,
AllowSingleHosts: false, AllowSingleHosts: false,
ExitNodeIP: netaddr.MustParseIP("100.64.5.6"), ExitNodeIP: netip.MustParseAddr("100.64.5.6"),
CorpDNS: false, CorpDNS: false,
ShieldsUp: true, ShieldsUp: true,
AdvertiseTags: []string{"tag:foo", "tag:bar"}, AdvertiseTags: []string{"tag:foo", "tag:bar"},
Hostname: "myhostname", Hostname: "myhostname",
ForceDaemon: true, ForceDaemon: true,
AdvertiseRoutes: []netaddr.IPPrefix{ AdvertiseRoutes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.0.0.0/16"), netip.MustParsePrefix("10.0.0.0/16"),
netaddr.MustParseIPPrefix("0.0.0.0/0"), netip.MustParsePrefix("0.0.0.0/0"),
netaddr.MustParseIPPrefix("::/0"), netip.MustParsePrefix("::/0"),
}, },
NetfilterMode: preftype.NetfilterNoDivert, NetfilterMode: preftype.NetfilterNoDivert,
OperatorUser: "alice", OperatorUser: "alice",
@ -280,14 +281,14 @@ func TestCheckForAccidentalSettingReverts(t *testing.T) {
ControlURL: ipn.DefaultControlURL, ControlURL: ipn.DefaultControlURL,
RouteAll: true, RouteAll: true,
AllowSingleHosts: false, AllowSingleHosts: false,
ExitNodeIP: netaddr.MustParseIP("100.64.5.6"), ExitNodeIP: netip.MustParseAddr("100.64.5.6"),
CorpDNS: false, CorpDNS: false,
ShieldsUp: true, ShieldsUp: true,
AdvertiseTags: []string{"tag:foo", "tag:bar"}, AdvertiseTags: []string{"tag:foo", "tag:bar"},
Hostname: "myhostname", Hostname: "myhostname",
ForceDaemon: true, ForceDaemon: true,
AdvertiseRoutes: []netaddr.IPPrefix{ AdvertiseRoutes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.0.0.0/16"), netip.MustParsePrefix("10.0.0.0/16"),
}, },
NetfilterMode: preftype.NetfilterNoDivert, NetfilterMode: preftype.NetfilterNoDivert,
OperatorUser: "alice", OperatorUser: "alice",
@ -345,9 +346,9 @@ func TestCheckForAccidentalSettingReverts(t *testing.T) {
CorpDNS: true, CorpDNS: true,
NetfilterMode: preftype.NetfilterOn, NetfilterMode: preftype.NetfilterOn,
AdvertiseRoutes: []netaddr.IPPrefix{ AdvertiseRoutes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("0.0.0.0/0"), netip.MustParsePrefix("0.0.0.0/0"),
netaddr.MustParseIPPrefix("::/0"), netip.MustParsePrefix("::/0"),
netaddr.MustParseIPPrefix("1.2.0.0/16"), netip.MustParsePrefix("1.2.0.0/16"),
}, },
}, },
want: accidentalUpPrefix + " --operator=expbits --advertise-exit-node --advertise-routes=1.2.0.0/16", want: accidentalUpPrefix + " --operator=expbits --advertise-exit-node --advertise-routes=1.2.0.0/16",
@ -361,9 +362,9 @@ func TestCheckForAccidentalSettingReverts(t *testing.T) {
CorpDNS: true, CorpDNS: true,
NetfilterMode: preftype.NetfilterOn, NetfilterMode: preftype.NetfilterOn,
AdvertiseRoutes: []netaddr.IPPrefix{ AdvertiseRoutes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("0.0.0.0/0"), netip.MustParsePrefix("0.0.0.0/0"),
netaddr.MustParseIPPrefix("::/0"), netip.MustParsePrefix("::/0"),
netaddr.MustParseIPPrefix("1.2.0.0/16"), netip.MustParsePrefix("1.2.0.0/16"),
}, },
}, },
want: accidentalUpPrefix + " --advertise-routes=1.2.0.0/16 --operator=expbits --advertise-exit-node", want: accidentalUpPrefix + " --advertise-routes=1.2.0.0/16 --operator=expbits --advertise-exit-node",
@ -391,14 +392,14 @@ func TestCheckForAccidentalSettingReverts(t *testing.T) {
CorpDNS: true, CorpDNS: true,
NetfilterMode: preftype.NetfilterOn, NetfilterMode: preftype.NetfilterOn,
ExitNodeIP: netaddr.MustParseIP("100.64.5.4"), ExitNodeIP: netip.MustParseAddr("100.64.5.4"),
}, },
want: accidentalUpPrefix + " --hostname=foo --exit-node=100.64.5.4", want: accidentalUpPrefix + " --hostname=foo --exit-node=100.64.5.4",
}, },
{ {
name: "error_exit_node_omit_with_id_pref", name: "error_exit_node_omit_with_id_pref",
flags: []string{"--hostname=foo"}, flags: []string{"--hostname=foo"},
curExitNodeIP: netaddr.MustParseIP("100.64.5.7"), curExitNodeIP: netip.MustParseAddr("100.64.5.7"),
curPrefs: &ipn.Prefs{ curPrefs: &ipn.Prefs{
ControlURL: ipn.DefaultControlURL, ControlURL: ipn.DefaultControlURL,
AllowSingleHosts: true, AllowSingleHosts: true,
@ -412,7 +413,7 @@ func TestCheckForAccidentalSettingReverts(t *testing.T) {
{ {
name: "error_exit_node_and_allow_lan_omit_with_id_pref", // Isue 3480 name: "error_exit_node_and_allow_lan_omit_with_id_pref", // Isue 3480
flags: []string{"--hostname=foo"}, flags: []string{"--hostname=foo"},
curExitNodeIP: netaddr.MustParseIP("100.2.3.4"), curExitNodeIP: netip.MustParseAddr("100.2.3.4"),
curPrefs: &ipn.Prefs{ curPrefs: &ipn.Prefs{
ControlURL: ipn.DefaultControlURL, ControlURL: ipn.DefaultControlURL,
AllowSingleHosts: true, AllowSingleHosts: true,
@ -563,8 +564,8 @@ func TestPrefsFromUpArgs(t *testing.T) {
AllowSingleHosts: true, AllowSingleHosts: true,
CorpDNS: true, CorpDNS: true,
AdvertiseRoutes: []netaddr.IPPrefix{ AdvertiseRoutes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("0.0.0.0/0"), netip.MustParsePrefix("0.0.0.0/0"),
netaddr.MustParseIPPrefix("::/0"), netip.MustParsePrefix("::/0"),
}, },
NetfilterMode: preftype.NetfilterOn, NetfilterMode: preftype.NetfilterOn,
}, },
@ -631,7 +632,7 @@ func TestPrefsFromUpArgs(t *testing.T) {
exitNodeIP: "100.105.106.107", exitNodeIP: "100.105.106.107",
}, },
st: &ipnstate.Status{ st: &ipnstate.Status{
TailscaleIPs: []netaddr.IP{netaddr.MustParseIP("100.105.106.107")}, TailscaleIPs: []netaddr.IP{netip.MustParseAddr("100.105.106.107")},
}, },
wantErr: `cannot use 100.105.106.107 as an exit node as it is a local IP address to this machine; did you mean --advertise-exit-node?`, wantErr: `cannot use 100.105.106.107 as an exit node as it is a local IP address to this machine; did you mean --advertise-exit-node?`,
}, },
@ -672,7 +673,7 @@ func TestPrefsFromUpArgs(t *testing.T) {
WantRunning: true, WantRunning: true,
NoSNAT: true, NoSNAT: true,
AdvertiseRoutes: []netaddr.IPPrefix{ AdvertiseRoutes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("fd7a:115c:a1e0:b1a::bb:10.0.0.0/112"), netip.MustParsePrefix("fd7a:115c:a1e0:b1a::bb:10.0.0.0/112"),
}, },
}, },
}, },

@ -28,7 +28,6 @@ import (
"tailscale.com/control/controlhttp" "tailscale.com/control/controlhttp"
"tailscale.com/hostinfo" "tailscale.com/hostinfo"
"tailscale.com/ipn" "tailscale.com/ipn"
"tailscale.com/net/netaddr"
"tailscale.com/net/tsaddr" "tailscale.com/net/tsaddr"
"tailscale.com/paths" "tailscale.com/paths"
"tailscale.com/safesocket" "tailscale.com/safesocket"
@ -405,7 +404,7 @@ func runVia(ctx context.Context, args []string) error {
default: default:
return errors.New("expect either <site-id> <v4-cidr> or <v6-route>") return errors.New("expect either <site-id> <v4-cidr> or <v6-route>")
case 1: case 1:
ipp, err := netaddr.ParseIPPrefix(args[0]) ipp, err := netip.ParsePrefix(args[0])
if err != nil { if err != nil {
return err return err
} }
@ -430,7 +429,7 @@ func runVia(ctx context.Context, args []string) error {
if siteID > 0xff { if siteID > 0xff {
return fmt.Errorf("site-id values over 255 are currently reserved") return fmt.Errorf("site-id values over 255 are currently reserved")
} }
ipp, err := netaddr.ParseIPPrefix(args[1]) ipp, err := netip.ParsePrefix(args[1])
if err != nil { if err != nil {
return err return err
} }

@ -14,6 +14,7 @@ import (
"log" "log"
"mime" "mime"
"net/http" "net/http"
"net/netip"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -85,7 +86,7 @@ func runCp(ctx context.Context, args []string) error {
hadBrackets = true hadBrackets = true
target = strings.TrimSuffix(strings.TrimPrefix(target, "["), "]") target = strings.TrimSuffix(strings.TrimPrefix(target, "["), "]")
} }
if ip, err := netaddr.ParseIP(target); err == nil && ip.Is6() && !hadBrackets { if ip, err := netip.ParseAddr(target); err == nil && ip.Is6() && !hadBrackets {
return fmt.Errorf("an IPv6 literal must be written as [%s]", ip) return fmt.Errorf("an IPv6 literal must be written as [%s]", ip)
} else if hadBrackets && (err != nil || !ip.Is6()) { } else if hadBrackets && (err != nil || !ip.Is6()) {
return errors.New("unexpected brackets around target") return errors.New("unexpected brackets around target")
@ -168,7 +169,7 @@ func runCp(ctx context.Context, args []string) error {
} }
func getTargetStableID(ctx context.Context, ipStr string) (id tailcfg.StableNodeID, isOffline bool, err error) { func getTargetStableID(ctx context.Context, ipStr string) (id tailcfg.StableNodeID, isOffline bool, err error) {
ip, err := netaddr.ParseIP(ipStr) ip, err := netip.ParseAddr(ipStr)
if err != nil { if err != nil {
return "", false, err return "", false, err
} }

@ -9,10 +9,10 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"net/netip"
"github.com/peterbourgon/ff/v3/ffcli" "github.com/peterbourgon/ff/v3/ffcli"
"tailscale.com/ipn/ipnstate" "tailscale.com/ipn/ipnstate"
"tailscale.com/net/netaddr"
) )
var ipCmd = &ffcli.Command{ var ipCmd = &ffcli.Command{
@ -100,7 +100,7 @@ func runIP(ctx context.Context, args []string) error {
} }
func peerMatchingIP(st *ipnstate.Status, ipStr string) (ps *ipnstate.PeerStatus, ok bool) { func peerMatchingIP(st *ipnstate.Status, ipStr string) (ps *ipnstate.PeerStatus, ok bool) {
ip, err := netaddr.ParseIP(ipStr) ip, err := netip.ParseAddr(ipStr)
if err != nil { if err != nil {
return return
} }

@ -11,13 +11,13 @@ import (
"fmt" "fmt"
"log" "log"
"net" "net"
"net/netip"
"os" "os"
"strings" "strings"
"time" "time"
"github.com/peterbourgon/ff/v3/ffcli" "github.com/peterbourgon/ff/v3/ffcli"
"tailscale.com/ipn/ipnstate" "tailscale.com/ipn/ipnstate"
"tailscale.com/net/netaddr"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
) )
@ -116,7 +116,7 @@ func runPing(ctx context.Context, args []string) error {
for { for {
n++ n++
ctx, cancel := context.WithTimeout(ctx, pingArgs.timeout) ctx, cancel := context.WithTimeout(ctx, pingArgs.timeout)
pr, err := localClient.Ping(ctx, netaddr.MustParseIP(ip), pingType()) pr, err := localClient.Ping(ctx, netip.MustParseAddr(ip), pingType())
cancel() cancel()
if err != nil { if err != nil {
if errors.Is(err, context.DeadlineExceeded) { if errors.Is(err, context.DeadlineExceeded) {

@ -10,6 +10,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"log" "log"
"net/netip"
"os" "os"
"os/user" "os/user"
"path/filepath" "path/filepath"
@ -19,7 +20,6 @@ import (
"github.com/peterbourgon/ff/v3/ffcli" "github.com/peterbourgon/ff/v3/ffcli"
"tailscale.com/envknob" "tailscale.com/envknob"
"tailscale.com/ipn/ipnstate" "tailscale.com/ipn/ipnstate"
"tailscale.com/net/netaddr"
"tailscale.com/net/tsaddr" "tailscale.com/net/tsaddr"
"tailscale.com/version" "tailscale.com/version"
) )
@ -163,7 +163,7 @@ func nodeDNSNameFromArg(st *ipnstate.Status, arg string) (dnsName string, ok boo
if arg == "" { if arg == "" {
return return
} }
argIP, _ := netaddr.ParseIP(arg) argIP, _ := netip.ParseAddr(arg)
for _, ps := range st.Peer { for _, ps := range st.Peer {
dnsName = ps.DNSName dnsName = ps.DNSName
if argIP.IsValid() { if argIP.IsValid() {
@ -202,7 +202,7 @@ func isSSHOverTailscale() bool {
if !ok { if !ok {
return false return false
} }
ip, err := netaddr.ParseIP(ipStr) ip, err := netip.ParseAddr(ipStr)
if err != nil { if err != nil {
return false return false
} }

@ -13,6 +13,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"log" "log"
"net/netip"
"os" "os"
"reflect" "reflect"
"runtime" "runtime"
@ -199,8 +200,8 @@ func warnf(format string, args ...any) {
} }
var ( var (
ipv4default = netaddr.MustParseIPPrefix("0.0.0.0/0") ipv4default = netip.MustParsePrefix("0.0.0.0/0")
ipv6default = netaddr.MustParseIPPrefix("::/0") ipv6default = netip.MustParsePrefix("::/0")
) )
func validateViaPrefix(ipp netaddr.IPPrefix) error { func validateViaPrefix(ipp netaddr.IPPrefix) error {
@ -229,7 +230,7 @@ func calcAdvertiseRoutes(advertiseRoutes string, advertiseDefaultRoute bool) ([]
var default4, default6 bool var default4, default6 bool
advroutes := strings.Split(advertiseRoutes, ",") advroutes := strings.Split(advertiseRoutes, ",")
for _, s := range advroutes { for _, s := range advroutes {
ipp, err := netaddr.ParseIPPrefix(s) ipp, err := netip.ParsePrefix(s)
if err != nil { if err != nil {
return nil, fmt.Errorf("%q is not a valid IP address or CIDR prefix", s) return nil, fmt.Errorf("%q is not a valid IP address or CIDR prefix", s)
} }
@ -255,8 +256,8 @@ func calcAdvertiseRoutes(advertiseRoutes string, advertiseDefaultRoute bool) ([]
} }
} }
if advertiseDefaultRoute { if advertiseDefaultRoute {
routeMap[netaddr.MustParseIPPrefix("0.0.0.0/0")] = true routeMap[netip.MustParsePrefix("0.0.0.0/0")] = true
routeMap[netaddr.MustParseIPPrefix("::/0")] = true routeMap[netip.MustParsePrefix("::/0")] = true
} }
routes := make([]netaddr.IPPrefix, 0, len(routeMap)) routes := make([]netaddr.IPPrefix, 0, len(routeMap))
for r := range routeMap { for r := range routeMap {

@ -20,6 +20,7 @@ import (
"net" "net"
"net/http" "net/http"
"net/http/cgi" "net/http/cgi"
"net/netip"
"net/url" "net/url"
"os" "os"
"os/exec" "os/exec"
@ -28,7 +29,6 @@ import (
"github.com/peterbourgon/ff/v3/ffcli" "github.com/peterbourgon/ff/v3/ffcli"
"tailscale.com/ipn" "tailscale.com/ipn"
"tailscale.com/net/netaddr"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/types/preftype" "tailscale.com/types/preftype"
"tailscale.com/util/groupmember" "tailscale.com/util/groupmember"
@ -393,8 +393,8 @@ func webHandler(w http.ResponseWriter, r *http.Request) {
Status: st.BackendState, Status: st.BackendState,
DeviceName: deviceName, DeviceName: deviceName,
} }
exitNodeRouteV4 := netaddr.MustParseIPPrefix("0.0.0.0/0") exitNodeRouteV4 := netip.MustParsePrefix("0.0.0.0/0")
exitNodeRouteV6 := netaddr.MustParseIPPrefix("::/0") exitNodeRouteV6 := netip.MustParsePrefix("::/0")
for _, r := range prefs.AdvertiseRoutes { for _, r := range prefs.AdvertiseRoutes {
if r == exitNodeRouteV4 || r == exitNodeRouteV6 { if r == exitNodeRouteV4 || r == exitNodeRouteV6 {
data.AdvertiseExitNode = true data.AdvertiseExitNode = true

@ -20,6 +20,7 @@ import (
"net" "net"
"net/http" "net/http"
"net/http/httptrace" "net/http/httptrace"
"net/netip"
"net/url" "net/url"
"os" "os"
"strings" "strings"
@ -269,8 +270,8 @@ func debugPortmap(ctx context.Context) error {
gatewayAndSelfIP := func() (gw, self netaddr.IP, ok bool) { gatewayAndSelfIP := func() (gw, self netaddr.IP, ok bool) {
if v := os.Getenv("TS_DEBUG_GW_SELF"); strings.Contains(v, "/") { if v := os.Getenv("TS_DEBUG_GW_SELF"); strings.Contains(v, "/") {
i := strings.Index(v, "/") i := strings.Index(v, "/")
gw = netaddr.MustParseIP(v[:i]) gw = netip.MustParseAddr(v[:i])
self = netaddr.MustParseIP(v[i+1:]) self = netip.MustParseAddr(v[i+1:])
return gw, self, true return gw, self, true
} }
return linkMon.GatewayAndSelfIP() return linkMon.GatewayAndSelfIP()

@ -11,6 +11,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"net/netip"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -609,5 +610,5 @@ func (c *Client) LocalAddr() (netaddr.IPPort, error) {
if a == nil { if a == nil {
return netaddr.IPPort{}, errors.New("nil addr") return netaddr.IPPort{}, errors.New("nil addr")
} }
return netaddr.ParseIPPort(a.String()) return netip.ParseAddrPort(a.String())
} }

@ -25,6 +25,7 @@ import (
"math/rand" "math/rand"
"net" "net"
"net/http" "net/http"
"net/netip"
"os/exec" "os/exec"
"runtime" "runtime"
"strconv" "strconv"
@ -663,7 +664,7 @@ func (s *Server) accept(ctx context.Context, nc Conn, brw *bufio.ReadWriter, rem
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
defer cancel() defer cancel()
remoteIPPort, _ := netaddr.ParseIPPort(remoteAddr) remoteIPPort, _ := netip.ParseAddrPort(remoteAddr)
c := &sclient{ c := &sclient{
connNum: connNum, connNum: connNum,
@ -1768,7 +1769,7 @@ func parseSSOutput(raw string) map[netaddr.IPPort]BytesSentRecv {
if len(ipInfo) < 5 { if len(ipInfo) < 5 {
continue continue
} }
src, err := netaddr.ParseIPPort(ipInfo[4]) src, err := netip.ParseAddrPort(ipInfo[4])
if err != nil { if err != nil {
continue continue
} }

@ -22,6 +22,7 @@ import (
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"
"net/netip"
"net/url" "net/url"
"runtime" "runtime"
"strings" "strings"
@ -583,7 +584,7 @@ func shouldDialProto(s string, pred func(netaddr.IP) bool) bool {
if s == "" { if s == "" {
return true return true
} }
ip, _ := netaddr.ParseIP(s) ip, _ := netip.ParseAddr(s)
return pred(ip) return pred(ip)
} }

@ -6,6 +6,7 @@ package disco
import ( import (
"fmt" "fmt"
"net/netip"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -61,8 +62,8 @@ func TestMarshalAndParse(t *testing.T) {
name: "call_me_maybe_endpoints", name: "call_me_maybe_endpoints",
m: &CallMeMaybe{ m: &CallMeMaybe{
MyNumber: []netaddr.IPPort{ MyNumber: []netaddr.IPPort{
netaddr.MustParseIPPort("1.2.3.4:567"), netip.MustParseAddrPort("1.2.3.4:567"),
netaddr.MustParseIPPort("[2001::3456]:789"), netip.MustParseAddrPort("[2001::3456]:789"),
}, },
}, },
want: "03 00 00 00 00 00 00 00 00 00 00 00 ff ff 01 02 03 04 02 37 20 01 00 00 00 00 00 00 00 00 00 00 00 00 34 56 03 15", want: "03 00 00 00 00 00 00 00 00 00 00 00 ff ff 01 02 03 04 02 37 20 01 00 00 00 00 00 00 00 00 00 00 00 00 34 56 03 15",
@ -94,7 +95,7 @@ func TestMarshalAndParse(t *testing.T) {
} }
func mustIPPort(s string) netaddr.IPPort { func mustIPPort(s string) netaddr.IPPort {
ipp, err := netaddr.ParseIPPort(s) ipp, err := netip.ParseAddrPort(s)
if err != nil { if err != nil {
panic(err) panic(err)
} }

@ -23,18 +23,18 @@ import (
func ipps(ippStrs ...string) (ipps []netaddr.IPPrefix) { func ipps(ippStrs ...string) (ipps []netaddr.IPPrefix) {
for _, s := range ippStrs { for _, s := range ippStrs {
if ip, err := netaddr.ParseIP(s); err == nil { if ip, err := netip.ParseAddr(s); err == nil {
ipps = append(ipps, netip.PrefixFrom(ip, ip.BitLen())) ipps = append(ipps, netip.PrefixFrom(ip, ip.BitLen()))
continue continue
} }
ipps = append(ipps, netaddr.MustParseIPPrefix(s)) ipps = append(ipps, netip.MustParsePrefix(s))
} }
return return
} }
func ips(ss ...string) (ips []netaddr.IP) { func ips(ss ...string) (ips []netaddr.IP) {
for _, s := range ss { for _, s := range ss {
ips = append(ips, netaddr.MustParseIP(s)) ips = append(ips, netip.MustParseAddr(s))
} }
return return
} }

@ -1208,19 +1208,19 @@ func (b *LocalBackend) setFilter(f *filter.Filter) {
var removeFromDefaultRoute = []netaddr.IPPrefix{ var removeFromDefaultRoute = []netaddr.IPPrefix{
// RFC1918 LAN ranges // RFC1918 LAN ranges
netaddr.MustParseIPPrefix("192.168.0.0/16"), netip.MustParsePrefix("192.168.0.0/16"),
netaddr.MustParseIPPrefix("172.16.0.0/12"), netip.MustParsePrefix("172.16.0.0/12"),
netaddr.MustParseIPPrefix("10.0.0.0/8"), netip.MustParsePrefix("10.0.0.0/8"),
// IPv4 link-local // IPv4 link-local
netaddr.MustParseIPPrefix("169.254.0.0/16"), netip.MustParsePrefix("169.254.0.0/16"),
// IPv4 multicast // IPv4 multicast
netaddr.MustParseIPPrefix("224.0.0.0/4"), netip.MustParsePrefix("224.0.0.0/4"),
// Tailscale IPv4 range // Tailscale IPv4 range
tsaddr.CGNATRange(), tsaddr.CGNATRange(),
// IPv6 Link-local addresses // IPv6 Link-local addresses
netaddr.MustParseIPPrefix("fe80::/10"), netip.MustParsePrefix("fe80::/10"),
// IPv6 multicast // IPv6 multicast
netaddr.MustParseIPPrefix("ff00::/8"), netip.MustParsePrefix("ff00::/8"),
// Tailscale IPv6 range // Tailscale IPv6 range
tsaddr.TailscaleULARange(), tsaddr.TailscaleULARange(),
} }
@ -2346,7 +2346,7 @@ func dnsConfigForNetmap(nm *netmap.NetworkMap, prefs *ipn.Prefs, logf logger.Log
// TODO: more // TODO: more
continue continue
} }
ip, err := netaddr.ParseIP(rec.Value) ip, err := netip.ParseAddr(rec.Value)
if err != nil { if err != nil {
// Ignore. // Ignore.
continue continue
@ -2622,8 +2622,8 @@ func magicDNSRootDomains(nm *netmap.NetworkMap) []dnsname.FQDN {
} }
var ( var (
ipv4Default = netaddr.MustParseIPPrefix("0.0.0.0/0") ipv4Default = netip.MustParsePrefix("0.0.0.0/0")
ipv6Default = netaddr.MustParseIPPrefix("::/0") ipv6Default = netip.MustParsePrefix("::/0")
) )
// peerRoutes returns the routerConfig.Routes to access peers. // peerRoutes returns the routerConfig.Routes to access peers.

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
"net/netip"
"reflect" "reflect"
"testing" "testing"
"time" "time"
@ -26,13 +27,13 @@ import (
) )
func TestNetworkMapCompare(t *testing.T) { func TestNetworkMapCompare(t *testing.T) {
prefix1, err := netaddr.ParseIPPrefix("192.168.0.0/24") prefix1, err := netip.ParsePrefix("192.168.0.0/24")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
node1 := &tailcfg.Node{Addresses: []netaddr.IPPrefix{prefix1}} node1 := &tailcfg.Node{Addresses: []netaddr.IPPrefix{prefix1}}
prefix2, err := netaddr.ParseIPPrefix("10.0.0.0/8") prefix2, err := netip.ParsePrefix("10.0.0.0/8")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -185,7 +186,7 @@ func TestShrinkDefaultRoute(t *testing.T) {
// and localAddresses would normally come from calling interfaces.LocalAddresses. // and localAddresses would normally come from calling interfaces.LocalAddresses.
var b netipx.IPSetBuilder var b netipx.IPSetBuilder
for _, c := range []string{"127.0.0.0/8", "192.168.9.0/24", "fe80::/32"} { for _, c := range []string{"127.0.0.0/8", "192.168.9.0/24", "fe80::/32"} {
p := netaddr.MustParseIPPrefix(c) p := netip.MustParsePrefix(c)
b.AddPrefix(p) b.AddPrefix(p)
} }
localInterfaceRoutes, err := b.IPSet() localInterfaceRoutes, err := b.IPSet()
@ -193,28 +194,28 @@ func TestShrinkDefaultRoute(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
hostIPs := []netaddr.IP{ hostIPs := []netaddr.IP{
netaddr.MustParseIP("127.0.0.1"), netip.MustParseAddr("127.0.0.1"),
netaddr.MustParseIP("192.168.9.39"), netip.MustParseAddr("192.168.9.39"),
netaddr.MustParseIP("fe80::1"), netip.MustParseAddr("fe80::1"),
netaddr.MustParseIP("fe80::437d:feff:feca:49a7"), netip.MustParseAddr("fe80::437d:feff:feca:49a7"),
} }
localAddresses := []netaddr.IP{ localAddresses := []netaddr.IP{
netaddr.MustParseIP("192.168.9.39"), netip.MustParseAddr("192.168.9.39"),
} }
for _, test := range tests { for _, test := range tests {
def := netaddr.MustParseIPPrefix(test.route) def := netip.MustParsePrefix(test.route)
got, err := shrinkDefaultRoute(def, localInterfaceRoutes, hostIPs) got, err := shrinkDefaultRoute(def, localInterfaceRoutes, hostIPs)
if err != nil { if err != nil {
t.Fatalf("shrinkDefaultRoute(%q): %v", test.route, err) t.Fatalf("shrinkDefaultRoute(%q): %v", test.route, err)
} }
for _, ip := range test.in { for _, ip := range test.in {
if !got.Contains(netaddr.MustParseIP(ip)) { if !got.Contains(netip.MustParseAddr(ip)) {
t.Errorf("shrink(%q).Contains(%v) = false, want true", test.route, ip) t.Errorf("shrink(%q).Contains(%v) = false, want true", test.route, ip)
} }
} }
for _, ip := range test.out { for _, ip := range test.out {
if got.Contains(netaddr.MustParseIP(ip)) { if got.Contains(netip.MustParseAddr(ip)) {
t.Errorf("shrink(%q).Contains(%v) = true, want false", test.route, ip) t.Errorf("shrink(%q).Contains(%v) = true, want false", test.route, ip)
} }
} }
@ -228,7 +229,7 @@ func TestShrinkDefaultRoute(t *testing.T) {
} }
func TestPeerRoutes(t *testing.T) { func TestPeerRoutes(t *testing.T) {
pp := netaddr.MustParseIPPrefix pp := netip.MustParsePrefix
tests := []struct { tests := []struct {
name string name string
peers []wgcfg.Peer peers []wgcfg.Peer
@ -363,13 +364,13 @@ func TestPeerAPIBase(t *testing.T) {
name: "self_only_4_them_both", name: "self_only_4_them_both",
nm: &netmap.NetworkMap{ nm: &netmap.NetworkMap{
Addresses: []netaddr.IPPrefix{ Addresses: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("100.64.1.1/32"), netip.MustParsePrefix("100.64.1.1/32"),
}, },
}, },
peer: &tailcfg.Node{ peer: &tailcfg.Node{
Addresses: []netaddr.IPPrefix{ Addresses: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("100.64.1.2/32"), netip.MustParsePrefix("100.64.1.2/32"),
netaddr.MustParseIPPrefix("fe70::2/128"), netip.MustParsePrefix("fe70::2/128"),
}, },
Hostinfo: (&tailcfg.Hostinfo{ Hostinfo: (&tailcfg.Hostinfo{
Services: []tailcfg.Service{ Services: []tailcfg.Service{
@ -384,13 +385,13 @@ func TestPeerAPIBase(t *testing.T) {
name: "self_only_6_them_both", name: "self_only_6_them_both",
nm: &netmap.NetworkMap{ nm: &netmap.NetworkMap{
Addresses: []netaddr.IPPrefix{ Addresses: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("fe70::1/128"), netip.MustParsePrefix("fe70::1/128"),
}, },
}, },
peer: &tailcfg.Node{ peer: &tailcfg.Node{
Addresses: []netaddr.IPPrefix{ Addresses: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("100.64.1.2/32"), netip.MustParsePrefix("100.64.1.2/32"),
netaddr.MustParseIPPrefix("fe70::2/128"), netip.MustParsePrefix("fe70::2/128"),
}, },
Hostinfo: (&tailcfg.Hostinfo{ Hostinfo: (&tailcfg.Hostinfo{
Services: []tailcfg.Service{ Services: []tailcfg.Service{
@ -405,14 +406,14 @@ func TestPeerAPIBase(t *testing.T) {
name: "self_both_them_only_4", name: "self_both_them_only_4",
nm: &netmap.NetworkMap{ nm: &netmap.NetworkMap{
Addresses: []netaddr.IPPrefix{ Addresses: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("100.64.1.1/32"), netip.MustParsePrefix("100.64.1.1/32"),
netaddr.MustParseIPPrefix("fe70::1/128"), netip.MustParsePrefix("fe70::1/128"),
}, },
}, },
peer: &tailcfg.Node{ peer: &tailcfg.Node{
Addresses: []netaddr.IPPrefix{ Addresses: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("100.64.1.2/32"), netip.MustParsePrefix("100.64.1.2/32"),
netaddr.MustParseIPPrefix("fe70::2/128"), netip.MustParsePrefix("fe70::2/128"),
}, },
Hostinfo: (&tailcfg.Hostinfo{ Hostinfo: (&tailcfg.Hostinfo{
Services: []tailcfg.Service{ Services: []tailcfg.Service{
@ -426,14 +427,14 @@ func TestPeerAPIBase(t *testing.T) {
name: "self_both_them_only_6", name: "self_both_them_only_6",
nm: &netmap.NetworkMap{ nm: &netmap.NetworkMap{
Addresses: []netaddr.IPPrefix{ Addresses: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("100.64.1.1/32"), netip.MustParsePrefix("100.64.1.1/32"),
netaddr.MustParseIPPrefix("fe70::1/128"), netip.MustParsePrefix("fe70::1/128"),
}, },
}, },
peer: &tailcfg.Node{ peer: &tailcfg.Node{
Addresses: []netaddr.IPPrefix{ Addresses: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("100.64.1.2/32"), netip.MustParsePrefix("100.64.1.2/32"),
netaddr.MustParseIPPrefix("fe70::2/128"), netip.MustParsePrefix("fe70::2/128"),
}, },
Hostinfo: (&tailcfg.Hostinfo{ Hostinfo: (&tailcfg.Hostinfo{
Services: []tailcfg.Service{ Services: []tailcfg.Service{
@ -447,14 +448,14 @@ func TestPeerAPIBase(t *testing.T) {
name: "self_both_them_no_peerapi_service", name: "self_both_them_no_peerapi_service",
nm: &netmap.NetworkMap{ nm: &netmap.NetworkMap{
Addresses: []netaddr.IPPrefix{ Addresses: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("100.64.1.1/32"), netip.MustParsePrefix("100.64.1.1/32"),
netaddr.MustParseIPPrefix("fe70::1/128"), netip.MustParsePrefix("fe70::1/128"),
}, },
}, },
peer: &tailcfg.Node{ peer: &tailcfg.Node{
Addresses: []netaddr.IPPrefix{ Addresses: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("100.64.1.2/32"), netip.MustParsePrefix("100.64.1.2/32"),
netaddr.MustParseIPPrefix("fe70::2/128"), netip.MustParsePrefix("fe70::2/128"),
}, },
}, },
want: "", want: "",
@ -558,7 +559,7 @@ func TestInternalAndExternalInterfaces(t *testing.T) {
return il return il
} }
newInterface := func(name, pfx string, wsl2, loopback bool) interfacePrefix { newInterface := func(name, pfx string, wsl2, loopback bool) interfacePrefix {
ippfx := netaddr.MustParseIPPrefix(pfx) ippfx := netip.MustParsePrefix(pfx)
ip := interfaces.Interface{ ip := interfaces.Interface{
Interface: &net.Interface{}, Interface: &net.Interface{},
AltAddrs: []net.Addr{ AltAddrs: []net.Addr{

@ -16,6 +16,7 @@ import (
"io/fs" "io/fs"
"net" "net"
"net/http" "net/http"
"net/netip"
"net/url" "net/url"
"os" "os"
"path" "path"
@ -985,7 +986,7 @@ func (h *peerAPIHandler) replyToDNSQueries() bool {
if remoteIP.Is6() { if remoteIP.Is6() {
// autogroup:internet for IPv6 is defined to start with 2000::/3, // autogroup:internet for IPv6 is defined to start with 2000::/3,
// so use 2000::0 as the probe "the internet" address. // so use 2000::0 as the probe "the internet" address.
dstIP = netaddr.MustParseIP("2000::") dstIP = netip.MustParseAddr("2000::")
} }
verdict := f.CheckTCP(remoteIP, dstIP, 53) verdict := f.CheckTCP(remoteIP, dstIP, 53)
return verdict == filter.Accept return verdict == filter.Accept

@ -13,6 +13,7 @@ import (
"math/rand" "math/rand"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/netip"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -583,7 +584,7 @@ func TestPeerAPIReplyToDNSQueries(t *testing.T) {
t.Errorf("for isSelf = false; want true") t.Errorf("for isSelf = false; want true")
} }
h.isSelf = false h.isSelf = false
h.remoteAddr = netaddr.MustParseIPPort("100.150.151.152:12345") h.remoteAddr = netip.MustParseAddrPort("100.150.151.152:12345")
eng, _ := wgengine.NewFakeUserspaceEngine(logger.Discard, 0) eng, _ := wgengine.NewFakeUserspaceEngine(logger.Discard, 0)
h.ps = &peerAPIServer{ h.ps = &peerAPIServer{
@ -596,8 +597,8 @@ func TestPeerAPIReplyToDNSQueries(t *testing.T) {
} }
h.ps.b.prefs = &ipn.Prefs{ h.ps.b.prefs = &ipn.Prefs{
AdvertiseRoutes: []netaddr.IPPrefix{ AdvertiseRoutes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("0.0.0.0/0"), netip.MustParsePrefix("0.0.0.0/0"),
netaddr.MustParseIPPrefix("::/0"), netip.MustParsePrefix("::/0"),
}, },
} }
if !h.ps.b.OfferingExitNode() { if !h.ps.b.OfferingExitNode() {
@ -621,7 +622,7 @@ func TestPeerAPIReplyToDNSQueries(t *testing.T) {
} }
// Also test IPv6. // Also test IPv6.
h.remoteAddr = netaddr.MustParseIPPort("[fe70::1]:12345") h.remoteAddr = netip.MustParseAddrPort("[fe70::1]:12345")
if !h.replyToDNSQueries() { if !h.replyToDNSQueries() {
t.Errorf("unexpectedly IPv6 deny; wanted to be a DNS server") t.Errorf("unexpectedly IPv6 deny; wanted to be a DNS server")
} }

@ -16,6 +16,7 @@ import (
"log" "log"
"net" "net"
"net/http" "net/http"
"net/netip"
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
@ -146,11 +147,11 @@ func (s *Server) getConnIdentity(c net.Conn) (ci connIdentity, err error) {
ci.Creds, _ = peercred.Get(c) ci.Creds, _ = peercred.Get(c)
return ci, nil return ci, nil
} }
la, err := netaddr.ParseIPPort(c.LocalAddr().String()) la, err := netip.ParseAddrPort(c.LocalAddr().String())
if err != nil { if err != nil {
return ci, fmt.Errorf("parsing local address: %w", err) return ci, fmt.Errorf("parsing local address: %w", err)
} }
ra, err := netaddr.ParseIPPort(c.RemoteAddr().String()) ra, err := netip.ParseAddrPort(c.RemoteAddr().String())
if err != nil { if err != nil {
return ci, fmt.Errorf("parsing local remote: %w", err) return ci, fmt.Errorf("parsing local remote: %w", err)
} }

@ -16,6 +16,7 @@ import (
"net" "net"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"net/netip"
"net/url" "net/url"
"reflect" "reflect"
"runtime" "runtime"
@ -225,7 +226,7 @@ func (h *Handler) serveWhoIs(w http.ResponseWriter, r *http.Request) {
var ipp netaddr.IPPort var ipp netaddr.IPPort
if v := r.FormValue("addr"); v != "" { if v := r.FormValue("addr"); v != "" {
var err error var err error
ipp, err = netaddr.ParseIPPort(v) ipp, err = netip.ParseAddrPort(v)
if err != nil { if err != nil {
http.Error(w, "invalid 'addr' parameter", 400) http.Error(w, "invalid 'addr' parameter", 400)
return return
@ -667,7 +668,7 @@ func (h *Handler) servePing(w http.ResponseWriter, r *http.Request) {
http.Error(w, "missing 'ip' parameter", 400) http.Error(w, "missing 'ip' parameter", 400)
return return
} }
ip, err := netaddr.ParseIP(ipStr) ip, err := netip.ParseAddr(ipStr)
if err != nil { if err != nil {
http.Error(w, "invalid IP", 400) http.Error(w, "invalid IP", 400)
return return

@ -524,7 +524,7 @@ func exitNodeIPOfArg(s string, st *ipnstate.Status) (ip netaddr.IP, err error) {
if s == "" { if s == "" {
return ip, os.ErrInvalid return ip, os.ErrInvalid
} }
ip, err = netaddr.ParseIP(s) ip, err = netip.ParseAddr(s)
if err == nil { if err == nil {
// If we're online already and have a netmap, double check that the IP // If we're online already and have a netmap, double check that the IP
// address specified is valid. // address specified is valid.

@ -9,6 +9,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/netip"
"os" "os"
"reflect" "reflect"
"strings" "strings"
@ -64,7 +65,7 @@ func TestPrefsEqual(t *testing.T) {
nets := func(strs ...string) (ns []netaddr.IPPrefix) { nets := func(strs ...string) (ns []netaddr.IPPrefix) {
for _, s := range strs { for _, s := range strs {
n, err := netaddr.ParseIPPrefix(s) n, err := netip.ParsePrefix(s)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -137,13 +138,13 @@ func TestPrefsEqual(t *testing.T) {
}, },
{ {
&Prefs{ExitNodeIP: netaddr.MustParseIP("1.2.3.4")}, &Prefs{ExitNodeIP: netip.MustParseAddr("1.2.3.4")},
&Prefs{}, &Prefs{},
false, false,
}, },
{ {
&Prefs{ExitNodeIP: netaddr.MustParseIP("1.2.3.4")}, &Prefs{ExitNodeIP: netip.MustParseAddr("1.2.3.4")},
&Prefs{ExitNodeIP: netaddr.MustParseIP("1.2.3.4")}, &Prefs{ExitNodeIP: netip.MustParseAddr("1.2.3.4")},
true, true,
}, },
@ -415,7 +416,7 @@ func TestPrefsPretty(t *testing.T) {
}, },
{ {
Prefs{ Prefs{
ExitNodeIP: netaddr.MustParseIP("1.2.3.4"), ExitNodeIP: netip.MustParseAddr("1.2.3.4"),
}, },
"linux", "linux",
`Prefs{ra=false mesh=false dns=false want=false exit=1.2.3.4 lan=false routes=[] nf=off Persist=nil}`, `Prefs{ra=false mesh=false dns=false want=false exit=1.2.3.4 lan=false routes=[] nf=off Persist=nil}`,
@ -659,7 +660,7 @@ func TestPrefsExitNode(t *testing.T) {
t.Errorf("default shouldn't advertise exit node") t.Errorf("default shouldn't advertise exit node")
} }
p.AdvertiseRoutes = []netaddr.IPPrefix{ p.AdvertiseRoutes = []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.0.0.0/16"), netip.MustParsePrefix("10.0.0.0/16"),
} }
p.SetAdvertiseExitNode(true) p.SetAdvertiseExitNode(true)
if got, want := len(p.AdvertiseRoutes), 3; got != want { if got, want := len(p.AdvertiseRoutes), 3; got != want {
@ -682,7 +683,7 @@ func TestPrefsExitNode(t *testing.T) {
} }
func TestExitNodeIPOfArg(t *testing.T) { func TestExitNodeIPOfArg(t *testing.T) {
mustIP := netaddr.MustParseIP mustIP := netip.MustParseAddr
tests := []struct { tests := []struct {
name string name string
arg string arg string

@ -8,6 +8,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/fs" "io/fs"
"net/netip"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -81,7 +82,7 @@ func testDirect(t *testing.T, fs wholeFileFS) {
m := directManager{logf: t.Logf, fs: fs} m := directManager{logf: t.Logf, fs: fs}
if err := m.SetDNS(OSConfig{ 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."}, SearchDomains: []dnsname.FQDN{"ts.net.", "ts-dns.test."},
MatchDomains: []dnsname.FQDN{"ignored."}, MatchDomains: []dnsname.FQDN{"ignored."},
}); err != nil { }); err != nil {
@ -108,7 +109,7 @@ search ts.net ts-dns.test
assertBaseState(t) assertBaseState(t)
// Test that Close cleans up resolv.conf. // 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) t.Fatal(err)
} }
if err := m.Close(); err != nil { if err := m.Close(); err != nil {
@ -150,21 +151,21 @@ func TestReadResolve(t *testing.T) {
{in: `nameserver 192.168.0.100`, {in: `nameserver 192.168.0.100`,
want: OSConfig{ want: OSConfig{
Nameservers: []netaddr.IP{ Nameservers: []netaddr.IP{
netaddr.MustParseIP("192.168.0.100"), netip.MustParseAddr("192.168.0.100"),
}, },
}, },
}, },
{in: `nameserver 192.168.0.100 # comment`, {in: `nameserver 192.168.0.100 # comment`,
want: OSConfig{ want: OSConfig{
Nameservers: []netaddr.IP{ Nameservers: []netaddr.IP{
netaddr.MustParseIP("192.168.0.100"), netip.MustParseAddr("192.168.0.100"),
}, },
}, },
}, },
{in: `nameserver 192.168.0.100#`, {in: `nameserver 192.168.0.100#`,
want: OSConfig{ want: OSConfig{
Nameservers: []netaddr.IP{ Nameservers: []netaddr.IP{
netaddr.MustParseIP("192.168.0.100"), netip.MustParseAddr("192.168.0.100"),
}, },
}, },
}, },

@ -5,6 +5,7 @@
package dns package dns
import ( import (
"net/netip"
"runtime" "runtime"
"strings" "strings"
"testing" "testing"
@ -425,14 +426,14 @@ func TestManager(t *testing.T) {
func mustIPs(strs ...string) (ret []netaddr.IP) { func mustIPs(strs ...string) (ret []netaddr.IP) {
for _, s := range strs { for _, s := range strs {
ret = append(ret, netaddr.MustParseIP(s)) ret = append(ret, netip.MustParseAddr(s))
} }
return ret return ret
} }
func mustIPPs(strs ...string) (ret []netaddr.IPPort) { func mustIPPs(strs ...string) (ret []netaddr.IPPort) {
for _, s := range strs { for _, s := range strs {
ret = append(ret, netaddr.MustParseIPPort(s)) ret = append(ret, netip.MustParseAddrPort(s))
} }
return ret return ret
} }
@ -459,7 +460,7 @@ func hosts(strs ...string) (ret map[dnsname.FQDN][]netaddr.IP) {
var key dnsname.FQDN var key dnsname.FQDN
ret = map[dnsname.FQDN][]netaddr.IP{} ret = map[dnsname.FQDN][]netaddr.IP{}
for _, s := range strs { for _, s := range strs {
if ip, err := netaddr.ParseIP(s); err == nil { if ip, err := netip.ParseAddr(s); err == nil {
if key == "" { if key == "" {
panic("IP provided before name") panic("IP provided before name")
} }
@ -479,7 +480,7 @@ func hostsR(strs ...string) (ret map[dnsname.FQDN][]dnstype.Resolver) {
var key dnsname.FQDN var key dnsname.FQDN
ret = map[dnsname.FQDN][]dnstype.Resolver{} ret = map[dnsname.FQDN][]dnstype.Resolver{}
for _, s := range strs { for _, s := range strs {
if ip, err := netaddr.ParseIP(s); err == nil { if ip, err := netip.ParseAddr(s); err == nil {
if key == "" { if key == "" {
panic("IP provided before name") panic("IP provided before name")
} }
@ -504,12 +505,12 @@ func upstreams(strs ...string) (ret map[dnsname.FQDN][]*dnstype.Resolver) {
panic("IPPort provided before suffix") panic("IPPort provided before suffix")
} }
ret[key] = nil ret[key] = nil
} else if ipp, err := netaddr.ParseIPPort(s); err == nil { } else if ipp, err := netip.ParseAddrPort(s); err == nil {
if key == "" { if key == "" {
panic("IPPort provided before suffix") panic("IPPort provided before suffix")
} }
ret[key] = append(ret[key], &dnstype.Resolver{Addr: ipp.String()}) 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 == "" { if key == "" {
panic("IPPort provided before suffix") panic("IPPort provided before suffix")
} }

@ -7,6 +7,7 @@ package dns
import ( import (
"errors" "errors"
"fmt" "fmt"
"net/netip"
"os/exec" "os/exec"
"sort" "sort"
"strings" "strings"
@ -422,9 +423,9 @@ func (m windowsManager) getBasePrimaryResolver() (resolvers []netaddr.IP, err er
} }
var siteLocalResolvers = []netaddr.IP{ var siteLocalResolvers = []netaddr.IP{
netaddr.MustParseIP("fec0:0:0:ffff::1"), netip.MustParseAddr("fec0:0:0:ffff::1"),
netaddr.MustParseIP("fec0:0:0:ffff::2"), netip.MustParseAddr("fec0:0:0:ffff::2"),
netaddr.MustParseIP("fec0:0:0:ffff::3"), netip.MustParseAddr("fec0:0:0:ffff::3"),
} }
func isWindows10OrBetter() bool { func isWindows10OrBetter() bool {

@ -8,6 +8,7 @@ import (
"context" "context"
"fmt" "fmt"
"math/rand" "math/rand"
"net/netip"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -91,7 +92,7 @@ func TestManagerWindowsGPMove(t *testing.T) {
// Upon initialization of cfg, we should not have any NRPT rules // Upon initialization of cfg, we should not have any NRPT rules
ensureNoRules(t) ensureNoRules(t)
resolvers := []netaddr.IP{netaddr.MustParseIP("1.1.1.1")} resolvers := []netaddr.IP{netip.MustParseAddr("1.1.1.1")}
domains := genRandomSubdomains(t, 1) domains := genRandomSubdomains(t, 1)
// 1. Populate local NRPT // 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 // Upon initialization of cfg, we should not have any NRPT rules
ensureNoRules(t) 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) domains := genRandomSubdomains(t, 2*nrptMaxDomainsPerRule+1)

@ -10,6 +10,7 @@ package dns
import ( import (
"context" "context"
"fmt" "fmt"
"net/netip"
"sort" "sort"
"time" "time"
@ -312,7 +313,7 @@ func (m *nmManager) GetBaseConfig() (OSConfig, error) {
if v, ok := cfg["nameservers"]; ok { if v, ok := cfg["nameservers"]; ok {
if ips, ok := v.Value().([]string); ok { if ips, ok := v.Value().([]string); ok {
for _, s := range ips { for _, s := range ips {
ip, err := netaddr.ParseIP(s) ip, err := netip.ParseAddr(s)
if err != nil { if err != nil {
// hmm, what do? Shouldn't really happen. // hmm, what do? Shouldn't really happen.
continue continue

@ -7,6 +7,7 @@
package publicdns package publicdns
import ( import (
"net/netip"
"sync" "sync"
"tailscale.com/net/netaddr" "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 // addDoH parses a given well-formed ip string into a netaddr.IP type and
// adds it to both knownDoH and dohIPsOFBase maps. // adds it to both knownDoH and dohIPsOFBase maps.
func addDoH(ipStr, base string) { func addDoH(ipStr, base string) {
ip := netaddr.MustParseIP(ipStr) ip := netip.MustParseAddr(ipStr)
knownDoH[ip] = base knownDoH[ip] = base
dohIPsOfBase[base] = append(dohIPsOfBase[base], ip) dohIPsOfBase[base] = append(dohIPsOfBase[base], ip)
} }

@ -5,6 +5,7 @@
package publicdns package publicdns
import ( import (
"net/netip"
"testing" "testing"
"tailscale.com/net/netaddr" "tailscale.com/net/netaddr"
@ -26,8 +27,8 @@ func TestDohV6(t *testing.T) {
firstIP netaddr.IP firstIP netaddr.IP
want bool want bool
}{ }{
{"https://cloudflare-dns.com/dns-query", netaddr.MustParseIP("2606:4700:4700::1111"), true}, {"https://cloudflare-dns.com/dns-query", netip.MustParseAddr("2606:4700:4700::1111"), true},
{"https://dns.google/dns-query", netaddr.MustParseIP("2001:4860:4860::8888"), true}, {"https://dns.google/dns-query", netip.MustParseAddr("2001:4860:4860::8888"), true},
{"bogus", netaddr.IP{}, false}, {"bogus", netaddr.IP{}, false},
} }
for _, test := range tests { for _, test := range tests {

@ -16,6 +16,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"net/netip"
"os" "os"
"strings" "strings"
@ -74,7 +75,7 @@ func Parse(r io.Reader) (*Config, error) {
if len(nameserver) == len(s) { if len(nameserver) == len(s) {
return nil, fmt.Errorf("missing space after \"nameserver\" in %q", line) return nil, fmt.Errorf("missing space after \"nameserver\" in %q", line)
} }
ip, err := netaddr.ParseIP(nameserver) ip, err := netip.ParseAddr(nameserver)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -5,6 +5,7 @@
package resolvconffile package resolvconffile
import ( import (
"net/netip"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -22,21 +23,21 @@ func TestParse(t *testing.T) {
{in: `nameserver 192.168.0.100`, {in: `nameserver 192.168.0.100`,
want: &Config{ want: &Config{
Nameservers: []netaddr.IP{ Nameservers: []netaddr.IP{
netaddr.MustParseIP("192.168.0.100"), netip.MustParseAddr("192.168.0.100"),
}, },
}, },
}, },
{in: `nameserver 192.168.0.100 # comment`, {in: `nameserver 192.168.0.100 # comment`,
want: &Config{ want: &Config{
Nameservers: []netaddr.IP{ Nameservers: []netaddr.IP{
netaddr.MustParseIP("192.168.0.100"), netip.MustParseAddr("192.168.0.100"),
}, },
}, },
}, },
{in: `nameserver 192.168.0.100#`, {in: `nameserver 192.168.0.100#`,
want: &Config{ want: &Config{
Nameservers: []netaddr.IP{ 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] ip4Str = fqdn[:lastDot]
} }
ip4, err := netaddr.ParseIP(ip4Str) ip4, err := netip.ParseAddr(ip4Str)
if err != nil { if err != nil {
return netaddr.IP{}, false // badly formed, dont respond return netaddr.IP{}, false // badly formed, dont respond
} }
@ -1068,7 +1068,7 @@ func rawNameToLower(name []byte) string {
// 1.2.3.4 // 1.2.3.4
func rdnsNameToIPv4(name dnsname.FQDN) (ip netaddr.IP, ok bool) { func rdnsNameToIPv4(name dnsname.FQDN) (ip netaddr.IP, ok bool) {
s := strings.TrimSuffix(name.WithTrailingDot(), rdnsv4Suffix) s := strings.TrimSuffix(name.WithTrailingDot(), rdnsv4Suffix)
ip, err := netaddr.ParseIP(s) ip, err := netip.ParseAddr(s)
if err != nil { if err != nil {
return netaddr.IP{}, false return netaddr.IP{}, false
} }
@ -1196,7 +1196,7 @@ func unARPA(a string) (ipStr string, ok bool) {
if strings.HasSuffix(a, suf4) { if strings.HasSuffix(a, suf4) {
s := strings.TrimSuffix(a, suf4) s := strings.TrimSuffix(a, suf4)
// Parse and reverse octets. // Parse and reverse octets.
ip, err := netaddr.ParseIP(s) ip, err := netip.ParseAddr(s)
if err != nil || !ip.Is4() { if err != nil || !ip.Is4() {
return "", false return "", false
} }

@ -13,6 +13,7 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"net" "net"
"net/netip"
"reflect" "reflect"
"runtime" "runtime"
"strconv" "strconv"
@ -32,13 +33,13 @@ import (
) )
var ( var (
testipv4 = netaddr.MustParseIP("1.2.3.4") testipv4 = netip.MustParseAddr("1.2.3.4")
testipv6 = netaddr.MustParseIP("0001:0203:0405:0607:0809:0a0b:0c0d:0e0f") testipv6 = netip.MustParseAddr("0001:0203:0405:0607:0809:0a0b:0c0d:0e0f")
testipv4Arpa = dnsname.FQDN("4.3.2.1.in-addr.arpa.") 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.") 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{ var dnsCfg = Config{
@ -237,7 +238,7 @@ func syncRespond(r *Resolver, query []byte) ([]byte, error) {
} }
func mustIP(str string) netaddr.IP { func mustIP(str string) netaddr.IP {
ip, err := netaddr.ParseIP(str) ip, err := netip.ParseAddr(str)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -342,11 +343,11 @@ func TestResolveLocal(t *testing.T) {
{"mx-nxdomain", "test3.ipn.dev.", dns.TypeMX, netaddr.IP{}, dns.RCodeNameError}, {"mx-nxdomain", "test3.ipn.dev.", dns.TypeMX, netaddr.IP{}, dns.RCodeNameError},
{"ns-nxdomain", "test3.ipn.dev.", dns.TypeNS, 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}, {"onion-domain", "footest.onion.", dns.TypeA, netaddr.IP{}, dns.RCodeNameError},
{"magicdns", dnsSymbolicFQDN, dns.TypeA, netaddr.MustParseIP("100.100.100.100"), 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, netaddr.MustParseIP("fd7a:115c:a1e0:b1a:0:ff:1.2.3.4"), 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, netaddr.MustParseIP("fd7a:115c:a1e0:b1a:0:1:10.0.0.1"), 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, netaddr.MustParseIP("fd7a:115c:a1e0:b1a:0:ff:4.3.2.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, netaddr.MustParseIP("fd7a:115c:a1e0:b1a:0:1:1.0.0.10"), 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", 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}, {"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) { func TestDelegateSplitRoute(t *testing.T) {
test4 := netaddr.MustParseIP("2.3.4.5") test4 := netip.MustParseAddr("2.3.4.5")
test6 := netaddr.MustParseIP("ff::1") test6 := netip.MustParseAddr("ff::1")
server1 := serveDNS(t, "127.0.0.1:0", server1 := serveDNS(t, "127.0.0.1:0",
"test.site.", resolveToIP(testipv4, testipv6, "dns.test.site.")) "test.site.", resolveToIP(testipv4, testipv6, "dns.test.site."))
@ -1048,16 +1049,16 @@ func TestHandleExitNodeDNSQueryWithNetPkg(t *testing.T) {
dnsHandler(), dnsHandler(),
"one-a.test.", "one-a.test.",
dnsHandler(netaddr.MustParseIP("1.2.3.4")), dnsHandler(netip.MustParseAddr("1.2.3.4")),
"two-a.test.", "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.", "one-aaaa.test.",
dnsHandler(netaddr.MustParseIP("1::2")), dnsHandler(netip.MustParseAddr("1::2")),
"two-aaaa.test.", "two-aaaa.test.",
dnsHandler(netaddr.MustParseIP("1::2"), netaddr.MustParseIP("3::4")), dnsHandler(netip.MustParseAddr("1::2"), netip.MustParseAddr("3::4")),
"nx-domain.test.", "nx-domain.test.",
resolveToNXDOMAIN, resolveToNXDOMAIN,

@ -10,6 +10,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"net" "net"
"net/netip"
"reflect" "reflect"
"testing" "testing"
"time" "time"
@ -42,7 +43,7 @@ func TestDialCall_DNSWasTrustworthy(t *testing.T) {
ip netaddr.IP // IP we pretended to dial ip netaddr.IP // IP we pretended to dial
err error // the dial error or nil for success err error // the dial error or nil for success
} }
mustIP := netaddr.MustParseIP mustIP := netip.MustParseAddr
errFail := errors.New("some connect failure") errFail := errors.New("some connect failure")
tests := []struct { tests := []struct {
name string name string
@ -90,7 +91,7 @@ func TestDialCall_DNSWasTrustworthy(t *testing.T) {
func TestDialCall_uniqueIPs(t *testing.T) { func TestDialCall_uniqueIPs(t *testing.T) {
dc := &dialCall{} dc := &dialCall{}
mustIP := netaddr.MustParseIP mustIP := netip.MustParseAddr
errFail := errors.New("some connect failure") errFail := errors.New("some connect failure")
dc.noteDialResult(mustIP("2003::1"), errFail) dc.noteDialResult(mustIP("2003::1"), errFail)
dc.noteDialResult(mustIP("2003::2"), errFail) dc.noteDialResult(mustIP("2003::2"), errFail)
@ -116,10 +117,10 @@ func TestResolverAllHostStaticResult(t *testing.T) {
r := &Resolver{ r := &Resolver{
SingleHost: "foo.bar", SingleHost: "foo.bar",
SingleHostStaticResult: []netaddr.IP{ SingleHostStaticResult: []netaddr.IP{
netaddr.MustParseIP("2001:4860:4860::8888"), netip.MustParseAddr("2001:4860:4860::8888"),
netaddr.MustParseIP("2001:4860:4860::8844"), netip.MustParseAddr("2001:4860:4860::8844"),
netaddr.MustParseIP("8.8.8.8"), netip.MustParseAddr("8.8.8.8"),
netaddr.MustParseIP("8.8.4.4"), netip.MustParseAddr("8.8.4.4"),
}, },
} }
ip4, ip6, allIPs, err := r.LookupIP(context.Background(), "foo.bar") ip4, ip6, allIPs, err := r.LookupIP(context.Background(), "foo.bar")

@ -18,6 +18,7 @@ import (
"math/rand" "math/rand"
"net" "net"
"net/http" "net/http"
"net/netip"
"net/url" "net/url"
"time" "time"
@ -29,7 +30,7 @@ import (
) )
func Lookup(ctx context.Context, host string) ([]netaddr.IP, error) { 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 return []netaddr.IP{ip}, nil
} }
@ -42,10 +43,10 @@ func Lookup(ctx context.Context, host string) ([]netaddr.IP, error) {
var cands4, cands6 []nameIP var cands4, cands6 []nameIP
for _, dr := range dm.Regions { for _, dr := range dm.Regions {
for _, n := range dr.Nodes { 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}) 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}) cands6 = append(cands6, nameIP{n.HostName, ip})
} }
} }

@ -5,19 +5,19 @@
package flowtrack package flowtrack
import ( import (
"net/netip"
"testing" "testing"
"tailscale.com/net/netaddr"
"tailscale.com/tstest" "tailscale.com/tstest"
) )
func TestCache(t *testing.T) { func TestCache(t *testing.T) {
c := &Cache{MaxEntries: 2} c := &Cache{MaxEntries: 2}
k1 := Tuple{Src: netaddr.MustParseIPPort("1.1.1.1:1"), Dst: netaddr.MustParseIPPort("1.1.1.1:1")} k1 := Tuple{Src: netip.MustParseAddrPort("1.1.1.1:1"), Dst: netip.MustParseAddrPort("1.1.1.1:1")}
k2 := Tuple{Src: netaddr.MustParseIPPort("1.1.1.1:1"), Dst: netaddr.MustParseIPPort("2.2.2.2:2")} k2 := Tuple{Src: netip.MustParseAddrPort("1.1.1.1:1"), Dst: netip.MustParseAddrPort("2.2.2.2:2")}
k3 := Tuple{Src: netaddr.MustParseIPPort("1.1.1.1:1"), Dst: netaddr.MustParseIPPort("3.3.3.3:3")} k3 := Tuple{Src: netip.MustParseAddrPort("1.1.1.1:1"), Dst: netip.MustParseAddrPort("3.3.3.3:3")}
k4 := Tuple{Src: netaddr.MustParseIPPort("1.1.1.1:1"), Dst: netaddr.MustParseIPPort("4.4.4.4:4")} k4 := Tuple{Src: netip.MustParseAddrPort("1.1.1.1:1"), Dst: netip.MustParseAddrPort("4.4.4.4:4")}
wantLen := func(want int) { wantLen := func(want int) {
t.Helper() t.Helper()

@ -10,6 +10,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
"net/netip"
"runtime" "runtime"
"sort" "sort"
"strings" "strings"
@ -630,7 +631,7 @@ func isUsableV6(ip netaddr.IP) bool {
} }
var ( var (
v6Global1 = netaddr.MustParseIPPrefix("2000::/3") v6Global1 = netip.MustParsePrefix("2000::/3")
) )
// anyInterestingIP reports whether pfxs contains any IP that matches // anyInterestingIP reports whether pfxs contains any IP that matches

@ -6,6 +6,7 @@ package interfaces
import ( import (
"errors" "errors"
"net/netip"
"os/exec" "os/exec"
"testing" "testing"
@ -72,7 +73,7 @@ func likelyHomeRouterIPDarwinExec() (ret netaddr.IP, ok bool) {
if !mem.Contains(flagsm, mem.S("G")) { if !mem.Contains(flagsm, mem.S("G")) {
return nil 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() { if err == nil && ip.IsPrivate() {
ret = ip ret = ip
// We've found what we're looking for. // We've found what we're looking for.

@ -12,6 +12,7 @@ import (
"io" "io"
"log" "log"
"net" "net"
"net/netip"
"os" "os"
"os/exec" "os/exec"
"runtime" "runtime"
@ -125,7 +126,7 @@ func likelyHomeRouterIPAndroid() (ret netaddr.IP, ok bool) {
return nil return nil
} }
ipb := line[:sp] 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 ret = ip
log.Printf("interfaces: found Android default route %v", ip) log.Printf("interfaces: found Android default route %v", ip)
} }

@ -7,6 +7,7 @@ package interfaces
import ( import (
"encoding/json" "encoding/json"
"net" "net"
"net/netip"
"testing" "testing"
"tailscale.com/net/netaddr" "tailscale.com/net/netaddr"
@ -64,7 +65,7 @@ func TestIsUsableV6(t *testing.T) {
} }
for _, test := range tests { 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) t.Errorf("isUsableV6(%s) = %v, want %v", test.name, got, test.want)
} }
} }
@ -76,17 +77,17 @@ func TestStateEqualFilteredIPFilter(t *testing.T) {
s1 := &State{ s1 := &State{
InterfaceIPs: map[string][]netaddr.IPPrefix{"x": { InterfaceIPs: map[string][]netaddr.IPPrefix{"x": {
netaddr.MustParseIPPrefix("42.0.0.0/8"), netip.MustParsePrefix("42.0.0.0/8"),
netaddr.MustParseIPPrefix("169.254.0.0/16"), // link local unicast netip.MustParsePrefix("169.254.0.0/16"), // link local unicast
}}, }},
Interface: map[string]Interface{"x": {Interface: &net.Interface{Name: "x"}}}, Interface: map[string]Interface{"x": {Interface: &net.Interface{Name: "x"}}},
} }
s2 := &State{ s2 := &State{
InterfaceIPs: map[string][]netaddr.IPPrefix{"x": { InterfaceIPs: map[string][]netaddr.IPPrefix{"x": {
netaddr.MustParseIPPrefix("42.0.0.0/8"), netip.MustParsePrefix("42.0.0.0/8"),
netaddr.MustParseIPPrefix("169.254.0.0/16"), // link local unicast netip.MustParsePrefix("169.254.0.0/16"), // link local unicast
netaddr.MustParseIPPrefix("127.0.0.0/8"), // loopback (added) netip.MustParsePrefix("127.0.0.0/8"), // loopback (added)
}}, }},
Interface: map[string]Interface{"x": {Interface: &net.Interface{Name: "x"}}}, Interface: map[string]Interface{"x": {Interface: &net.Interface{Name: "x"}}},
} }
@ -127,7 +128,7 @@ func TestStateString(t *testing.T) {
}, },
InterfaceIPs: map[string][]netaddr.IPPrefix{ InterfaceIPs: map[string][]netaddr.IPPrefix{
"eth0": []netaddr.IPPrefix{ "eth0": []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.0.0.2/8"), netip.MustParsePrefix("10.0.0.2/8"),
}, },
}, },
HaveV4: true, 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 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 == "" { if n.IPv6 == "" {
return true return true
} }
ip, _ := netaddr.ParseIP(n.IPv6) ip, _ := netip.ParseAddr(n.IPv6)
return ip.Is6() return ip.Is6()
} }
@ -479,7 +479,7 @@ func nodeMight4(n *tailcfg.DERPNode) bool {
if n.IPv4 == "" { if n.IPv4 == "" {
return true return true
} }
ip, _ := netaddr.ParseIP(n.IPv4) ip, _ := netip.ParseAddr(n.IPv4)
return ip.Is4() return ip.Is4()
} }
@ -1290,7 +1290,7 @@ func (c *Client) nodeAddr(ctx context.Context, n *tailcfg.DERPNode, proto probeP
return return
} }
if n.STUNTestIP != "" { if n.STUNTestIP != "" {
ip, err := netaddr.ParseIP(n.STUNTestIP) ip, err := netip.ParseAddr(n.STUNTestIP)
if err != nil { if err != nil {
return return
} }
@ -1306,7 +1306,7 @@ func (c *Client) nodeAddr(ctx context.Context, n *tailcfg.DERPNode, proto probeP
switch proto { switch proto {
case probeIPv4: case probeIPv4:
if n.IPv4 != "" { if n.IPv4 != "" {
ip, _ := netaddr.ParseIP(n.IPv4) ip, _ := netip.ParseAddr(n.IPv4)
if !ip.Is4() { if !ip.Is4() {
return return
} }
@ -1314,7 +1314,7 @@ func (c *Client) nodeAddr(ctx context.Context, n *tailcfg.DERPNode, proto probeP
} }
case probeIPv6: case probeIPv6:
if n.IPv6 != "" { if n.IPv6 != "" {
ip, _ := netaddr.ParseIP(n.IPv6) ip, _ := netip.ParseAddr(n.IPv6)
if !ip.Is6() { if !ip.Is6() {
return return
} }

@ -17,8 +17,8 @@ package netns
import ( import (
"context" "context"
"net" "net"
"net/netip"
"tailscale.com/net/netaddr"
"tailscale.com/net/netknob" "tailscale.com/net/netknob"
"tailscale.com/syncs" "tailscale.com/syncs"
"tailscale.com/types/logger" "tailscale.com/types/logger"
@ -100,6 +100,6 @@ func isLocalhost(addr string) bool {
return true return true
} }
ip, _ := netaddr.ParseIP(host) ip, _ := netip.ParseAddr(host)
return ip.IsLoopback() return ip.IsLoopback()
} }

@ -5,17 +5,17 @@
package packet package packet
import ( import (
"net/netip"
"testing" "testing"
"tailscale.com/net/netaddr"
"tailscale.com/types/ipproto" "tailscale.com/types/ipproto"
) )
func TestICMPv6PingResponse(t *testing.T) { func TestICMPv6PingResponse(t *testing.T) {
pingHdr := ICMP6Header{ pingHdr := ICMP6Header{
IP6Header: IP6Header{ IP6Header: IP6Header{
Src: netaddr.MustParseIP("1::1"), Src: netip.MustParseAddr("1::1"),
Dst: netaddr.MustParseIP("2::2"), Dst: netip.MustParseAddr("2::2"),
IPProto: ipproto.ICMPv6, IPProto: ipproto.ICMPv6,
}, },
Type: ICMP6EchoRequest, Type: ICMP6EchoRequest,

@ -6,6 +6,7 @@ package packet
import ( import (
"bytes" "bytes"
"net/netip"
"reflect" "reflect"
"testing" "testing"
@ -27,7 +28,7 @@ const (
) )
func mustIPPort(s string) netaddr.IPPort { func mustIPPort(s string) netaddr.IPPort {
ipp, err := netaddr.ParseIPPort(s) ipp, err := netip.ParseAddrPort(s)
if err != nil { if err != nil {
panic(err) panic(err)
} }

@ -5,9 +5,8 @@
package packet package packet
import ( import (
"net/netip"
"testing" "testing"
"tailscale.com/net/netaddr"
) )
func TestTailscaleRejectedHeader(t *testing.T) { func TestTailscaleRejectedHeader(t *testing.T) {
@ -17,10 +16,10 @@ func TestTailscaleRejectedHeader(t *testing.T) {
}{ }{
{ {
h: TailscaleRejectedHeader{ h: TailscaleRejectedHeader{
IPSrc: netaddr.MustParseIP("5.5.5.5"), IPSrc: netip.MustParseAddr("5.5.5.5"),
IPDst: netaddr.MustParseIP("1.2.3.4"), IPDst: netip.MustParseAddr("1.2.3.4"),
Src: netaddr.MustParseIPPort("1.2.3.4:567"), Src: netip.MustParseAddrPort("1.2.3.4:567"),
Dst: netaddr.MustParseIPPort("5.5.5.5:443"), Dst: netip.MustParseAddrPort("5.5.5.5:443"),
Proto: TCP, Proto: TCP,
Reason: RejectedDueToACLs, Reason: RejectedDueToACLs,
}, },
@ -28,10 +27,10 @@ func TestTailscaleRejectedHeader(t *testing.T) {
}, },
{ {
h: TailscaleRejectedHeader{ h: TailscaleRejectedHeader{
IPSrc: netaddr.MustParseIP("2::2"), IPSrc: netip.MustParseAddr("2::2"),
IPDst: netaddr.MustParseIP("1::1"), IPDst: netip.MustParseAddr("1::1"),
Src: netaddr.MustParseIPPort("[1::1]:567"), Src: netip.MustParseAddrPort("[1::1]:567"),
Dst: netaddr.MustParseIPPort("[2::2]:443"), Dst: netip.MustParseAddrPort("[2::2]:443"),
Proto: UDP, Proto: UDP,
Reason: RejectedDueToShieldsUp, Reason: RejectedDueToShieldsUp,
}, },
@ -39,10 +38,10 @@ func TestTailscaleRejectedHeader(t *testing.T) {
}, },
{ {
h: TailscaleRejectedHeader{ h: TailscaleRejectedHeader{
IPSrc: netaddr.MustParseIP("2::2"), IPSrc: netip.MustParseAddr("2::2"),
IPDst: netaddr.MustParseIP("1::1"), IPDst: netip.MustParseAddr("1::1"),
Src: netaddr.MustParseIPPort("[1::1]:567"), Src: netip.MustParseAddrPort("[1::1]:567"),
Dst: netaddr.MustParseIPPort("[2::2]:443"), Dst: netip.MustParseAddrPort("[2::2]:443"),
Proto: UDP, Proto: UDP,
Reason: RejectedDueToIPForwarding, Reason: RejectedDueToIPForwarding,
MaybeBroken: true, MaybeBroken: true,

@ -6,6 +6,7 @@ package portmapper
import ( import (
"encoding/binary" "encoding/binary"
"net/netip"
"testing" "testing"
"tailscale.com/net/netaddr" "tailscale.com/net/netaddr"
@ -21,7 +22,7 @@ func TestParsePCPMapResponse(t *testing.T) {
if mapping == nil { if mapping == nil {
t.Fatalf("got nil mapping when expected non-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 { if mapping.external != expectedAddr {
t.Errorf("mismatched external address, got: %v, want: %v", 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. // 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 // createOrGetMapping either creates a new mapping or returns a cached
// valid one. // valid one.

@ -16,6 +16,7 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"net/http" "net/http"
"net/netip"
"net/url" "net/url"
"strings" "strings"
"time" "time"
@ -170,7 +171,7 @@ func getUPnPClient(ctx context.Context, logf logger.Logf, gw netaddr.IP, meta uP
return nil, err return nil, err
} }
ipp, err := netaddr.ParseIPPort(u.Host) ipp, err := netip.ParseAddrPort(u.Host)
if err != nil { if err != nil {
return nil, fmt.Errorf("unexpected host %q in %q", u.Host, meta.Location) 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 // TODO this doesn't seem right
return netaddr.IPPort{}, false return netaddr.IPPort{}, false
} }
externalIP, err := netaddr.ParseIP(extIP) externalIP, err := netip.ParseAddr(extIP)
if err != nil { if err != nil {
return netaddr.IPPort{}, false return netaddr.IPPort{}, false
} }

@ -9,12 +9,12 @@ import (
"context" "context"
"fmt" "fmt"
"net" "net"
"net/netip"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"testing" "testing"
"tailscale.com/net/netaddr"
"tailscale.com/net/stun" "tailscale.com/net/stun"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/types/nettype" "tailscale.com/types/nettype"
@ -106,7 +106,7 @@ func DERPMapOf(stun ...string) *tailcfg.DERPMap {
panic(fmt.Sprintf("bogus port %q in %q", portStr, hostPortStr)) panic(fmt.Sprintf("bogus port %q in %q", portStr, hostPortStr))
} }
var ipv4, ipv6 string var ipv4, ipv6 string
ip, err := netaddr.ParseIP(host) ip, err := netip.ParseAddr(host)
if err != nil { if err != nil {
panic(fmt.Sprintf("bogus non-IP STUN host %q in %q", host, hostPortStr)) 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) { func mustPrefix(v *netaddr.IPPrefix, prefix string) {
var err error var err error
*v, err = netaddr.ParseIPPrefix(prefix) *v, err = netip.ParsePrefix(prefix)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -253,8 +253,8 @@ func ContainsExitRoutes(rr []netaddr.IPPrefix) bool {
} }
var ( var (
allIPv4 = netaddr.MustParseIPPrefix("0.0.0.0/0") allIPv4 = netip.MustParsePrefix("0.0.0.0/0")
allIPv6 = netaddr.MustParseIPPrefix("::/0") allIPv6 = netip.MustParsePrefix("::/0")
) )
// AllIPv4 returns 0.0.0.0/0. // AllIPv4 returns 0.0.0.0/0.

@ -5,6 +5,7 @@
package tsaddr package tsaddr
import ( import (
"net/netip"
"testing" "testing"
"tailscale.com/net/netaddr" "tailscale.com/net/netaddr"
@ -52,30 +53,30 @@ func TestCGNATRange(t *testing.T) {
} }
func TestNewContainsIPFunc(t *testing.T) { func TestNewContainsIPFunc(t *testing.T) {
f := NewContainsIPFunc([]netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.0.0.0/8")}) f := NewContainsIPFunc([]netaddr.IPPrefix{netip.MustParsePrefix("10.0.0.0/8")})
if f(netaddr.MustParseIP("8.8.8.8")) { if f(netip.MustParseAddr("8.8.8.8")) {
t.Fatal("bad") t.Fatal("bad")
} }
if !f(netaddr.MustParseIP("10.1.2.3")) { if !f(netip.MustParseAddr("10.1.2.3")) {
t.Fatal("bad") t.Fatal("bad")
} }
f = NewContainsIPFunc([]netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.1.2.3/32")}) f = NewContainsIPFunc([]netaddr.IPPrefix{netip.MustParsePrefix("10.1.2.3/32")})
if !f(netaddr.MustParseIP("10.1.2.3")) { if !f(netip.MustParseAddr("10.1.2.3")) {
t.Fatal("bad") t.Fatal("bad")
} }
f = NewContainsIPFunc([]netaddr.IPPrefix{ f = NewContainsIPFunc([]netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.1.2.3/32"), netip.MustParsePrefix("10.1.2.3/32"),
netaddr.MustParseIPPrefix("::2/128"), netip.MustParsePrefix("::2/128"),
}) })
if !f(netaddr.MustParseIP("::2")) { if !f(netip.MustParseAddr("::2")) {
t.Fatal("bad") t.Fatal("bad")
} }
f = NewContainsIPFunc([]netaddr.IPPrefix{ f = NewContainsIPFunc([]netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.1.2.3/32"), netip.MustParsePrefix("10.1.2.3/32"),
netaddr.MustParseIPPrefix("10.1.2.4/32"), netip.MustParsePrefix("10.1.2.4/32"),
netaddr.MustParseIPPrefix("::2/128"), netip.MustParsePrefix("::2/128"),
}) })
if !f(netaddr.MustParseIP("10.1.2.4")) { if !f(netip.MustParseAddr("10.1.2.4")) {
t.Fatal("bad") 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" {"fd7a:115c:a1e0:b1b::bb:10.2.1.4", "fd7a:115c:a1e0:b1b:0:bb:a02:104"}, // "b1b",not "bia"
} }
for _, tt := range tests { 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) t.Errorf("for %q: got %q, want %q", tt.ip, got, tt.want)
} }
} }

@ -9,6 +9,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"net" "net"
"net/netip"
"strconv" "strconv"
"strings" "strings"
@ -68,7 +69,7 @@ func dnsMapFromNetworkMap(nm *netmap.NetworkMap) dnsMap {
if rec.Type != "" { if rec.Type != "" {
continue continue
} }
ip, err := netaddr.ParseIP(rec.Value) ip, err := netip.ParseAddr(rec.Value)
if err != nil { if err != nil {
continue continue
} }
@ -103,7 +104,7 @@ func (m dnsMap) resolveMemory(ctx context.Context, network, addr string) (_ neta
// addr malformed or invalid port. // addr malformed or invalid port.
return netaddr.IPPort{}, err 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. // addr was literal ip:port.
return netaddr.IPPortFrom(ip, port), nil return netaddr.IPPortFrom(ip, port), nil
} }

@ -5,6 +5,7 @@
package tsdial package tsdial
import ( import (
"net/netip"
"reflect" "reflect"
"testing" "testing"
@ -14,8 +15,8 @@ import (
) )
func TestDNSMapFromNetworkMap(t *testing.T) { func TestDNSMapFromNetworkMap(t *testing.T) {
pfx := netaddr.MustParseIPPrefix pfx := netip.MustParsePrefix
ip := netaddr.MustParseIP ip := netip.MustParseAddr
tests := []struct { tests := []struct {
name string name string
nm *netmap.NetworkMap nm *netmap.NetworkMap

@ -11,6 +11,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
"net/netip"
"runtime" "runtime"
"strings" "strings"
"sync" "sync"
@ -330,7 +331,7 @@ func (d *Dialer) dialPeerAPI(ctx context.Context, network, addr string) (net.Con
default: default:
return nil, fmt.Errorf("peerAPI dial requires tcp; %q not supported", network) 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 { if err != nil {
return nil, fmt.Errorf("peerAPI dial requires ip:port, not name resolution: %w", err) return nil, fmt.Errorf("peerAPI dial requires ip:port, not name resolution: %w", err)
} }

@ -8,6 +8,7 @@ import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"net/netip"
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
@ -28,11 +29,11 @@ import (
) )
func udp4(src, dst string, sport, dport uint16) []byte { func udp4(src, dst string, sport, dport uint16) []byte {
sip, err := netaddr.ParseIP(src) sip, err := netip.ParseAddr(src)
if err != nil { if err != nil {
panic(err) panic(err)
} }
dip, err := netaddr.ParseIP(dst) dip, err := netip.ParseAddr(dst)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -49,11 +50,11 @@ func udp4(src, dst string, sport, dport uint16) []byte {
} }
func tcp4syn(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 { if err != nil {
panic(err) panic(err)
} }
dip, err := netaddr.ParseIP(dst) dip, err := netip.ParseAddr(dst)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -79,7 +80,7 @@ func tcp4syn(src, dst string, sport, dport uint16) []byte {
func nets(nets ...string) (ret []netaddr.IPPrefix) { func nets(nets ...string) (ret []netaddr.IPPrefix) {
for _, s := range nets { for _, s := range nets {
if i := strings.IndexByte(s, '/'); i == -1 { if i := strings.IndexByte(s, '/'); i == -1 {
ip, err := netaddr.ParseIP(s) ip, err := netip.ParseAddr(s)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -89,7 +90,7 @@ func nets(nets ...string) (ret []netaddr.IPPrefix) {
} }
ret = append(ret, netaddr.IPPrefixFrom(ip, bits)) ret = append(ret, netaddr.IPPrefixFrom(ip, bits))
} else { } else {
pfx, err := netaddr.ParseIPPrefix(s) pfx, err := netip.ParsePrefix(s)
if err != nil { if err != nil {
panic(err) 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")}, {IPProto: protos, Srcs: nets("1.2.3.4"), Dsts: netports("5.6.7.8:98")},
} }
var sb netipx.IPSetBuilder 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() ipSet, _ := sb.IPSet()
tun.SetFilter(filter.New(matches, ipSet, ipSet, nil, logf)) tun.SetFilter(filter.New(matches, ipSet, ipSet, nil, logf))
} }
@ -428,7 +429,7 @@ func TestAtomic64Alignment(t *testing.T) {
func TestPeerAPIBypass(t *testing.T) { func TestPeerAPIBypass(t *testing.T) {
wrapperWithPeerAPI := &Wrapper{ wrapperWithPeerAPI := &Wrapper{
PeerAPIPort: func(ip netaddr.IP) (port uint16, ok bool) { 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 60000, true
} }
return return

@ -20,6 +20,7 @@ import (
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"
"net/netip"
"net/url" "net/url"
"os" "os"
"os/exec" "os/exec"
@ -1227,7 +1228,7 @@ func (c *conn) principalMatchesTailscaleIdentity(p *tailcfg.SSHPrincipal) bool {
return true return true
} }
if p.NodeIP != "" { if p.NodeIP != "" {
if ip, _ := netaddr.ParseIP(p.NodeIP); ip == ci.src.Addr() { if ip, _ := netip.ParseAddr(p.NodeIP); ip == ci.src.Addr() {
return true return true
} }
} }

@ -16,6 +16,7 @@ import (
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/netip"
"os" "os"
"os/exec" "os/exec"
"os/user" "os/user"
@ -27,7 +28,6 @@ import (
"tailscale.com/ipn/ipnlocal" "tailscale.com/ipn/ipnlocal"
"tailscale.com/ipn/store/mem" "tailscale.com/ipn/store/mem"
"tailscale.com/net/netaddr"
"tailscale.com/net/tsdial" "tailscale.com/net/tsdial"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/tempfork/gliderlabs/ssh" "tailscale.com/tempfork/gliderlabs/ssh"
@ -153,7 +153,7 @@ func TestMatchRule(t *testing.T) {
Principals: []*tailcfg.SSHPrincipal{{NodeIP: "1.2.3.4"}}, Principals: []*tailcfg.SSHPrincipal{{NodeIP: "1.2.3.4"}},
SSHUsers: map[string]string{"*": "ubuntu"}, SSHUsers: map[string]string{"*": "ubuntu"},
}, },
ci: &sshConnInfo{src: netaddr.MustParseIPPort("1.2.3.4:30343")}, ci: &sshConnInfo{src: netip.MustParseAddrPort("1.2.3.4:30343")},
wantUser: "ubuntu", wantUser: "ubuntu",
}, },
{ {
@ -246,8 +246,8 @@ func TestSSH(t *testing.T) {
sc.localUser = u sc.localUser = u
sc.info = &sshConnInfo{ sc.info = &sshConnInfo{
sshUser: "test", sshUser: "test",
src: netaddr.MustParseIPPort("1.2.3.4:32342"), src: netip.MustParseAddrPort("1.2.3.4:32342"),
dst: netaddr.MustParseIPPort("1.2.3.5:22"), dst: netip.MustParseAddrPort("1.2.3.5:22"),
node: &tailcfg.Node{}, node: &tailcfg.Node{},
uprof: &tailcfg.UserProfile{}, uprof: &tailcfg.UserProfile{},
} }

@ -7,6 +7,7 @@ package tailcfg
import ( import (
"encoding" "encoding"
"encoding/json" "encoding/json"
"net/netip"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -41,7 +42,7 @@ func TestHostinfoEqual(t *testing.T) {
nets := func(strs ...string) (ns []netaddr.IPPrefix) { nets := func(strs ...string) (ns []netaddr.IPPrefix) {
for _, s := range strs { for _, s := range strs {
n, err := netaddr.ParseIPPrefix(s) n, err := netip.ParsePrefix(s)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -224,12 +225,12 @@ func TestHostinfoHowEqual(t *testing.T) {
a: &Hostinfo{ a: &Hostinfo{
IPNVersion: "1", IPNVersion: "1",
ShieldsUp: false, ShieldsUp: false,
RoutableIPs: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.2.3.0/24")}, RoutableIPs: []netaddr.IPPrefix{netip.MustParsePrefix("1.2.3.0/24")},
}, },
b: &Hostinfo{ b: &Hostinfo{
IPNVersion: "2", IPNVersion: "2",
ShieldsUp: true, ShieldsUp: true,
RoutableIPs: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.2.3.0/25")}, RoutableIPs: []netaddr.IPPrefix{netip.MustParsePrefix("1.2.3.0/25")},
}, },
want: []string{"IPNVersion", "ShieldsUp", "RoutableIPs"}, want: []string{"IPNVersion", "ShieldsUp", "RoutableIPs"},
}, },

@ -18,6 +18,7 @@ import (
"log" "log"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/netip"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -830,7 +831,7 @@ func (n *testNode) AwaitIPs() []netaddr.IP {
addrs = make([]netaddr.IP, len(ipslice)) addrs = make([]netaddr.IP, len(ipslice))
for i, ip := range ipslice { for i, ip := range ipslice {
netIP, err := netaddr.ParseIP(ip) netIP, err := netip.ParseAddr(ip)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -19,6 +19,7 @@ import (
"math/rand" "math/rand"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/netip"
"net/url" "net/url"
"sort" "sort"
"strings" "strings"
@ -859,7 +860,7 @@ func filterInvalidIPv6Endpoints(eps []string) []string {
} }
func keepClientEndpoint(ep string) bool { func keepClientEndpoint(ep string) bool {
ipp, err := netaddr.ParseIPPort(ep) ipp, err := netip.ParseAddrPort(ep)
if err != nil { if err != nil {
// Shouldn't have made it this far if we unmarshalled // Shouldn't have made it this far if we unmarshalled
// the incoming JSON response. // the incoming JSON response.

@ -14,6 +14,7 @@ import (
"log" "log"
"net" "net"
"net/http" "net/http"
"net/netip"
"os" "os"
"os/exec" "os/exec"
"path" "path"
@ -240,5 +241,5 @@ outer:
} }
func bytes2Netaddr(inp []byte) netaddr.IP { func bytes2Netaddr(inp []byte) netaddr.IP {
return netaddr.MustParseIP(string(bytes.TrimSpace(inp))) return netip.MustParseAddr(string(bytes.TrimSpace(inp)))
} }

@ -13,6 +13,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"net" "net"
"net/netip"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -452,7 +453,7 @@ func (h *Harness) testDistro(t *testing.T, d Distro, ipm ipMapping) {
t.Fatalf("can't get IP: %v", err) t.Fatalf("can't get IP: %v", err)
} }
netaddr.MustParseIP(string(bytes.TrimSpace(ipBytes))) netip.MustParseAddr(string(bytes.TrimSpace(ipBytes)))
}) })
t.Run("ping-"+tt.ipProto, func(t *testing.T) { t.Run("ping-"+tt.ipProto, func(t *testing.T) {

@ -81,7 +81,7 @@ func (p *Packet) setLocator(msg string, args ...any) {
} }
func mustPrefix(s string) netaddr.IPPrefix { func mustPrefix(s string) netaddr.IPPrefix {
ipp, err := netaddr.ParseIPPrefix(s) ipp, err := netip.ParsePrefix(s)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -680,7 +680,7 @@ func (m *Machine) ListenPacket(ctx context.Context, network, address string) (ne
return nil, err return nil, err
} }
if host != "" { if host != "" {
ip, err = netaddr.ParseIP(host) ip, err = netip.ParseAddr(host)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -841,7 +841,7 @@ func (c *conn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
} }
func (c *conn) WriteTo(p []byte, addr net.Addr) (n int, err error) { func (c *conn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
ipp, err := netaddr.ParseIPPort(addr.String()) ipp, err := netip.ParseAddrPort(addr.String())
if err != nil { if err != nil {
return 0, fmt.Errorf("bogus addr %T %q", addr, addr.String()) return 0, fmt.Errorf("bogus addr %T %q", addr, addr.String())
} }

@ -342,7 +342,7 @@ func testFirewall(t *testing.T, f *Firewall, tests []fwTest) {
} }
func ipp(str string) netaddr.IPPort { func ipp(str string) netaddr.IPPort {
ipp, err := netaddr.ParseIPPort(str) ipp, err := netip.ParseAddrPort(str)
if err != nil { if err != nil {
panic(err) panic(err)
} }

@ -17,6 +17,7 @@ import (
"net" "net"
"net/http" "net/http"
_ "net/http/pprof" _ "net/http/pprof"
"net/netip"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -29,7 +30,6 @@ import (
"go4.org/mem" "go4.org/mem"
"tailscale.com/envknob" "tailscale.com/envknob"
"tailscale.com/metrics" "tailscale.com/metrics"
"tailscale.com/net/netaddr"
"tailscale.com/net/tsaddr" "tailscale.com/net/tsaddr"
"tailscale.com/types/logger" "tailscale.com/types/logger"
"tailscale.com/version" "tailscale.com/version"
@ -70,7 +70,7 @@ func AllowDebugAccess(r *http.Request) bool {
if err != nil { if err != nil {
return false return false
} }
ip, err := netaddr.ParseIP(ipStr) ip, err := netip.ParseAddr(ipStr)
if err != nil { if err != nil {
return false return false
} }

@ -7,7 +7,11 @@ package dnstype
//go:generate go run tailscale.com/cmd/cloner --type=Resolver --clonefunc=true //go:generate go run tailscale.com/cmd/cloner --type=Resolver --clonefunc=true
import "tailscale.com/net/netaddr" import (
"net/netip"
"tailscale.com/net/netaddr"
)
// Resolver is the configuration for one DNS resolver. // Resolver is the configuration for one DNS resolver.
type Resolver struct { type Resolver struct {
@ -37,10 +41,10 @@ func (r *Resolver) IPPort() (ipp netaddr.IPPort, ok bool) {
// cases. // cases.
return return
} }
if ip, err := netaddr.ParseIP(r.Addr); err == nil { if ip, err := netip.ParseAddr(r.Addr); err == nil {
return netaddr.IPPortFrom(ip, 53), true return netaddr.IPPortFrom(ip, 53), true
} }
if ipp, err := netaddr.ParseIPPort(r.Addr); err == nil { if ipp, err := netip.ParseAddrPort(r.Addr); err == nil {
return ipp, true return ipp, true
} }
return return

@ -7,6 +7,7 @@ package views
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"net/netip"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -18,7 +19,7 @@ import (
func TestViewsJSON(t *testing.T) { func TestViewsJSON(t *testing.T) {
mustCIDR := func(cidrs ...string) (out []netaddr.IPPrefix) { mustCIDR := func(cidrs ...string) (out []netaddr.IPPrefix) {
for _, cidr := range cidrs { for _, cidr := range cidrs {
out = append(out, netaddr.MustParseIPPrefix(cidr)) out = append(out, netip.MustParsePrefix(cidr))
} }
return return
} }

@ -13,6 +13,7 @@ import (
"io" "io"
"math" "math"
"math/rand" "math/rand"
"net/netip"
"reflect" "reflect"
"runtime" "runtime"
"testing" "testing"
@ -199,24 +200,24 @@ func getVal() []any {
}, },
&router.Config{ &router.Config{
Routes: []netaddr.IPPrefix{ Routes: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("1.2.3.0/24"), netip.MustParsePrefix("1.2.3.0/24"),
netaddr.MustParseIPPrefix("1234::/64"), netip.MustParsePrefix("1234::/64"),
}, },
}, },
map[dnsname.FQDN][]netaddr.IP{ map[dnsname.FQDN][]netaddr.IP{
dnsname.FQDN("a."): {netaddr.MustParseIP("1.2.3.4"), netaddr.MustParseIP("4.3.2.1")}, dnsname.FQDN("a."): {netip.MustParseAddr("1.2.3.4"), netip.MustParseAddr("4.3.2.1")},
dnsname.FQDN("b."): {netaddr.MustParseIP("8.8.8.8"), netaddr.MustParseIP("9.9.9.9")}, dnsname.FQDN("b."): {netip.MustParseAddr("8.8.8.8"), netip.MustParseAddr("9.9.9.9")},
dnsname.FQDN("c."): {netaddr.MustParseIP("6.6.6.6"), netaddr.MustParseIP("7.7.7.7")}, dnsname.FQDN("c."): {netip.MustParseAddr("6.6.6.6"), netip.MustParseAddr("7.7.7.7")},
dnsname.FQDN("d."): {netaddr.MustParseIP("6.7.6.6"), netaddr.MustParseIP("7.7.7.8")}, dnsname.FQDN("d."): {netip.MustParseAddr("6.7.6.6"), netip.MustParseAddr("7.7.7.8")},
dnsname.FQDN("e."): {netaddr.MustParseIP("6.8.6.6"), netaddr.MustParseIP("7.7.7.9")}, dnsname.FQDN("e."): {netip.MustParseAddr("6.8.6.6"), netip.MustParseAddr("7.7.7.9")},
dnsname.FQDN("f."): {netaddr.MustParseIP("6.9.6.6"), netaddr.MustParseIP("7.7.7.0")}, dnsname.FQDN("f."): {netip.MustParseAddr("6.9.6.6"), netip.MustParseAddr("7.7.7.0")},
}, },
map[dnsname.FQDN][]netaddr.IPPort{ map[dnsname.FQDN][]netaddr.IPPort{
dnsname.FQDN("a."): {netaddr.MustParseIPPort("1.2.3.4:11"), netaddr.MustParseIPPort("4.3.2.1:22")}, dnsname.FQDN("a."): {netip.MustParseAddrPort("1.2.3.4:11"), netip.MustParseAddrPort("4.3.2.1:22")},
dnsname.FQDN("b."): {netaddr.MustParseIPPort("8.8.8.8:11"), netaddr.MustParseIPPort("9.9.9.9:22")}, dnsname.FQDN("b."): {netip.MustParseAddrPort("8.8.8.8:11"), netip.MustParseAddrPort("9.9.9.9:22")},
dnsname.FQDN("c."): {netaddr.MustParseIPPort("8.8.8.8:12"), netaddr.MustParseIPPort("9.9.9.9:23")}, dnsname.FQDN("c."): {netip.MustParseAddrPort("8.8.8.8:12"), netip.MustParseAddrPort("9.9.9.9:23")},
dnsname.FQDN("d."): {netaddr.MustParseIPPort("8.8.8.8:13"), netaddr.MustParseIPPort("9.9.9.9:24")}, dnsname.FQDN("d."): {netip.MustParseAddrPort("8.8.8.8:13"), netip.MustParseAddrPort("9.9.9.9:24")},
dnsname.FQDN("e."): {netaddr.MustParseIPPort("8.8.8.8:14"), netaddr.MustParseIPPort("9.9.9.9:25")}, dnsname.FQDN("e."): {netip.MustParseAddrPort("8.8.8.8:14"), netip.MustParseAddrPort("9.9.9.9:25")},
}, },
map[key.DiscoPublic]bool{ map[key.DiscoPublic]bool{
key.DiscoPublicFromRaw32(mem.B([]byte{1: 1, 31: 0})): true, key.DiscoPublicFromRaw32(mem.B([]byte{1: 1, 31: 0})): true,
@ -405,7 +406,7 @@ func TestGetTypeHasher(t *testing.T) {
var ( var (
someInt = int('A') someInt = int('A')
someComplex128 = complex128(1 + 2i) someComplex128 = complex128(1 + 2i)
someIP = netaddr.MustParseIP("1.2.3.4") someIP = netip.MustParseAddr("1.2.3.4")
) )
tests := []struct { tests := []struct {
name string name string
@ -497,7 +498,7 @@ func TestGetTypeHasher(t *testing.T) {
}, },
{ {
name: "netaddr.IP", name: "netaddr.IP",
val: netaddr.MustParseIP("fe80::123%foo"), val: netip.MustParseAddr("fe80::123%foo"),
out: "\r\x00\x00\x00\x00\x00\x00\x00fe80::123%foo", out: "\r\x00\x00\x00\x00\x00\x00\x00fe80::123%foo",
}, },
{ {
@ -650,7 +651,7 @@ var filterRules = []tailcfg.FilterRule{
}}, }},
IPProto: []int{1, 2, 3, 4}, IPProto: []int{1, 2, 3, 4},
CapGrant: []tailcfg.CapGrant{{ CapGrant: []tailcfg.CapGrant{{
Dsts: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.2.3.4/32")}, Dsts: []netaddr.IPPrefix{netip.MustParsePrefix("1.2.3.4/32")},
Caps: []string{"foo"}, Caps: []string{"foo"},
}}, }},
}, },

@ -9,6 +9,7 @@ package wf
import ( import (
"fmt" "fmt"
"net/netip"
"os" "os"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
@ -18,10 +19,10 @@ import (
// Known addresses. // Known addresses.
var ( var (
linkLocalRange = netaddr.MustParseIPPrefix("ff80::/10") linkLocalRange = netip.MustParsePrefix("ff80::/10")
linkLocalDHCPMulticast = netaddr.MustParseIP("ff02::1:2") linkLocalDHCPMulticast = netip.MustParseAddr("ff02::1:2")
siteLocalDHCPMulticast = netaddr.MustParseIP("ff05::1:3") siteLocalDHCPMulticast = netip.MustParseAddr("ff05::1:3")
linkLocalRouterMulticast = netaddr.MustParseIP("ff02::2") linkLocalRouterMulticast = netip.MustParseAddr("ff02::2")
) )
type direction int type direction int

@ -13,19 +13,19 @@ import (
"net" "net"
"net/http" "net/http"
"net/http/pprof" "net/http/pprof"
"net/netip"
"os" "os"
"strconv" "strconv"
"time" "time"
"tailscale.com/net/netaddr"
"tailscale.com/types/logger" "tailscale.com/types/logger"
) )
const PayloadSize = 1000 const PayloadSize = 1000
const ICMPMinSize = 24 const ICMPMinSize = 24
var Addr1 = netaddr.MustParseIPPrefix("100.64.1.1/32") var Addr1 = netip.MustParsePrefix("100.64.1.1/32")
var Addr2 = netaddr.MustParseIPPrefix("100.64.1.2/32") var Addr2 = netip.MustParsePrefix("100.64.1.2/32")
func main() { func main() {
var logf logger.Logf = log.Printf var logf logger.Logf = log.Printf

@ -7,6 +7,7 @@ package filter
import ( import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"net/netip"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
@ -439,16 +440,16 @@ func TestLoggingPrivacy(t *testing.T) {
} }
var logB netipx.IPSetBuilder var logB netipx.IPSetBuilder
logB.AddPrefix(netaddr.MustParseIPPrefix("100.64.0.0/10")) logB.AddPrefix(netip.MustParsePrefix("100.64.0.0/10"))
logB.AddPrefix(tsaddr.TailscaleULARange()) logB.AddPrefix(tsaddr.TailscaleULARange())
f := newFilter(logf) f := newFilter(logf)
f.logIPs, _ = logB.IPSet() f.logIPs, _ = logB.IPSet()
var ( var (
ts4 = netaddr.IPPortFrom(tsaddr.CGNATRange().Addr().Next(), 1234) ts4 = netaddr.IPPortFrom(tsaddr.CGNATRange().Addr().Next(), 1234)
internet4 = netaddr.IPPortFrom(netaddr.MustParseIP("8.8.8.8"), 1234) internet4 = netaddr.IPPortFrom(netip.MustParseAddr("8.8.8.8"), 1234)
ts6 = netaddr.IPPortFrom(tsaddr.TailscaleULARange().Addr().Next(), 1234) ts6 = netaddr.IPPortFrom(tsaddr.TailscaleULARange().Addr().Next(), 1234)
internet6 = netaddr.IPPortFrom(netaddr.MustParseIP("2001::1"), 1234) internet6 = netaddr.IPPortFrom(netip.MustParseAddr("2001::1"), 1234)
) )
tests := []struct { tests := []struct {
@ -551,7 +552,7 @@ func TestLoggingPrivacy(t *testing.T) {
} }
} }
var mustIP = netaddr.MustParseIP var mustIP = netip.MustParseAddr
func parsed(proto ipproto.Proto, src, dst string, sport, dport uint16) packet.Parsed { func parsed(proto ipproto.Proto, src, dst string, sport, dport uint16) packet.Parsed {
sip, dip := mustIP(src), mustIP(dst) sip, dip := mustIP(src), mustIP(dst)
@ -657,7 +658,7 @@ func parseHexPkt(t *testing.T, h string) *packet.Parsed {
} }
func mustIPPort(s string) netaddr.IPPort { func mustIPPort(s string) netaddr.IPPort {
ipp, err := netaddr.ParseIPPort(s) ipp, err := netip.ParseAddrPort(s)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -666,7 +667,7 @@ func mustIPPort(s string) netaddr.IPPort {
func pfx(strs ...string) (ret []netaddr.IPPrefix) { func pfx(strs ...string) (ret []netaddr.IPPrefix) {
for _, s := range strs { for _, s := range strs {
pfx, err := netaddr.ParseIPPrefix(s) pfx, err := netip.ParsePrefix(s)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -678,7 +679,7 @@ func pfx(strs ...string) (ret []netaddr.IPPrefix) {
func nets(nets ...string) (ret []netaddr.IPPrefix) { func nets(nets ...string) (ret []netaddr.IPPrefix) {
for _, s := range nets { for _, s := range nets {
if !strings.Contains(s, "/") { if !strings.Contains(s, "/") {
ip, err := netaddr.ParseIP(s) ip, err := netip.ParseAddr(s)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -688,7 +689,7 @@ func nets(nets ...string) (ret []netaddr.IPPrefix) {
} }
ret = append(ret, netaddr.IPPrefixFrom(ip, bits)) ret = append(ret, netaddr.IPPrefixFrom(ip, bits))
} else { } else {
pfx, err := netaddr.ParseIPPrefix(s) pfx, err := netip.ParsePrefix(s)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -770,16 +771,16 @@ func TestMatchesFromFilterRules(t *testing.T) {
}, },
Dsts: []NetPortRange{ Dsts: []NetPortRange{
{ {
Net: netaddr.MustParseIPPrefix("0.0.0.0/0"), Net: netip.MustParsePrefix("0.0.0.0/0"),
Ports: PortRange{22, 22}, Ports: PortRange{22, 22},
}, },
{ {
Net: netaddr.MustParseIPPrefix("::0/0"), Net: netip.MustParsePrefix("::0/0"),
Ports: PortRange{22, 22}, Ports: PortRange{22, 22},
}, },
}, },
Srcs: []netaddr.IPPrefix{ Srcs: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("100.64.1.1/32"), netip.MustParsePrefix("100.64.1.1/32"),
}, },
Caps: []CapMatch{}, Caps: []CapMatch{},
}, },
@ -804,12 +805,12 @@ func TestMatchesFromFilterRules(t *testing.T) {
}, },
Dsts: []NetPortRange{ Dsts: []NetPortRange{
{ {
Net: netaddr.MustParseIPPrefix("1.2.0.0/16"), Net: netip.MustParsePrefix("1.2.0.0/16"),
Ports: PortRange{22, 22}, Ports: PortRange{22, 22},
}, },
}, },
Srcs: []netaddr.IPPrefix{ Srcs: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("100.64.1.1/32"), netip.MustParsePrefix("100.64.1.1/32"),
}, },
Caps: []CapMatch{}, Caps: []CapMatch{},
}, },
@ -834,8 +835,8 @@ func TestMatchesFromFilterRules(t *testing.T) {
func TestNewAllowAllForTest(t *testing.T) { func TestNewAllowAllForTest(t *testing.T) {
f := NewAllowAllForTest(logger.Discard) f := NewAllowAllForTest(logger.Discard)
src := netaddr.MustParseIP("100.100.2.3") src := netip.MustParseAddr("100.100.2.3")
dst := netaddr.MustParseIP("100.100.1.2") dst := netip.MustParseAddr("100.100.1.2")
res := f.CheckTCP(src, dst, 80) res := f.CheckTCP(src, dst, 80)
if res.IsDrop() { if res.IsDrop() {
t.Fatalf("unexpected drop verdict: %v", res) t.Fatalf("unexpected drop verdict: %v", res)
@ -885,7 +886,7 @@ func TestCaps(t *testing.T) {
SrcIPs: []string{"*"}, SrcIPs: []string{"*"},
CapGrant: []tailcfg.CapGrant{{ CapGrant: []tailcfg.CapGrant{{
Dsts: []netaddr.IPPrefix{ Dsts: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("0.0.0.0/0"), netip.MustParsePrefix("0.0.0.0/0"),
}, },
Caps: []string{"is_ipv4"}, Caps: []string{"is_ipv4"},
}}, }},
@ -894,7 +895,7 @@ func TestCaps(t *testing.T) {
SrcIPs: []string{"*"}, SrcIPs: []string{"*"},
CapGrant: []tailcfg.CapGrant{{ CapGrant: []tailcfg.CapGrant{{
Dsts: []netaddr.IPPrefix{ Dsts: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("::/0"), netip.MustParsePrefix("::/0"),
}, },
Caps: []string{"is_ipv6"}, Caps: []string{"is_ipv6"},
}}, }},
@ -903,7 +904,7 @@ func TestCaps(t *testing.T) {
SrcIPs: []string{"100.199.0.0/16"}, SrcIPs: []string{"100.199.0.0/16"},
CapGrant: []tailcfg.CapGrant{{ CapGrant: []tailcfg.CapGrant{{
Dsts: []netaddr.IPPrefix{ Dsts: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("100.200.0.0/16"), netip.MustParsePrefix("100.200.0.0/16"),
}, },
Caps: []string{"some_super_admin"}, Caps: []string{"some_super_admin"},
}}, }},
@ -951,7 +952,7 @@ func TestCaps(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got := filt.AppendCaps(nil, netaddr.MustParseIP(tt.src), netaddr.MustParseIP(tt.dst)) got := filt.AppendCaps(nil, netip.MustParseAddr(tt.src), netip.MustParseAddr(tt.dst))
if !reflect.DeepEqual(got, tt.want) { if !reflect.DeepEqual(got, tt.want) {
t.Errorf("got %q; want %q", got, tt.want) t.Errorf("got %q; want %q", got, tt.want)
} }

@ -6,6 +6,7 @@ package filter
import ( import (
"fmt" "fmt"
"net/netip"
"strings" "strings"
"go4.org/netipx" "go4.org/netipx"
@ -122,7 +123,7 @@ func parseIPSet(arg string, bits *int) ([]netaddr.IPPrefix, error) {
}, nil }, nil
} }
if strings.Contains(arg, "/") { if strings.Contains(arg, "/") {
pfx, err := netaddr.ParseIPPrefix(arg) pfx, err := netip.ParsePrefix(arg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -133,11 +134,11 @@ func parseIPSet(arg string, bits *int) ([]netaddr.IPPrefix, error) {
} }
if strings.Count(arg, "-") == 1 { if strings.Count(arg, "-") == 1 {
ip1s, ip2s, _ := strings.Cut(arg, "-") ip1s, ip2s, _ := strings.Cut(arg, "-")
ip1, err := netaddr.ParseIP(ip1s) ip1, err := netip.ParseAddr(ip1s)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ip2, err := netaddr.ParseIP(ip2s) ip2, err := netip.ParseAddr(ip2s)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -147,7 +148,7 @@ func parseIPSet(arg string, bits *int) ([]netaddr.IPPrefix, error) {
} }
return r.Prefixes(), nil return r.Prefixes(), nil
} }
ip, err := netaddr.ParseIP(arg) ip, err := netip.ParseAddr(arg)
if err != nil { if err != nil {
return nil, fmt.Errorf("invalid IP address %q", arg) return nil, fmt.Errorf("invalid IP address %q", arg)
} }

@ -441,7 +441,7 @@ func (c *Conn) addDerpPeerRoute(peer key.NodePublic, derpID int, dc *derphttp.Cl
mak.Set(&c.derpRoute, peer, derpRoute{derpID, dc}) mak.Set(&c.derpRoute, peer, derpRoute{derpID, dc})
} }
var derpMagicIPAddr = netaddr.MustParseIP(tailcfg.DerpMagicIP) var derpMagicIPAddr = netip.MustParseAddr(tailcfg.DerpMagicIP)
// activeDerp contains fields for an active DERP connection. // activeDerp contains fields for an active DERP connection.
type activeDerp struct { type activeDerp struct {
@ -1034,7 +1034,7 @@ func (c *Conn) determineEndpoints(ctx context.Context) ([]tailcfg.Endpoint, erro
// back. // back.
return []tailcfg.Endpoint{ return []tailcfg.Endpoint{
{ {
Addr: netaddr.MustParseIPPort("[fe80:123:456:789::1]:12345"), Addr: netip.MustParseAddrPort("[fe80:123:456:789::1]:12345"),
Type: tailcfg.EndpointLocal, Type: tailcfg.EndpointLocal,
}, },
}, nil }, nil
@ -1044,7 +1044,7 @@ func (c *Conn) determineEndpoints(ctx context.Context) ([]tailcfg.Endpoint, erro
var eps []tailcfg.Endpoint // unique endpoints var eps []tailcfg.Endpoint // unique endpoints
ipp := func(s string) (ipp netaddr.IPPort) { ipp := func(s string) (ipp netaddr.IPPort) {
ipp, _ = netaddr.ParseIPPort(s) ipp, _ = netip.ParseAddrPort(s)
return return
} }
addAddr := func(ipp netaddr.IPPort, et tailcfg.EndpointType) { addAddr := func(ipp netaddr.IPPort, et tailcfg.EndpointType) {
@ -2359,7 +2359,7 @@ func (c *Conn) SetNetworkMap(nm *netmap.NetworkMap) {
c.logf("magicsock: created endpoint key=%s: disco=%s; %v", n.Key.ShortString(), n.DiscoKey.ShortString(), logger.ArgWriter(func(w *bufio.Writer) { c.logf("magicsock: created endpoint key=%s: disco=%s; %v", n.Key.ShortString(), n.DiscoKey.ShortString(), logger.ArgWriter(func(w *bufio.Writer) {
const derpPrefix = "127.3.3.40:" const derpPrefix = "127.3.3.40:"
if strings.HasPrefix(n.DERP, derpPrefix) { if strings.HasPrefix(n.DERP, derpPrefix) {
ipp, _ := netaddr.ParseIPPort(n.DERP) ipp, _ := netip.ParseAddrPort(n.DERP)
regionID := int(ipp.Port()) regionID := int(ipp.Port())
code := c.derpRegionCodeLocked(regionID) code := c.derpRegionCodeLocked(regionID)
if code != "" { if code != "" {
@ -3751,7 +3751,7 @@ func (de *endpoint) updateFromNode(n *tailcfg.Node) {
if n.DERP == "" { if n.DERP == "" {
de.derpAddr = netaddr.IPPort{} de.derpAddr = netaddr.IPPort{}
} else { } else {
de.derpAddr, _ = netaddr.ParseIPPort(n.DERP) de.derpAddr, _ = netip.ParseAddrPort(n.DERP)
} }
for _, st := range de.endpointState { for _, st := range de.endpointState {
@ -3762,7 +3762,7 @@ func (de *endpoint) updateFromNode(n *tailcfg.Node) {
// Seems unlikely. // Seems unlikely.
continue continue
} }
ipp, err := netaddr.ParseIPPort(epStr) ipp, err := netip.ParseAddrPort(epStr)
if err != nil { if err != nil {
de.c.logf("magicsock: bogus netmap endpoint %q", epStr) de.c.logf("magicsock: bogus netmap endpoint %q", epStr)
continue continue

@ -787,11 +787,11 @@ func TestActiveDiscovery(t *testing.T) {
inet := natlab.NewInternet() inet := natlab.NewInternet()
lan1 := &natlab.Network{ lan1 := &natlab.Network{
Name: "lan1", Name: "lan1",
Prefix4: netaddr.MustParseIPPrefix("192.168.0.0/24"), Prefix4: netip.MustParsePrefix("192.168.0.0/24"),
} }
lan2 := &natlab.Network{ lan2 := &natlab.Network{
Name: "lan2", Name: "lan2",
Prefix4: netaddr.MustParseIPPrefix("192.168.1.0/24"), Prefix4: netip.MustParsePrefix("192.168.1.0/24"),
} }
sif := mstun.Attach("eth0", inet) sif := mstun.Attach("eth0", inet)
@ -1010,24 +1010,24 @@ func testTwoDevicePing(t *testing.T, d *devices) {
m1cfg := &wgcfg.Config{ m1cfg := &wgcfg.Config{
Name: "peer1", Name: "peer1",
PrivateKey: m1.privateKey, PrivateKey: m1.privateKey,
Addresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.0.0.1/32")}, Addresses: []netaddr.IPPrefix{netip.MustParsePrefix("1.0.0.1/32")},
Peers: []wgcfg.Peer{ Peers: []wgcfg.Peer{
{ {
PublicKey: m2.privateKey.Public(), PublicKey: m2.privateKey.Public(),
DiscoKey: m2.conn.DiscoPublicKey(), DiscoKey: m2.conn.DiscoPublicKey(),
AllowedIPs: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.0.0.2/32")}, AllowedIPs: []netaddr.IPPrefix{netip.MustParsePrefix("1.0.0.2/32")},
}, },
}, },
} }
m2cfg := &wgcfg.Config{ m2cfg := &wgcfg.Config{
Name: "peer2", Name: "peer2",
PrivateKey: m2.privateKey, PrivateKey: m2.privateKey,
Addresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.0.0.2/32")}, Addresses: []netaddr.IPPrefix{netip.MustParsePrefix("1.0.0.2/32")},
Peers: []wgcfg.Peer{ Peers: []wgcfg.Peer{
{ {
PublicKey: m1.privateKey.Public(), PublicKey: m1.privateKey.Public(),
DiscoKey: m1.conn.DiscoPublicKey(), DiscoKey: m1.conn.DiscoPublicKey(),
AllowedIPs: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.0.0.1/32")}, AllowedIPs: []netaddr.IPPrefix{netip.MustParsePrefix("1.0.0.1/32")},
}, },
}, },
} }
@ -1247,7 +1247,7 @@ func addTestEndpoint(tb testing.TB, conn *Conn, sendConn net.PacketConn) (key.No
if err != nil { if err != nil {
tb.Fatal(err) tb.Fatal(err)
} }
conn.addValidDiscoPathForTest(nodeKey, netaddr.MustParseIPPort(sendConn.LocalAddr().String())) conn.addValidDiscoPathForTest(nodeKey, netip.MustParseAddrPort(sendConn.LocalAddr().String()))
return nodeKey, discoKey return nodeKey, discoKey
} }
@ -1597,7 +1597,7 @@ func TestEndpointSetsEqual(t *testing.T) {
func TestBetterAddr(t *testing.T) { func TestBetterAddr(t *testing.T) {
const ms = time.Millisecond const ms = time.Millisecond
al := func(ipps string, d time.Duration) addrLatency { al := func(ipps string, d time.Duration) addrLatency {
return addrLatency{netaddr.MustParseIPPort(ipps), d} return addrLatency{netip.MustParseAddrPort(ipps), d}
} }
zero := addrLatency{} zero := addrLatency{}
tests := []struct { tests := []struct {

@ -29,7 +29,7 @@ import (
"tailscale.com/wgengine/winnet" "tailscale.com/wgengine/winnet"
) )
var wintunLinkLocal = netaddr.MustParseIP("fe80::99d0:ec2d:b2e7:536b") var wintunLinkLocal = netip.MustParseAddr("fe80::99d0:ec2d:b2e7:536b")
// monitorDefaultRoutes subscribes to route change events and updates // monitorDefaultRoutes subscribes to route change events and updates
// the Tailscale tunnel interface's MTU to match that of the // the Tailscale tunnel interface's MTU to match that of the

@ -8,12 +8,12 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"net" "net"
"net/netip"
"strings" "strings"
"testing" "testing"
"go4.org/netipx" "go4.org/netipx"
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg" "golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
"tailscale.com/net/netaddr"
) )
func randIP() net.IP { func randIP() net.IP {
@ -35,7 +35,7 @@ func randRouteData() *winipcfg.RouteData {
func TestRouteLess(t *testing.T) { func TestRouteLess(t *testing.T) {
type D = winipcfg.RouteData type D = winipcfg.RouteData
ipnet := func(s string) net.IPNet { ipnet := func(s string) net.IPNet {
ipp, err := netaddr.ParseIPPrefix(s) ipp, err := netip.ParsePrefix(s)
if err != nil { if err != nil {
t.Fatalf("error parsing test data %q: %v", s, err) t.Fatalf("error parsing test data %q: %v", s, err)
} }

@ -8,6 +8,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"math/rand" "math/rand"
"net/netip"
"os" "os"
"sort" "sort"
"strings" "strings"
@ -17,7 +18,6 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/vishvananda/netlink" "github.com/vishvananda/netlink"
"golang.zx2c4.com/wireguard/tun" "golang.zx2c4.com/wireguard/tun"
"tailscale.com/net/netaddr"
"tailscale.com/tstest" "tailscale.com/tstest"
"tailscale.com/types/logger" "tailscale.com/types/logger"
"tailscale.com/wgengine/monitor" "tailscale.com/wgengine/monitor"
@ -711,7 +711,7 @@ func TestDelRouteIdempotent(t *testing.T) {
"192.0.2.0/24", // RFC 5737 "192.0.2.0/24", // RFC 5737
"2001:DB8::/32", // RFC 3849 "2001:DB8::/32", // RFC 3849
} { } {
cidr := netaddr.MustParseIPPrefix(s) cidr := netip.MustParsePrefix(s)
if err := lt.r.addRoute(cidr); err != nil { if err := lt.r.addRoute(cidr); err != nil {
t.Error(err) t.Error(err)
continue continue

@ -5,6 +5,7 @@
package router package router
import ( import (
"net/netip"
"reflect" "reflect"
"testing" "testing"
@ -15,7 +16,7 @@ import (
func mustCIDRs(ss ...string) []netaddr.IPPrefix { func mustCIDRs(ss ...string) []netaddr.IPPrefix {
var ret []netaddr.IPPrefix var ret []netaddr.IPPrefix
for _, s := range ss { for _, s := range ss {
ret = append(ret, netaddr.MustParseIPPrefix(s)) ret = append(ret, netip.MustParsePrefix(s))
} }
return ret return ret
} }
@ -37,7 +38,7 @@ func TestConfigEqual(t *testing.T) {
nets := func(strs ...string) (ns []netaddr.IPPrefix) { nets := func(strs ...string) (ns []netaddr.IPPrefix) {
for _, s := range strs { for _, s := range strs {
n, err := netaddr.ParseIPPrefix(s) n, err := netip.ParsePrefix(s)
if err != nil { if err != nil {
panic(err) panic(err)
} }

@ -1589,9 +1589,9 @@ func dnsIPsOverTailscale(dnsCfg *dns.Config, routerCfg *router.Config) (ret []ne
add := func(resolvers []*dnstype.Resolver) { add := func(resolvers []*dnstype.Resolver) {
for _, r := range resolvers { for _, r := range resolvers {
ip, err := netaddr.ParseIP(r.Addr) ip, err := netip.ParseAddr(r.Addr)
if err != nil { if err != nil {
if ipp, err := netaddr.ParseIPPort(r.Addr); err == nil { if ipp, err := netip.ParseAddrPort(r.Addr); err == nil {
ip = ipp.Addr() ip = ipp.Addr()
} else { } else {
continue continue

@ -6,6 +6,7 @@ package wgengine
import ( import (
"fmt" "fmt"
"net/netip"
"reflect" "reflect"
"testing" "testing"
@ -223,9 +224,9 @@ func nkFromHex(hex string) key.NodePublic {
// an experiment to see if genLocalAddrFunc was worth it. As of Go // an experiment to see if genLocalAddrFunc was worth it. As of Go
// 1.16, it still very much is. (30-40x faster) // 1.16, it still very much is. (30-40x faster)
func BenchmarkGenLocalAddrFunc(b *testing.B) { func BenchmarkGenLocalAddrFunc(b *testing.B) {
la1 := netaddr.MustParseIP("1.2.3.4") la1 := netip.MustParseAddr("1.2.3.4")
la2 := netaddr.MustParseIP("::4") la2 := netip.MustParseAddr("::4")
lanot := netaddr.MustParseIP("5.5.5.5") lanot := netip.MustParseAddr("5.5.5.5")
var x bool var x bool
b.Run("map1", func(b *testing.B) { b.Run("map1", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()

@ -30,13 +30,13 @@ func TestDeviceConfig(t *testing.T) {
return k.Public(), k return k.Public(), k
} }
k1, pk1 := newK() k1, pk1 := newK()
ip1 := netaddr.MustParseIPPrefix("10.0.0.1/32") ip1 := netip.MustParsePrefix("10.0.0.1/32")
k2, pk2 := newK() k2, pk2 := newK()
ip2 := netaddr.MustParseIPPrefix("10.0.0.2/32") ip2 := netip.MustParsePrefix("10.0.0.2/32")
k3, _ := newK() k3, _ := newK()
ip3 := netaddr.MustParseIPPrefix("10.0.0.3/32") ip3 := netip.MustParsePrefix("10.0.0.3/32")
cfg1 := &Config{ cfg1 := &Config{
PrivateKey: pk1, PrivateKey: pk1,

@ -8,6 +8,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"io" "io"
"net/netip"
"reflect" "reflect"
"runtime" "runtime"
"testing" "testing"
@ -67,7 +68,7 @@ func BenchmarkFromUAPI(b *testing.B) {
return k.Public(), k return k.Public(), k
} }
k1, pk1 := newK() k1, pk1 := newK()
ip1 := netaddr.MustParseIPPrefix("10.0.0.1/32") ip1 := netip.MustParsePrefix("10.0.0.1/32")
peer := Peer{ peer := Peer{
PublicKey: k1, PublicKey: k1,

Loading…
Cancel
Save