mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 13:18:53 +00:00
cmd/natc: cleanup unused state
perPeerState no longer needs to know the v6ULA. Updates #14667 Signed-off-by: Fran Bull <fran@tailscale.com>
This commit is contained in:
@@ -24,7 +24,6 @@ var ErrNoIPsAvailable = errors.New("no IPs available")
|
|||||||
type IPPool struct {
|
type IPPool struct {
|
||||||
perPeerMap syncs.Map[tailcfg.NodeID, *perPeerState]
|
perPeerMap syncs.Map[tailcfg.NodeID, *perPeerState]
|
||||||
IPSet *netipx.IPSet
|
IPSet *netipx.IPSet
|
||||||
V6ULA netip.Prefix
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ipp *IPPool) DomainForIP(from tailcfg.NodeID, addr netip.Addr) (string, bool) {
|
func (ipp *IPPool) DomainForIP(from tailcfg.NodeID, addr netip.Addr) (string, bool) {
|
||||||
@@ -44,7 +43,6 @@ func (ipp *IPPool) DomainForIP(from tailcfg.NodeID, addr netip.Addr) (string, bo
|
|||||||
func (ipp *IPPool) IPForDomain(from tailcfg.NodeID, domain string) (netip.Addr, error) {
|
func (ipp *IPPool) IPForDomain(from tailcfg.NodeID, domain string) (netip.Addr, error) {
|
||||||
npps := &perPeerState{
|
npps := &perPeerState{
|
||||||
ipset: ipp.IPSet,
|
ipset: ipp.IPSet,
|
||||||
v6ULA: ipp.V6ULA,
|
|
||||||
}
|
}
|
||||||
ps, _ := ipp.perPeerMap.LoadOrStore(from, npps)
|
ps, _ := ipp.perPeerMap.LoadOrStore(from, npps)
|
||||||
return ps.ipForDomain(domain)
|
return ps.ipForDomain(domain)
|
||||||
@@ -52,7 +50,6 @@ func (ipp *IPPool) IPForDomain(from tailcfg.NodeID, domain string) (netip.Addr,
|
|||||||
|
|
||||||
// perPeerState holds the state for a single peer.
|
// perPeerState holds the state for a single peer.
|
||||||
type perPeerState struct {
|
type perPeerState struct {
|
||||||
v6ULA netip.Prefix
|
|
||||||
ipset *netipx.IPSet
|
ipset *netipx.IPSet
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
@@ -19,8 +19,7 @@ func TestIPPoolExhaustion(t *testing.T) {
|
|||||||
var ipsb netipx.IPSetBuilder
|
var ipsb netipx.IPSetBuilder
|
||||||
ipsb.AddPrefix(smallPrefix)
|
ipsb.AddPrefix(smallPrefix)
|
||||||
addrPool := must.Get(ipsb.IPSet())
|
addrPool := must.Get(ipsb.IPSet())
|
||||||
v6ULA := netip.MustParsePrefix("fd7a:115c:a1e0:a99c:0001::/80")
|
pool := IPPool{IPSet: addrPool}
|
||||||
pool := IPPool{V6ULA: v6ULA, IPSet: addrPool}
|
|
||||||
|
|
||||||
assignedIPs := make(map[netip.Addr]string)
|
assignedIPs := make(map[netip.Addr]string)
|
||||||
|
|
||||||
@@ -52,9 +51,6 @@ func TestIPPoolExhaustion(t *testing.T) {
|
|||||||
if addr.Is4() && !smallPrefix.Contains(addr) {
|
if addr.Is4() && !smallPrefix.Contains(addr) {
|
||||||
t.Errorf("IP %s for domain %q not in expected range %s", addr, domain, smallPrefix)
|
t.Errorf("IP %s for domain %q not in expected range %s", addr, domain, smallPrefix)
|
||||||
}
|
}
|
||||||
if addr.Is6() && !v6ULA.Contains(addr) {
|
|
||||||
t.Errorf("IP %s for domain %q not in expected range %s", addr, domain, v6ULA)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// expect one error for each iteration with the 5th domain
|
// expect one error for each iteration with the 5th domain
|
||||||
@@ -73,7 +69,6 @@ func TestIPPool(t *testing.T) {
|
|||||||
ipsb.AddPrefix(netip.MustParsePrefix("100.64.1.0/24"))
|
ipsb.AddPrefix(netip.MustParsePrefix("100.64.1.0/24"))
|
||||||
addrPool := must.Get(ipsb.IPSet())
|
addrPool := must.Get(ipsb.IPSet())
|
||||||
pool := IPPool{
|
pool := IPPool{
|
||||||
V6ULA: netip.MustParsePrefix("fd7a:115c:a1e0:a99c:0001::/80"),
|
|
||||||
IPSet: addrPool,
|
IPSet: addrPool,
|
||||||
}
|
}
|
||||||
from := tailcfg.NodeID(12345)
|
from := tailcfg.NodeID(12345)
|
||||||
|
@@ -153,7 +153,7 @@ func main() {
|
|||||||
whois: lc,
|
whois: lc,
|
||||||
v6ULA: v6ULA,
|
v6ULA: v6ULA,
|
||||||
ignoreDsts: ignoreDstTable,
|
ignoreDsts: ignoreDstTable,
|
||||||
ipPool: &ippool.IPPool{V6ULA: v6ULA, IPSet: addrPool},
|
ipPool: &ippool.IPPool{IPSet: addrPool},
|
||||||
routes: routes,
|
routes: routes,
|
||||||
dnsAddr: dnsAddr,
|
dnsAddr: dnsAddr,
|
||||||
resolver: net.DefaultResolver,
|
resolver: net.DefaultResolver,
|
||||||
|
@@ -270,7 +270,7 @@ func TestDNSResponse(t *testing.T) {
|
|||||||
ignoreDsts: &bart.Table[bool]{},
|
ignoreDsts: &bart.Table[bool]{},
|
||||||
routes: routes,
|
routes: routes,
|
||||||
v6ULA: v6ULA,
|
v6ULA: v6ULA,
|
||||||
ipPool: &ippool.IPPool{V6ULA: v6ULA, IPSet: addrPool},
|
ipPool: &ippool.IPPool{IPSet: addrPool},
|
||||||
dnsAddr: dnsAddr,
|
dnsAddr: dnsAddr,
|
||||||
}
|
}
|
||||||
c.ignoreDsts.Insert(netip.MustParsePrefix("8.8.4.4/32"), true)
|
c.ignoreDsts.Insert(netip.MustParsePrefix("8.8.4.4/32"), true)
|
||||||
|
Reference in New Issue
Block a user