Skip to content

Fix network interface statistics on OpenBSD and DragonFly BSD, and gateways on DragonFly - #3788

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dragonfly-network
Oct 11, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dragonfly-network

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

BsdNetworkIF read netstat -bI <if> by fixed column index and gave up when a row had fewer than 12 columns. Only FreeBSD prints 12:

netstat -bI counters Before After
FreeBSD Ipkts Ierrs Idrop Ibytes Opkts Oerrs Obytes Coll correct unchanged values; -n added so netstat no longer resolves host names
DragonFly BSD the same without Idrop (11 columns) all 0 bytes correct
OpenBSD Ibytes Obytes only (6 columns) all 0 bytes from -b, packets/errors/collisions from netstat -nI (Ifail/Ofail/Colls)

The parser now reads the link-level row against the header, matching values from the end of the row, because the loopback row has an empty Address column on DragonFly and OpenBSD.

FreeBsdNetworkParams (also used by DragonFly) ran route -4|-6 get default; DragonFly's route has no -4/-6, so both gateways were empty. It now runs route -n get default and route -n get -inet6 default, the commands OpenBSD and NetBSD already use.

All changes are in oshi-common, so JNA and FFM share them.

Verified

  • DragonFly 6.4 (cfarm152), JNA and FFM: traffic 49.3 GiB in / 33.3 GiB out, matching netstat; IPv4 gateway 140.211.167.129 (was empty). The box has no IPv6 default route, so the IPv6 gateway stays empty.
  • FreeBSD 16-CURRENT (cfarm430), JNA and FFM: counters still match netstat; gateways 172.18.4.1 and 2600:3c18:e002:2e11::1.
  • OpenBSD 7.9 (cfarm220): no JDK on the box, so covered by BsdNetworkIFTest fixtures taken from its real output.

Not changed

  • DragonFly packet counts stay 0: its own netstat shows 0 packets on the vtnet0 link row (the driver counts bytes only).
  • DragonFly's IPv6 address list is empty because the JDK's NetworkInterface does not return IPv6 addresses there; FreeBSD's JDK does. Not an OSHI issue.
  • NetBsdNetworkIF duplicates the OpenBSD two-command path; folding it into BsdNetworkIF is left for a follow-up.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed network traffic statistics reporting on OpenBSD and DragonFly BSD, including handling differences in system output.
    • Corrected default gateway lookups on DragonFly BSD.
    • Fixed FreeBSD hostname lookups when reading network interface statistics.
  • Tests
    • Added coverage for network statistics parsing across FreeBSD, DragonFly BSD, and OpenBSD.

BsdNetworkIF read netstat -bI by fixed column index and gave up on
fewer than 12 columns. FreeBSD prints 12, but DragonFly BSD has no
Idrop column (11) and OpenBSD prints only Ibytes and Obytes with -b
(6), so every counter was 0 on both. Parse the link-level row against
the header instead, matching values from the end of the row because
the loopback row has an empty Address column on DragonFly and OpenBSD.
Where -b gives no packet counts (OpenBSD), read them from netstat -nI,
which names its error and collision columns Ifail/Ofail/Colls. Pass -n
so netstat does not resolve addresses to host names.

FreeBSD's default gateway lookups used route -4/-6, which DragonFly's
route does not accept, leaving both gateways empty there. Use
route -n get [-inet6] default, as OpenBSD and NetBSD already do.

Verified on cfarm152 (DragonFly 6.4) and cfarm430 (FreeBSD
16-CURRENT), JNA and FFM; OpenBSD by fixtures from cfarm220.
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b629b0a5-e57f-4887-9483-5d9dd159c6fa

📥 Commits

Reviewing files that changed from the base of the PR and between e528211 and 61335e8.


📒 Files selected for processing (4)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdNetworkParams.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdNetworkIFTest.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.


📜 Recent review details
⏰ Context from checks skipped due to timeout. (12)
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Error Prone
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)

🧰 Additional context used
📚 Code guidelines (2)
AGENTS.md — auto-discovered
CONTRIBUTING.md — auto-discovered

📓 Path-based instructions (2)
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-common` may not reference `com.sun.jna.**`, `java.lang.foreign.**`, or any `System.load`/`loadLibrary`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdNetworkParams.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdNetworkIFTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.java

Source excerpt: The Changelog lets users know what's changed.

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • CHANGELOG.md

🔇 Additional comments (1)
oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdNetworkParams.java (1)

43-48: LGTM!



📝 Walkthrough

Walkthrough

BSD network-statistics parsing now maps counters by heading and handles output variations across FreeBSD, DragonFly BSD, and OpenBSD. FreeBSD default-gateway lookups use updated route command options.

Changes

BSD network statistics and gateway lookups

Layer / File(s) Summary
Parse BSD network statistics
oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.java, oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdNetworkIFTest.java, CHANGELOG.md
BsdNetworkIF parses counters by heading, supplements missing packet counters, and defaults missing counters to zero. Tests cover platform-specific output and invalid or incomplete input. The changelog records the network-statistics fixes and related gateway update.
Update FreeBSD gateway route commands
oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdNetworkParams.java
IPv4 and IPv6 default-gateway lookups use route -n get default and route -n get -inet6 default, respectively.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to 61335

No confirmed issue currently prevents merging. BSD platform behavior remains unverified in the available evidence.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarizes the main changes to BSD network interface statistics and gateway lookups. It is specific and related to the pull request.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

Full details: Docstring Coverage

Explanation

Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. (1 skipped: 1 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit reads the counters by their names,
Then checks each BSD’s varied frames.
Missing packets get another call,
Empty rows return no counts at all.
New routes guide the gateways home,
While I nibble clover as I roam.

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.18519% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.53%. Comparing base (e528211) to head (61335e8).

Files with missing lines Patch % Lines
...hi/hardware/common/platform/unix/BsdNetworkIF.java 84.00% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3788      +/-   ##
============================================
- Coverage     80.58%   80.53%   -0.06%     
- Complexity       83      530     +447     
============================================
  Files           724      724              
  Lines         25991    26005      +14     
  Branches       4391     4395       +4     
============================================
- Hits          20946    20943       -3     
- Misses         2800     2813      +13     
- Partials       2245     2249       +4     
Flag Coverage Δ
freebsd 36.55% <81.48%> (+0.02%) ⬆️
linux 40.28% <40.74%> (+0.02%) ⬆️
macos 41.11% <40.74%> (-0.02%) ⬇️
netbsd 35.23% <40.74%> (+0.03%) ⬆️
openbsd 35.80% <77.77%> (+0.06%) ⬆️
solaris 37.09% <40.74%> (-0.01%) ⬇️
windows 47.36% <40.74%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis
dbwiddis merged commit 2e4454d into oshi:master Oct 11, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the dragonfly-network branch October 12, 2026 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant