Repository navigation
Fix BSD route parsing: truncated trailing netmask reported as prefix 0 - #52
Merged
Merged
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
Co-authored-by: xmh0511 <17973891+xmh0511@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix BSD route reporting for truncated netmask
Fix BSD route parsing: truncated trailing netmask reported as prefix 0
Oct 10, 2026
xmh0511
marked this pull request as ready for review
October 12, 2026 08:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On macOS,
RouteListener::listen()reports ordinary routes such as10.0.0.0/8as prefix 0, so they look like default routes. BSD truncates netmask sockaddrs to their significant bytes. WhenRTA_NETMASKis the last address, the remaining buffer was shorter thansize_of::<sockaddr>(), so the walk skipped it andmessage_to_routemapped the missing entry toprefix = 0.RouteManager::list()was unaffected because its sysctl dumps carry more addresses after the netmask.I couldn't build or test this on macOS or a BSD, so it is untested.
RouteListener::listen()against the issue's RFC1918 routes should now report prefixes 8, 12, 16 and 16.All changes are in
src/unix_bsd/mod.rs:message_to_route)sa_lenfirst and advances by the aligned length instead of requiring a fullsockaddrto remain.&buf[..min(sa_len, buf.len())]) rather than a&sockaddr.&sockaddronly when a fullsockaddris available andsa_lenfits in the buffer. A short non-netmask address is skipped, but the walk still advances past it so later addresses stay aligned.cur_posruns past the message.ROUNDUPnow usesusize, so it can't overflowu8forsa_len≥ 253.leading_ones.transmutethat read 16 bytes from a 5–8 byte region.deserialize_res)RTM_ADD,RTM_DELETE,RTM_CHANGEandRTM_GETare parsed. Other types, such asRTM_IFINFO, are skipped beforertm_errnois read.Err(Os { code: <mtu> }). That error also discarded anyRTM_ADD/RTM_DELETEbatched into the sameread().list()usesNET_RT_DUMP, which emitsRTM_GET, so it still passes the filter.