Repository navigation
Count IPv6 traffic in network protocol statistics - #969
Merged
Merged
Conversation
The ip, udp and icmp protocol counters were read only from /proc/net/snmp, which is IPv4-only, so IPv6 traffic was never counted. In a dual-stack pod, TCP over IPv6 didn't move the ip byte counters, and IPv6 UDP datagrams and ping6 didn't move the udp and icmp ones. Also read /proc/<pid>/net/snmp6 and add the Ip6, Udp6 and Icmp6 counters to their IPv4 counterparts: packets, ip octets (Ip6InOctets/Ip6OutOctets), and the matching drop and error counters so they cover the same traffic as the packet counts. TCP is unchanged because the kernel's Tcp counters already cover both families. If snmp6 is missing (IPv6 disabled in the guest), only the IPv4 counters are used. Add unit tests for merging IPv4 and IPv6 counters, IPv6-only input and a missing snmp6.
JaewonHur
force-pushed
the
support-ipv6
branch
from
October 16, 2026 15:25
400fd3d to
fb7d737
Compare
noah-thor
reviewed
Oct 16, 2026
Comment on lines
+70
to
+74
| /// `snmp` and `netstat` alternate a header line (`Proto: name name ...`) with a value line | ||
| /// (`Proto: 1 2 ...`). `snmp6` has one `Name value` pair per line. Fields are matched by | ||
| /// name so new kernel columns don't break parsing. IPv6 counters from `snmp6` are kept apart | ||
| /// from the IPv4 ones in `udp6`, `icmp6` and `ip6`, and stay `nil` when `snmp6` is absent. | ||
| public init(snmp: String, netstat: String? = nil, snmp6: String? = nil) { |
Contributor
There was a problem hiding this comment.
nit: This comment wording is very confusing to me
Comment on lines
+137
to
+141
| ip6.receivedPackets = ip6Table["InReceives"] ?? 0 | ||
| ip6.transmittedPackets = ip6Table["OutRequests"] ?? 0 | ||
| ip6.receivedBytes = ip6Table["InOctets"] ?? 0 | ||
| ip6.transmittedBytes = ip6Table["OutOctets"] ?? 0 | ||
| ip6.receivedDrops = sum(ip6Table, "InDiscards", "InNoRoutes") |
Contributor
There was a problem hiding this comment.
Why are some of these optional but when we sum they are not?
Comment on lines
+163
to
+169
| /// ``` | ||
| /// Ip6InReceives 50 | ||
| /// Ip6InOctets 1000 | ||
| /// Udp6InDatagrams 60 | ||
| /// Udp6NoPorts 5 | ||
| /// Icmp6InMsgs 6 | ||
| /// ``` |
| // The same mapping as IPv4, but every IPv6 counter is in snmp6, including octets and InNoRoutes. | ||
| let udp6Table = Self.snmp6Fields(snmp6, prefix: "Udp6") | ||
| var udp6 = Counters() | ||
| udp6.receivedPackets = udp6Table["InDatagrams"] ?? 0 |
Contributor
There was a problem hiding this comment.
I think in the future, we should make keyed constants like this enum values
Comment on lines
+126
to
+130
| let s = ProcNetSnmp(snmp: Self.snmp, netstat: Self.netstat, snmp6: Self.snmp6) | ||
| // The IPv4 counters are unchanged by snmp6. | ||
| #expect(s.ip == ProcNetSnmp(snmp: Self.snmp, netstat: Self.netstat).ip) | ||
| #expect(s.udp == ProcNetSnmp(snmp: Self.snmp, netstat: Self.netstat).udp) | ||
| #expect(s.icmp == ProcNetSnmp(snmp: Self.snmp, netstat: Self.netstat).icmp) |
Contributor
There was a problem hiding this comment.
Unchanged why? Do we change anything in this test?
Contributor
Author
There was a problem hiding this comment.
It was trying to say passing snmp6: Self.snmp6 above should not change ipv4 values like s.ip below. Let me make it clear.
JaewonHur
force-pushed
the
support-ipv6
branch
from
October 16, 2026 17:44
fb7d737 to
90ff168
Compare
noah-thor
approved these changes
Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The ip, udp and icmp protocol counters were read only from /proc/net/snmp, which is IPv4-only, so IPv6 traffic was never counted. In a dual-stack setup, TCP over IPv6 didn't move the ip byte counters, and IPv6 UDP datagrams and ping6 didn't move the udp and icmp ones.
Also read /proc//net/snmp6 and add the Ip6, Udp6 and Icmp6 counters to their IPv4 counterparts: packets, ip octets (Ip6InOctets/Ip6OutOctets), and the matching drop and error counters so they cover the same traffic as the packet counts. TCP is unchanged because the kernel's Tcp counters already cover both families. If snmp6 is missing (IPv6 disabled in the guest), only the IPv4 counters are used.
Add unit tests for merging IPv4 and IPv6 counters, IPv6-only input and a missing snmp6.