Skip to content

TUN inbound: Refine gateway and autoSystemRoutingTable on macOS#6434

Merged
RPRX merged 1 commit into
XTLS:mainfrom
OneXray:macos-tun-validation
Jul 7, 2026
Merged

TUN inbound: Refine gateway and autoSystemRoutingTable on macOS#6434
RPRX merged 1 commit into
XTLS:mainfrom
OneXray:macos-tun-validation

Conversation

@yiguodev

@yiguodev yiguodev commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • allow Darwin TUN to use the first IPv4 prefix from gateway for the utun point-to-point address
  • keep 169.254.10.1/30 as the default fallback when gateway is not configured
  • use the selected gateway when adding/removing IPv4 system routes
  • document macOS gateway, autoSystemRoutingTable, and dns behavior
  • add Darwin unit tests for gateway selection

Validation

  • git diff --check
  • go test ./proxy/tun -count=1
  • go test ./infra/conf ./infra/conf/serial ./proxy/tun -count=1

AI Coding by GPT-5.5 Extra High

@yiguodev

yiguodev commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator Author
  1. 优化 macOS 的 gateway 支持。
  2. 实测 IPv4 路由正常。
  3. 实测 link-local IPv6 足够使用。
  4. 如果 stable release 在等 macOS 的裸核 tun 支持的话,可以考虑发一个 stable version 了。

@yiguodev
yiguodev marked this pull request as ready for review July 5, 2026 09:22
Copilot AI review requested due to automatic review settings July 5, 2026 09:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates the Darwin (macOS) TUN implementation to derive the utun point-to-point IPv4 addressing and IPv4 system-route gateway from the configured gateway list (first IPv4 prefix), with a safe default fallback (169.254.10.1/30). It also documents the macOS behavior and adds unit tests for gateway selection.

Changes:

  • Add selectDarwinGateway logic to choose the first IPv4 gateway prefix (or fall back to defaultDarwinGateway) and validate that a usable local IPv4 address exists.
  • Use the selected gateway both for utun point-to-point configuration (setIPAddress) and as the IPv4 gateway when adding/removing system routes.
  • Update TUN documentation for macOS behavior and add darwin-only unit tests for gateway selection.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
proxy/tun/tun_darwin.go Selects/validates a macOS gateway prefix, configures utun addressing from it, and uses it for IPv4 system route gateway.
proxy/tun/tun_darwin_test.go Adds darwin-only unit tests covering default selection, IPv4 selection, IPv6 skipping, and validation failures.
proxy/tun/README.md Documents macOS gateway, autoSystemRoutingTable, and dns behavior (including defaults and IPv6 notes).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Jasper344612

Copy link
Copy Markdown
Contributor

如果 stable release 在等 macOS 的裸核 tun 支持的话,可以考虑发一个 stable version 了。

应该不是

@RPRX RPRX changed the title Support configurable macOS TUN gateway TUN inbound: Refine gateway and autoSystemRoutingTable on macOS Jul 7, 2026
@RPRX
RPRX merged commit 0495b17 into XTLS:main Jul 7, 2026
40 checks passed
@RPRX

RPRX commented Jul 7, 2026

Copy link
Copy Markdown
Member

@yiguodev
yiguodev deleted the macos-tun-validation branch July 7, 2026 11:34
@RPRX

RPRX commented Jul 7, 2026

Copy link
Copy Markdown
Member

@yiguodev 三大系统的 TUN 就差 macOS 还没实现进程匹配了,你研究一下,希望下一个 PR 是这个,确实能发 stable 了

RPRX pushed a commit that referenced this pull request Jul 8, 2026
@autorepobot

Copy link
Copy Markdown

2dust/v2rayN#9715

@iambabyninja

iambabyninja commented Jul 19, 2026

Copy link
Copy Markdown
Member

@yiguodev
Good afternoon! Based on information received from the clients developers:
Commit 987290b (merged July 8, PR #6434 — "Routing: process supports macOS as well") added calls to proc_pidinfo / proc_pidfdinfo / proc_pidpath from /usr/lib/libproc.dylib. These are public on macOS but private on iOS. Since the app ships as "Designed for iPad," Apple's scanner picks them up and flags it during review.

Rejection reason: Guideline 2.5.1 (Performance — Software Requirements) — unapproved use of public APIs, specifically citing NEVPNManager, on the grounds that API behavior may change unpredictably.

@RPRX

RPRX commented Jul 20, 2026

Copy link
Copy Markdown
Member

@iambabyninja 是这个 PR #6447@yiguodev 话说 Go 有没有 !ios 这种东西?或者有没有 !gomobile 之类的

@yiguodev

Copy link
Copy Markdown
Collaborator Author

修改中,一会发 PR 。

@yiguodev

Copy link
Copy Markdown
Collaborator Author

@iambabyninja fixed in #6524

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.

6 participants