mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-12 13:48:01 +00:00
all: adapt to opaque netaddr types
This commit is a mishmash of automated edits using gofmt: gofmt -r 'netaddr.IPPort{IP: a, Port: b} -> netaddr.IPPortFrom(a, b)' -w . gofmt -r 'netaddr.IPPrefix{IP: a, Port: b} -> netaddr.IPPrefixFrom(a, b)' -w . gofmt -r 'a.IP.Is4 -> a.IP().Is4' -w . gofmt -r 'a.IP.As16 -> a.IP().As16' -w . gofmt -r 'a.IP.Is6 -> a.IP().Is6' -w . gofmt -r 'a.IP.As4 -> a.IP().As4' -w . gofmt -r 'a.IP.String -> a.IP().String' -w . And regexps: \w*(.*)\.Port = (.*) -> $1 = $1.WithPort($2) \w*(.*)\.IP = (.*) -> $1 = $1.WithIP($2) And lots of manual fixups. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:

committed by
Josh Bleecher Snyder

parent
4f92f405ee
commit
25df067dd0
@@ -87,7 +87,7 @@ func main() {
|
||||
}
|
||||
|
||||
logf("initialized ok.")
|
||||
traf.Start(Addr1.IP, Addr2.IP, PayloadSize+ICMPMinSize, 0)
|
||||
traf.Start(Addr1.IP(), Addr2.IP(), PayloadSize+ICMPMinSize, 0)
|
||||
|
||||
var cur, prev Snapshot
|
||||
var pps int64
|
||||
|
@@ -78,7 +78,7 @@ func runOnce(b *testing.B, setup SetupFunc, payload int) {
|
||||
logf("initialized. (n=%v)", b.N)
|
||||
b.SetBytes(int64(payload))
|
||||
|
||||
traf.Start(Addr1.IP, Addr2.IP, payload, int64(b.N))
|
||||
traf.Start(Addr1.IP(), Addr2.IP(), payload, int64(b.N))
|
||||
|
||||
var cur, prev Snapshot
|
||||
var pps int64
|
||||
|
@@ -98,8 +98,8 @@ const (
|
||||
// everything. Use in tests only, as it permits some kinds of spoofing
|
||||
// attacks to reach the OS network stack.
|
||||
func NewAllowAllForTest(logf logger.Logf) *Filter {
|
||||
any4 := netaddr.IPPrefix{IP: netaddr.IPv4(0, 0, 0, 0), Bits: 0}
|
||||
any6 := netaddr.IPPrefix{IP: netaddr.IPFrom16([16]byte{}), Bits: 0}
|
||||
any4 := netaddr.IPPrefixFrom(netaddr.IPv4(0, 0, 0, 0), 0)
|
||||
any6 := netaddr.IPPrefixFrom(netaddr.IPFrom16([16]byte{}), 0)
|
||||
ms := []Match{
|
||||
{
|
||||
Srcs: []netaddr.IPPrefix{any4},
|
||||
@@ -185,12 +185,12 @@ func matchesFamily(ms matches, keep func(netaddr.IP) bool) matches {
|
||||
var retm Match
|
||||
retm.IPProto = m.IPProto
|
||||
for _, src := range m.Srcs {
|
||||
if keep(src.IP) {
|
||||
if keep(src.IP()) {
|
||||
retm.Srcs = append(retm.Srcs, src)
|
||||
}
|
||||
}
|
||||
for _, dst := range m.Dsts {
|
||||
if keep(dst.Net.IP) {
|
||||
if keep(dst.Net.IP()) {
|
||||
retm.Dsts = append(retm.Dsts, dst)
|
||||
}
|
||||
}
|
||||
@@ -266,12 +266,10 @@ func (f *Filter) CheckTCP(srcIP, dstIP netaddr.IP, dstPort uint16) Response {
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
pkt.Src.IP = srcIP
|
||||
pkt.Dst.IP = dstIP
|
||||
pkt.Src = netaddr.IPPortFrom(srcIP, 0)
|
||||
pkt.Dst = netaddr.IPPortFrom(dstIP, dstPort)
|
||||
pkt.IPProto = ipproto.TCP
|
||||
pkt.TCPFlags = packet.TCPSyn
|
||||
pkt.Src.Port = 0
|
||||
pkt.Dst.Port = dstPort
|
||||
|
||||
return f.RunIn(pkt, 0)
|
||||
}
|
||||
@@ -321,7 +319,7 @@ func (f *Filter) runIn4(q *packet.Parsed) (r Response, why string) {
|
||||
// A compromised peer could try to send us packets for
|
||||
// destinations we didn't explicitly advertise. This check is to
|
||||
// prevent that.
|
||||
if !f.local.Contains(q.Dst.IP) {
|
||||
if !f.local.Contains(q.Dst.IP()) {
|
||||
return Drop, "destination not allowed"
|
||||
}
|
||||
|
||||
@@ -378,7 +376,7 @@ func (f *Filter) runIn6(q *packet.Parsed) (r Response, why string) {
|
||||
// A compromised peer could try to send us packets for
|
||||
// destinations we didn't explicitly advertise. This check is to
|
||||
// prevent that.
|
||||
if !f.local.Contains(q.Dst.IP) {
|
||||
if !f.local.Contains(q.Dst.IP()) {
|
||||
return Drop, "destination not allowed"
|
||||
}
|
||||
|
||||
@@ -480,11 +478,11 @@ func (f *Filter) pre(q *packet.Parsed, rf RunFlags, dir direction) Response {
|
||||
return Drop
|
||||
}
|
||||
|
||||
if q.Dst.IP.IsMulticast() {
|
||||
if q.Dst.IP().IsMulticast() {
|
||||
f.logRateLimit(rf, q, dir, Drop, "multicast")
|
||||
return Drop
|
||||
}
|
||||
if q.Dst.IP.IsLinkLocalUnicast() && q.Dst.IP != gcpDNSAddr {
|
||||
if q.Dst.IP().IsLinkLocalUnicast() && q.Dst.IP() != gcpDNSAddr {
|
||||
f.logRateLimit(rf, q, dir, Drop, "link-local-unicast")
|
||||
return Drop
|
||||
}
|
||||
@@ -506,7 +504,7 @@ func (f *Filter) pre(q *packet.Parsed, rf RunFlags, dir direction) Response {
|
||||
|
||||
// loggingAllowed reports whether p can appear in logs at all.
|
||||
func (f *Filter) loggingAllowed(p *packet.Parsed) bool {
|
||||
return f.logIPs.Contains(p.Src.IP) && f.logIPs.Contains(p.Dst.IP)
|
||||
return f.logIPs.Contains(p.Src.IP()) && f.logIPs.Contains(p.Dst.IP())
|
||||
}
|
||||
|
||||
// omitDropLogging reports whether packet p, which has already been
|
||||
@@ -518,5 +516,5 @@ func omitDropLogging(p *packet.Parsed, dir direction) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
return p.Dst.IP.IsMulticast() || (p.Dst.IP.IsLinkLocalUnicast() && p.Dst.IP != gcpDNSAddr) || p.IPProto == ipproto.IGMP
|
||||
return p.Dst.IP().IsMulticast() || (p.Dst.IP().IsLinkLocalUnicast() && p.Dst.IP() != gcpDNSAddr) || p.IPProto == ipproto.IGMP
|
||||
}
|
||||
|
@@ -120,9 +120,9 @@ func TestFilter(t *testing.T) {
|
||||
if test.p.IPProto == ipproto.TCP {
|
||||
var got Response
|
||||
if test.p.IPVersion == 4 {
|
||||
got = acl.CheckTCP(test.p.Src.IP, test.p.Dst.IP, test.p.Dst.Port)
|
||||
got = acl.CheckTCP(test.p.Src.IP(), test.p.Dst.IP(), test.p.Dst.Port())
|
||||
} else {
|
||||
got = acl.CheckTCP(test.p.Src.IP, test.p.Dst.IP, test.p.Dst.Port)
|
||||
got = acl.CheckTCP(test.p.Src.IP(), test.p.Dst.IP(), test.p.Dst.Port())
|
||||
}
|
||||
if test.want != got {
|
||||
t.Errorf("#%d CheckTCP got=%v want=%v packet:%v", i, got, test.want, test.p)
|
||||
@@ -254,7 +254,9 @@ func TestParseIPSet(t *testing.T) {
|
||||
}
|
||||
t.Errorf("parseIPSet(%q, %v) error: %v; want error %q", tt.host, tt.bits, err, tt.wantErr)
|
||||
}
|
||||
if diff := cmp.Diff(got, tt.want, cmp.Comparer(func(a, b netaddr.IP) bool { return a == b })); diff != "" {
|
||||
compareIP := cmp.Comparer(func(a, b netaddr.IP) bool { return a == b })
|
||||
compareIPPrefix := cmp.Comparer(func(a, b netaddr.IPPrefix) bool { return a == b })
|
||||
if diff := cmp.Diff(got, tt.want, compareIP, compareIPPrefix); diff != "" {
|
||||
t.Errorf("parseIPSet(%q, %v) = %s; want %s", tt.host, tt.bits, got, tt.want)
|
||||
continue
|
||||
}
|
||||
@@ -425,10 +427,10 @@ func TestLoggingPrivacy(t *testing.T) {
|
||||
f.logIPs = logB.IPSet()
|
||||
|
||||
var (
|
||||
ts4 = netaddr.IPPort{IP: tsaddr.CGNATRange().IP.Next(), Port: 1234}
|
||||
internet4 = netaddr.IPPort{IP: netaddr.MustParseIP("8.8.8.8"), Port: 1234}
|
||||
ts6 = netaddr.IPPort{IP: tsaddr.TailscaleULARange().IP.Next(), Port: 1234}
|
||||
internet6 = netaddr.IPPort{IP: netaddr.MustParseIP("2001::1"), Port: 1234}
|
||||
ts4 = netaddr.IPPortFrom(tsaddr.CGNATRange().IP().Next(), 1234)
|
||||
internet4 = netaddr.IPPortFrom(netaddr.MustParseIP("8.8.8.8"), 1234)
|
||||
ts6 = netaddr.IPPortFrom(tsaddr.TailscaleULARange().IP().Next(), 1234)
|
||||
internet6 = netaddr.IPPortFrom(netaddr.MustParseIP("2001::1"), 1234)
|
||||
)
|
||||
|
||||
tests := []struct {
|
||||
@@ -545,10 +547,8 @@ func parsed(proto ipproto.Proto, src, dst string, sport, dport uint16) packet.Pa
|
||||
var ret packet.Parsed
|
||||
ret.Decode(dummyPacket)
|
||||
ret.IPProto = proto
|
||||
ret.Src.IP = sip
|
||||
ret.Src.Port = sport
|
||||
ret.Dst.IP = dip
|
||||
ret.Dst.Port = dport
|
||||
ret.Src = netaddr.IPPortFrom(sip, sport)
|
||||
ret.Dst = netaddr.IPPortFrom(dip, dport)
|
||||
ret.TCPFlags = packet.TCPSyn
|
||||
|
||||
if sip.Is4() {
|
||||
@@ -674,7 +674,7 @@ func nets(nets ...string) (ret []netaddr.IPPrefix) {
|
||||
if ip.Is6() {
|
||||
bits = 128
|
||||
}
|
||||
ret = append(ret, netaddr.IPPrefix{IP: ip, Bits: bits})
|
||||
ret = append(ret, netaddr.IPPrefixFrom(ip, bits))
|
||||
} else {
|
||||
pfx, err := netaddr.ParseIPPrefix(s)
|
||||
if err != nil {
|
||||
|
@@ -85,14 +85,14 @@ func (ms matches) match(q *packet.Parsed) bool {
|
||||
if !protoInList(q.IPProto, m.IPProto) {
|
||||
continue
|
||||
}
|
||||
if !ipInList(q.Src.IP, m.Srcs) {
|
||||
if !ipInList(q.Src.IP(), m.Srcs) {
|
||||
continue
|
||||
}
|
||||
for _, dst := range m.Dsts {
|
||||
if !dst.Net.Contains(q.Dst.IP) {
|
||||
if !dst.Net.Contains(q.Dst.IP()) {
|
||||
continue
|
||||
}
|
||||
if !dst.Ports.contains(q.Dst.Port) {
|
||||
if !dst.Ports.contains(q.Dst.Port()) {
|
||||
continue
|
||||
}
|
||||
return true
|
||||
@@ -103,11 +103,11 @@ func (ms matches) match(q *packet.Parsed) bool {
|
||||
|
||||
func (ms matches) matchIPsOnly(q *packet.Parsed) bool {
|
||||
for _, m := range ms {
|
||||
if !ipInList(q.Src.IP, m.Srcs) {
|
||||
if !ipInList(q.Src.IP(), m.Srcs) {
|
||||
continue
|
||||
}
|
||||
for _, dst := range m.Dsts {
|
||||
if dst.Net.Contains(q.Dst.IP) {
|
||||
if dst.Net.Contains(q.Dst.IP()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@@ -99,8 +99,8 @@ func parseIPSet(arg string, bits *int) ([]netaddr.IPPrefix, error) {
|
||||
if arg == "*" {
|
||||
// User explicitly requested wildcard.
|
||||
return []netaddr.IPPrefix{
|
||||
{IP: zeroIP4, Bits: 0},
|
||||
{IP: zeroIP6, Bits: 0},
|
||||
netaddr.IPPrefixFrom(zeroIP4, 0),
|
||||
netaddr.IPPrefixFrom(zeroIP6, 0),
|
||||
}, nil
|
||||
}
|
||||
if strings.Contains(arg, "/") {
|
||||
@@ -124,7 +124,7 @@ func parseIPSet(arg string, bits *int) ([]netaddr.IPPrefix, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := netaddr.IPRange{From: ip1, To: ip2}
|
||||
r := netaddr.IPRangeFrom(ip1, ip2)
|
||||
if !r.Valid() {
|
||||
return nil, fmt.Errorf("invalid IP range %q", arg)
|
||||
}
|
||||
@@ -141,5 +141,5 @@ func parseIPSet(arg string, bits *int) ([]netaddr.IPPrefix, error) {
|
||||
}
|
||||
bits8 = uint8(*bits)
|
||||
}
|
||||
return []netaddr.IPPrefix{{IP: ip, Bits: bits8}}, nil
|
||||
return []netaddr.IPPrefix{netaddr.IPPrefixFrom(ip, bits8)}, nil
|
||||
}
|
||||
|
@@ -62,7 +62,7 @@ func (c *Conn) createLegacyEndpointLocked(pk key.Public, addrs wgcfg.IPPortSet,
|
||||
|
||||
// Add entries to c.addrsByUDP.
|
||||
for _, ipp := range a.ipPorts {
|
||||
if ipp.IP == derpMagicIPAddr {
|
||||
if ipp.IP() == derpMagicIPAddr {
|
||||
continue
|
||||
}
|
||||
c.addrsByUDP[ipp] = a
|
||||
@@ -70,7 +70,7 @@ func (c *Conn) createLegacyEndpointLocked(pk key.Public, addrs wgcfg.IPPortSet,
|
||||
|
||||
// Remove previous c.addrsByUDP entries that are no longer in the new set.
|
||||
for _, ipp := range oldIPP {
|
||||
if ipp.IP != derpMagicIPAddr && c.addrsByUDP[ipp] != a {
|
||||
if ipp.IP() != derpMagicIPAddr && c.addrsByUDP[ipp] != a {
|
||||
delete(c.addrsByUDP, ipp)
|
||||
}
|
||||
}
|
||||
@@ -388,8 +388,8 @@ type addrSet struct {
|
||||
// derpID returns this addrSet's home DERP node, or 0 if none is found.
|
||||
func (as *addrSet) derpID() int {
|
||||
for _, ua := range as.ipPorts {
|
||||
if ua.IP == derpMagicIPAddr {
|
||||
return int(ua.Port)
|
||||
if ua.IP() == derpMagicIPAddr {
|
||||
return int(ua.Port())
|
||||
}
|
||||
}
|
||||
return 0
|
||||
@@ -428,7 +428,7 @@ func (a *addrSet) DstToString() string {
|
||||
return a.rawdst
|
||||
}
|
||||
func (a *addrSet) DstIP() net.IP {
|
||||
return a.dst().IP.IPAddr().IP // TODO: add netaddr accessor to cut an alloc here?
|
||||
return a.dst().IP().IPAddr().IP // TODO: add netaddr accessor to cut an alloc here?
|
||||
}
|
||||
func (a *addrSet) SrcIP() net.IP { return nil }
|
||||
func (a *addrSet) SrcToString() string { return "" }
|
||||
@@ -437,7 +437,7 @@ func (a *addrSet) ClearSrc() {}
|
||||
// updateDst records receipt of a packet from new. This is used to
|
||||
// potentially update the transmit address used for this addrSet.
|
||||
func (a *addrSet) updateDst(new netaddr.IPPort) error {
|
||||
if new.IP == derpMagicIPAddr {
|
||||
if new.IP() == derpMagicIPAddr {
|
||||
// Never consider DERP addresses as a viable candidate for
|
||||
// either curAddr or roamAddr. It's only ever a last resort
|
||||
// choice, never a preferred choice.
|
||||
@@ -539,7 +539,7 @@ func (as *addrSet) populatePeerStatus(ps *ipnstate.PeerStatus) {
|
||||
|
||||
ps.LastWrite = as.lastSend
|
||||
for i, ua := range as.ipPorts {
|
||||
if ua.IP == derpMagicIPAddr {
|
||||
if ua.IP() == derpMagicIPAddr {
|
||||
continue
|
||||
}
|
||||
uaStr := ua.String()
|
||||
|
@@ -832,7 +832,7 @@ func (c *Conn) Ping(peer *tailcfg.Node, res *ipnstate.PingResult, cb func(*ipnst
|
||||
return
|
||||
}
|
||||
if len(peer.Addresses) > 0 {
|
||||
res.NodeIP = peer.Addresses[0].IP.String()
|
||||
res.NodeIP = peer.Addresses[0].IP().String()
|
||||
}
|
||||
res.NodeName = peer.Name // prefer DNS name
|
||||
if res.NodeName == "" {
|
||||
@@ -878,11 +878,11 @@ func (c *Conn) Ping(peer *tailcfg.Node, res *ipnstate.PingResult, cb func(*ipnst
|
||||
// c.mu must be held
|
||||
func (c *Conn) populateCLIPingResponseLocked(res *ipnstate.PingResult, latency time.Duration, ep netaddr.IPPort) {
|
||||
res.LatencySeconds = latency.Seconds()
|
||||
if ep.IP != derpMagicIPAddr {
|
||||
if ep.IP() != derpMagicIPAddr {
|
||||
res.Endpoint = ep.String()
|
||||
return
|
||||
}
|
||||
regionID := int(ep.Port)
|
||||
regionID := int(ep.Port())
|
||||
res.DERPRegionID = regionID
|
||||
if c.derpMap != nil {
|
||||
if dr, ok := c.derpMap.Regions[regionID]; ok {
|
||||
@@ -965,7 +965,7 @@ func (c *Conn) goDerpConnect(node int) {
|
||||
if node == 0 {
|
||||
return
|
||||
}
|
||||
go c.derpWriteChanOfAddr(netaddr.IPPort{IP: derpMagicIPAddr, Port: uint16(node)}, key.Public{})
|
||||
go c.derpWriteChanOfAddr(netaddr.IPPortFrom(derpMagicIPAddr, uint16(node)), key.Public{})
|
||||
}
|
||||
|
||||
// determineEndpoints returns the machine's endpoint addresses. It
|
||||
@@ -1037,7 +1037,7 @@ func (c *Conn) determineEndpoints(ctx context.Context) ([]tailcfg.Endpoint, erro
|
||||
ips = loopback
|
||||
}
|
||||
for _, ip := range ips {
|
||||
addAddr(netaddr.IPPort{IP: ip, Port: uint16(localAddr.Port)}, tailcfg.EndpointLocal)
|
||||
addAddr(netaddr.IPPortFrom(ip, uint16(localAddr.Port)), tailcfg.EndpointLocal)
|
||||
}
|
||||
} else {
|
||||
// Our local endpoint is bound to a particular address.
|
||||
@@ -1169,7 +1169,7 @@ func (c *Conn) sendUDPStd(addr *net.UDPAddr, b []byte) (sent bool, err error) {
|
||||
// IPv6 address when the local machine doesn't have IPv6 support
|
||||
// returns (false, nil); it's not an error, but nothing was sent.
|
||||
func (c *Conn) sendAddr(addr netaddr.IPPort, pubKey key.Public, b []byte) (sent bool, err error) {
|
||||
if addr.IP != derpMagicIPAddr {
|
||||
if addr.IP() != derpMagicIPAddr {
|
||||
return c.sendUDP(addr, b)
|
||||
}
|
||||
|
||||
@@ -1211,10 +1211,10 @@ const bufferedDerpWritesBeforeDrop = 32
|
||||
// If peer is non-zero, it can be used to find an active reverse
|
||||
// path, without using addr.
|
||||
func (c *Conn) derpWriteChanOfAddr(addr netaddr.IPPort, peer key.Public) chan<- derpWriteRequest {
|
||||
if addr.IP != derpMagicIPAddr {
|
||||
if addr.IP() != derpMagicIPAddr {
|
||||
return nil
|
||||
}
|
||||
regionID := int(addr.Port)
|
||||
regionID := int(addr.Port())
|
||||
|
||||
if c.networkDown() {
|
||||
return nil
|
||||
@@ -1402,7 +1402,7 @@ func (c *Conn) runDerpReader(ctx context.Context, derpFakeAddr netaddr.IPPort, d
|
||||
}
|
||||
|
||||
didCopy := make(chan struct{}, 1)
|
||||
regionID := int(derpFakeAddr.Port)
|
||||
regionID := int(derpFakeAddr.Port())
|
||||
res := derpReadResult{regionID: regionID}
|
||||
var pkt derp.ReceivedPacket
|
||||
res.copyBuf = func(dst []byte) int {
|
||||
@@ -1676,7 +1676,7 @@ func (c *Conn) processDERPReadResult(dm derpReadResult, b []byte) (n int, ep con
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
ipp := netaddr.IPPort{IP: derpMagicIPAddr, Port: uint16(regionID)}
|
||||
ipp := netaddr.IPPortFrom(derpMagicIPAddr, uint16(regionID))
|
||||
if c.handleDiscoMessage(b[:n], ipp) {
|
||||
return 0, nil
|
||||
}
|
||||
@@ -1922,7 +1922,7 @@ func (c *Conn) handleDiscoMessage(msg []byte, src netaddr.IPPort) (isDiscoMsg bo
|
||||
}
|
||||
de.handlePongConnLocked(dm, src)
|
||||
case *disco.CallMeMaybe:
|
||||
if src.IP != derpMagicIPAddr {
|
||||
if src.IP() != derpMagicIPAddr {
|
||||
// CallMeMaybe messages should only come via DERP.
|
||||
c.logf("[unexpected] CallMeMaybe packets should only come via DERP")
|
||||
return
|
||||
@@ -2722,7 +2722,7 @@ func (c *Conn) resetEndpointStates() {
|
||||
|
||||
// packIPPort packs an IPPort into the form wanted by WireGuard.
|
||||
func packIPPort(ua netaddr.IPPort) []byte {
|
||||
ip := ua.IP.Unmap()
|
||||
ip := ua.IP().Unmap()
|
||||
a := ip.As16()
|
||||
ipb := a[:]
|
||||
if ip.Is4() {
|
||||
@@ -2730,8 +2730,8 @@ func packIPPort(ua netaddr.IPPort) []byte {
|
||||
}
|
||||
b := make([]byte, 0, len(ipb)+2)
|
||||
b = append(b, ipb...)
|
||||
b = append(b, byte(ua.Port))
|
||||
b = append(b, byte(ua.Port>>8))
|
||||
b = append(b, byte(ua.Port()))
|
||||
b = append(b, byte(ua.Port()>>8))
|
||||
return b
|
||||
}
|
||||
|
||||
@@ -2972,15 +2972,15 @@ func peerShort(k key.Public) string {
|
||||
}
|
||||
|
||||
func sbPrintAddr(sb *strings.Builder, a netaddr.IPPort) {
|
||||
is6 := a.IP.Is6()
|
||||
is6 := a.IP().Is6()
|
||||
if is6 {
|
||||
sb.WriteByte('[')
|
||||
}
|
||||
fmt.Fprintf(sb, "%s", a.IP)
|
||||
fmt.Fprintf(sb, "%s", a.IP())
|
||||
if is6 {
|
||||
sb.WriteByte(']')
|
||||
}
|
||||
fmt.Fprintf(sb, ":%d", a.Port)
|
||||
fmt.Fprintf(sb, ":%d", a.Port())
|
||||
}
|
||||
|
||||
func (c *Conn) derpRegionCodeOfAddrLocked(ipPort string) string {
|
||||
@@ -3017,15 +3017,15 @@ func (c *Conn) UpdateStatus(sb *ipnstate.StatusBuilder) {
|
||||
if !addr.IsSingleIP() {
|
||||
continue
|
||||
}
|
||||
sb.AddTailscaleIP(addr.IP)
|
||||
sb.AddTailscaleIP(addr.IP())
|
||||
// TailAddr previously only allowed for a
|
||||
// single Tailscale IP. For compatibility for
|
||||
// a couple releases starting with 1.8, keep
|
||||
// that field pulled out separately.
|
||||
if addr.IP.Is4() {
|
||||
tailAddr4 = addr.IP.String()
|
||||
if addr.IP().Is4() {
|
||||
tailAddr4 = addr.IP().String()
|
||||
}
|
||||
tailscaleIPs = append(tailscaleIPs, addr.IP)
|
||||
tailscaleIPs = append(tailscaleIPs, addr.IP())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3084,8 +3084,8 @@ func (c *Conn) UpdateStatus(sb *ipnstate.StatusBuilder) {
|
||||
}
|
||||
|
||||
func ippDebugString(ua netaddr.IPPort) string {
|
||||
if ua.IP == derpMagicIPAddr {
|
||||
return fmt.Sprintf("derp-%d", ua.Port)
|
||||
if ua.IP() == derpMagicIPAddr {
|
||||
return fmt.Sprintf("derp-%d", ua.Port())
|
||||
}
|
||||
return ua.String()
|
||||
}
|
||||
@@ -3254,10 +3254,7 @@ func (de *discoEndpoint) initFakeUDPAddr() {
|
||||
addr[0] = 0xfd
|
||||
addr[1] = 0x00
|
||||
binary.BigEndian.PutUint64(addr[2:], uint64(reflect.ValueOf(de).Pointer()))
|
||||
de.fakeWGAddr = netaddr.IPPort{
|
||||
IP: netaddr.IPFrom16(addr),
|
||||
Port: 12345,
|
||||
}
|
||||
de.fakeWGAddr = netaddr.IPPortFrom(netaddr.IPFrom16(addr), 12345)
|
||||
}
|
||||
|
||||
// isFirstRecvActivityInAwhile notes that receive activity has occured for this
|
||||
@@ -3632,7 +3629,7 @@ func (de *discoEndpoint) handlePongConnLocked(m *disco.Pong, src netaddr.IPPort)
|
||||
de.mu.Lock()
|
||||
defer de.mu.Unlock()
|
||||
|
||||
isDerp := src.IP == derpMagicIPAddr
|
||||
isDerp := src.IP() == derpMagicIPAddr
|
||||
|
||||
sp, ok := de.sentPing[m.TxID]
|
||||
if !ok {
|
||||
@@ -3708,13 +3705,13 @@ func betterAddr(a, b addrLatency) bool {
|
||||
if a.IsZero() {
|
||||
return false
|
||||
}
|
||||
if a.IP.Is6() && b.IP.Is4() {
|
||||
if a.IP().Is6() && b.IP().Is4() {
|
||||
// Prefer IPv6 for being a bit more robust, as long as
|
||||
// the latencies are roughly equivalent.
|
||||
if a.latency/10*9 < b.latency {
|
||||
return true
|
||||
}
|
||||
} else if a.IP.Is4() && b.IP.Is6() {
|
||||
} else if a.IP().Is4() && b.IP().Is6() {
|
||||
if betterAddr(b, a) {
|
||||
return false
|
||||
}
|
||||
@@ -3754,7 +3751,7 @@ func (de *discoEndpoint) handleCallMeMaybe(m *disco.CallMeMaybe) {
|
||||
}
|
||||
var newEPs []netaddr.IPPort
|
||||
for _, ep := range m.MyNumber {
|
||||
if ep.IP.Is6() && ep.IP.IsLinkLocalUnicast() {
|
||||
if ep.IP().Is6() && ep.IP().IsLinkLocalUnicast() {
|
||||
// We send these out, but ignore them for now.
|
||||
// TODO: teach the ping code to ping on all interfaces
|
||||
// for these.
|
||||
|
@@ -252,13 +252,13 @@ func meshStacks(logf logger.Logf, ms []*magicStack) (cleanup func()) {
|
||||
nm := &netmap.NetworkMap{
|
||||
PrivateKey: me.privateKey,
|
||||
NodeKey: tailcfg.NodeKey(me.privateKey.Public()),
|
||||
Addresses: []netaddr.IPPrefix{{IP: netaddr.IPv4(1, 0, 0, byte(myIdx+1)), Bits: 32}},
|
||||
Addresses: []netaddr.IPPrefix{netaddr.IPPrefixFrom(netaddr.IPv4(1, 0, 0, byte(myIdx+1)), 32)},
|
||||
}
|
||||
for i, peer := range ms {
|
||||
if i == myIdx {
|
||||
continue
|
||||
}
|
||||
addrs := []netaddr.IPPrefix{{IP: netaddr.IPv4(1, 0, 0, byte(i+1)), Bits: 32}}
|
||||
addrs := []netaddr.IPPrefix{netaddr.IPPrefixFrom(netaddr.IPv4(1, 0, 0, byte(i+1)), 32)}
|
||||
peer := &tailcfg.Node{
|
||||
ID: tailcfg.NodeID(i + 1),
|
||||
Name: fmt.Sprintf("node%d", i+1),
|
||||
@@ -433,7 +433,7 @@ func TestPickDERPFallback(t *testing.T) {
|
||||
// But move if peers are elsewhere.
|
||||
const otherNode = 789
|
||||
c.addrsByKey = map[key.Public]*addrSet{
|
||||
{1}: {ipPorts: []netaddr.IPPort{{IP: derpMagicIPAddr, Port: otherNode}}},
|
||||
{1}: {ipPorts: []netaddr.IPPort{netaddr.IPPortFrom(derpMagicIPAddr, otherNode)}},
|
||||
}
|
||||
if got := c.pickDERPFallback(); got != otherNode {
|
||||
t.Errorf("didn't join peers: got %v; want %v", got, someNode)
|
||||
@@ -887,8 +887,8 @@ func testTwoDevicePing(t *testing.T, d *devices) {
|
||||
defer m2.Close()
|
||||
|
||||
addrs := []netaddr.IPPort{
|
||||
{IP: d.m1IP, Port: m1.conn.LocalPort()},
|
||||
{IP: d.m2IP, Port: m2.conn.LocalPort()},
|
||||
netaddr.IPPortFrom(d.m1IP, m1.conn.LocalPort()),
|
||||
netaddr.IPPortFrom(d.m2IP, m2.conn.LocalPort()),
|
||||
}
|
||||
cfgs := makeConfigs(t, addrs)
|
||||
|
||||
@@ -1555,7 +1555,7 @@ func TestEndpointSetsEqual(t *testing.T) {
|
||||
s := func(ports ...uint16) (ret []tailcfg.Endpoint) {
|
||||
for _, port := range ports {
|
||||
ret = append(ret, tailcfg.Endpoint{
|
||||
Addr: netaddr.IPPort{Port: port},
|
||||
Addr: netaddr.IPPortFrom(netaddr.IP{}, port),
|
||||
})
|
||||
}
|
||||
return
|
||||
|
@@ -130,11 +130,11 @@ func netaddrIP(std net.IP) netaddr.IP {
|
||||
|
||||
func netaddrIPPrefix(std net.IP, bits uint8) netaddr.IPPrefix {
|
||||
ip, _ := netaddr.FromStdIP(std)
|
||||
return netaddr.IPPrefix{IP: ip, Bits: bits}
|
||||
return netaddr.IPPrefixFrom(ip, bits)
|
||||
}
|
||||
|
||||
func condNetAddrPrefix(ipp netaddr.IPPrefix) string {
|
||||
if ipp.IP.IsZero() {
|
||||
if ipp.IP().IsZero() {
|
||||
return ""
|
||||
}
|
||||
return ipp.String()
|
||||
@@ -157,7 +157,7 @@ type newRouteMessage struct {
|
||||
const tsTable = 52
|
||||
|
||||
func (m *newRouteMessage) ignore() bool {
|
||||
return m.Table == tsTable || tsaddr.IsTailscaleIP(m.Dst.IP)
|
||||
return m.Table == tsTable || tsaddr.IsTailscaleIP(m.Dst.IP())
|
||||
}
|
||||
|
||||
// newAddrMessage is a message for a new address being added.
|
||||
|
@@ -179,7 +179,7 @@ func DNSMapFromNetworkMap(nm *netmap.NetworkMap) DNSMap {
|
||||
suffix := nm.MagicDNSSuffix()
|
||||
|
||||
if nm.Name != "" && len(nm.Addresses) > 0 {
|
||||
ip := nm.Addresses[0].IP
|
||||
ip := nm.Addresses[0].IP()
|
||||
ret[strings.TrimRight(nm.Name, ".")] = ip
|
||||
if dnsname.HasSuffix(nm.Name, suffix) {
|
||||
ret[dnsname.TrimSuffix(nm.Name, suffix)] = ip
|
||||
@@ -187,7 +187,7 @@ func DNSMapFromNetworkMap(nm *netmap.NetworkMap) DNSMap {
|
||||
}
|
||||
for _, p := range nm.Peers {
|
||||
if p.Name != "" && len(p.Addresses) > 0 {
|
||||
ip := p.Addresses[0].IP
|
||||
ip := p.Addresses[0].IP()
|
||||
ret[strings.TrimRight(p.Name, ".")] = ip
|
||||
if dnsname.HasSuffix(p.Name, suffix) {
|
||||
ret[dnsname.TrimSuffix(p.Name, suffix)] = ip
|
||||
@@ -227,8 +227,8 @@ func (ns *Impl) removeSubnetAddress(ip netaddr.IP) {
|
||||
|
||||
func ipPrefixToAddressWithPrefix(ipp netaddr.IPPrefix) tcpip.AddressWithPrefix {
|
||||
return tcpip.AddressWithPrefix{
|
||||
Address: tcpip.Address(ipp.IP.IPAddr().IP),
|
||||
PrefixLen: int(ipp.Bits),
|
||||
Address: tcpip.Address(ipp.IP().IPAddr().IP),
|
||||
PrefixLen: int(ipp.Bits()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ func (m DNSMap) Resolve(ctx context.Context, addr string) (netaddr.IPPort, error
|
||||
// Try MagicDNS first, else otherwise a real DNS lookup.
|
||||
ip := m[host]
|
||||
if !ip.IsZero() {
|
||||
return netaddr.IPPort{IP: ip, Port: uint16(port16)}, nil
|
||||
return netaddr.IPPortFrom(ip, uint16(port16)), nil
|
||||
}
|
||||
|
||||
// No MagicDNS name so try real DNS.
|
||||
@@ -335,7 +335,7 @@ func (m DNSMap) Resolve(ctx context.Context, addr string) (netaddr.IPPort, error
|
||||
return netaddr.IPPort{}, fmt.Errorf("DNS lookup returned no results for %q", host)
|
||||
}
|
||||
ip, _ = netaddr.FromStdIP(ips[0])
|
||||
return netaddr.IPPort{IP: ip, Port: uint16(port16)}, nil
|
||||
return netaddr.IPPortFrom(ip, uint16(port16)), nil
|
||||
}
|
||||
|
||||
func (ns *Impl) DialContextTCP(ctx context.Context, addr string) (*gonet.TCPConn, error) {
|
||||
@@ -349,11 +349,11 @@ func (ns *Impl) DialContextTCP(ctx context.Context, addr string) (*gonet.TCPConn
|
||||
}
|
||||
remoteAddress := tcpip.FullAddress{
|
||||
NIC: nicID,
|
||||
Addr: tcpip.Address(remoteIPPort.IP.IPAddr().IP),
|
||||
Port: remoteIPPort.Port,
|
||||
Addr: tcpip.Address(remoteIPPort.IP().IPAddr().IP),
|
||||
Port: remoteIPPort.Port(),
|
||||
}
|
||||
var ipType tcpip.NetworkProtocolNumber
|
||||
if remoteIPPort.IP.Is4() {
|
||||
if remoteIPPort.IP().Is4() {
|
||||
ipType = ipv4.ProtocolNumber
|
||||
} else {
|
||||
ipType = ipv6.ProtocolNumber
|
||||
@@ -395,7 +395,7 @@ func (ns *Impl) isLocalIP(ip netaddr.IP) bool {
|
||||
}
|
||||
|
||||
func (ns *Impl) injectInbound(p *packet.Parsed, t *tstun.Wrapper) filter.Response {
|
||||
if ns.onlySubnets && ns.isLocalIP(p.Dst.IP) {
|
||||
if ns.onlySubnets && ns.isLocalIP(p.Dst.IP()) {
|
||||
// In hybrid ("only subnets") mode, bail out early if
|
||||
// the traffic is destined for an actual Tailscale
|
||||
// address. The real host OS interface will handle it.
|
||||
|
@@ -115,8 +115,8 @@ func (e *userspaceEngine) trackOpenPostFilterOut(pp *packet.Parsed, t *tstun.Wra
|
||||
// Don't start timers tracking those. They won't succeed anyway. Avoids log spam
|
||||
// like:
|
||||
// open-conn-track: timeout opening (100.115.73.60:52501 => 17.125.252.5:443); no associated peer node
|
||||
if runtime.GOOS == "ios" && flow.Dst.Port == 443 && !tsaddr.IsTailscaleIP(flow.Dst.IP) {
|
||||
if _, err := e.peerForIP(flow.Dst.IP); err != nil {
|
||||
if runtime.GOOS == "ios" && flow.Dst.Port() == 443 && !tsaddr.IsTailscaleIP(flow.Dst.IP()) {
|
||||
if _, err := e.peerForIP(flow.Dst.IP()); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@ func (e *userspaceEngine) onOpenTimeout(flow flowtrack.Tuple) {
|
||||
}
|
||||
|
||||
// Diagnose why it might've timed out.
|
||||
n, err := e.peerForIP(flow.Dst.IP)
|
||||
n, err := e.peerForIP(flow.Dst.IP())
|
||||
if err != nil {
|
||||
e.logf("open-conn-track: timeout opening %v; peerForIP: %v", flow, err)
|
||||
return
|
||||
@@ -193,7 +193,7 @@ func (e *userspaceEngine) onOpenTimeout(flow flowtrack.Tuple) {
|
||||
if ps == nil {
|
||||
onlyZeroRoute := true // whether peerForIP returned n only because its /0 route matched
|
||||
for _, r := range n.AllowedIPs {
|
||||
if r.Bits != 0 && r.Contains(flow.Dst.IP) {
|
||||
if r.Bits() != 0 && r.Contains(flow.Dst.IP()) {
|
||||
onlyZeroRoute = false
|
||||
break
|
||||
}
|
||||
|
@@ -324,16 +324,16 @@ func configureInterface(cfg *Config, tun *tun.NativeTun) (retErr error) {
|
||||
var firstGateway6 *net.IP
|
||||
addresses := make([]*net.IPNet, 0, len(cfg.LocalAddrs))
|
||||
for _, addr := range cfg.LocalAddrs {
|
||||
if (addr.IP.Is4() && ipif4 == nil) || (addr.IP.Is6() && ipif6 == nil) {
|
||||
if (addr.IP().Is4() && ipif4 == nil) || (addr.IP().Is6() && ipif6 == nil) {
|
||||
// Can't program addresses for disabled protocol.
|
||||
continue
|
||||
}
|
||||
ipnet := addr.IPNet()
|
||||
addresses = append(addresses, ipnet)
|
||||
gateway := ipnet.IP
|
||||
if addr.IP.Is4() && firstGateway4 == nil {
|
||||
if addr.IP().Is4() && firstGateway4 == nil {
|
||||
firstGateway4 = &gateway
|
||||
} else if addr.IP.Is6() && firstGateway6 == nil {
|
||||
} else if addr.IP().Is6() && firstGateway6 == nil {
|
||||
firstGateway6 = &gateway
|
||||
}
|
||||
}
|
||||
@@ -342,12 +342,12 @@ func configureInterface(cfg *Config, tun *tun.NativeTun) (retErr error) {
|
||||
foundDefault4 := false
|
||||
foundDefault6 := false
|
||||
for _, route := range cfg.Routes {
|
||||
if (route.IP.Is4() && ipif4 == nil) || (route.IP.Is6() && ipif6 == nil) {
|
||||
if (route.IP().Is4() && ipif4 == nil) || (route.IP().Is6() && ipif6 == nil) {
|
||||
// Can't program routes for disabled protocol.
|
||||
continue
|
||||
}
|
||||
|
||||
if route.IP.Is6() && firstGateway6 == nil {
|
||||
if route.IP().Is6() && firstGateway6 == nil {
|
||||
// Windows won't let us set IPv6 routes without having an
|
||||
// IPv6 local address set. However, when we've configured
|
||||
// a default route, we want to forcibly grab IPv6 traffic
|
||||
@@ -357,16 +357,16 @@ func configureInterface(cfg *Config, tun *tun.NativeTun) (retErr error) {
|
||||
ipnet := &net.IPNet{tsaddr.Tailscale4To6Placeholder().IPAddr().IP, net.CIDRMask(128, 128)}
|
||||
addresses = append(addresses, ipnet)
|
||||
firstGateway6 = &ipnet.IP
|
||||
} else if route.IP.Is4() && firstGateway4 == nil {
|
||||
} else if route.IP().Is4() && firstGateway4 == nil {
|
||||
// TODO: do same dummy behavior as v6?
|
||||
return errors.New("due to a Windows limitation, one cannot have interface routes without an interface address")
|
||||
}
|
||||
|
||||
ipn := route.IPNet()
|
||||
var gateway net.IP
|
||||
if route.IP.Is4() {
|
||||
if route.IP().Is4() {
|
||||
gateway = *firstGateway4
|
||||
} else if route.IP.Is6() {
|
||||
} else if route.IP().Is6() {
|
||||
gateway = *firstGateway6
|
||||
}
|
||||
r := winipcfg.RouteData{
|
||||
@@ -385,13 +385,13 @@ func configureInterface(cfg *Config, tun *tun.NativeTun) (retErr error) {
|
||||
// then the interface's IP won't be pingable.
|
||||
continue
|
||||
}
|
||||
if route.IP.Is4() {
|
||||
if route.Bits == 0 {
|
||||
if route.IP().Is4() {
|
||||
if route.Bits() == 0 {
|
||||
foundDefault4 = true
|
||||
}
|
||||
r.NextHop = *firstGateway4
|
||||
} else if route.IP.Is6() {
|
||||
if route.Bits == 0 {
|
||||
} else if route.IP().Is6() {
|
||||
if route.Bits() == 0 {
|
||||
foundDefault6 = true
|
||||
}
|
||||
r.NextHop = *firstGateway6
|
||||
@@ -760,11 +760,8 @@ func filterRoutes(routes []*winipcfg.RouteData, dontDelete []netaddr.IPPrefix) [
|
||||
if nr.IsSingleIP() {
|
||||
continue
|
||||
}
|
||||
lastIP := nr.Range().To
|
||||
ddm[netaddr.IPPrefix{
|
||||
IP: lastIP,
|
||||
Bits: lastIP.BitLen(),
|
||||
}] = true
|
||||
lastIP := nr.Range().To()
|
||||
ddm[netaddr.IPPrefixFrom(lastIP, lastIP.BitLen())] = true
|
||||
}
|
||||
filtered := make([]*winipcfg.RouteData, 0, len(routes))
|
||||
for _, r := range routes {
|
||||
|
@@ -360,7 +360,7 @@ func (r *linuxRouter) setNetfilterMode(mode preftype.NetfilterMode) error {
|
||||
}
|
||||
|
||||
for cidr := range r.addrs {
|
||||
if err := r.addLoopbackRule(cidr.IP); err != nil {
|
||||
if err := r.addLoopbackRule(cidr.IP()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -372,13 +372,13 @@ func (r *linuxRouter) setNetfilterMode(mode preftype.NetfilterMode) error {
|
||||
// address is already assigned to the interface, or if the addition
|
||||
// fails.
|
||||
func (r *linuxRouter) addAddress(addr netaddr.IPPrefix) error {
|
||||
if !r.v6Available && addr.IP.Is6() {
|
||||
if !r.v6Available && addr.IP().Is6() {
|
||||
return nil
|
||||
}
|
||||
if err := r.cmd.run("ip", "addr", "add", addr.String(), "dev", r.tunname); err != nil {
|
||||
return fmt.Errorf("adding address %q to tunnel interface: %w", addr, err)
|
||||
}
|
||||
if err := r.addLoopbackRule(addr.IP); err != nil {
|
||||
if err := r.addLoopbackRule(addr.IP()); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -388,10 +388,10 @@ func (r *linuxRouter) addAddress(addr netaddr.IPPrefix) error {
|
||||
// the address is not assigned to the interface, or if the removal
|
||||
// fails.
|
||||
func (r *linuxRouter) delAddress(addr netaddr.IPPrefix) error {
|
||||
if !r.v6Available && addr.IP.Is6() {
|
||||
if !r.v6Available && addr.IP().Is6() {
|
||||
return nil
|
||||
}
|
||||
if err := r.delLoopbackRule(addr.IP); err != nil {
|
||||
if err := r.delLoopbackRule(addr.IP()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := r.cmd.run("ip", "addr", "del", addr.String(), "dev", r.tunname); err != nil {
|
||||
@@ -463,7 +463,7 @@ func (r *linuxRouter) addThrowRoute(cidr netaddr.IPPrefix) error {
|
||||
}
|
||||
|
||||
func (r *linuxRouter) addRouteDef(routeDef []string, cidr netaddr.IPPrefix) error {
|
||||
if !r.v6Available && cidr.IP.Is6() {
|
||||
if !r.v6Available && cidr.IP().Is6() {
|
||||
return nil
|
||||
}
|
||||
args := append([]string{"ip", "route", "add"}, routeDef...)
|
||||
@@ -490,7 +490,7 @@ func (r *linuxRouter) delThrowRoute(cidr netaddr.IPPrefix) error {
|
||||
}
|
||||
|
||||
func (r *linuxRouter) delRouteDef(routeDef []string, cidr netaddr.IPPrefix) error {
|
||||
if !r.v6Available && cidr.IP.Is6() {
|
||||
if !r.v6Available && cidr.IP().Is6() {
|
||||
return nil
|
||||
}
|
||||
args := append([]string{"ip", "route", "del"}, routeDef...)
|
||||
@@ -520,7 +520,7 @@ func dashFam(ip netaddr.IP) string {
|
||||
}
|
||||
|
||||
func (r *linuxRouter) hasRoute(routeDef []string, cidr netaddr.IPPrefix) (bool, error) {
|
||||
args := append([]string{"ip", dashFam(cidr.IP), "route", "show"}, routeDef...)
|
||||
args := append([]string{"ip", dashFam(cidr.IP()), "route", "show"}, routeDef...)
|
||||
if r.ipRuleAvailable {
|
||||
args = append(args, "table", tailscaleRouteTable)
|
||||
}
|
||||
|
@@ -69,11 +69,11 @@ func (r *openbsdRouter) Set(cfg *Config) error {
|
||||
localAddr4 := netaddr.IPPrefix{}
|
||||
localAddr6 := netaddr.IPPrefix{}
|
||||
for _, addr := range cfg.LocalAddrs {
|
||||
if addr.IP.Is4() {
|
||||
if addr.IP().Is4() {
|
||||
numIPv4++
|
||||
localAddr4 = addr
|
||||
}
|
||||
if addr.IP.Is6() {
|
||||
if addr.IP().Is6() {
|
||||
numIPv6++
|
||||
localAddr6 = addr
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func (r *openbsdRouter) Set(cfg *Config) error {
|
||||
|
||||
routedel := []string{"route", "-q", "-n",
|
||||
"del", "-inet", r.local4.String(),
|
||||
"-iface", r.local4.IP.String()}
|
||||
"-iface", r.local4.IP().String()}
|
||||
if out, err := cmd(routedel...).CombinedOutput(); err != nil {
|
||||
r.logf("route del failed: %v: %v\n%s", routedel, err, out)
|
||||
if errq == nil {
|
||||
@@ -120,7 +120,7 @@ func (r *openbsdRouter) Set(cfg *Config) error {
|
||||
|
||||
routeadd := []string{"route", "-q", "-n",
|
||||
"add", "-inet", localAddr4.String(),
|
||||
"-iface", localAddr4.IP.String()}
|
||||
"-iface", localAddr4.IP().String()}
|
||||
if out, err := cmd(routeadd...).CombinedOutput(); err != nil {
|
||||
r.logf("route add failed: %v: %v\n%s", routeadd, err, out)
|
||||
if errq == nil {
|
||||
@@ -134,7 +134,7 @@ func (r *openbsdRouter) Set(cfg *Config) error {
|
||||
// in https://github.com/tailscale/tailscale/issues/1307 we made
|
||||
// FreeBSD use a /48 for IPv6 addresses, which is nice because we
|
||||
// don't need to additionally add routing entries. Do that here too.
|
||||
localAddr6 = netaddr.IPPrefix{localAddr6.IP, 48}
|
||||
localAddr6 = netaddr.IPPrefixFrom(localAddr6.IP(), 48)
|
||||
}
|
||||
|
||||
if localAddr6 != r.local6 {
|
||||
@@ -171,10 +171,10 @@ func (r *openbsdRouter) Set(cfg *Config) error {
|
||||
if _, keep := newRoutes[route]; !keep {
|
||||
net := route.IPNet()
|
||||
nip := net.IP.Mask(net.Mask)
|
||||
nstr := fmt.Sprintf("%v/%d", nip, route.Bits)
|
||||
nstr := fmt.Sprintf("%v/%d", nip, route.Bits())
|
||||
routedel := []string{"route", "-q", "-n",
|
||||
"del", "-inet", nstr,
|
||||
"-iface", localAddr4.IP.String()}
|
||||
"-iface", localAddr4.IP().String()}
|
||||
out, err := cmd(routedel...).CombinedOutput()
|
||||
if err != nil {
|
||||
r.logf("route del failed: %v: %v\n%s", routedel, err, out)
|
||||
@@ -188,10 +188,10 @@ func (r *openbsdRouter) Set(cfg *Config) error {
|
||||
if _, exists := r.routes[route]; !exists {
|
||||
net := route.IPNet()
|
||||
nip := net.IP.Mask(net.Mask)
|
||||
nstr := fmt.Sprintf("%v/%d", nip, route.Bits)
|
||||
nstr := fmt.Sprintf("%v/%d", nip, route.Bits())
|
||||
routeadd := []string{"route", "-q", "-n",
|
||||
"add", "-inet", nstr,
|
||||
"-iface", localAddr4.IP.String()}
|
||||
"-iface", localAddr4.IP().String()}
|
||||
out, err := cmd(routeadd...).CombinedOutput()
|
||||
if err != nil {
|
||||
r.logf("addr add failed: %v: %v\n%s", routeadd, err, out)
|
||||
|
@@ -87,7 +87,7 @@ func (r *userspaceBSDRouter) Up() error {
|
||||
}
|
||||
|
||||
func inet(p netaddr.IPPrefix) string {
|
||||
if p.IP.Is6() {
|
||||
if p.IP().Is6() {
|
||||
return "inet6"
|
||||
}
|
||||
return "inet"
|
||||
@@ -116,15 +116,15 @@ func (r *userspaceBSDRouter) Set(cfg *Config) (reterr error) {
|
||||
}
|
||||
for _, addr := range r.addrsToAdd(cfg.LocalAddrs) {
|
||||
var arg []string
|
||||
if runtime.GOOS == "freebsd" && addr.IP.Is6() && addr.Bits == 128 {
|
||||
if runtime.GOOS == "freebsd" && addr.IP().Is6() && addr.Bits() == 128 {
|
||||
// FreeBSD rejects tun addresses of the form fc00::1/128 -> fc00::1,
|
||||
// https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=218508
|
||||
// Instead add our whole /48, which works because we use a /48 route.
|
||||
// Full history: https://github.com/tailscale/tailscale/issues/1307
|
||||
tmp := netaddr.IPPrefix{IP: addr.IP, Bits: 48}
|
||||
tmp := netaddr.IPPrefixFrom(addr.IP(), 48)
|
||||
arg = []string{"ifconfig", r.tunname, inet(tmp), tmp.String()}
|
||||
} else {
|
||||
arg = []string{"ifconfig", r.tunname, inet(addr), addr.String(), addr.IP.String()}
|
||||
arg = []string{"ifconfig", r.tunname, inet(addr), addr.String(), addr.IP().String()}
|
||||
}
|
||||
out, err := cmd(arg...).CombinedOutput()
|
||||
if err != nil {
|
||||
@@ -148,7 +148,7 @@ func (r *userspaceBSDRouter) Set(cfg *Config) (reterr error) {
|
||||
if _, keep := newRoutes[route]; !keep {
|
||||
net := route.IPNet()
|
||||
nip := net.IP.Mask(net.Mask)
|
||||
nstr := fmt.Sprintf("%v/%d", nip, route.Bits)
|
||||
nstr := fmt.Sprintf("%v/%d", nip, route.Bits())
|
||||
del := "del"
|
||||
if version.OS() == "macOS" {
|
||||
del = "delete"
|
||||
@@ -168,7 +168,7 @@ func (r *userspaceBSDRouter) Set(cfg *Config) (reterr error) {
|
||||
if _, exists := r.routes[route]; !exists {
|
||||
net := route.IPNet()
|
||||
nip := net.IP.Mask(net.Mask)
|
||||
nstr := fmt.Sprintf("%v/%d", nip, route.Bits)
|
||||
nstr := fmt.Sprintf("%v/%d", nip, route.Bits())
|
||||
routeadd := []string{"route", "-q", "-n",
|
||||
"add", "-" + inet(route), nstr,
|
||||
"-iface", r.tunname}
|
||||
|
@@ -91,7 +91,7 @@ func (r *winRouter) Set(cfg *Config) error {
|
||||
|
||||
func hasDefaultRoute(routes []netaddr.IPPrefix) bool {
|
||||
for _, route := range routes {
|
||||
if route.Bits == 0 {
|
||||
if route.Bits() == 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@@ -399,7 +399,7 @@ func (e *userspaceEngine) handleLocalPackets(p *packet.Parsed, t *tstun.Wrapper)
|
||||
isLocalAddr, ok := e.isLocalAddr.Load().(func(netaddr.IP) bool)
|
||||
if !ok {
|
||||
e.logf("[unexpected] e.isLocalAddr was nil, can't check for loopback packet")
|
||||
} else if isLocalAddr(p.Dst.IP) {
|
||||
} else if isLocalAddr(p.Dst.IP()) {
|
||||
// macOS NetworkExtension directs packets destined to the
|
||||
// tunnel's local IP address into the tunnel, instead of
|
||||
// looping back within the kernel network stack. We have to
|
||||
@@ -415,7 +415,7 @@ func (e *userspaceEngine) handleLocalPackets(p *packet.Parsed, t *tstun.Wrapper)
|
||||
|
||||
// handleDNS is an outbound pre-filter resolving Tailscale domains.
|
||||
func (e *userspaceEngine) handleDNS(p *packet.Parsed, t *tstun.Wrapper) filter.Response {
|
||||
if p.Dst.IP == magicDNSIP && p.Dst.Port == magicDNSPort && p.IPProto == ipproto.UDP {
|
||||
if p.Dst.IP() == magicDNSIP && p.Dst.Port() == magicDNSPort && p.IPProto == ipproto.UDP {
|
||||
err := e.dns.EnqueueRequest(append([]byte(nil), p.Payload()...), p.Src)
|
||||
if err != nil {
|
||||
e.logf("dns: enqueue: %v", err)
|
||||
@@ -440,10 +440,10 @@ func (e *userspaceEngine) pollResolver() {
|
||||
h := packet.UDP4Header{
|
||||
IP4Header: packet.IP4Header{
|
||||
Src: magicDNSIP,
|
||||
Dst: to.IP,
|
||||
Dst: to.IP(),
|
||||
},
|
||||
SrcPort: magicDNSPort,
|
||||
DstPort: to.Port,
|
||||
DstPort: to.Port(),
|
||||
}
|
||||
hlen := h.Len()
|
||||
|
||||
@@ -620,8 +620,8 @@ func (e *userspaceEngine) maybeReconfigWireguardLocked(discoChanged map[key.Publ
|
||||
trackDisco = append(trackDisco, dk)
|
||||
recentlyActive := false
|
||||
for _, cidr := range p.AllowedIPs {
|
||||
trackIPs = append(trackIPs, cidr.IP)
|
||||
recentlyActive = recentlyActive || e.isActiveSince(dk, cidr.IP, activeCutoff)
|
||||
trackIPs = append(trackIPs, cidr.IP())
|
||||
recentlyActive = recentlyActive || e.isActiveSince(dk, cidr.IP(), activeCutoff)
|
||||
}
|
||||
if recentlyActive {
|
||||
min.Peers = append(min.Peers, *p)
|
||||
@@ -1156,8 +1156,8 @@ func (e *userspaceEngine) mySelfIPMatchingFamily(dst netaddr.IP) (src netaddr.IP
|
||||
return netaddr.IP{}, errors.New("no netmap")
|
||||
}
|
||||
for _, a := range e.netMap.Addresses {
|
||||
if a.IsSingleIP() && a.IP.BitLen() == dst.BitLen() {
|
||||
return a.IP, nil
|
||||
if a.IsSingleIP() && a.IP().BitLen() == dst.BitLen() {
|
||||
return a.IP(), nil
|
||||
}
|
||||
}
|
||||
if len(e.netMap.Addresses) == 0 {
|
||||
@@ -1293,7 +1293,7 @@ func (e *userspaceEngine) peerForIP(ip netaddr.IP) (n *tailcfg.Node, err error)
|
||||
var bestInNM *tailcfg.Node
|
||||
for _, p := range nm.Peers {
|
||||
for _, a := range p.Addresses {
|
||||
if a.IP == ip && a.IsSingleIP() && tsaddr.IsTailscaleIP(ip) {
|
||||
if a.IP() == ip && a.IsSingleIP() && tsaddr.IsTailscaleIP(ip) {
|
||||
return p, nil
|
||||
}
|
||||
}
|
||||
@@ -1301,7 +1301,7 @@ func (e *userspaceEngine) peerForIP(ip netaddr.IP) (n *tailcfg.Node, err error)
|
||||
if !cidr.Contains(ip) {
|
||||
continue
|
||||
}
|
||||
if bestInNMPrefix.IsZero() || cidr.Bits > bestInNMPrefix.Bits {
|
||||
if bestInNMPrefix.IsZero() || cidr.Bits() > bestInNMPrefix.Bits() {
|
||||
bestInNMPrefix = cidr
|
||||
bestInNM = p
|
||||
}
|
||||
@@ -1319,7 +1319,7 @@ func (e *userspaceEngine) peerForIP(ip netaddr.IP) (n *tailcfg.Node, err error)
|
||||
if !cidr.Contains(ip) {
|
||||
continue
|
||||
}
|
||||
if best.IsZero() || cidr.Bits > best.Bits {
|
||||
if best.IsZero() || cidr.Bits() > best.Bits() {
|
||||
best = cidr
|
||||
bestKey = tailcfg.NodeKey(p.PublicKey)
|
||||
}
|
||||
@@ -1337,7 +1337,7 @@ func (e *userspaceEngine) peerForIP(ip netaddr.IP) (n *tailcfg.Node, err error)
|
||||
if bestInNM == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if bestInNMPrefix.Bits == 0 {
|
||||
if bestInNMPrefix.Bits() == 0 {
|
||||
return nil, errors.New("exit node found but not enabled")
|
||||
}
|
||||
return nil, fmt.Errorf("node %q found, but not using its %v route", bestInNM.ComputedNameWithHost, bestInNMPrefix)
|
||||
|
@@ -102,7 +102,7 @@ func TestUserspaceEngineReconfig(t *testing.T) {
|
||||
Peers: []wgcfg.Peer{
|
||||
{
|
||||
AllowedIPs: []netaddr.IPPrefix{
|
||||
{IP: netaddr.IPv4(100, 100, 99, 1), Bits: 32},
|
||||
netaddr.IPPrefixFrom(netaddr.IPv4(100, 100, 99, 1), 32),
|
||||
},
|
||||
Endpoints: wgcfg.Endpoints{DiscoKey: dkFromHex(discoHex)},
|
||||
},
|
||||
|
@@ -37,7 +37,7 @@ func nodeDebugName(n *tailcfg.Node) string {
|
||||
// cidrIsSubnet reports whether cidr is a non-default-route subnet
|
||||
// exported by node that is not one of its own self addresses.
|
||||
func cidrIsSubnet(node *tailcfg.Node, cidr netaddr.IPPrefix) bool {
|
||||
if cidr.Bits == 0 {
|
||||
if cidr.Bits() == 0 {
|
||||
return false
|
||||
}
|
||||
if !cidr.IsSingleIP() {
|
||||
@@ -93,7 +93,7 @@ func WGCfg(nm *netmap.NetworkMap, logf logger.Logf, flags netmap.WGConfigFlags,
|
||||
}
|
||||
didExitNodeWarn := false
|
||||
for _, allowedIP := range peer.AllowedIPs {
|
||||
if allowedIP.Bits == 0 && peer.StableID != exitNode {
|
||||
if allowedIP.Bits() == 0 && peer.StableID != exitNode {
|
||||
if didExitNodeWarn {
|
||||
// Don't log about both the IPv4 /0 and IPv6 /0.
|
||||
continue
|
||||
@@ -104,11 +104,11 @@ func WGCfg(nm *netmap.NetworkMap, logf logger.Logf, flags netmap.WGConfigFlags,
|
||||
}
|
||||
fmt.Fprintf(skippedUnselected, "%q (%v)", nodeDebugName(peer), peer.Key.ShortString())
|
||||
continue
|
||||
} else if allowedIP.IsSingleIP() && tsaddr.IsTailscaleIP(allowedIP.IP) && (flags&netmap.AllowSingleHosts) == 0 {
|
||||
} else if allowedIP.IsSingleIP() && tsaddr.IsTailscaleIP(allowedIP.IP()) && (flags&netmap.AllowSingleHosts) == 0 {
|
||||
if skippedIPs.Len() > 0 {
|
||||
skippedIPs.WriteString(", ")
|
||||
}
|
||||
fmt.Fprintf(skippedIPs, "%v from %q (%v)", allowedIP.IP, nodeDebugName(peer), peer.Key.ShortString())
|
||||
fmt.Fprintf(skippedIPs, "%v from %q (%v)", allowedIP.IP(), nodeDebugName(peer), peer.Key.ShortString())
|
||||
continue
|
||||
} else if cidrIsSubnet(peer, allowedIP) {
|
||||
if (flags & netmap.AllowSubnetRoutes) == 0 {
|
||||
|
Reference in New Issue
Block a user