Xray Route Exclude Address#9469
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for excluding specific CIDR ranges from Xray TUN auto-routing by performing CIDR subtraction (whole Internet minus excluded ranges) using the new IPNetwork2 dependency, plus validation and tests.
Changes:
- Add
IPNetwork2package and central version pinning. - Generate
tunInbound.settings.autoSystemRoutingTablefrom0.0.0.0/0(and::/0) minusRouteExcludeAddress. - Add validation error messaging + unit test coverage for the new route-exclude behavior.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayInboundService.cs | Builds include-route list by subtracting excluded CIDRs and sets autoSystemRoutingTable. |
| v2rayN/ServiceLib/ServiceLib.csproj | Adds IPNetwork2 package reference. |
| v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx | Adds localized validation error string (ZH-Hans). |
| v2rayN/ServiceLib/Resx/ResUI.resx | Adds localized validation error string (EN). |
| v2rayN/ServiceLib/Resx/ResUI.Designer.cs | Updates strongly-typed resource accessor for new message. |
| v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs | Validates RouteExcludeAddress entries via IPNetwork2.Parse. |
| v2rayN/ServiceLib.Tests/CoreConfig/V2ray/CoreConfigV2rayServiceTests.cs | Adds test asserting exclude routes remove 0.0.0.0/0 and yield expected fragments. |
| v2rayN/ServiceLib.Tests/CoreConfig/CoreConfigTestFactory.cs | Ensures IsTunEnabled respects config and adds helper config factory for exclude list. |
| v2rayN/Directory.Packages.props | Pins IPNetwork2 version. |
Files not reviewed (1)
- v2rayN/ServiceLib/Resx/ResUI.Designer.cs: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+94
to
+106
| if (context.IsTunEnabled && context.AppConfig.TunModeItem.RouteExcludeAddress is { Count: > 0 }) | ||
| { | ||
| foreach (var addr in context.AppConfig.TunModeItem.RouteExcludeAddress) | ||
| { | ||
| try | ||
| { | ||
| IPNetwork2.Parse(addr); | ||
| } | ||
| catch | ||
| { | ||
| validatorResult.Errors.Add(string.Format(ResUI.MsgTunRouteExcludeInvalidAddress, addr)); | ||
| } | ||
| } |
Comment on lines
+83
to
+85
| var excludeList = _config.TunModeItem.RouteExcludeAddress.Select(IPNetwork2.Parse) | ||
| .Where(x => x != null).ToList(); | ||
|
|
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.
Xray Route Exclude Address
添加 IPNetwork2 库以实现 IP CIDR 减法