Skip to content

Xray Route Exclude Address#9469

Merged
2dust merged 3 commits into
2dust:masterfrom
DHR60:fix1
Jun 5, 2026
Merged

Xray Route Exclude Address#9469
2dust merged 3 commits into
2dust:masterfrom
DHR60:fix1

Conversation

@DHR60
Copy link
Copy Markdown
Contributor

@DHR60 DHR60 commented Jun 4, 2026

Xray Route Exclude Address

添加 IPNetwork2 库以实现 IP CIDR 减法

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 IPNetwork2 package and central version pinning.
  • Generate tunInbound.settings.autoSystemRoutingTable from 0.0.0.0/0 (and ::/0) minus RouteExcludeAddress.
  • 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();

@2dust 2dust merged commit b6cfce0 into 2dust:master Jun 5, 2026
1 check 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.

3 participants