mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 11:59:13 +00:00
Improves Tun2Socks address handling
This commit is contained in:
parent
f3adb57e68
commit
f64f72ba7f
2 changed files with 47 additions and 7 deletions
|
@ -1253,12 +1253,49 @@ public static class ConfigHandler
|
|||
ProfileItem? itemSocks = null;
|
||||
if (node.ConfigType != EConfigType.Custom && coreType != ECoreType.sing_box && config.TunModeItem.EnableTun)
|
||||
{
|
||||
var tun2SocksAddress = node.Address;
|
||||
if (node.ConfigType > EConfigType.Group)
|
||||
{
|
||||
static async Task<List<string>> GetChildNodeAddressesAsync(string parentIndexId)
|
||||
{
|
||||
var childAddresses = new List<string>();
|
||||
if (!ProfileGroupItemManager.Instance.TryGet(parentIndexId, out var groupItem) || groupItem.ChildItems.IsNullOrEmpty())
|
||||
return childAddresses;
|
||||
|
||||
var childIds = Utils.String2List(groupItem.ChildItems);
|
||||
|
||||
foreach (var childId in childIds)
|
||||
{
|
||||
var childNode = await AppManager.Instance.GetProfileItem(childId);
|
||||
if (childNode == null)
|
||||
continue;
|
||||
|
||||
if (!childNode.IsComplex())
|
||||
{
|
||||
childAddresses.Add(childNode.Address);
|
||||
}
|
||||
else if (childNode.ConfigType > EConfigType.Group)
|
||||
{
|
||||
var subAddresses = await GetChildNodeAddressesAsync(childNode.IndexId);
|
||||
childAddresses.AddRange(subAddresses);
|
||||
}
|
||||
}
|
||||
|
||||
return childAddresses;
|
||||
}
|
||||
|
||||
var lstAddresses = await GetChildNodeAddressesAsync(node.IndexId);
|
||||
if (lstAddresses.Count > 0)
|
||||
{
|
||||
tun2SocksAddress = Utils.List2String(lstAddresses);
|
||||
}
|
||||
}
|
||||
itemSocks = new ProfileItem()
|
||||
{
|
||||
CoreType = ECoreType.sing_box,
|
||||
ConfigType = EConfigType.SOCKS,
|
||||
Address = Global.Loopback,
|
||||
SpiderX = node.Address, // Tun2SocksAddress
|
||||
SpiderX = tun2SocksAddress, // Tun2SocksAddress
|
||||
Port = AppManager.Instance.GetLocalPort(EInboundProtocol.socks)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -414,16 +414,19 @@ public partial class CoreConfigSingboxService
|
|||
return 0;
|
||||
}
|
||||
|
||||
var domain = string.Empty;
|
||||
List<string> domain = new();
|
||||
if (Utils.IsDomain(node.Address)) // normal outbound
|
||||
{
|
||||
domain = node.Address;
|
||||
domain.Add(node.Address);
|
||||
}
|
||||
else if (node.Address == Global.Loopback && node.SpiderX.IsNotEmpty() && Utils.IsDomain(node.SpiderX)) // Tun2SocksAddress
|
||||
if (node.Address == Global.Loopback && node.SpiderX.IsNotEmpty()) // Tun2SocksAddress
|
||||
{
|
||||
domain = node.SpiderX;
|
||||
domain.AddRange(Utils.String2List(node.SpiderX)
|
||||
.Where(Utils.IsDomain)
|
||||
.Distinct()
|
||||
.ToList());
|
||||
}
|
||||
if (domain.IsNullOrEmpty())
|
||||
if (domain.Count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -432,7 +435,7 @@ public partial class CoreConfigSingboxService
|
|||
singboxConfig.dns.rules.Insert(0, new Rule4Sbox
|
||||
{
|
||||
server = server,
|
||||
domain = [domain],
|
||||
domain = domain,
|
||||
});
|
||||
|
||||
return await Task.FromResult(0);
|
||||
|
|
Loading…
Reference in a new issue