Repository navigation
NetBSD: read the routing table from the kernel, not netstat - #3742
Conversation
Pre-existing bug, found by NativeComparisonTest now running on NetBSD. NetBsdNetworkParamsJNA fetched NET_RT_DUMP through the generic NetBsdSysctlUtil.sysctl(int[]), which returns the whole buffer sized by the first call and ignores the byte count the second call reports. The kernel over-estimates a routing dump, so the tail was uninitialized memory; the parse then failed and getRoutes() silently fell back to netstat, whose output keeps the embedded interface index in interface-local multicast (ff01:1::/32). Use the shared BsdRouteDumpJNA, as FreeBSD and OpenBSD already do; it trims to the length the second call reports. The FFM twin already did the same through BsdRouteDumpFFM.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: 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)
📝 WalkthroughWalkthroughNetBSD route queries now delegate to the shared BSD JNA route-dump implementation when available. They use the superclass fallback when JNA is unavailable. The changelog documents the correction. ChangesNetBSD route dump delegation
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation 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 1 functions across 1 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. A rabbit checks the routes at dawn Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3742 +/- ##
============================================
- Coverage 80.32% 80.22% -0.10%
- Complexity 83 4714 +4631
============================================
Files 711 711
Lines 25602 25598 -4
Branches 4320 4319 -1
============================================
- Hits 20565 20537 -28
- Misses 2821 2841 +20
- Partials 2216 2220 +4
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:
|
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 #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.
NetworkParams.getRoutes()on NetBSD was falling back tonetstateven where the JNA native library is available, so its routes differed from every other BSD's.Cause
NetBsdNetworkParamsJNAfetchedNET_RT_DUMPthrough the genericNetBsdSysctlUtil.sysctl(int[]), which sizes its buffer from the firstsysctlcall and returns all of it, ignoring the byte count the second call reports. The kernel over-estimates a routing dump, so the buffer ended in uninitialized memory;RouteTableDump.parsethen failed on the garbage andgetRoutes()fell through tonetstat -rn.The fallback is not equivalent: NetBSD's
netstatleaves the interface index embedded in interface-local multicast addresses, printingff01:1::/32where the kernel dump yieldsff01::/32on the right interface.This fix uses the shared
BsdRouteDumpJNA, as FreeBSD and OpenBSD already do; it trims to the length the second call reports. The FFM twin was already correct, throughBsdRouteDumpFFM.Testing
Verified on a NetBSD 10.1 VM with
java-jnainstalled:getRoutes()now returns the kernel's table, andNativeComparisonTestagrees with the FFM implementation, which is how the bug surfaced.Note for reviewers: the underlying helper,
SysctlUtilJNA.sysctl(call, name, log, level), still returns the untrimmed buffer. Its only other NetBSD caller asks forkern.cp_time, which is fixed-size and unaffected, so this change stays scoped to the routing dump rather than altering a helper every BSD shares.Summary by CodeRabbit
ff01:1::format.