[PR #6070] [MERGED] [client] Use fwmark-aware route lookup for raw socket UDP checksum source #28983

Closed
opened 2026-08-05 08:07:15 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6070
Author: @lixmal
Created: 5/5/2026
Status: Merged
Merged: 5/5/2026
Merged by: @lixmal

Base: mainHead: fix/sharedsock-fwmark-route-lookup


📝 Commits (2)

  • e88b46b Use fwmark-aware route lookup for raw socket UDP checksum source
  • f451f87 Guard nil raw socket in sharedsock WriteTo

📊 Changes

1 file changed (+21 additions, -35 deletions)

View changed files

📝 sharedsock/sock_linux.go (+21 -35)

📄 Description

Describe your changes

Fixes #4503 on Linux: enabling an exit node (0.0.0.0/0 route) caused already-P2P connections to fall back to Relayed.

The Linux raw-socket path that ICE/STUN traffic shares with WireGuard precomputed the UDP checksum from a source IP returned by a fwmark-unaware route lookup. Once an exit-node peer installed 0.0.0.0/0, that lookup started returning the wt0 source while the kernel (honoring SO_MARK) actually sent the packet from the underlay interface, so receivers dropped the packets on checksum mismatch and ICE silently fell back to relay.

  • Replace the periodic libp2p/go-netroute snapshot in sharedsock with a per-send netlink.RouteGetWithOptions call that passes the control-plane fwmark when advanced routing is on, so the precomputed UDP pseudo-header source matches the IP source the kernel will use on the wire.
  • Drop the now-unused router cache, mutex, and refresh goroutine.

#4503

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Internal Linux networking detail with no user-facing surface.

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Bug Fixes

    • Improved dynamic source IP resolution for network routing, enhancing compatibility with advanced routing configurations.
  • Refactor

    • Optimized socket routing logic by removing periodic cache refresh mechanism, reducing resource overhead while maintaining routing accuracy on a per-destination basis.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/6070 **Author:** [@lixmal](https://github.com/lixmal) **Created:** 5/5/2026 **Status:** ✅ Merged **Merged:** 5/5/2026 **Merged by:** [@lixmal](https://github.com/lixmal) **Base:** `main` ← **Head:** `fix/sharedsock-fwmark-route-lookup` --- ### 📝 Commits (2) - [`e88b46b`](https://github.com/netbirdio/netbird/commit/e88b46b429995b0581bf8749c3d83060ed057886) Use fwmark-aware route lookup for raw socket UDP checksum source - [`f451f87`](https://github.com/netbirdio/netbird/commit/f451f87261407c377c94e62e3e86171dc4c47f3f) Guard nil raw socket in sharedsock WriteTo ### 📊 Changes **1 file changed** (+21 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `sharedsock/sock_linux.go` (+21 -35) </details> ### 📄 Description ## Describe your changes Fixes #4503 on Linux: enabling an exit node (`0.0.0.0/0` route) caused already-P2P connections to fall back to Relayed. The Linux raw-socket path that ICE/STUN traffic shares with WireGuard precomputed the UDP checksum from a source IP returned by a fwmark-unaware route lookup. Once an exit-node peer installed `0.0.0.0/0`, that lookup started returning the wt0 source while the kernel (honoring `SO_MARK`) actually sent the packet from the underlay interface, so receivers dropped the packets on checksum mismatch and ICE silently fell back to relay. - Replace the periodic `libp2p/go-netroute` snapshot in sharedsock with a per-send `netlink.RouteGetWithOptions` call that passes the control-plane fwmark when advanced routing is on, so the precomputed UDP pseudo-header source matches the IP source the kernel will use on the wire. - Drop the now-unused router cache, mutex, and refresh goroutine. ## Issue ticket number and link #4503 ## Stack <!-- branch-stack --> ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) Internal Linux networking detail with no user-facing surface. ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved dynamic source IP resolution for network routing, enhancing compatibility with advanced routing configurations. * **Refactor** * Optimized socket routing logic by removing periodic cache refresh mechanism, reducing resource overhead while maintaining routing accuracy on a per-destination basis. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 08:07:15 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#28983