Skip to content

fix: filter macOS interface notifications before parsing route headers - #53

Merged
vnt-dev merged 1 commit into
tun-rs:mainfrom
lanthora:fix-macos-route-notifications
Oct 12, 2026
Merged

vnt-dev merged 1 commit into
tun-rs:mainfrom
lanthora:fix-macos-route-notifications

Conversation

@lanthora

@lanthora lanthora commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

macOS routing sockets deliver both route and interface notifications, which use different header layouts. The parser previously interpreted every message as rt_msghdr before checking its type. For RTM_IFINFO, the interface MTU occupies the same offset as rtm_errno, causing an MTU of 1500 to produce Unknown error: 1500 and terminate listening.

This change checks the common message prefix first and only parses RTM_ADD, RTM_DELETE, RTM_CHANGE, and RTM_GET as route messages on macOS. It also validates message lengths and reads route headers without requiring buffer alignment. Actual route errors remain propagated.

Validation:

  • Reproduced error 1500 with a regression test before the fix.
  • All 16 library tests pass with the async feature.
  • Added coverage for MTUs 1500/9000, mixed interface and route messages, short non-route notifications, and malformed message lengths.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of routing messages with invalid or incomplete lengths, which are now rejected instead of being incorrectly processed.
    • Non-route notifications are skipped so they don’t prevent later route messages from being handled. Malformed route messages still surface as errors.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 34d46c8e-b9d4-4d2f-b58a-8eb802b5a41a

📥 Commits

Reviewing files that changed from the base of the PR and between 6cbee3d and 4789455.


📒 Files selected for processing (1)
  • src/unix_bsd/mod.rs

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



📝 Walkthrough

Walkthrough

The BSD routing-message parser now validates message prefixes, lengths, and route-header size. On macOS, it skips unsupported message types before reading a route header. Regression tests cover notifications and malformed message lengths.

Changes

BSD route message parsing

Layer / File(s) Summary
Validate and decode route messages
src/unix_bsd/mod.rs
deserialize_res checks message bounds and header size, skips unsupported macOS message types, and reads route headers unaligned. The route-conversion call passes the header by reference. Regression tests cover notifications, route errors, and malformed lengths.

Priority: ➖ Normal

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

Change: Bug fix

Suggested reviewers: yaucp


Merge Risk: ⚪ Minimal · up to 47894

This change stops macOS interface notifications from being misparsed as route errors and rejects malformed route messages with a clear error. No new merge-blocking risk was found.

Architecture Summary

Architecture risk: 🟡 Medium · up to 47894

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/unix_bsd/mod.rs: deserialize_res now validates message framing and header size, returning InvalidData for truncated prefixes, invalid lengths, and truncated route headers instead of relying on a complete aligned header and stopping on zero length. It skips unsupported macOS message types and reads the validated header unaligned.
  • observed — Modified behavior in src/unix_bsd/mod.rs: The call now passes rt_hdr by reference to message_to_route.
  • observed — Modified behavior in src/unix_bsd/mod.rs: Added macOS regression tests covering interface notifications with MTU values, propagation of route errors after interface or short address notifications, and InvalidData errors for malformed message lengths.

Reliability and maintainability

  • inferred — Risk-relevant change factors for src: blast_radius_2; direct_dependents_2

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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: filtering macOS interface notifications before parsing route headers.
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.

  • 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

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

@vnt-dev
vnt-dev merged commit f13344c into tun-rs:main Oct 12, 2026
7 checks passed
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.

2 participants