Skip to content

Read the NetBSD routing table with NetBSD's PF_ROUTE - #3814

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:netbsd-route-dump-mib
Oct 16, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:netbsd-route-dump-mib

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

The NET_RT_DUMP sysctl request used protocol family 17. That is PF_ROUTE on macOS, FreeBSD, DragonFly BSD and OpenBSD, but on NetBSD 17 is the obsolete AF_OROUTE and PF_ROUTE is 34 (sys/socket.h). On NetBSD every call to getRoutes() logged ERROR Didn't get buffer length for NET_RT_DUMP and fell back to running netstat. The native read added in #3742 had never succeeded there.

Changes

  • RouteTableDump.Layout gains a PF_ROUTE column, set to 34 for NetBSD and 17 for the others, beside each platform's other routing message values.
  • BsdRouteDumpJNA and BsdRouteDumpFFM take the layout from their callers rather than hard-coding 17. The FreeBSD callers pass routeLayout(), so DragonFly BSD keeps its own layout.
  • RouteComparisonTest now covers NetBSD as well, reading the interface name from column 6 of NetBSD's netstat output. The testnetbsdjna job in unix.yaml runs it on pushes to master.

Testing

I tested on cfarm428, a NetBSD 10.1 evbarm aarch64 VM:

  • A direct call returns 9656 bytes and 45 routes through both JNA and FFM, and the two lists are identical. They match a live netstat -rn, 16 IPv4 routes plus 29 IPv6.
  • NetBSD's netstat keeps the embedded KAME scope in interface-local multicast routes (ff01:1::/32). The native read strips it (ff01::/32).
  • With the same command as the CI job, ./mvnw clean test -Paggregate-coverage with the pkgsrc libjnidispatch, all four RouteComparisonTest tests pass and every module reports 0 failures.
  • The SystemInfoTest report no longer logs the error in any of three configurations: JNA without the native library, JNA with it, and FFM.
  • Not tested: the other BSDs, which are untouched apart from the new parameter and still pass 17.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed route-table retrieval on NetBSD. Network route information is now read directly from the kernel instead of falling back to netstat when the request fails.

The NET_RT_DUMP request named protocol family 17, which is PF_ROUTE on
macOS, FreeBSD, DragonFly BSD and OpenBSD but the obsolete AF_OROUTE on
NetBSD, where PF_ROUTE is 34. On NetBSD every call failed, logged an
error and fell back to running netstat, so the native routing table
added in oshi#3742 was never read there.

The value now sits in RouteTableDump.Layout beside the platform's other
routing message values, and the JNA and FFM drivers take the layout from
their callers.

RouteComparisonTest now covers NetBSD as well, with the interface name
in column 6 of its netstat output. Verified on a NetBSD 10.1 aarch64 VM:
JNA and FFM read the same 45 routes netstat -rn lists, and the full
-Paggregate-coverage run passes with all four comparison tests.
@coderabbitai

coderabbitai Bot commented Oct 16, 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: be35bb06-cf40-43ac-a08e-bf8ed077f2df
📥 Commits

Reviewing files that changed from the base of the PR and between ac0ac7f and 3c26177.

📒 Files selected for processing: 11
  • CHANGELOG.md
  • oshi-benchmark/src/test/java/oshi/comparison/RouteComparisonTest.java
  • oshi-common/src/main/java/oshi/util/driver/unix/RouteTableDump.java
  • oshi-core-ffm/src/main/java/oshi/driver/unix/bsd/BsdRouteDumpFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/netbsd/NetBsdNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsFFM.java
  • oshi-core/src/main/java/oshi/driver/unix/bsd/BsdRouteDumpJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsJNA.java

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

📜 Recent review details
⏰ Context from checks skipped due to timeout: 9
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Error Prone
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Analyze (java)
🧰 Additional context used
📚 Code guidelines: 2
AGENTS.md — auto-discovered
CONTRIBUTING.md — auto-discovered
📓 Path-based instructions: 3
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-core-ffm` may not reference `com.sun.jna.**`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/netbsd/NetBsdNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/driver/unix/bsd/BsdRouteDumpFFM.java
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/util/driver/unix/RouteTableDump.java
Applicability reference: AGENTS.md: # AGENTS.md Instructions for AI coding agents working in the OSHI repository.

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • CHANGELOG.md
📝 Walkthrough

The BSD route-dump query now receives a platform-specific PF_ROUTE value from RouteTableDump.Layout. NetBSD uses 34, while the other listed layouts use 17. JNA and FFM callers pass layouts explicitly, and the route comparison benchmark includes NetBSD.

Changes: BSD route protocol family

Layer / File(s) Summary
Platform layout and route-dump queries
oshi-common/.../RouteTableDump.java, oshi-core/.../BsdRouteDumpJNA.java, oshi-core-ffm/.../BsdRouteDumpFFM.java, oshi-core/.../unix/{freebsd,netbsd,openbsd}/*NetworkParamsJNA.java, oshi-core-ffm/.../unix/{freebsd,netbsd,openbsd}/*NetworkParamsFFM.java
RouteTableDump.Layout now stores each platform’s PF_ROUTE value. The JNA and FFM query utilities use the supplied layout value, and the platform callers pass their layouts.
NetBSD route comparison coverage and changelog
oshi-benchmark/src/test/java/oshi/comparison/RouteComparisonTest.java, CHANGELOG.md
The comparison test now selects NetBSD’s binding, interface-name column, and layout. The changelog describes the NetBSD kernel routing-table query and its prior netstat fallback.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 3c261

The NetBSD route query now uses its platform’s protocol-family value, while the other inspected BSD layouts are preserved. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 10 files. (1 skipped:… 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: using NetBSD's PF_ROUTE to read the routing table.
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 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 10 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 checked the routes at dawn,
And found the family value wrong.
“Thirty-four,” it said with cheer,
“Now NetBSD routes are clear!”
It thumped its paws and hopped along.

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

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.82%. Comparing base (7e4e5e6) to head (3c26177).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3814      +/-   ##
============================================
- Coverage     80.86%   80.82%   -0.05%     
+ Complexity      657      655       -2     
============================================
  Files           725      725              
  Lines         26021    26024       +3     
  Branches       4421     4421              
============================================
- Hits          21043    21034       -9     
- Misses         2758     2768      +10     
- Partials       2220     2222       +2     
Flag Coverage Δ
freebsd 37.12% <76.47%> (-0.01%) ⬇️
linux 41.15% <47.05%> (-0.01%) ⬇️
macos 42.29% <47.05%> (-0.04%) ⬇️
netbsd 36.42% <76.47%> (-0.01%) ⬇️
openbsd 37.02% <76.47%> (+0.01%) ⬆️
solaris 38.30% <47.05%> (+<0.01%) ⬆️
windows 48.56% <47.05%> (-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 34d0794 into oshi:master Oct 16, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the netbsd-route-dump-mib branch October 16, 2026 05:59
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