mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-20 00:31:17 -08:00
inc_counter looked up the per-CPU counter, incremented it in place, and then called bpf_map_update_elem to store the same value back. For a BPF_MAP_TYPE_PERCPU_HASH the pointer returned by the lookup already is this CPU's slot, so the write-back was redundant, and it is the one step that takes the hash bucket spinlock. The program runs for every received packet, not just STUN, and updates two counters each time, so a busy DERP paid two locked map updates per incoming TCP segment. Keep the update only for the miss path, which runs once per key. While here, make inc_counter and handle_counters return void. Neither caller looked at the result. TestXDP cleared the counters map before every case, so it only ever exercised the key insertion path. Add a subtest that runs the same packet repeatedly without clearing, to cover the in-place increment of an existing key. Regenerate the bpf2go outputs with clang 18.1.8 and the bpf2go from the cilium/ebpf v0.22.0 already in go.mod, which is also why the generated Go files pick up structs.HostLayout and the object name constants. Fixes #22463 Signed-off-by: Mike O'Driscoll <[email protected]> Co-authored-by: Brad Fitzpatrick <[email protected]>