net/tstun: fix stale identifier references in the subnet counter comments

countSubnetRouteTraffic became countSubnetRouteParsed and evictRetainedLocked
is just evictRetained. Also documents the ordering the self-address and route
setters rely on: the engine calls both from the same Reconfig, addresses first.

Updates tailscale/corp#45684

Change-Id: I2e71d3f69fc1a47b9030b55bd5d7462daae38634
Signed-off-by: Kabir Sikand <[email protected]>
This commit is contained in:
Kabir Sikand committed 2026-07-29 17:59:31 +00:00
1 parent 5e2822f9b6
commit cfdc9aeeb9
3 files changed
+11 -4

No files matched your search

+2 -2
View File
@@ -41,7 +41,7 @@ const (
// maxRetainedRoutes caps how many routes' counters are kept alive for the
// process's lifetime; see subnetCounters.counters for why retention is
// needed and evictRetainedLocked for what happens past the cap.
// needed and evictRetained for what happens past the cap.
//
// A subnet router's advertised set is admin-configured and small; the cap
// only matters if it churns unexpectedly. 4 KiB of routeCounters is a few
@@ -186,7 +186,7 @@ func newSubnetCounters(reg *usermetric.Registry, table *atomicPrefixTable) *subn
//
// 4via6 routes are excluded too, for M1. Their prefixes live inside
// fd7a:115c:a1e0::/48, so both endpoints of 4via6 traffic are Tailscale
// addresses and countSubnetRouteTraffic's "exactly one Tailscale endpoint"
// addresses and countSubnetRouteParsed's "exactly one Tailscale endpoint"
// test never admits such a packet. Admitting the route anyway would publish
// four series that can never move, which reads to an operator as an idle
// router rather than an unsupported route type. Counting 4via6 properly needs
+2 -2
View File
@@ -402,7 +402,7 @@ func TestSubnetCountersExitNodeOnlyNotEnabled(t *testing.T) {
// TestSubnetCountersViaRouteExcluded checks that 4via6 routes get no series.
// Both endpoints of 4via6 traffic are inside the Tailscale ULA range, so
// countSubnetRouteTraffic can never attribute a packet to one, and publishing
// countSubnetRouteParsed can never attribute a packet to one, and publishing
// four permanently-zero series would read as "this route is idle".
func TestSubnetCountersViaRouteExcluded(t *testing.T) {
sc := newTestSubnetCounters()
@@ -530,7 +530,7 @@ func TestWrapperSubnetRouteCountingStalePacket(t *testing.T) {
// TestSubnetCountersHotPathNoAllocs pins the real hooks, not just the
// forAddr+add pair, to zero allocations. A prefix.String() creeping back into
// countSubnetRouteTraffic would allocate twice per packet.
// countSubnetRouteParsed would allocate twice per packet.
func TestSubnetCountersHotPathNoAllocs(t *testing.T) {
bus := eventbustest.NewBus(t)
_, tun := newFakeTUN(t.Logf, bus, false)
+7
View File
@@ -1615,6 +1615,13 @@ type selfTailscaleAddrs struct {
// traffic from the node's own; a4 and a6 are typically
// [tsaddr.FirstTailscaleAddrs] of the node's wireguard config addresses.
// Callers may pass invalid addresses for either family.
//
// The engine calls this and SetSubnetRoutes from the same Reconfig, in that
// order, so the addresses are in place before a route becomes countable. A
// reconfig that changes both leaves a window of a few instructions where the
// counters see the new addresses with the old routes; the consequence is at
// most a handful of packets attributed as forwarded when they were the node's
// own, which is not worth a lock on the packet path to close.
func (t *Wrapper) SetSelfTailscaleAddrs(a4, a6 netip.Addr) {
if old := t.selfAddrs.Load(); old != nil && old.v4 == a4 && old.v6 == a6 {
return