mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-19 13:42:24 +00:00
Adds Sing-box legacy DNS config support
This commit is contained in:
parent
f2c7cb4e43
commit
60d40747a0
4 changed files with 69 additions and 7 deletions
|
@ -227,6 +227,12 @@ public class Server4Sbox
|
||||||
public string? server { get; set; }
|
public string? server { get; set; }
|
||||||
public string? server_resolver { get; set; }
|
public string? server_resolver { get; set; }
|
||||||
[JsonPropertyName("interface")] public string? Interface { get; set; }
|
[JsonPropertyName("interface")] public string? Interface { get; set; }
|
||||||
|
// Deprecated
|
||||||
|
public string? address { get; set; }
|
||||||
|
public string? address_resolver { get; set; }
|
||||||
|
public string? address_strategy { get; set; }
|
||||||
|
public string? strategy { get; set; }
|
||||||
|
// Deprecated End
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Experimental4Sbox
|
public class Experimental4Sbox
|
||||||
|
|
|
@ -4,14 +4,12 @@
|
||||||
"tag": "remote",
|
"tag": "remote",
|
||||||
"type": "tcp",
|
"type": "tcp",
|
||||||
"server": "8.8.8.8",
|
"server": "8.8.8.8",
|
||||||
"strategy": "prefer_ipv4",
|
|
||||||
"detour": "proxy"
|
"detour": "proxy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tag": "local",
|
"tag": "local",
|
||||||
"type": "udp",
|
"type": "udp",
|
||||||
"server": "223.5.5.5",
|
"server": "223.5.5.5"
|
||||||
"strategy": "prefer_ipv4"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"rules": [
|
"rules": [
|
||||||
|
|
|
@ -4,14 +4,12 @@
|
||||||
"tag": "remote",
|
"tag": "remote",
|
||||||
"type": "tcp",
|
"type": "tcp",
|
||||||
"server": "8.8.8.8",
|
"server": "8.8.8.8",
|
||||||
"strategy": "prefer_ipv4",
|
|
||||||
"detour": "proxy"
|
"detour": "proxy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tag": "local",
|
"tag": "local",
|
||||||
"type": "udp",
|
"type": "udp",
|
||||||
"server": "223.5.5.5",
|
"server": "223.5.5.5"
|
||||||
"strategy": "prefer_ipv4"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"rules": [
|
"rules": [
|
||||||
|
|
|
@ -1427,8 +1427,15 @@ public class CoreConfigSingboxService
|
||||||
}
|
}
|
||||||
singboxConfig.dns = dns4Sbox;
|
singboxConfig.dns = dns4Sbox;
|
||||||
|
|
||||||
|
if (dns4Sbox.servers != null && dns4Sbox.servers.Count > 0 && dns4Sbox.servers.First().address.IsNullOrEmpty())
|
||||||
|
{
|
||||||
await GenDnsDomains(node, singboxConfig, item);
|
await GenDnsDomains(node, singboxConfig, item);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await GenDnsDomainsLegacy(node, singboxConfig, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logging.SaveLog(_tag, ex);
|
Logging.SaveLog(_tag, ex);
|
||||||
|
@ -1525,6 +1532,59 @@ public class CoreConfigSingboxService
|
||||||
return await Task.FromResult(0);
|
return await Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<int> GenDnsDomainsLegacy(ProfileItem? node, SingboxConfig singboxConfig, DNSItem? dNSItem)
|
||||||
|
{
|
||||||
|
var dns4Sbox = singboxConfig.dns ?? new();
|
||||||
|
dns4Sbox.servers ??= [];
|
||||||
|
dns4Sbox.rules ??= [];
|
||||||
|
|
||||||
|
var tag = "local_local";
|
||||||
|
dns4Sbox.servers.Add(new()
|
||||||
|
{
|
||||||
|
tag = tag,
|
||||||
|
address = string.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.SingboxDomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress,
|
||||||
|
detour = Global.DirectTag,
|
||||||
|
strategy = string.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom,
|
||||||
|
});
|
||||||
|
dns4Sbox.rules.Insert(0, new()
|
||||||
|
{
|
||||||
|
server = tag,
|
||||||
|
clash_mode = ERuleMode.Direct.ToString()
|
||||||
|
});
|
||||||
|
dns4Sbox.rules.Insert(0, new()
|
||||||
|
{
|
||||||
|
server = dns4Sbox.servers.Where(t => t.detour == Global.ProxyTag).Select(t => t.tag).FirstOrDefault() ?? "remote",
|
||||||
|
clash_mode = ERuleMode.Global.ToString()
|
||||||
|
});
|
||||||
|
|
||||||
|
var lstDomain = singboxConfig.outbounds
|
||||||
|
.Where(t => t.server.IsNotEmpty() && Utils.IsDomain(t.server))
|
||||||
|
.Select(t => t.server)
|
||||||
|
.Distinct()
|
||||||
|
.ToList();
|
||||||
|
if (lstDomain != null && lstDomain.Count > 0)
|
||||||
|
{
|
||||||
|
dns4Sbox.rules.Insert(0, new()
|
||||||
|
{
|
||||||
|
server = tag,
|
||||||
|
domain = lstDomain
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//Tun2SocksAddress
|
||||||
|
if (_config.TunModeItem.EnableTun && node?.ConfigType == EConfigType.SOCKS && Utils.IsDomain(node?.Sni))
|
||||||
|
{
|
||||||
|
dns4Sbox.rules.Insert(0, new()
|
||||||
|
{
|
||||||
|
server = tag,
|
||||||
|
domain = [node?.Sni]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
singboxConfig.dns = dns4Sbox;
|
||||||
|
return await Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<int> GenExperimental(SingboxConfig singboxConfig)
|
private async Task<int> GenExperimental(SingboxConfig singboxConfig)
|
||||||
{
|
{
|
||||||
//if (_config.guiItem.enableStatistics)
|
//if (_config.guiItem.enableStatistics)
|
||||||
|
|
Loading…
Reference in a new issue