Enable extra inbound for tun mode

pull/3943/head
2dust 2023-06-04 17:11:37 +08:00
parent b176ad03aa
commit 2fd21690a5
2 changed files with 29 additions and 20 deletions

View File

@ -107,29 +107,18 @@ namespace v2rayN.Handler
{ {
try try
{ {
if (_config.tunModeItem.enableTun) singboxConfig.inbounds.Clear();
if (!_config.tunModeItem.enableTun || (_config.tunModeItem.enableTun && _config.tunModeItem.enableExInbound))
{ {
singboxConfig.inbounds.Clear(); var inbound = new Inbound4Sbox()
if (_config.tunModeItem.mtu <= 0)
{ {
_config.tunModeItem.mtu = Convert.ToInt32(Global.TunMtus[0]); type = Global.InboundSocks,
} tag = Global.InboundSocks,
if (Utils.IsNullOrEmpty(_config.tunModeItem.stack)) listen = Global.Loopback,
{ };
_config.tunModeItem.stack = Global.TunStacks[0]; singboxConfig.inbounds.Add(inbound);
}
var tunInbound = Utils.FromJson<Inbound4Sbox>(Utils.GetEmbedText(Global.TunSingboxInboundFileName));
tunInbound.mtu = _config.tunModeItem.mtu;
tunInbound.strict_route = _config.tunModeItem.strictRoute;
tunInbound.stack = _config.tunModeItem.stack;
singboxConfig.inbounds.Add(tunInbound);
}
else
{
var inbound = singboxConfig.inbounds[0];
inbound.listen_port = LazyConfig.Instance.GetLocalPort(Global.InboundSocks); inbound.listen_port = LazyConfig.Instance.GetLocalPort(Global.InboundSocks);
inbound.sniff = _config.inbound[0].sniffingEnabled; inbound.sniff = _config.inbound[0].sniffingEnabled;
inbound.sniff_override_destination = _config.inbound[0].routeOnly ? false : _config.inbound[0].sniffingEnabled; inbound.sniff_override_destination = _config.inbound[0].routeOnly ? false : _config.inbound[0].sniffingEnabled;
@ -174,6 +163,25 @@ namespace v2rayN.Handler
} }
} }
} }
if (_config.tunModeItem.enableTun)
{
if (_config.tunModeItem.mtu <= 0)
{
_config.tunModeItem.mtu = Convert.ToInt32(Global.TunMtus[0]);
}
if (Utils.IsNullOrEmpty(_config.tunModeItem.stack))
{
_config.tunModeItem.stack = Global.TunStacks[0];
}
var tunInbound = Utils.FromJson<Inbound4Sbox>(Utils.GetEmbedText(Global.TunSingboxInboundFileName));
tunInbound.mtu = _config.tunModeItem.mtu;
tunInbound.strict_route = _config.tunModeItem.strictRoute;
tunInbound.stack = _config.tunModeItem.stack;
singboxConfig.inbounds.Add(tunInbound);
}
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -163,6 +163,7 @@ namespace v2rayN.Mode
public bool strictRoute { get; set; } public bool strictRoute { get; set; }
public string stack { get; set; } public string stack { get; set; }
public int mtu { get; set; } public int mtu { get; set; }
public bool enableExInbound { get; set; }
} }
[Serializable] [Serializable]