Skip to content

Use the shared BSD netstat parser for NetBSD network interfaces - #3807

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:netbsd-network-if
Oct 14, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:netbsd-network-if

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

NetBsdNetworkIF read netstat -bI and netstat -iI by fixed column position and returned without updating when the link-level row had fewer than six fields. Interfaces with no link-level address print five, so they reported no traffic. From cfarm428 (NetBSD 10.1):

Name  Mtu   Network       Address               Ibytes     Obytes
lo0   33624 <Link>                           178247481  178247481

lo0 and npflog0 both read as zero on master.

NetBSD's netstat format is the one BsdNetworkIF already handles for OpenBSD: -bnI prints only Ibytes/Obytes, and -nI prints Ipkts Ierrs Opkts Oerrs Colls. BsdNetworkIF.parseNetstat maps values to headings from the end of the row, which is what makes an empty Address column harmless. So NetBSD's hardware layer now uses BsdNetworkIF, NetBsdNetworkIF is removed, and the javadoc and comments in BsdNetworkIF name NetBSD. The class lived in an implementation package, not oshi.hardware, and is not @PublicApi.

Verification

  • BsdNetworkIFTest.testParseNetstatNetBsd uses output captured on cfarm428: vioif0 with -bnI and -nI, the address-less lo0 row, and npflog0.
  • Gate clean on oshi-common,oshi-core,oshi-core-ffm including -Perror-prone. Nothing else referenced the removed class, including the comparison tests.
  • Not run live on NetBSD: cfarm428 has no JDK. The fixtures are its real output.

Summary by CodeRabbit

  • Bug Fixes
    • NetBSD network traffic is now reported for interfaces without link-layer addresses, including loopback interfaces.
    • Network statistics now support NetBSD’s byte-only netstat output.

NetBsdNetworkIF read netstat -bI and -iI by fixed column position and gave
up when the link-level row had fewer than six fields. Rows with no
address, such as lo0 and npflog0, have five, so those interfaces reported
no traffic at all.

NetBSD's format is OpenBSD's: -bnI prints only the byte counts, and -nI
the packet, Ierrs/Oerrs and Colls columns. BsdNetworkIF already handles
that, matching values to headings from the end of the row, so NetBSD now
uses it and NetBsdNetworkIF is removed. Tested with output captured on
NetBSD 10.1.
@coderabbitai

coderabbitai Bot commented Oct 14, 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: 06d54be9-4009-4e5b-923e-4245af9d5010
📥 Commits

Reviewing files that changed from the base of the PR and between 530e202 and a831bcc.

📒 Files selected for processing: 5
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdNetworkIF.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdNetworkIFTest.java
💤 Files with no reviewable changes: 1
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdNetworkIF.java

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

📜 Recent review details
⏰ Context from checks skipped due to timeout: 13
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Error Prone
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle)
🧰 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/test/java/oshi/hardware/common/platform/unix/BsdNetworkIFTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.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: 4
oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.java: 1

20-20: LGTM!

Also applies to: 55-55, 62-62, 74-76

oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdNetworkIFTest.java: 1

96-134: LGTM!

CHANGELOG.md: 1

18-18: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java: 1

24-24: LGTM!

Also applies to: 75-75

📝 Walkthrough

NetBSD network interface retrieval now uses the shared BSD implementation. Tests cover NetBSD netstat output for byte counters, packet statistics, and interfaces without link-layer addresses.

Changes: NetBSD network reporting

Layer / File(s) Summary
Shared parser coverage
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
The shared BSD implementation documentation now includes NetBSD. Tests cover NetBSD counter output, including rows without link-layer addresses. The changelog records the reporting change.
NetBSD interface wiring
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java, oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdNetworkIF.java
The NetBSD hardware abstraction layer now retrieves interfaces through BsdNetworkIF. The NetBSD-specific implementation was removed.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to a831b

The change is ready to merge after normal checks; no actionable NetBSD network-reporting risk remains identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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 and concisely describes the main change: replacing the NetBSD-specific implementation with the shared BSD netstat parser.
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 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 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 checks the counters bright,
As lo0 hops into the light.
Byte by byte, the totals flow,
Packet rows now join the show.
NetBSD’s network paths align,
And carrots celebrate the sign!

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

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.85%. Comparing base (530e202) to head (a831bcc).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3807      +/-   ##
============================================
- Coverage     80.89%   80.85%   -0.05%     
- Complexity      418      644     +226     
============================================
  Files           725      725              
  Lines         25981    25981              
  Branches       4416     4416              
============================================
- Hits          21017    21006      -11     
- Misses         2744     2756      +12     
+ Partials       2220     2219       -1     
Flag Coverage Δ
freebsd 37.10% <0.00%> (+0.02%) ⬆️
linux 41.21% <0.00%> (+0.05%) ⬆️
macos 42.33% <0.00%> (-0.02%) ⬇️
netbsd 36.42% <100.00%> (-0.01%) ⬇️
openbsd 37.03% <0.00%> (+0.03%) ⬆️
solaris 38.33% <0.00%> (+0.02%) ⬆️
windows 48.60% <0.00%> (+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 c0a77e3 into oshi:master Oct 14, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the netbsd-network-if branch October 14, 2026 03:47
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