Repository navigation
Read BSD TCP statistics from the lines netstat prints - #3803
Merged
Merged
Conversation
OpenBSD, NetBSD and DragonFly BSD read TCP and UDP statistics through the shared netstat -s parser, which matched none of their connection lines and mapped others to unrelated counters: - active and passive openings were always 0; they are now read from "connection requests" and "connection accepts" - connections established held the count ever established; it is now the number of IPv4 connections netstat -n -f inet lists as established, as on FreeBSD and macOS - failures came from "bad connection attempts" (bad SYNs) and resets from the SYN cache's "dropped due to RST"; they now come from "embryonic connections dropped" and the drops among "connections closed", the counters FreeBSD's native path reads - retransmissions no longer add DragonFly's "retransmitted by SACK" line - UDP receive errors no longer include "with no checksum", which is valid over IPv4, and FreeBSD's "undelivered" wording now counts as no port Singular forms, printed for a count of 1, are matched too. The invented BSD fixtures are replaced with real output from OpenBSD 7.9, DragonFly 6.4 and FreeBSD 16. Verified against live netstat on DragonFly 6.4.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3803 +/- ##
============================================
+ Coverage 80.68% 80.69% +0.01%
- Complexity 404 633 +229
============================================
Files 725 725
Lines 25928 25936 +8
Branches 4404 4406 +2
============================================
+ Hits 20920 20930 +10
+ Misses 2778 2777 -1
+ Partials 2230 2229 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
OpenBSD, NetBSD and DragonFly BSD get
InternetProtocolStatsfrom the sharednetstat -sparser inNetStat. Checked against real output from all four BSDs (wording is identical across them), most of the TCP fields were wrong:connection requests/connection acceptsconnections established (including accepts), the count ever established (88159 on the OpenBSD box)netstat -n -f inetlists asESTABLISHED, as FreeBSD and macOS already dobad connection attempts(bad SYNs)embryonic connections dropped, thetcps_conndropsFreeBSD's native path readsdropped due to RST, a counter nested under the SYN cacheDinconnections closed (including D drops), FreeBSD'stcps_dropsretransmitted by SACKdata packets (B bytes) retransmittedUDP: receive errors no longer include
with no checksum(a checksum is optional over IPv4, and FreeBSD's native path does not count it), and FreeBSD'sbroadcast/multicast datagram(s) undeliveredwording now counts as no port, so the FreeBSDnetstatfallback agrees with its sysctl path. Singular forms, which netstat prints for a count of 1, are matched throughout.Code changes:
NetStat.queryTcpStats(String, long)takes the current established count from the caller; FreeBSD's fallback uses it instead of rebuildingTcpStatsby hand.NetStat.queryBsdTcpStats()combines it withnetstat -n -f inet; OpenBSD, NetBSD and DragonFly call it.queryTcpnetstatcounts plaintcprows as IPv4, which is how OpenBSD and NetBSD label them.NetStatTestare replaced with real output from OpenBSD 7.9, DragonFly 6.4 and FreeBSD 16, keeping the lines that used to be misread.Verification
oshi-commonclean, including-Perror-prone.getTCPv4Stats()andgetUDPv4Stats()agree with livenetstat -son every field, and established (2) withnetstat -n -f inet.netstat -n -f inetformat confirmed on both.