feature/conn25,types/appctype: serve active Conn25 state over localapi
At /v0/conn25-state. State includes whether the node is configured for Connectors 2025, as well as client-specific and connector-specific state, if the node is acting in those contexts. Client-specific state includes the reserved Magic IPs and Transit IPs on the client that have not been returned to their IP pools, and their associated apps, domains, real destination IPs, and active flow counts. We also report IP pool utilization: the number of magic and transit IPs in use versus each pool's capacity, split by IP family. Connector-specific state includes a peer list of clients that have registered Transit IPs with the connector, and the apps are real destination IPs the Transit IPs map to. Updates tailscale/corp#40125 Signed-off-by: Michael Ben-Ami <mzb@tailscale.com>
This commit is contained in:
committed by
mzbenami
parent
71e5a98404
commit
b2de420e3d
@@ -5,6 +5,7 @@ package conn25
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"net/netip"
|
||||
|
||||
"go4.org/netipx"
|
||||
@@ -140,3 +141,37 @@ func (ipp *ippool) reconfig(ipSet *netipx.IPSet) *ippool {
|
||||
}
|
||||
return newPool
|
||||
}
|
||||
|
||||
// inUseCount returns the number of addresses currently handed out from the
|
||||
// pool. It is safe to call on a nil or uninitialized pool, returning 0.
|
||||
func (ipp *ippool) inUseCount() int64 {
|
||||
if ipp == nil || ipp.inUse == nil {
|
||||
return 0
|
||||
}
|
||||
return int64(ipp.inUse.Len())
|
||||
}
|
||||
|
||||
// capacity returns the total number of addresses defined by the pool's ipSet.
|
||||
// It is safe to call on a nil or uninitialized pool, returning 0. The count is
|
||||
// clamped to [math.MaxInt64] because an IP pool (particularly IPv6) can define
|
||||
// far more addresses than fit in an int64.
|
||||
func (ipp *ippool) capacity() int64 {
|
||||
if ipp == nil || ipp.ipSet == nil {
|
||||
return 0
|
||||
}
|
||||
var count int64
|
||||
for _, pfx := range ipp.ipSet.Prefixes() {
|
||||
bits := pfx.Addr().BitLen() - pfx.Bits()
|
||||
// 1<<bits can exceed an int64 (e.g. a /64 IPv6 pool), so clamp.
|
||||
if bits >= 63 {
|
||||
return math.MaxInt64
|
||||
}
|
||||
addend := int64(1) << bits
|
||||
if count > math.MaxInt64-addend {
|
||||
// Summing multiple large prefixes would overflow.
|
||||
return math.MaxInt64
|
||||
}
|
||||
count += addend
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user