all: remove LenIter, use Go 1.22 range-over-int instead

Updates #11058
Updates golang/go#65685

Change-Id: Ibb216b346e511d486271ab3d84e4546c521e4e22
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
knyar/install
Brad Fitzpatrick 9 months ago committed by Brad Fitzpatrick
parent ff1391a97e
commit e1bd7488d0

@ -264,7 +264,7 @@ func (i *jsIPN) run(jsCallbacks js.Value) {
name = p.Hostinfo().Hostname() name = p.Hostinfo().Hostname()
} }
addrs := make([]string, p.Addresses().Len()) addrs := make([]string, p.Addresses().Len())
for i := range p.Addresses().LenIter() { for i := range p.Addresses().Len() {
addrs[i] = p.Addresses().At(i).Addr().String() addrs[i] = p.Addresses().At(i).Addr().String()
} }
return jsNetMapPeerNode{ return jsNetMapPeerNode{
@ -582,7 +582,7 @@ func mapSlice[T any, M any](a []T, f func(T) M) []M {
func mapSliceView[T any, M any](a views.Slice[T], f func(T) M) []M { func mapSliceView[T any, M any](a views.Slice[T], f func(T) M) []M {
n := make([]M, a.Len()) n := make([]M, a.Len())
for i := range a.LenIter() { for i := range a.Len() {
n[i] = f(a.At(i)) n[i] = f(a.At(i))
} }
return n return n

@ -728,7 +728,7 @@ func peerChangeDiff(was tailcfg.NodeView, n *tailcfg.Node) (_ *tailcfg.PeerChang
return nil, false return nil, false
} }
for i := range va.LenIter() { for i := range va.Len() {
if !va.At(i).Equal(vb.At(i)) { if !va.At(i).Equal(vb.At(i)) {
return nil, false return nil, false
} }

@ -792,7 +792,7 @@ func (b *LocalBackend) UpdateStatus(sb *ipnstate.StatusBuilder) {
var tailscaleIPs []netip.Addr var tailscaleIPs []netip.Addr
if b.netMap != nil { if b.netMap != nil {
addrs := b.netMap.GetAddresses() addrs := b.netMap.GetAddresses()
for i := range addrs.LenIter() { for i := range addrs.Len() {
if addr := addrs.At(i); addr.IsSingleIP() { if addr := addrs.At(i); addr.IsSingleIP() {
sb.AddTailscaleIP(addr.Addr()) sb.AddTailscaleIP(addr.Addr())
tailscaleIPs = append(tailscaleIPs, addr.Addr()) tailscaleIPs = append(tailscaleIPs, addr.Addr())
@ -856,7 +856,7 @@ func (b *LocalBackend) populatePeerStatusLocked(sb *ipnstate.StatusBuilder) {
lastSeen = *p.LastSeen() lastSeen = *p.LastSeen()
} }
tailscaleIPs := make([]netip.Addr, 0, p.Addresses().Len()) tailscaleIPs := make([]netip.Addr, 0, p.Addresses().Len())
for i := range p.Addresses().LenIter() { for i := range p.Addresses().Len() {
addr := p.Addresses().At(i) addr := p.Addresses().At(i)
if addr.IsSingleIP() && tsaddr.IsTailscaleIP(addr.Addr()) { if addr.IsSingleIP() && tsaddr.IsTailscaleIP(addr.Addr()) {
tailscaleIPs = append(tailscaleIPs, addr.Addr()) tailscaleIPs = append(tailscaleIPs, addr.Addr())
@ -977,7 +977,7 @@ func (b *LocalBackend) peerCapsLocked(src netip.Addr) tailcfg.PeerCapMap {
return nil return nil
} }
addrs := b.netMap.GetAddresses() addrs := b.netMap.GetAddresses()
for i := range addrs.LenIter() { for i := range addrs.Len() {
a := addrs.At(i) a := addrs.At(i)
if !a.IsSingleIP() { if !a.IsSingleIP() {
continue continue
@ -1433,7 +1433,7 @@ func setExitNodeID(prefs *ipn.Prefs, nm *netmap.NetworkMap) (prefsChanged bool)
} }
for _, peer := range nm.Peers { for _, peer := range nm.Peers {
for i := range peer.Addresses().LenIter() { for i := range peer.Addresses().Len() {
addr := peer.Addresses().At(i) addr := peer.Addresses().At(i)
if !addr.IsSingleIP() || addr.Addr() != prefs.ExitNodeIP { if !addr.IsSingleIP() || addr.Addr() != prefs.ExitNodeIP {
continue continue
@ -1877,7 +1877,7 @@ func (b *LocalBackend) updateFilterLocked(netMap *netmap.NetworkMap, prefs ipn.P
logNetsB.RemovePrefix(tsaddr.ChromeOSVMRange()) logNetsB.RemovePrefix(tsaddr.ChromeOSVMRange())
if haveNetmap { if haveNetmap {
addrs = netMap.GetAddresses() addrs = netMap.GetAddresses()
for i := range addrs.LenIter() { for i := range addrs.Len() {
localNetsB.AddPrefix(addrs.At(i)) localNetsB.AddPrefix(addrs.At(i))
} }
packetFilter = netMap.PacketFilter packetFilter = netMap.PacketFilter
@ -1987,7 +1987,7 @@ func packetFilterPermitsUnlockedNodes(peers map[tailcfg.NodeID]tailcfg.NodeView,
continue continue
} }
numUnlocked++ numUnlocked++
for i := range p.AllowedIPs().LenIter() { // not only addresses! for i := range p.AllowedIPs().Len() { // not only addresses!
b.AddPrefix(p.AllowedIPs().At(i)) b.AddPrefix(p.AllowedIPs().At(i))
} }
} }
@ -3640,14 +3640,14 @@ func dnsConfigForNetmap(nm *netmap.NetworkMap, peers map[tailcfg.NodeID]tailcfg.
return // TODO: propagate error? return // TODO: propagate error?
} }
var have4 bool var have4 bool
for i := range addrs.LenIter() { for i := range addrs.Len() {
if addrs.At(i).Addr().Is4() { if addrs.At(i).Addr().Is4() {
have4 = true have4 = true
break break
} }
} }
var ips []netip.Addr var ips []netip.Addr
for i := range addrs.LenIter() { for i := range addrs.Len() {
addr := addrs.At(i) addr := addrs.At(i)
if selfV6Only { if selfV6Only {
if addr.Addr().Is6() { if addr.Addr().Is6() {
@ -3936,7 +3936,7 @@ func (b *LocalBackend) initPeerAPIListener() {
b.peerAPIServer = ps b.peerAPIServer = ps
isNetstack := b.sys.IsNetstack() isNetstack := b.sys.IsNetstack()
for i := range addrs.LenIter() { for i := range addrs.Len() {
a := addrs.At(i) a := addrs.At(i)
var ln net.Listener var ln net.Listener
var err error var err error
@ -4250,7 +4250,7 @@ func (b *LocalBackend) enterStateLockedOnEntry(newState ipn.State) {
case ipn.Running: case ipn.Running:
var addrStrs []string var addrStrs []string
addrs := netMap.GetAddresses() addrs := netMap.GetAddresses()
for i := range addrs.LenIter() { for i := range addrs.Len() {
addrStrs = append(addrStrs, addrs.At(i).Addr().String()) addrStrs = append(addrStrs, addrs.At(i).Addr().String())
} }
systemd.Status("Connected; %s; %s", activeLogin, strings.Join(addrStrs, " ")) systemd.Status("Connected; %s; %s", activeLogin, strings.Join(addrStrs, " "))
@ -4626,7 +4626,7 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) {
b.nodeByAddr[k] = 0 b.nodeByAddr[k] = 0
} }
addNode := func(n tailcfg.NodeView) { addNode := func(n tailcfg.NodeView) {
for i := range n.Addresses().LenIter() { for i := range n.Addresses().Len() {
if ipp := n.Addresses().At(i); ipp.IsSingleIP() { if ipp := n.Addresses().At(i); ipp.IsSingleIP() {
b.nodeByAddr[ipp.Addr()] = n.ID() b.nodeByAddr[ipp.Addr()] = n.ID()
} }
@ -5062,7 +5062,7 @@ func (b *LocalBackend) SetDNS(ctx context.Context, name, value string) error {
func peerAPIPorts(peer tailcfg.NodeView) (p4, p6 uint16) { func peerAPIPorts(peer tailcfg.NodeView) (p4, p6 uint16) {
svcs := peer.Hostinfo().Services() svcs := peer.Hostinfo().Services()
for i := range svcs.LenIter() { for i := range svcs.Len() {
s := svcs.At(i) s := svcs.At(i)
switch s.Proto { switch s.Proto {
case tailcfg.PeerAPI4: case tailcfg.PeerAPI4:
@ -5095,7 +5095,7 @@ func peerAPIBase(nm *netmap.NetworkMap, peer tailcfg.NodeView) string {
var have4, have6 bool var have4, have6 bool
addrs := nm.GetAddresses() addrs := nm.GetAddresses()
for i := range addrs.LenIter() { for i := range addrs.Len() {
a := addrs.At(i) a := addrs.At(i)
if !a.IsSingleIP() { if !a.IsSingleIP() {
continue continue
@ -5118,7 +5118,7 @@ func peerAPIBase(nm *netmap.NetworkMap, peer tailcfg.NodeView) string {
} }
func nodeIP(n tailcfg.NodeView, pred func(netip.Addr) bool) netip.Addr { func nodeIP(n tailcfg.NodeView, pred func(netip.Addr) bool) netip.Addr {
for i := range n.Addresses().LenIter() { for i := range n.Addresses().Len() {
a := n.Addresses().At(i) a := n.Addresses().At(i)
if a.IsSingleIP() && pred(a.Addr()) { if a.IsSingleIP() && pred(a.Addr()) {
return a.Addr() return a.Addr()
@ -5296,7 +5296,7 @@ func wireguardExitNodeDNSResolvers(nm *netmap.NetworkMap, peers map[tailcfg.Node
resolvers := p.ExitNodeDNSResolvers() resolvers := p.ExitNodeDNSResolvers()
if !resolvers.IsNil() && resolvers.Len() > 0 { if !resolvers.IsNil() && resolvers.Len() > 0 {
copies := make([]*dnstype.Resolver, resolvers.Len()) copies := make([]*dnstype.Resolver, resolvers.Len())
for i := range resolvers.LenIter() { for i := range resolvers.Len() {
copies[i] = resolvers.At(i).AsStruct() copies[i] = resolvers.At(i).AsStruct()
} }
return copies, true return copies, true
@ -5319,7 +5319,7 @@ func peerCanProxyDNS(p tailcfg.NodeView) bool {
// If p.Cap is not populated (e.g. older control server), then do the old // If p.Cap is not populated (e.g. older control server), then do the old
// thing of searching through services. // thing of searching through services.
services := p.Hostinfo().Services() services := p.Hostinfo().Services()
for i := range services.LenIter() { for i := range services.Len() {
if s := services.At(i); s.Proto == tailcfg.PeerAPIDNS && s.Port >= 1 { if s := services.At(i); s.Proto == tailcfg.PeerAPIDNS && s.Port >= 1 {
return true return true
} }
@ -5495,7 +5495,7 @@ func (b *LocalBackend) handleQuad100Port80Conn(w http.ResponseWriter, r *http.Re
return return
} }
io.WriteString(w, "<p>Local addresses:</p><ul>\n") io.WriteString(w, "<p>Local addresses:</p><ul>\n")
for i := range addrs.LenIter() { for i := range addrs.Len() {
fmt.Fprintf(w, "<li>%v</li>\n", addrs.At(i).Addr()) fmt.Fprintf(w, "<li>%v</li>\n", addrs.At(i).Addr())
} }
io.WriteString(w, "</ul>\n") io.WriteString(w, "</ul>\n")

@ -100,7 +100,7 @@ func (b *LocalBackend) tkaFilterNetmapLocked(nm *netmap.NetworkMap) {
TailscaleIPs: make([]netip.Addr, p.Addresses().Len()), TailscaleIPs: make([]netip.Addr, p.Addresses().Len()),
NodeKey: p.Key(), NodeKey: p.Key(),
} }
for i := range p.Addresses().LenIter() { for i := range p.Addresses().Len() {
addr := p.Addresses().At(i) addr := p.Addresses().At(i)
if addr.IsSingleIP() && tsaddr.IsTailscaleIP(addr.Addr()) { if addr.IsSingleIP() && tsaddr.IsTailscaleIP(addr.Addr()) {
fp.TailscaleIPs[i] = addr.Addr() fp.TailscaleIPs[i] = addr.Addr()

@ -222,7 +222,7 @@ func (b *LocalBackend) updateServeTCPPortNetMapAddrListenersLocked(ports []uint1
} }
addrs := nm.GetAddresses() addrs := nm.GetAddresses()
for i := range addrs.LenIter() { for i := range addrs.Len() {
a := addrs.At(i) a := addrs.At(i)
for _, p := range ports { for _, p := range ports {
addrPort := netip.AddrPortFrom(a.Addr(), p) addrPort := netip.AddrPortFrom(a.Addr(), p)

@ -121,7 +121,7 @@ func (b *LocalBackend) updateWebClientListenersLocked() {
} }
addrs := b.netMap.GetAddresses() addrs := b.netMap.GetAddresses()
for i := range addrs.LenIter() { for i := range addrs.Len() {
addrPort := netip.AddrPortFrom(addrs.At(i).Addr(), webClientPort) addrPort := netip.AddrPortFrom(addrs.At(i).Addr(), webClientPort)
if _, ok := b.webClientListeners[addrPort]; ok { if _, ok := b.webClientListeners[addrPort]; ok {
continue // already listening continue // already listening

@ -203,7 +203,7 @@ func NewContainsIPFunc(addrs views.Slice[netip.Prefix]) func(ip netip.Addr) bool
} }
// General case: // General case:
m := map[netip.Addr]bool{} m := map[netip.Addr]bool{}
for i := range addrs.LenIter() { for i := range addrs.Len() {
m[addrs.At(i).Addr()] = true m[addrs.At(i).Addr()] = true
} }
return func(ip netip.Addr) bool { return m[ip] } return func(ip netip.Addr) bool { return m[ip] }
@ -229,7 +229,7 @@ func PrefixIs6(p netip.Prefix) bool { return p.Addr().Is6() }
// IPv6 /0 route. // IPv6 /0 route.
func ContainsExitRoutes(rr views.Slice[netip.Prefix]) bool { func ContainsExitRoutes(rr views.Slice[netip.Prefix]) bool {
var v4, v6 bool var v4, v6 bool
for i := range rr.LenIter() { for i := range rr.Len() {
r := rr.At(i) r := rr.At(i)
if r == allIPv4 { if r == allIPv4 {
v4 = true v4 = true
@ -243,7 +243,7 @@ func ContainsExitRoutes(rr views.Slice[netip.Prefix]) bool {
// ContainsNonExitSubnetRoutes reports whether v contains Subnet // ContainsNonExitSubnetRoutes reports whether v contains Subnet
// Routes other than ExitNode Routes. // Routes other than ExitNode Routes.
func ContainsNonExitSubnetRoutes(rr views.Slice[netip.Prefix]) bool { func ContainsNonExitSubnetRoutes(rr views.Slice[netip.Prefix]) bool {
for i := range rr.LenIter() { for i := range rr.Len() {
if rr.At(i).Bits() != 0 { if rr.At(i).Bits() != 0 {
return true return true
} }
@ -274,7 +274,7 @@ func SortPrefixes(p []netip.Prefix) {
// in that match f. // in that match f.
func FilterPrefixesCopy(in views.Slice[netip.Prefix], f func(netip.Prefix) bool) []netip.Prefix { func FilterPrefixesCopy(in views.Slice[netip.Prefix], f func(netip.Prefix) bool) []netip.Prefix {
var out []netip.Prefix var out []netip.Prefix
for i := range in.LenIter() { for i := range in.Len() {
if v := in.At(i); f(v) { if v := in.At(i); f(v) {
out = append(out, v) out = append(out, v)
} }

@ -42,7 +42,7 @@ func dnsMapFromNetworkMap(nm *netmap.NetworkMap) dnsMap {
if dnsname.HasSuffix(nm.Name, suffix) { if dnsname.HasSuffix(nm.Name, suffix) {
ret[canonMapKey(dnsname.TrimSuffix(nm.Name, suffix))] = ip ret[canonMapKey(dnsname.TrimSuffix(nm.Name, suffix))] = ip
} }
for i := range addrs.LenIter() { for i := range addrs.Len() {
if addrs.At(i).Addr().Is4() { if addrs.At(i).Addr().Is4() {
have4 = true have4 = true
} }
@ -52,7 +52,7 @@ func dnsMapFromNetworkMap(nm *netmap.NetworkMap) dnsMap {
if p.Name() == "" { if p.Name() == "" {
continue continue
} }
for i := range p.Addresses().LenIter() { for i := range p.Addresses().Len() {
a := p.Addresses().At(i) a := p.Addresses().At(i)
ip := a.Addr() ip := a.Addr()
if ip.Is4() && !have4 { if ip.Is4() && !have4 {

@ -428,7 +428,7 @@ func (s *Server) TailscaleIPs() (ip4, ip6 netip.Addr) {
return return
} }
addrs := nm.GetAddresses() addrs := nm.GetAddresses()
for i := range addrs.LenIter() { for i := range addrs.Len() {
addr := addrs.At(i) addr := addrs.At(i)
ip := addr.Addr() ip := addr.Addr()
if ip.Is6() { if ip.Is6() {

@ -77,11 +77,6 @@ func (v ByteSlice[T]) AppendTo(dst T) T {
return append(dst, v.ж...) return append(dst, v.ж...)
} }
// LenIter returns a slice the same length as the v.Len().
// The caller can then range over it to get the valid indexes.
// It does not allocate.
func (v ByteSlice[T]) LenIter() []struct{} { return make([]struct{}, len(v.ж)) }
// At returns the byte at index `i` of the slice. // At returns the byte at index `i` of the slice.
func (v ByteSlice[T]) At(i int) byte { return v.ж[i] } func (v ByteSlice[T]) At(i int) byte { return v.ж[i] }
@ -154,11 +149,6 @@ func (v SliceView[T, V]) IsNil() bool { return v.ж == nil }
// Len returns the length of the slice. // Len returns the length of the slice.
func (v SliceView[T, V]) Len() int { return len(v.ж) } func (v SliceView[T, V]) Len() int { return len(v.ж) }
// LenIter returns a slice the same length as the v.Len().
// The caller can then range over it to get the valid indexes.
// It does not allocate.
func (v SliceView[T, V]) LenIter() []struct{} { return make([]struct{}, len(v.ж)) }
// At returns a View of the element at index `i` of the slice. // At returns a View of the element at index `i` of the slice.
func (v SliceView[T, V]) At(i int) V { return v.ж[i].View() } func (v SliceView[T, V]) At(i int) V { return v.ж[i].View() }
@ -245,11 +235,6 @@ func (v Slice[T]) IsNil() bool { return v.ж == nil }
// Len returns the length of the slice. // Len returns the length of the slice.
func (v Slice[T]) Len() int { return len(v.ж) } func (v Slice[T]) Len() int { return len(v.ж) }
// LenIter returns a slice the same length as the v.Len().
// The caller can then range over it to get the valid indexes.
// It does not allocate.
func (v Slice[T]) LenIter() []struct{} { return make([]struct{}, len(v.ж)) }
// At returns the element at index `i` of the slice. // At returns the element at index `i` of the slice.
func (v Slice[T]) At(i int) T { return v.ж[i] } func (v Slice[T]) At(i int) T { return v.ж[i] }

@ -141,27 +141,6 @@ func TestViewUtils(t *testing.T) {
qt.Equals, true) qt.Equals, true)
} }
func TestLenIter(t *testing.T) {
orig := []string{"foo", "bar"}
var got []string
v := SliceOf(orig)
for i := range v.LenIter() {
got = append(got, v.At(i))
}
if !reflect.DeepEqual(orig, got) {
t.Errorf("got %q; want %q", got, orig)
}
x := 0
n := testing.AllocsPerRun(10000, func() {
for range v.LenIter() {
x++
}
})
if n > 0 {
t.Errorf("allocs = %v; want 0", n)
}
}
func TestSliceEqual(t *testing.T) { func TestSliceEqual(t *testing.T) {
a := SliceOf([]string{"foo", "bar"}) a := SliceOf([]string{"foo", "bar"})
b := SliceOf([]string{"foo", "bar"}) b := SliceOf([]string{"foo", "bar"})

@ -102,7 +102,7 @@ func (c *Conn) ServeHTTPDebug(w http.ResponseWriter, r *http.Request) {
sort.Slice(ent, func(i, j int) bool { return ent[i].pub.Less(ent[j].pub) }) sort.Slice(ent, func(i, j int) bool { return ent[i].pub.Less(ent[j].pub) })
peers := map[key.NodePublic]tailcfg.NodeView{} peers := map[key.NodePublic]tailcfg.NodeView{}
for i := range c.peers.LenIter() { for i := range c.peers.Len() {
p := c.peers.At(i) p := c.peers.At(i)
peers[p.Key()] = p peers[p.Key()] = p
} }

@ -1366,7 +1366,7 @@ func (de *endpoint) updateFromNode(n tailcfg.NodeView, heartbeatDisabled bool, p
} }
func (de *endpoint) setEndpointsLocked(eps interface { func (de *endpoint) setEndpointsLocked(eps interface {
LenIter() []struct{} Len() int
At(i int) netip.AddrPort At(i int) netip.AddrPort
}) { }) {
for _, st := range de.endpointState { for _, st := range de.endpointState {
@ -1374,7 +1374,7 @@ func (de *endpoint) setEndpointsLocked(eps interface {
} }
var newIpps []netip.AddrPort var newIpps []netip.AddrPort
for i := range eps.LenIter() { for i := range eps.Len() {
if i > math.MaxInt16 { if i > math.MaxInt16 {
// Seems unlikely. // Seems unlikely.
break break

@ -1793,7 +1793,7 @@ func nodesEqual(x, y views.Slice[tailcfg.NodeView]) bool {
if x.Len() != y.Len() { if x.Len() != y.Len() {
return false return false
} }
for i := range x.LenIter() { for i := range x.Len() {
if !x.At(i).Equal(y.At(i)) { if !x.At(i).Equal(y.At(i)) {
return false return false
} }
@ -2056,7 +2056,7 @@ func (c *Conn) logEndpointCreated(n tailcfg.NodeView) {
fmt.Fprintf(w, "derp=%v%s ", regionID, code) fmt.Fprintf(w, "derp=%v%s ", regionID, code)
} }
for i := range n.AllowedIPs().LenIter() { for i := range n.AllowedIPs().Len() {
a := n.AllowedIPs().At(i) a := n.AllowedIPs().At(i)
if a.IsSingleIP() { if a.IsSingleIP() {
fmt.Fprintf(w, "aip=%v ", a.Addr()) fmt.Fprintf(w, "aip=%v ", a.Addr())
@ -2064,7 +2064,7 @@ func (c *Conn) logEndpointCreated(n tailcfg.NodeView) {
fmt.Fprintf(w, "aip=%v ", a) fmt.Fprintf(w, "aip=%v ", a)
} }
} }
for i := range n.Endpoints().LenIter() { for i := range n.Endpoints().Len() {
ep := n.Endpoints().At(i) ep := n.Endpoints().At(i)
fmt.Fprintf(w, "ep=%v ", ep) fmt.Fprintf(w, "ep=%v ", ep)
} }

@ -366,12 +366,12 @@ func (ns *Impl) UpdateNetstackIPs(nm *netmap.NetworkMap) {
newPfx := make(map[netip.Prefix]bool) newPfx := make(map[netip.Prefix]bool)
if selfNode.Valid() { if selfNode.Valid() {
for i := range selfNode.Addresses().LenIter() { for i := range selfNode.Addresses().Len() {
p := selfNode.Addresses().At(i) p := selfNode.Addresses().At(i)
newPfx[p] = true newPfx[p] = true
} }
if ns.ProcessSubnets { if ns.ProcessSubnets {
for i := range selfNode.AllowedIPs().LenIter() { for i := range selfNode.AllowedIPs().Len() {
p := selfNode.AllowedIPs().At(i) p := selfNode.AllowedIPs().At(i)
newPfx[p] = true newPfx[p] = true
} }

@ -160,7 +160,7 @@ func (e *userspaceEngine) onOpenTimeout(flow flowtrack.Tuple) {
ps, found := e.getPeerStatusLite(n.Key()) ps, found := e.getPeerStatusLite(n.Key())
if !found { if !found {
onlyZeroRoute := true // whether peerForIP returned n only because its /0 route matched onlyZeroRoute := true // whether peerForIP returned n only because its /0 route matched
for i := range n.AllowedIPs().LenIter() { for i := range n.AllowedIPs().Len() {
r := n.AllowedIPs().At(i) r := n.AllowedIPs().At(i)
if r.Bits() != 0 && r.Contains(flow.Dst.Addr()) { if r.Bits() != 0 && r.Contains(flow.Dst.Addr()) {
onlyZeroRoute = false onlyZeroRoute = false

@ -780,7 +780,7 @@ func (e *userspaceEngine) updateActivityMapsLocked(trackNodes []key.NodePublic,
// hasOverlap checks if there is a IPPrefix which is common amongst the two // hasOverlap checks if there is a IPPrefix which is common amongst the two
// provided slices. // provided slices.
func hasOverlap(aips, rips views.Slice[netip.Prefix]) bool { func hasOverlap(aips, rips views.Slice[netip.Prefix]) bool {
for i := range aips.LenIter() { for i := range aips.Len() {
aip := aips.At(i) aip := aips.At(i)
if views.SliceContains(rips, aip) { if views.SliceContains(rips, aip) {
return true return true
@ -1233,7 +1233,7 @@ func (e *userspaceEngine) mySelfIPMatchingFamily(dst netip.Addr) (src netip.Addr
if addrs.Len() == 0 { if addrs.Len() == 0 {
return zero, errors.New("no self address in netmap") return zero, errors.New("no self address in netmap")
} }
for i := range addrs.LenIter() { for i := range addrs.Len() {
if a := addrs.At(i); a.IsSingleIP() && a.Addr().BitLen() == dst.BitLen() { if a := addrs.At(i); a.IsSingleIP() && a.Addr().BitLen() == dst.BitLen() {
return a.Addr(), nil return a.Addr(), nil
} }
@ -1379,7 +1379,7 @@ func (e *userspaceEngine) PeerForIP(ip netip.Addr) (ret PeerForIP, ok bool) {
// Check for exact matches before looking for subnet matches. // Check for exact matches before looking for subnet matches.
// TODO(bradfitz): add maps for these. on NetworkMap? // TODO(bradfitz): add maps for these. on NetworkMap?
for _, p := range nm.Peers { for _, p := range nm.Peers {
for i := range p.Addresses().LenIter() { for i := range p.Addresses().Len() {
a := p.Addresses().At(i) a := p.Addresses().At(i)
if a.Addr() == ip && a.IsSingleIP() && tsaddr.IsTailscaleIP(ip) { if a.Addr() == ip && a.IsSingleIP() && tsaddr.IsTailscaleIP(ip) {
return PeerForIP{Node: p, Route: a}, true return PeerForIP{Node: p, Route: a}, true
@ -1387,7 +1387,7 @@ func (e *userspaceEngine) PeerForIP(ip netip.Addr) (ret PeerForIP, ok bool) {
} }
} }
addrs := nm.GetAddresses() addrs := nm.GetAddresses()
for i := range addrs.LenIter() { for i := range addrs.Len() {
if a := addrs.At(i); a.Addr() == ip && a.IsSingleIP() && tsaddr.IsTailscaleIP(ip) { if a := addrs.At(i); a.Addr() == ip && a.IsSingleIP() && tsaddr.IsTailscaleIP(ip) {
return PeerForIP{Node: nm.SelfNode, IsSelf: true, Route: a}, true return PeerForIP{Node: nm.SelfNode, IsSelf: true, Route: a}, true
} }

@ -41,7 +41,7 @@ func cidrIsSubnet(node tailcfg.NodeView, cidr netip.Prefix) bool {
if !cidr.IsSingleIP() { if !cidr.IsSingleIP() {
return true return true
} }
for i := range node.Addresses().LenIter() { for i := range node.Addresses().Len() {
selfCIDR := node.Addresses().At(i) selfCIDR := node.Addresses().At(i)
if cidr == selfCIDR { if cidr == selfCIDR {
return false return false
@ -100,7 +100,7 @@ func WGCfg(nm *netmap.NetworkMap, logf logger.Logf, flags netmap.WGConfigFlags,
didExitNodeWarn := false didExitNodeWarn := false
cpeer.V4MasqAddr = peer.SelfNodeV4MasqAddrForThisPeer() cpeer.V4MasqAddr = peer.SelfNodeV4MasqAddrForThisPeer()
cpeer.V6MasqAddr = peer.SelfNodeV6MasqAddrForThisPeer() cpeer.V6MasqAddr = peer.SelfNodeV6MasqAddrForThisPeer()
for i := range peer.AllowedIPs().LenIter() { for i := range peer.AllowedIPs().Len() {
allowedIP := peer.AllowedIPs().At(i) allowedIP := peer.AllowedIPs().At(i)
if allowedIP.Bits() == 0 && peer.StableID() != exitNode { if allowedIP.Bits() == 0 && peer.StableID() != exitNode {
if didExitNodeWarn { if didExitNodeWarn {

Loading…
Cancel
Save