mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-04 03:25:00 +03:00
@@ -63,59 +63,6 @@ public partial class CoreConfigSingboxService(CoreConfigContext context)
|
||||
ret.Success = true;
|
||||
|
||||
ret.Data = ApplyFullConfigTemplate();
|
||||
if (!context.AppConfig.TunModeItem.EnableLegacyProtect
|
||||
&& 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 = "socks",
|
||||
tag = "tun-protect-socks",
|
||||
listen = Global.Loopback,
|
||||
listen_port = context.TunProtectSocksPort,
|
||||
};
|
||||
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;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -24,7 +24,7 @@ public partial class CoreConfigSingboxService
|
||||
strategy = directDnsStrategy
|
||||
};
|
||||
|
||||
if (_config.TunModeItem.EnableTun)
|
||||
if (context.IsTunEnabled)
|
||||
{
|
||||
_coreConfig.route.auto_detect_interface = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user