net/netaddr: start migrating to net/netip via new netaddr adapter package

Updates #5162

Change-Id: Id7bdec303b25471f69d542f8ce43805328d56c12
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2022-07-24 20:08:42 -07:00
committed by Brad Fitzpatrick
parent 7b1a91dfd3
commit 7eaf5e509f
191 changed files with 1009 additions and 888 deletions

View File

@@ -7,7 +7,7 @@ package dnstype
//go:generate go run tailscale.com/cmd/cloner --type=Resolver --clonefunc=true
import "inet.af/netaddr"
import "tailscale.com/net/netaddr"
// Resolver is the configuration for one DNS resolver.
type Resolver struct {

View File

@@ -7,7 +7,7 @@
package dnstype
import (
"inet.af/netaddr"
"net/netip"
)
// Clone makes a deep copy of Resolver.
@@ -25,7 +25,7 @@ func (src *Resolver) Clone() *Resolver {
// A compilation failure here means this code must be regenerated, with the command at the top of this file.
var _ResolverCloneNeedsRegeneration = Resolver(struct {
Addr string
BootstrapResolution []netaddr.IP
BootstrapResolution []netip.Addr
}{})
// Clone duplicates src into dst and reports whether it succeeded.

View File

@@ -10,7 +10,7 @@ import (
"encoding/json"
"errors"
"inet.af/netaddr"
"tailscale.com/net/netaddr"
"tailscale.com/types/views"
)

View File

@@ -156,7 +156,7 @@ func (p NodePublic) Shard() uint8 {
// good-enough-for-sharding random, so we haphazardly
// combine raw values of the key to give us something sufficient.
s := uint8(p.k[31]) + uint8(p.k[30]) + uint8(p.k[20])
return s ^ uint8(p.k[2] + p.k[12])
return s ^ uint8(p.k[2]+p.k[12])
}
// ParseNodePublicUntyped parses an untyped 64-character hex value

View File

@@ -12,7 +12,7 @@ import (
"strings"
"time"
"inet.af/netaddr"
"tailscale.com/net/netaddr"
"tailscale.com/tailcfg"
"tailscale.com/types/key"
"tailscale.com/wgengine/filter"
@@ -81,7 +81,7 @@ func (nm *NetworkMap) PeerByTailscaleIP(ip netaddr.IP) (peer *tailcfg.Node, ok b
}
for _, n := range nm.Peers {
for _, a := range n.Addresses {
if a.IP() == ip {
if a.Addr() == ip {
return n, true
}
}

View File

@@ -9,7 +9,7 @@ import (
"testing"
"go4.org/mem"
"inet.af/netaddr"
"tailscale.com/net/netaddr"
"tailscale.com/tailcfg"
"tailscale.com/types/key"
)

View File

@@ -8,6 +8,7 @@ package nettype
import (
"context"
"net"
"net/netip"
)
// PacketListener defines the ListenPacket method as implemented
@@ -16,6 +17,10 @@ type PacketListener interface {
ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)
}
type PacketListenerWithNetIP interface {
ListenPacket(ctx context.Context, network, address string) (PacketConn, error)
}
// Std implements PacketListener using the Go net package's ListenPacket func.
type Std struct{}
@@ -23,3 +28,24 @@ func (Std) ListenPacket(ctx context.Context, network, address string) (net.Packe
var conf net.ListenConfig
return conf.ListenPacket(ctx, network, address)
}
type PacketConn interface {
net.PacketConn
WriteToUDPAddrPort([]byte, netip.AddrPort) (int, error)
}
func MakePacketListenerWithNetIP(ln PacketListener) PacketListenerWithNetIP {
return packetListenerAdapter{ln}
}
type packetListenerAdapter struct {
PacketListener
}
func (a packetListenerAdapter) ListenPacket(ctx context.Context, network, address string) (PacketConn, error) {
pc, err := a.PacketListener.ListenPacket(ctx, network, address)
if err != nil {
return nil, err
}
return pc.(PacketConn), nil
}

View File

@@ -10,7 +10,7 @@ import (
"encoding/json"
"errors"
"inet.af/netaddr"
"tailscale.com/net/netaddr"
"tailscale.com/net/tsaddr"
)

View File

@@ -12,7 +12,7 @@ import (
"testing"
qt "github.com/frankban/quicktest"
"inet.af/netaddr"
"tailscale.com/net/netaddr"
)
func TestViewsJSON(t *testing.T) {