mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-04 03:25:00 +03:00
Replace protect-ss with protect-socks (#9052)
This commit is contained in:
@@ -62,16 +62,23 @@ public partial class CoreConfigSingboxService(CoreConfigContext context)
|
||||
|
||||
ret.Data = ApplyFullConfigTemplate();
|
||||
if (!context.AppConfig.TunModeItem.EnableLegacyProtect
|
||||
&& context.TunProtectSsPort is > 0 and <= 65535)
|
||||
&& context.TunProtectSocksPort is > 0 and <= 65535)
|
||||
{
|
||||
// Replace relay proxy outbound, avoid mux or other feature cause issue, and add a socks inbound for tun protect
|
||||
var relayProxyIndex = _coreConfig.outbounds.FindIndex(o => o.tag == Global.ProxyTag);
|
||||
_coreConfig.outbounds[relayProxyIndex] = new Outbound4Sbox()
|
||||
{
|
||||
type = Global.ProtocolTypes[EConfigType.SOCKS],
|
||||
tag = Global.ProxyTag,
|
||||
server = Global.Loopback,
|
||||
server_port = context.ProxyRelaySocksPort,
|
||||
};
|
||||
var ssInbound = new
|
||||
{
|
||||
type = "shadowsocks",
|
||||
tag = "tun-protect-ss",
|
||||
type = "socks",
|
||||
tag = "tun-protect-socks",
|
||||
listen = Global.Loopback,
|
||||
listen_port = context.TunProtectSsPort,
|
||||
method = "none",
|
||||
password = "none",
|
||||
listen_port = context.TunProtectSocksPort,
|
||||
};
|
||||
var directRule = new Rule4Sbox()
|
||||
{
|
||||
|
||||
@@ -345,14 +345,6 @@ public partial class CoreConfigSingboxService
|
||||
{
|
||||
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;
|
||||
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)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -17,8 +17,8 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
|
||||
{
|
||||
if (!context.AppConfig.TunModeItem.EnableLegacyProtect
|
||||
&& context.IsTunEnabled
|
||||
&& context.TunProtectSsPort is > 0 and <= 65535
|
||||
&& context.ProxyRelaySsPort is > 0 and <= 65535)
|
||||
&& context.TunProtectSocksPort is > 0 and <= 65535
|
||||
&& context.ProxyRelaySocksPort is > 0 and <= 65535)
|
||||
{
|
||||
return GenerateClientProxyRelayConfig();
|
||||
}
|
||||
@@ -309,17 +309,16 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
|
||||
var protectNode = new ProfileItem()
|
||||
{
|
||||
CoreType = ECoreType.Xray,
|
||||
ConfigType = EConfigType.Shadowsocks,
|
||||
ConfigType = EConfigType.SOCKS,
|
||||
Address = Global.Loopback,
|
||||
Port = context.TunProtectSsPort,
|
||||
Password = Global.None,
|
||||
Port = context.TunProtectSocksPort,
|
||||
};
|
||||
protectNode.SetProtocolExtra(protectNode.GetProtocolExtra() with
|
||||
{
|
||||
SsMethod = Global.None,
|
||||
});
|
||||
|
||||
const string protectTag = "tun-protect-ss";
|
||||
const string protectTag = "tun-protect-socks";
|
||||
foreach (var outbound in _coreConfig.outbounds
|
||||
.Where(o => o.streamSettings?.sockopt?.dialerProxy?.IsNullOrEmpty() ?? true))
|
||||
{
|
||||
@@ -368,7 +367,7 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
|
||||
var hasBalancer = _coreConfig.routing.balancers is { Count: > 0 };
|
||||
_coreConfig.routing.rules.Add(new()
|
||||
{
|
||||
inboundTag = ["proxy-relay-ss"],
|
||||
inboundTag = ["proxy-relay-socks"],
|
||||
outboundTag = hasBalancer ? null : Global.ProxyTag,
|
||||
balancerTag = hasBalancer ? Global.ProxyTag + Global.BalancerTagSuffix : null,
|
||||
type = "field"
|
||||
@@ -380,15 +379,14 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
|
||||
configNode["inbounds"]!.AsArray().Add(new
|
||||
{
|
||||
listen = Global.Loopback,
|
||||
port = context.ProxyRelaySsPort,
|
||||
protocol = "shadowsocks",
|
||||
port = context.ProxyRelaySocksPort,
|
||||
protocol = "socks",
|
||||
settings = new
|
||||
{
|
||||
network = "tcp,udp",
|
||||
method = Global.None,
|
||||
password = Global.None,
|
||||
auth = "noauth",
|
||||
udp = true,
|
||||
},
|
||||
tag = "proxy-relay-ss",
|
||||
tag = "proxy-relay-socks",
|
||||
});
|
||||
|
||||
ret.Msg = string.Format(ResUI.SuccessfulConfiguration, "");
|
||||
|
||||
Reference in New Issue
Block a user