feature/conn25: return expired addrs from index lookups

We can use them for traffic until they are actually removed from the
table.

Updates tailscale/corp#43180

Co-authored-by: Fran Bull <fran@tailscale.com>
Co-authored-by: Michael Ben-Ami <mzb@tailscale.com>
Signed-off-by: Fran Bull <fran@tailscale.com>
Signed-off-by: Michael Ben-Ami <mzb@tailscale.com>
This commit is contained in:
Fran Bull
2026-06-30 13:56:21 -07:00
committed by franbull
co-authored by Michael Ben-Ami
parent b6e17df646
commit b228748a22
2 changed files with 4 additions and 13 deletions
+3 -3
View File
@@ -79,7 +79,7 @@ func (a *addrAssignments) insertWithExpiry(as *addrs, d time.Duration) error {
func (a *addrAssignments) lookupByDomainDst(domain dnsname.FQDN, dst netip.Addr) (*addrs, bool) {
v, ok := a.byDomainDst[domainDst{domain: domain, dst: dst}]
if !ok || v.expiresAt.Before(a.clock.Now()) {
if !ok {
return &addrs{}, false
}
return v, true
@@ -87,7 +87,7 @@ func (a *addrAssignments) lookupByDomainDst(domain dnsname.FQDN, dst netip.Addr)
func (a *addrAssignments) lookupByMagicIP(mip netip.Addr) (*addrs, bool) {
v, ok := a.byMagicIP[mip]
if !ok || v.expiresAt.Before(a.clock.Now()) {
if !ok {
return &addrs{}, false
}
return v, true
@@ -95,7 +95,7 @@ func (a *addrAssignments) lookupByMagicIP(mip netip.Addr) (*addrs, bool) {
func (a *addrAssignments) lookupByTransitIP(tip netip.Addr) (*addrs, bool) {
v, ok := a.byTransitIP[tip]
if !ok || v.expiresAt.Before(a.clock.Now()) {
if !ok {
return &addrs{}, false
}
return v, true
+1 -10
View File
@@ -41,17 +41,8 @@ func TestAssignmentsExpire(t *testing.T) {
if err == nil {
t.Fatal("expected an error but got nil")
}
// After a time greater than the default expiry passes, the assignment should
// not be returned.
clock.Advance(defaultExpiry * 2)
foundAsAfter, okAfter := assignments.lookupByMagicIP(as.magic)
if okAfter {
t.Fatal("expected not to find (expired)")
}
if foundAsAfter.isValid() {
t.Fatal("expected zero val")
}
// We should only be able to write old addresses again if they've been removed from the maps (eg with popExpired).
clock.Advance(defaultExpiry * 2)
err = assignments.insert(as)
if err == nil {
t.Fatal("expected an error but got nil")