Repository navigation
Decode /proc/net addresses in the host's byte order on Linux - #3852
Conversation
Linux prints an IPv4 address in /proc/net/route, and each 32-bit word of an address in /proc/net/tcp, tcp6, udp and udp6, with %08X of a __be32, so the digits come out in the host's byte order. Both parsers assumed a little-endian host, so on big-endian Linux such as s390x every route destination, gateway and mask, and every connection address, was byte-reversed: 127.0.0.1 read as 1.0.0.127, and a /23 mask as prefix length -1. Add ParseUtil.hexWordsToByteArray(String, ByteOrder) and pass the native byte order from RouteTable and from a new LinuxInternetProtocolStats.parseConnections seam, with fixtures captured on an aarch64 container and an s390x host. /proc/net/ipv6_route prints byte by byte and was already correct. Running the suite on s390x found three more problems. Util.is64Bit() read only sun.cpu.bits, which HotSpot does not set, and its os.arch fallback lacked s390x and riscv64; it now reads sun.arch.data.model first. AuxvTest guessed the word size from its own os.arch list, and SysfsTest assumed every Linux machine has DMI. Verified on cfarm191 (s390x, Debian 13): all oshi-common, oshi-core and oshi-core-ffm tests pass, and getConnections() matches ss.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Connection address decoding oshi-common/src/main/java/oshi/util/ParseUtil.java, oshi-common/src/main/java/oshi/software/common/os/linux/LinuxInternetProtocolStats.java, oshi-common/src/test/java/oshi/util/ParseUtilTest.java, oshi-common/src/test/java/oshi/software/common/os/linux/LinuxInternetProtocolStatsTest.java |
hexWordsToByteArray decodes hexadecimal words using the supplied byte order. Linux connection parsing passes native byte order through address parsing. Tests cover IPv4 and IPv6 data in both byte orders, including connection fields and process lookup. |
Route address decoding oshi-common/src/main/java/oshi/util/driver/linux/proc/RouteTable.java, oshi-common/src/test/java/oshi/util/driver/linux/proc/RouteTableTest.java, CHANGELOG.md |
IPv4 route parsing receives native byte order and decodes destination, mask, and gateway addresses accordingly. Tests cover little-endian and big-endian routes. The changelog records the address-reporting fix. |
64-bit architecture detection oshi-common/src/main/java/oshi/util/Util.java, oshi-common/src/test/java/oshi/util/driver/linux/proc/AuxvTest.java |
Bitness detection checks sun.arch.data.model before sun.cpu.bits and recognizes s390x and riscv64 when those properties are absent. The Auxv test selects its reader through Util.is64Bit(). |
Sysfs test assumption
| Layer / File(s) | Summary |
|---|---|
DMI directory check oshi-common/src/test/java/oshi/util/driver/linux/SysfsTest.java |
The non-null sysfs query test is skipped when SysPath.DMI_ID is not a directory. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Low
Merge Risk: 
Minimal · up to 267fb
-
The address decoding change has no identified merge-blocking issue.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title states the main change: Linux /proc/net address decoding now uses the host's byte order, which matches the changeset. The raw summary shows ParseUtil.hexWordsToByteArray(String, ByteOrder), native-order use in LinuxInternetProtocolStats and RouteTable, and tests for both little- and big-endian fixtures. The title is specific, concise, and not vague. It does not mention the Util.is64Bit or SysfsTest changes, which is acceptable because they are secondary.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 9 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- 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.
A rabbit reads the routes with care,
And sorts each byte with endian flair.
IPv4 and IPv6 now align,
While tests check every word and sign.
I nibble greens and hop along.
Problem
Linux prints IPv4 addresses in
/proc/net/route, and each 32-bit word of the addresses in/proc/net/tcp,tcp6,udpandudp6, with%08Xof a__be32. The digits therefore appear in the host's byte order. OSHI's parsers assumed a little-endian host, so on big-endian Linux every address came out byte-reversed. Measured on an s390x host (cfarm191, Debian 13):148.100.74.11.74.100.148148.100.74.0/23/230.74.100.148/-1127.0.0.11.0.0.127::1::100:0/proc/net/ipv6_routeis printed byte by byte, so IPv6 routes were already correct.Fix
ParseUtil.hexWordsToByteArray(String, ByteOrder)decodes hex text of 32-bit words printed in a given byte order.RouteTable.parseIpv4Routesand a newLinuxInternetProtocolStats.parseConnectionsseam take aByteOrder; production passesByteOrder.nativeOrder(). The previous unconditional per-word reversal is gone.ip route/ss -tnafrom the same moment: an aarch64 container (with2001:db8:1122:3344::1added so the byte order is unambiguous) and the s390x host. The existing route fixtures now state their byte order explicitly.The other
parseIntToIPcallers are Windows and macOS, which are always little-endian, and are unchanged.Found by running the suite on s390x
Util.is64Bit()was false on s390x and riscv64 under HotSpot: it read onlysun.cpu.bits, which HotSpot does not set, and itsos.archfallback list lacked both. It now readssun.arch.data.model(set by HotSpot and OpenJ9) first.getBitness()has its own fallback, so no caller's result changed visibly.AuxvTestguessed the native long size from its ownos.archlist; it now usesUtil.is64Bit().SysfsTestassumed every Linux machine has DMI; it now skips when/sys/devices/virtual/dmi/idis absent (s390x, many ARM boards).Verification
clean install -Perror-prone../mvnw testgreen across the reactor (oshi-common 1946 tests, oshi-core, oshi-core-ffm). LivegetConnections()now matchesss.Not addressed here, found by
-Paggregate-coverageon the same host: the native-free backend has no HWCAP reader, sogetProcessorID()differs from JNA on non-x86/non-ARM CPUs, and it reports""rather thanunknownfor a virtio disk with no model. Separate follow-ups.Summary by CodeRabbit