Guard against nil TC qdisc stats to prevent SIGSEGV (#4668)

Newer kernels report qdisc stats via TCA_STATS2 (Stats2) while older
kernels only populate the legacy TCA_STATS attribute (Stats). Whichever
is unused is left nil, so unconditionally dereferencing Stats crashed
with a SIGSEGV during telemetry init. Prefer Stats2 and fall back to
Stats, skipping when both are nil.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Pracht
2026-07-13 14:30:44 +02:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 2bd3b9d67f
commit 2c9eee4c54
+11 -2
View File
@@ -38,8 +38,17 @@ func getTCStats() (packets, drops uint32, err error) {
}
for _, qdisc := range qdiscs {
packets = packets + qdisc.Stats.Packets
drops = drops + qdisc.Stats.Drops
// Newer kernels report stats via TCA_STATS2 (Stats2), while older kernels
// only populate the legacy TCA_STATS attribute (Stats). Prefer Stats2 and
// fall back to Stats so counters are collected on both.
switch {
case qdisc.Stats2 != nil:
packets = packets + qdisc.Stats2.Packets
drops = drops + qdisc.Stats2.Drops
case qdisc.Stats != nil:
packets = packets + qdisc.Stats.Packets
drops = drops + qdisc.Stats.Drops
}
}
return