Prefer QDisc.Stats till go-tc addresses QDisc.Stats2 parsing (#4685)
This commit is contained in:
@@ -41,13 +41,14 @@ func getTCStats() (packets, drops uint32, err error) {
|
|||||||
// Newer kernels report stats via TCA_STATS2 (Stats2), while older kernels
|
// Newer kernels report stats via TCA_STATS2 (Stats2), while older kernels
|
||||||
// only populate the legacy TCA_STATS attribute (Stats). Prefer Stats2 and
|
// only populate the legacy TCA_STATS attribute (Stats). Prefer Stats2 and
|
||||||
// fall back to Stats so counters are collected on both.
|
// fall back to Stats so counters are collected on both.
|
||||||
switch {
|
//
|
||||||
case qdisc.Stats2 != nil:
|
// However, go-tc (through v0.4.8 and current main) mis-parses the nested TCA_STATS2
|
||||||
packets = packets + qdisc.Stats2.Packets
|
// as a flat struct, so Stats2.Packets/.Drops are garbage. The legacy
|
||||||
drops = drops + qdisc.Stats2.Drops
|
// TCA_STATS blob is a real flat struct and is parsed correctly, and modern
|
||||||
case qdisc.Stats != nil:
|
// kernels populate BOTH — so prefer Stats.
|
||||||
packets = packets + qdisc.Stats.Packets
|
if qdisc.Stats != nil {
|
||||||
drops = drops + qdisc.Stats.Drops
|
packets += qdisc.Stats.Packets
|
||||||
|
drops += qdisc.Stats.Drops
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user