mirror of
https://github.com/2dust/v2rayN.git
synced 2026-04-16 04:25:45 +00:00
Add xray tun support
This commit is contained in:
parent
53041906b3
commit
703f962ff5
15 changed files with 187 additions and 294 deletions
|
|
@ -52,10 +52,13 @@ internal static class WindowsUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task RemoveTunDevice()
|
public static async Task RemoveTunDevice()
|
||||||
|
{
|
||||||
|
var tunNameList = new List<string> { "singbox_tun", "xray_tun" };
|
||||||
|
foreach (var tunName in tunNameList)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var sum = MD5.HashData(Encoding.UTF8.GetBytes("wintunsingbox_tun"));
|
var sum = MD5.HashData(Encoding.UTF8.GetBytes($"wintun{tunName}"));
|
||||||
var guid = new Guid(sum);
|
var guid = new Guid(sum);
|
||||||
var pnpUtilPath = @"C:\Windows\System32\pnputil.exe";
|
var pnpUtilPath = @"C:\Windows\System32\pnputil.exe";
|
||||||
var arg = $$""" /remove-device "SWD\Wintun\{{{guid}}}" """;
|
var arg = $$""" /remove-device "SWD\Wintun\{{{guid}}}" """;
|
||||||
|
|
@ -69,3 +72,4 @@ internal static class WindowsUtils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ public class Global
|
||||||
public const string V2raySampleHttpResponseFileName = NamespaceSample + "SampleHttpResponse";
|
public const string V2raySampleHttpResponseFileName = NamespaceSample + "SampleHttpResponse";
|
||||||
public const string V2raySampleInbound = NamespaceSample + "SampleInbound";
|
public const string V2raySampleInbound = NamespaceSample + "SampleInbound";
|
||||||
public const string V2raySampleOutbound = NamespaceSample + "SampleOutbound";
|
public const string V2raySampleOutbound = NamespaceSample + "SampleOutbound";
|
||||||
|
public const string V2raySampleTunInbound = NamespaceSample + "SampleTunInbound";
|
||||||
|
public const string V2raySampleTunRules = NamespaceSample + "SampleTunRules";
|
||||||
public const string SingboxSampleOutbound = NamespaceSample + "SingboxSampleOutbound";
|
public const string SingboxSampleOutbound = NamespaceSample + "SingboxSampleOutbound";
|
||||||
public const string CustomRoutingFileName = NamespaceSample + "custom_routing_";
|
public const string CustomRoutingFileName = NamespaceSample + "custom_routing_";
|
||||||
public const string TunSingboxDNSFileName = NamespaceSample + "tun_singbox_dns";
|
public const string TunSingboxDNSFileName = NamespaceSample + "tun_singbox_dns";
|
||||||
|
|
@ -48,6 +50,7 @@ public class Global
|
||||||
public const string ProxyTag = "proxy";
|
public const string ProxyTag = "proxy";
|
||||||
public const string DirectTag = "direct";
|
public const string DirectTag = "direct";
|
||||||
public const string BlockTag = "block";
|
public const string BlockTag = "block";
|
||||||
|
public const string DnsOutboundTag = "dns";
|
||||||
public const string DnsTag = "dns-module";
|
public const string DnsTag = "dns-module";
|
||||||
public const string DirectDnsTag = "direct-dns";
|
public const string DirectDnsTag = "direct-dns";
|
||||||
public const string BalancerTagSuffix = "-round";
|
public const string BalancerTagSuffix = "-round";
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,6 @@ public record CoreConfigContextBuilderAllResult(
|
||||||
public CoreConfigContext ResolvedMainContext => PreSocksResult is not null
|
public CoreConfigContext ResolvedMainContext => PreSocksResult is not null
|
||||||
? MainResult.Context with
|
? MainResult.Context with
|
||||||
{
|
{
|
||||||
TunProtectSsPort = PreSocksResult.Context.TunProtectSsPort,
|
|
||||||
ProxyRelaySsPort = PreSocksResult.Context.ProxyRelaySsPort,
|
|
||||||
ProtectDomainList = [.. MainResult.Context.ProtectDomainList ?? [], .. PreSocksResult.Context.ProtectDomainList ?? []],
|
ProtectDomainList = [.. MainResult.Context.ProtectDomainList ?? [], .. PreSocksResult.Context.ProtectDomainList ?? []],
|
||||||
}
|
}
|
||||||
: MainResult.Context;
|
: MainResult.Context;
|
||||||
|
|
@ -58,8 +56,6 @@ public class CoreConfigContextBuilder
|
||||||
IsTunEnabled = config.TunModeItem.EnableTun,
|
IsTunEnabled = config.TunModeItem.EnableTun,
|
||||||
SimpleDnsItem = config.SimpleDNSItem,
|
SimpleDnsItem = config.SimpleDNSItem,
|
||||||
ProtectDomainList = [],
|
ProtectDomainList = [],
|
||||||
TunProtectSsPort = 0,
|
|
||||||
ProxyRelaySsPort = 0,
|
|
||||||
RawDnsItem = await AppManager.Instance.GetDNSItem(coreType),
|
RawDnsItem = await AppManager.Instance.GetDNSItem(coreType),
|
||||||
RoutingItem = await ConfigHandler.GetDefaultRouting(config),
|
RoutingItem = await ConfigHandler.GetDefaultRouting(config),
|
||||||
};
|
};
|
||||||
|
|
@ -148,39 +144,9 @@ public class CoreConfigContextBuilder
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nodeContext.IsTunEnabled
|
|
||||||
|| coreType != ECoreType.Xray
|
|
||||||
|| node.ConfigType == EConfigType.Custom)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tunProtectSsPort = Utils.GetFreePort();
|
|
||||||
var proxyRelaySsPort = Utils.GetFreePort();
|
|
||||||
var preItem = new ProfileItem()
|
|
||||||
{
|
|
||||||
CoreType = ECoreType.sing_box,
|
|
||||||
ConfigType = EConfigType.Shadowsocks,
|
|
||||||
Address = Global.Loopback,
|
|
||||||
Port = proxyRelaySsPort,
|
|
||||||
Password = Global.None,
|
|
||||||
};
|
|
||||||
preItem.SetProtocolExtra(preItem.GetProtocolExtra() with
|
|
||||||
{
|
|
||||||
SsMethod = Global.None,
|
|
||||||
});
|
|
||||||
var preResult2 = await Build(nodeContext.AppConfig, preItem);
|
|
||||||
return preResult2 with
|
|
||||||
{
|
|
||||||
Context = preResult2.Context with
|
|
||||||
{
|
|
||||||
ProtectDomainList = [.. nodeContext.ProtectDomainList ?? [], .. preResult2.Context.ProtectDomainList ?? []],
|
|
||||||
TunProtectSsPort = tunProtectSsPort,
|
|
||||||
ProxyRelaySsPort = proxyRelaySsPort,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resolves a node into the context, optionally wrapping it in a subscription-level proxy chain.
|
/// Resolves a node into the context, optionally wrapping it in a subscription-level proxy chain.
|
||||||
/// Returns the effective (possibly replaced) node and the validation result.
|
/// Returns the effective (possibly replaced) node and the validation result.
|
||||||
|
|
|
||||||
|
|
@ -1416,20 +1416,7 @@ public static class ConfigHandler
|
||||||
public static ProfileItem? GetPreSocksItem(Config config, ProfileItem node, ECoreType coreType)
|
public static ProfileItem? GetPreSocksItem(Config config, ProfileItem node, ECoreType coreType)
|
||||||
{
|
{
|
||||||
ProfileItem? itemSocks = null;
|
ProfileItem? itemSocks = null;
|
||||||
if (node.ConfigType != EConfigType.Custom
|
if (node.ConfigType == EConfigType.Custom
|
||||||
&& coreType != ECoreType.sing_box
|
|
||||||
&& config.TunModeItem.EnableTun
|
|
||||||
&& config.TunModeItem.EnableLegacyProtect)
|
|
||||||
{
|
|
||||||
itemSocks = new ProfileItem()
|
|
||||||
{
|
|
||||||
CoreType = ECoreType.sing_box,
|
|
||||||
ConfigType = EConfigType.SOCKS,
|
|
||||||
Address = Global.Loopback,
|
|
||||||
Port = AppManager.Instance.GetLocalPort(EInboundProtocol.socks)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else if (node.ConfigType == EConfigType.Custom
|
|
||||||
&& node.PreSocksPort is > 0 and <= 65535)
|
&& node.PreSocksPort is > 0 and <= 65535)
|
||||||
{
|
{
|
||||||
var preCoreType = config.TunModeItem.EnableTun ? ECoreType.sing_box : ECoreType.Xray;
|
var preCoreType = config.TunModeItem.EnableTun ? ECoreType.sing_box : ECoreType.Xray;
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,4 @@ public record CoreConfigContext
|
||||||
// TUN Compatibility
|
// TUN Compatibility
|
||||||
public bool IsTunEnabled { get; init; } = false;
|
public bool IsTunEnabled { get; init; } = false;
|
||||||
public HashSet<string> ProtectDomainList { get; init; } = new();
|
public HashSet<string> ProtectDomainList { get; init; } = new();
|
||||||
// -> tun inbound --(if routing proxy)--> relay outbound
|
|
||||||
// -> proxy core (relay inbound --> proxy outbound --(dialerProxy)--> protect outbound)
|
|
||||||
// -> protect inbound -> direct proxy outbound data -> internet
|
|
||||||
public int TunProtectSsPort { get; init; } = 0;
|
|
||||||
public int ProxyRelaySsPort { get; init; } = 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,18 @@ public class Inboundsettings4Ray
|
||||||
public bool? allowTransparent { get; set; }
|
public bool? allowTransparent { get; set; }
|
||||||
|
|
||||||
public List<AccountsItem4Ray>? accounts { get; set; }
|
public List<AccountsItem4Ray>? accounts { get; set; }
|
||||||
|
|
||||||
|
public string? name { get; set; }
|
||||||
|
|
||||||
|
public List<int>? MTU { get; set; }
|
||||||
|
|
||||||
|
public List<string>? gateway { get; set; }
|
||||||
|
|
||||||
|
public List<string>? autoSystemRoutingTable { get; set; }
|
||||||
|
|
||||||
|
public string? autoOutboundsInterface { get; set; }
|
||||||
|
|
||||||
|
// public List<string>? dns { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UsersItem4Ray
|
public class UsersItem4Ray
|
||||||
|
|
@ -509,6 +521,8 @@ public class AccountsItem4Ray
|
||||||
public class Sockopt4Ray
|
public class Sockopt4Ray
|
||||||
{
|
{
|
||||||
public string? dialerProxy { get; set; }
|
public string? dialerProxy { get; set; }
|
||||||
|
[JsonPropertyName("interface")]
|
||||||
|
public string? Interface { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FragmentItem4Ray
|
public class FragmentItem4Ray
|
||||||
|
|
|
||||||
26
v2rayN/ServiceLib/Sample/SampleTunInbound
Normal file
26
v2rayN/ServiceLib/Sample/SampleTunInbound
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"tag": "tun",
|
||||||
|
"protocol": "tun",
|
||||||
|
"settings": {
|
||||||
|
"name": "xray_tun",
|
||||||
|
"MTU": [
|
||||||
|
9000
|
||||||
|
],
|
||||||
|
"gateway": [
|
||||||
|
"172.18.0.1/30",
|
||||||
|
"fdfe:dcba:9876::1/126"
|
||||||
|
],
|
||||||
|
"autoSystemRoutingTable": [
|
||||||
|
"0.0.0.0/0",
|
||||||
|
"::/0"
|
||||||
|
],
|
||||||
|
"autoOutboundsInterface": "auto"
|
||||||
|
},
|
||||||
|
"sniffing": {
|
||||||
|
"enabled": true,
|
||||||
|
"destOverride": [
|
||||||
|
"http",
|
||||||
|
"tls"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
14
v2rayN/ServiceLib/Sample/SampleTunRules
Normal file
14
v2rayN/ServiceLib/Sample/SampleTunRules
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"network": "udp",
|
||||||
|
"port": "135,137-139,5353",
|
||||||
|
"outboundTag": "block"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ip": [
|
||||||
|
"224.0.0.0/3",
|
||||||
|
"ff00::/8"
|
||||||
|
],
|
||||||
|
"outboundTag": "block"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -38,6 +38,8 @@
|
||||||
<EmbeddedResource Include="Sample\SampleHttpResponse" />
|
<EmbeddedResource Include="Sample\SampleHttpResponse" />
|
||||||
<EmbeddedResource Include="Sample\SampleInbound" />
|
<EmbeddedResource Include="Sample\SampleInbound" />
|
||||||
<EmbeddedResource Include="Sample\SampleOutbound" />
|
<EmbeddedResource Include="Sample\SampleOutbound" />
|
||||||
|
<EmbeddedResource Include="Sample\SampleTunInbound" />
|
||||||
|
<EmbeddedResource Include="Sample\SampleTunRules" />
|
||||||
<EmbeddedResource Include="Sample\SingboxSampleClientConfig" />
|
<EmbeddedResource Include="Sample\SingboxSampleClientConfig" />
|
||||||
<EmbeddedResource Include="Sample\SingboxSampleOutbound" />
|
<EmbeddedResource Include="Sample\SingboxSampleOutbound" />
|
||||||
<EmbeddedResource Include="Sample\tun_singbox_dns" />
|
<EmbeddedResource Include="Sample\tun_singbox_dns" />
|
||||||
|
|
|
||||||
|
|
@ -61,52 +61,6 @@ public partial class CoreConfigSingboxService(CoreConfigContext context)
|
||||||
ret.Success = true;
|
ret.Success = true;
|
||||||
|
|
||||||
ret.Data = ApplyFullConfigTemplate();
|
ret.Data = ApplyFullConfigTemplate();
|
||||||
if (!context.AppConfig.TunModeItem.EnableLegacyProtect
|
|
||||||
&& context.TunProtectSsPort is > 0 and <= 65535)
|
|
||||||
{
|
|
||||||
var ssInbound = new
|
|
||||||
{
|
|
||||||
type = "shadowsocks",
|
|
||||||
tag = "tun-protect-ss",
|
|
||||||
listen = Global.Loopback,
|
|
||||||
listen_port = context.TunProtectSsPort,
|
|
||||||
method = "none",
|
|
||||||
password = "none",
|
|
||||||
};
|
|
||||||
var directRule = new Rule4Sbox()
|
|
||||||
{
|
|
||||||
inbound = new List<string> { ssInbound.tag },
|
|
||||||
outbound = Global.DirectTag,
|
|
||||||
};
|
|
||||||
var singboxConfigNode = JsonUtils.ParseJson(ret.Data.ToString())!.AsObject();
|
|
||||||
var inboundsNode = singboxConfigNode["inbounds"]!.AsArray();
|
|
||||||
inboundsNode.Add(JsonUtils.SerializeToNode(ssInbound, new JsonSerializerOptions
|
|
||||||
{
|
|
||||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
|
|
||||||
}));
|
|
||||||
var routeNode = singboxConfigNode["route"]?.AsObject();
|
|
||||||
var rulesNode = routeNode?["rules"]?.AsArray();
|
|
||||||
var protectRuleNode = JsonUtils.SerializeToNode(directRule,
|
|
||||||
new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull });
|
|
||||||
if (rulesNode != null)
|
|
||||||
{
|
|
||||||
rulesNode.Insert(0, protectRuleNode);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var newRulesNode = new JsonArray() { protectRuleNode };
|
|
||||||
if (routeNode is null)
|
|
||||||
{
|
|
||||||
var newRouteNode = new JsonObject() { ["rules"] = newRulesNode };
|
|
||||||
singboxConfigNode["route"] = newRouteNode;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
routeNode["rules"] = newRulesNode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret.Data = JsonUtils.Serialize(singboxConfigNode);
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
|
|
@ -345,14 +345,6 @@ public partial class CoreConfigSingboxService
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// The synthetic TUN relay outbound talks to the local Xray shadowsocks relay.
|
|
||||||
// Xray cannot terminate sing-box h2mux, so muxing here turns local relay traffic
|
|
||||||
// into sp.mux.sing-box.arpa pseudo-destinations and breaks DNS over TUN.
|
|
||||||
if (IsTunRelayProxyOutbound())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var muxEnabled = _node.MuxEnabled ?? _config.CoreBasicItem.MuxEnabled;
|
var muxEnabled = _node.MuxEnabled ?? _config.CoreBasicItem.MuxEnabled;
|
||||||
if (muxEnabled && _config.Mux4SboxItem.Protocol.IsNotEmpty())
|
if (muxEnabled && _config.Mux4SboxItem.Protocol.IsNotEmpty())
|
||||||
{
|
{
|
||||||
|
|
@ -372,21 +364,6 @@ public partial class CoreConfigSingboxService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsTunRelayProxyOutbound()
|
|
||||||
{
|
|
||||||
if (!context.IsTunEnabled
|
|
||||||
|| _node.ConfigType != EConfigType.Shadowsocks
|
|
||||||
|| _node.Address != Global.Loopback
|
|
||||||
|| _node.Port != context.ProxyRelaySsPort
|
|
||||||
|| _node.Password != Global.None)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var protocolExtra = _node.GetProtocolExtra();
|
|
||||||
return protocolExtra.SsMethod == Global.None;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FillOutboundTls(Outbound4Sbox outbound)
|
private void FillOutboundTls(Outbound4Sbox outbound)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,6 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
|
||||||
var ret = new RetResult();
|
var ret = new RetResult();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!context.AppConfig.TunModeItem.EnableLegacyProtect
|
|
||||||
&& context.IsTunEnabled
|
|
||||||
&& context.TunProtectSsPort is > 0 and <= 65535
|
|
||||||
&& context.ProxyRelaySsPort is > 0 and <= 65535)
|
|
||||||
{
|
|
||||||
return GenerateClientProxyRelayConfig();
|
|
||||||
}
|
|
||||||
if (_node == null
|
if (_node == null
|
||||||
|| !_node.IsValid())
|
|| !_node.IsValid())
|
||||||
{
|
{
|
||||||
|
|
@ -269,140 +262,5 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RetResult GenerateClientProxyRelayConfig()
|
|
||||||
{
|
|
||||||
var ret = new RetResult();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_node == null
|
|
||||||
|| !_node.IsValid())
|
|
||||||
{
|
|
||||||
ret.Msg = ResUI.CheckServerSettings;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_node.GetNetwork() is nameof(ETransport.quic))
|
|
||||||
{
|
|
||||||
ret.Msg = ResUI.Incorrectconfiguration + $" - {_node.GetNetwork()}";
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
|
||||||
if (result.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
_coreConfig = JsonUtils.Deserialize<V2rayConfig>(result);
|
|
||||||
if (_coreConfig == null)
|
|
||||||
{
|
|
||||||
ret.Msg = ResUI.FailedGenDefaultConfiguration;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
GenLog();
|
|
||||||
_coreConfig.outbounds.Clear();
|
|
||||||
GenOutbounds();
|
|
||||||
GenStatistic();
|
|
||||||
|
|
||||||
var protectNode = new ProfileItem()
|
|
||||||
{
|
|
||||||
CoreType = ECoreType.Xray,
|
|
||||||
ConfigType = EConfigType.Shadowsocks,
|
|
||||||
Address = Global.Loopback,
|
|
||||||
Port = context.TunProtectSsPort,
|
|
||||||
Password = Global.None,
|
|
||||||
};
|
|
||||||
protectNode.SetProtocolExtra(protectNode.GetProtocolExtra() with
|
|
||||||
{
|
|
||||||
SsMethod = Global.None,
|
|
||||||
});
|
|
||||||
|
|
||||||
const string protectTag = "tun-protect-ss";
|
|
||||||
foreach (var outbound in _coreConfig.outbounds
|
|
||||||
.Where(o => o.streamSettings?.sockopt?.dialerProxy?.IsNullOrEmpty() ?? true))
|
|
||||||
{
|
|
||||||
outbound.streamSettings ??= new();
|
|
||||||
outbound.streamSettings.sockopt ??= new();
|
|
||||||
outbound.streamSettings.sockopt.dialerProxy = protectTag;
|
|
||||||
}
|
|
||||||
// ech protected
|
|
||||||
foreach (var outbound in _coreConfig.outbounds
|
|
||||||
.Where(outbound => outbound.streamSettings?.tlsSettings?.echConfigList?.IsNullOrEmpty() == false))
|
|
||||||
{
|
|
||||||
outbound.streamSettings!.tlsSettings!.echSockopt ??= new();
|
|
||||||
outbound.streamSettings.tlsSettings.echSockopt.dialerProxy = protectTag;
|
|
||||||
}
|
|
||||||
// xhttp download protected
|
|
||||||
foreach (var outbound in _coreConfig.outbounds
|
|
||||||
.Where(o => o.streamSettings?.xhttpSettings?.extra is not null))
|
|
||||||
{
|
|
||||||
var xhttpExtra = JsonUtils.ParseJson(JsonUtils.Serialize(outbound.streamSettings.xhttpSettings!.extra));
|
|
||||||
if (xhttpExtra is not JsonObject xhttpExtraObject
|
|
||||||
|| xhttpExtraObject["downloadSettings"] is not JsonObject downloadSettings)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// dialerProxy
|
|
||||||
var sockopt = downloadSettings["sockopt"] as JsonObject ?? new JsonObject();
|
|
||||||
sockopt["dialerProxy"] = protectTag;
|
|
||||||
downloadSettings["sockopt"] = sockopt;
|
|
||||||
// ech protected
|
|
||||||
if (downloadSettings["tlsSettings"] is JsonObject tlsSettings
|
|
||||||
&& tlsSettings["echConfigList"] is not null)
|
|
||||||
{
|
|
||||||
tlsSettings["echSockopt"] = new JsonObject
|
|
||||||
{
|
|
||||||
["dialerProxy"] = protectTag
|
|
||||||
};
|
|
||||||
}
|
|
||||||
outbound.streamSettings.xhttpSettings.extra = xhttpExtraObject;
|
|
||||||
}
|
|
||||||
_coreConfig.outbounds.Add(new CoreConfigV2rayService(context with
|
|
||||||
{
|
|
||||||
Node = protectNode,
|
|
||||||
}).BuildProxyOutbound(protectTag));
|
|
||||||
|
|
||||||
_coreConfig.routing.rules ??= [];
|
|
||||||
var hasBalancer = _coreConfig.routing.balancers is { Count: > 0 };
|
|
||||||
_coreConfig.routing.rules.Add(new()
|
|
||||||
{
|
|
||||||
inboundTag = ["proxy-relay-ss"],
|
|
||||||
outboundTag = hasBalancer ? null : Global.ProxyTag,
|
|
||||||
balancerTag = hasBalancer ? Global.ProxyTag + Global.BalancerTagSuffix : null,
|
|
||||||
type = "field"
|
|
||||||
});
|
|
||||||
|
|
||||||
//_coreConfig.inbounds.Clear();
|
|
||||||
|
|
||||||
var configNode = JsonUtils.ParseJson(JsonUtils.Serialize(_coreConfig))!;
|
|
||||||
configNode["inbounds"]!.AsArray().Add(new
|
|
||||||
{
|
|
||||||
listen = Global.Loopback,
|
|
||||||
port = context.ProxyRelaySsPort,
|
|
||||||
protocol = "shadowsocks",
|
|
||||||
settings = new
|
|
||||||
{
|
|
||||||
network = "tcp,udp",
|
|
||||||
method = Global.None,
|
|
||||||
password = Global.None,
|
|
||||||
},
|
|
||||||
tag = "proxy-relay-ss",
|
|
||||||
});
|
|
||||||
|
|
||||||
ret.Msg = string.Format(ResUI.SuccessfulConfiguration, "");
|
|
||||||
ret.Success = true;
|
|
||||||
ret.Data = JsonUtils.Serialize(configNode);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logging.SaveLog(_tag, ex);
|
|
||||||
ret.Msg = ResUI.FailedGenDefaultConfiguration;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public gen function
|
#endregion public gen function
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,13 @@ public partial class CoreConfigV2rayService
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var listen = "0.0.0.0";
|
var listen = "0.0.0.0";
|
||||||
|
var listenPort = AppManager.Instance.GetLocalPort(EInboundProtocol.socks);
|
||||||
_coreConfig.inbounds = [];
|
_coreConfig.inbounds = [];
|
||||||
|
|
||||||
var inbound = BuildInbound(_config.Inbound.First(), EInboundProtocol.socks, true);
|
var inbound = BuildInbound(_config.Inbound.First(), EInboundProtocol.socks, true);
|
||||||
|
|
||||||
|
if (!context.IsTunEnabled
|
||||||
|
|| (context.IsTunEnabled && _node.Port != listenPort))
|
||||||
|
{
|
||||||
_coreConfig.inbounds.Add(inbound);
|
_coreConfig.inbounds.Add(inbound);
|
||||||
|
|
||||||
if (_config.Inbound.First().SecondLocalPortEnabled)
|
if (_config.Inbound.First().SecondLocalPortEnabled)
|
||||||
|
|
@ -30,7 +34,10 @@ public partial class CoreConfigV2rayService
|
||||||
if (_config.Inbound.First().User.IsNotEmpty() && _config.Inbound.First().Pass.IsNotEmpty())
|
if (_config.Inbound.First().User.IsNotEmpty() && _config.Inbound.First().Pass.IsNotEmpty())
|
||||||
{
|
{
|
||||||
inbound3.settings.auth = "password";
|
inbound3.settings.auth = "password";
|
||||||
inbound3.settings.accounts = new List<AccountsItem4Ray> { new() { user = _config.Inbound.First().User, pass = _config.Inbound.First().Pass } };
|
inbound3.settings.accounts = new List<AccountsItem4Ray>
|
||||||
|
{
|
||||||
|
new() { user = _config.Inbound.First().User, pass = _config.Inbound.First().Pass }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -39,6 +46,24 @@ public partial class CoreConfigV2rayService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context.IsTunEnabled)
|
||||||
|
{
|
||||||
|
if (_config.TunModeItem.Mtu <= 0)
|
||||||
|
{
|
||||||
|
_config.TunModeItem.Mtu = Global.TunMtus.First();
|
||||||
|
}
|
||||||
|
var tunInbound = JsonUtils.Deserialize<Inbounds4Ray>(EmbedUtils.GetEmbedText(Global.V2raySampleTunInbound)) ?? new Inbounds4Ray { };
|
||||||
|
tunInbound.settings.name = Utils.IsMacOS() ? $"utun{new Random().Next(99)}" : "xray_tun";
|
||||||
|
tunInbound.settings.MTU = [_config.TunModeItem.Mtu];
|
||||||
|
if (_config.TunModeItem.EnableIPv6Address == false)
|
||||||
|
{
|
||||||
|
tunInbound.settings.gateway = ["172.18.0.1/30"];
|
||||||
|
}
|
||||||
|
tunInbound.sniffing = inbound.sniffing;
|
||||||
|
_coreConfig.inbounds.Add(tunInbound);
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logging.SaveLog(_tag, ex);
|
Logging.SaveLog(_tag, ex);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,10 @@ public partial class CoreConfigV2rayService
|
||||||
GenObservatory(multipleLoad);
|
GenObservatory(multipleLoad);
|
||||||
GenBalancer(multipleLoad);
|
GenBalancer(multipleLoad);
|
||||||
}
|
}
|
||||||
|
if (context.IsTunEnabled)
|
||||||
|
{
|
||||||
|
_coreConfig.outbounds.Add(BuildDnsOutbound());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Outbounds4Ray> BuildAllProxyOutbounds(string baseTagName = Global.ProxyTag)
|
private List<Outbounds4Ray> BuildAllProxyOutbounds(string baseTagName = Global.ProxyTag)
|
||||||
|
|
@ -824,4 +828,10 @@ public partial class CoreConfigV2rayService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Outbounds4Ray BuildDnsOutbound()
|
||||||
|
{
|
||||||
|
var outbound = new Outbounds4Ray { tag = Global.DnsOutboundTag, protocol = "dns", };
|
||||||
|
return outbound;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,31 @@ public partial class CoreConfigV2rayService
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (_config.TunModeItem.EnableTun)
|
||||||
|
{
|
||||||
|
var tunRules = JsonUtils.Deserialize<List<RulesItem4Ray>>(EmbedUtils.GetEmbedText(Global.V2raySampleTunRules));
|
||||||
|
if (tunRules != null)
|
||||||
|
{
|
||||||
|
_coreConfig.routing.rules.AddRange(tunRules);
|
||||||
|
}
|
||||||
|
var (lstDnsExe, lstDirectExe) = BuildRoutingDirectExe();
|
||||||
|
_coreConfig.routing.rules.Add(new()
|
||||||
|
{
|
||||||
|
port = "53",
|
||||||
|
process = lstDnsExe,
|
||||||
|
outboundTag = Global.DnsOutboundTag,
|
||||||
|
});
|
||||||
|
_coreConfig.routing.rules.Add(new()
|
||||||
|
{
|
||||||
|
process = lstDirectExe,
|
||||||
|
outboundTag = Global.DirectTag,
|
||||||
|
});
|
||||||
|
_coreConfig.routing.rules.Add(new()
|
||||||
|
{
|
||||||
|
port = "53",
|
||||||
|
outboundTag = Global.DnsOutboundTag,
|
||||||
|
});
|
||||||
|
}
|
||||||
if (_coreConfig.routing?.rules != null)
|
if (_coreConfig.routing?.rules != null)
|
||||||
{
|
{
|
||||||
_coreConfig.routing.domainStrategy = _config.RoutingBasicItem.DomainStrategy;
|
_coreConfig.routing.domainStrategy = _config.RoutingBasicItem.DomainStrategy;
|
||||||
|
|
@ -205,4 +230,37 @@ public partial class CoreConfigV2rayService
|
||||||
}
|
}
|
||||||
return finalRule;
|
return finalRule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static (List<string> lstDnsExe, List<string> lstDirectExe) BuildRoutingDirectExe()
|
||||||
|
{
|
||||||
|
var dnsExeSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
var directExeSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
var coreInfoResult = CoreInfoManager.Instance.GetCoreInfo();
|
||||||
|
|
||||||
|
foreach (var coreConfig in coreInfoResult)
|
||||||
|
{
|
||||||
|
if (coreConfig.CoreType == ECoreType.v2rayN)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var baseExeName in coreConfig.CoreExes)
|
||||||
|
{
|
||||||
|
if (coreConfig.CoreType != ECoreType.sing_box)
|
||||||
|
{
|
||||||
|
dnsExeSet.Add(Utils.GetExeName(baseExeName));
|
||||||
|
}
|
||||||
|
directExeSet.Add(Utils.GetExeName(baseExeName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
directExeSet.Add("xray/");
|
||||||
|
directExeSet.Add("self/");
|
||||||
|
|
||||||
|
var lstDnsExe = new List<string>(dnsExeSet);
|
||||||
|
var lstDirectExe = new List<string>(directExeSet);
|
||||||
|
|
||||||
|
return (lstDnsExe, lstDirectExe);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue