diff --git a/net/tstun/subnetmetrics.go b/net/tstun/subnetmetrics.go index 8c0cf6a2a..7ba0ce351 100644 --- a/net/tstun/subnetmetrics.go +++ b/net/tstun/subnetmetrics.go @@ -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 diff --git a/net/tstun/subnetmetrics_test.go b/net/tstun/subnetmetrics_test.go index 43d12d475..1982e827f 100644 --- a/net/tstun/subnetmetrics_test.go +++ b/net/tstun/subnetmetrics_test.go @@ -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) diff --git a/net/tstun/wrap.go b/net/tstun/wrap.go index 0d7bc8086..fdddd4449 100644 --- a/net/tstun/wrap.go +++ b/net/tstun/wrap.go @@ -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