mirror of https://github.com/2dust/v2rayN
Migrating to singbox 1.12 support
parent
f7a42c038b
commit
786f260529
|
@ -29,7 +29,6 @@ public class Dns4Sbox
|
||||||
public bool? independent_cache { get; set; }
|
public bool? independent_cache { get; set; }
|
||||||
public bool? reverse_mapping { get; set; }
|
public bool? reverse_mapping { get; set; }
|
||||||
public string? client_subnet { get; set; }
|
public string? client_subnet { get; set; }
|
||||||
public Fakeip4Sbox? fakeip { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Route4Sbox
|
public class Route4Sbox
|
||||||
|
@ -134,6 +133,7 @@ public class Outbound4Sbox
|
||||||
public HyObfs4Sbox? obfs { get; set; }
|
public HyObfs4Sbox? obfs { get; set; }
|
||||||
public List<string>? outbounds { get; set; }
|
public List<string>? outbounds { get; set; }
|
||||||
public bool? interrupt_exist_connections { get; set; }
|
public bool? interrupt_exist_connections { get; set; }
|
||||||
|
public Rule4Sbox? domain_resolver { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Endpoints4Sbox
|
public class Endpoints4Sbox
|
||||||
|
@ -220,12 +220,14 @@ public class HyObfs4Sbox
|
||||||
public class Server4Sbox
|
public class Server4Sbox
|
||||||
{
|
{
|
||||||
public string? tag { get; set; }
|
public string? tag { get; set; }
|
||||||
public string? address { get; set; }
|
|
||||||
public string? address_resolver { get; set; }
|
|
||||||
public string? address_strategy { get; set; }
|
|
||||||
public string? strategy { get; set; }
|
|
||||||
public string? detour { get; set; }
|
public string? detour { get; set; }
|
||||||
|
public string? inet4_range { get; set; }
|
||||||
|
public string? inet6_range { get; set; }
|
||||||
public string? client_subnet { get; set; }
|
public string? client_subnet { get; set; }
|
||||||
|
public string? type { get; set; }
|
||||||
|
public string? server { get; set; }
|
||||||
|
public string? server_resolver { get; set; }
|
||||||
|
//public string? interface { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Experimental4Sbox
|
public class Experimental4Sbox
|
||||||
|
@ -255,13 +257,6 @@ public class Stats4Sbox
|
||||||
public List<string>? users { get; set; }
|
public List<string>? users { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Fakeip4Sbox
|
|
||||||
{
|
|
||||||
public bool enabled { get; set; }
|
|
||||||
public string inet4_range { get; set; }
|
|
||||||
public string inet6_range { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CacheFile4Sbox
|
public class CacheFile4Sbox
|
||||||
{
|
{
|
||||||
public bool enabled { get; set; }
|
public bool enabled { get; set; }
|
||||||
|
|
|
@ -2,19 +2,16 @@
|
||||||
"servers": [
|
"servers": [
|
||||||
{
|
{
|
||||||
"tag": "remote",
|
"tag": "remote",
|
||||||
"address": "tcp://8.8.8.8",
|
"type": "tcp",
|
||||||
|
"server": "8.8.8.8",
|
||||||
"strategy": "prefer_ipv4",
|
"strategy": "prefer_ipv4",
|
||||||
"detour": "proxy"
|
"detour": "proxy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tag": "local",
|
"tag": "local",
|
||||||
"address": "223.5.5.5",
|
"type": "udp",
|
||||||
"strategy": "prefer_ipv4",
|
"server": "223.5.5.5",
|
||||||
"detour": "direct"
|
"strategy": "prefer_ipv4"
|
||||||
},
|
|
||||||
{
|
|
||||||
"tag": "block",
|
|
||||||
"address": "rcode://success"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"rules": [
|
"rules": [
|
||||||
|
|
|
@ -2,19 +2,16 @@
|
||||||
"servers": [
|
"servers": [
|
||||||
{
|
{
|
||||||
"tag": "remote",
|
"tag": "remote",
|
||||||
"address": "tcp://8.8.8.8",
|
"type": "tcp",
|
||||||
|
"server": "8.8.8.8",
|
||||||
"strategy": "prefer_ipv4",
|
"strategy": "prefer_ipv4",
|
||||||
"detour": "proxy"
|
"detour": "proxy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tag": "local",
|
"tag": "local",
|
||||||
"address": "223.5.5.5",
|
"type": "udp",
|
||||||
"strategy": "prefer_ipv4",
|
"server": "223.5.5.5",
|
||||||
"detour": "direct"
|
"strategy": "prefer_ipv4"
|
||||||
},
|
|
||||||
{
|
|
||||||
"tag": "block",
|
|
||||||
"address": "rcode://success"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"rules": [
|
"rules": [
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System.Data;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
using DynamicData;
|
using DynamicData;
|
||||||
|
using ServiceLib.Models;
|
||||||
|
|
||||||
namespace ServiceLib.Services.CoreConfig;
|
namespace ServiceLib.Services.CoreConfig;
|
||||||
|
|
||||||
|
@ -611,6 +612,16 @@ public class CoreConfigSingboxService
|
||||||
outbound.server_port = node.Port;
|
outbound.server_port = node.Port;
|
||||||
outbound.type = Global.ProtocolTypes[node.ConfigType];
|
outbound.type = Global.ProtocolTypes[node.ConfigType];
|
||||||
|
|
||||||
|
if (Utils.IsDomain(node.Address))
|
||||||
|
{
|
||||||
|
outbound.domain_resolver = new()
|
||||||
|
{
|
||||||
|
server = "local_local",
|
||||||
|
// TODO
|
||||||
|
//strategy = string.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
switch (node.ConfigType)
|
switch (node.ConfigType)
|
||||||
{
|
{
|
||||||
case EConfigType.VMess:
|
case EConfigType.VMess:
|
||||||
|
@ -1453,17 +1464,71 @@ public class CoreConfigSingboxService
|
||||||
dns4Sbox.rules ??= [];
|
dns4Sbox.rules ??= [];
|
||||||
|
|
||||||
var tag = "local_local";
|
var tag = "local_local";
|
||||||
|
var localDnsAddress = string.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.SingboxDomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress;
|
||||||
|
string? localDnsType = null;
|
||||||
|
//string? dhcpDnsInterface = null;
|
||||||
|
if (localDnsAddress == "local")
|
||||||
|
{
|
||||||
|
localDnsType = "local";
|
||||||
|
localDnsAddress = null;
|
||||||
|
}
|
||||||
|
else if (localDnsAddress.StartsWith("dhcp"))
|
||||||
|
{
|
||||||
|
localDnsType = "dhcp";
|
||||||
|
//if (localDnsAddress.Length > 7) // dhcp://
|
||||||
|
//{
|
||||||
|
// localDnsAddress = localDnsAddress.Substring(7);
|
||||||
|
//}
|
||||||
|
localDnsAddress = null;
|
||||||
|
}
|
||||||
|
else if (localDnsAddress.StartsWith("tcp"))
|
||||||
|
{
|
||||||
|
localDnsType = "tcp";
|
||||||
|
if (localDnsAddress.Length > 6) // tcp://
|
||||||
|
{
|
||||||
|
localDnsAddress = localDnsAddress.Substring(6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (localDnsAddress.StartsWith("tls"))
|
||||||
|
{
|
||||||
|
localDnsType = "tls";
|
||||||
|
if (localDnsAddress.Length > 6) // tls://
|
||||||
|
{
|
||||||
|
localDnsAddress = localDnsAddress.Substring(6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (localDnsAddress.StartsWith("https"))
|
||||||
|
{
|
||||||
|
localDnsType = "https";
|
||||||
|
if (localDnsAddress.Length > 8) // https://
|
||||||
|
{
|
||||||
|
localDnsAddress = localDnsAddress.Substring(8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (localDnsAddress.StartsWith("quic"))
|
||||||
|
{
|
||||||
|
localDnsType = "quic";
|
||||||
|
if (localDnsAddress.Length > 7) // quic://
|
||||||
|
{
|
||||||
|
localDnsAddress = localDnsAddress.Substring(7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
localDnsType = "udp";
|
||||||
|
}
|
||||||
|
|
||||||
dns4Sbox.servers.Add(new()
|
dns4Sbox.servers.Add(new()
|
||||||
{
|
{
|
||||||
tag = tag,
|
tag = tag,
|
||||||
address = string.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.SingboxDomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress,
|
type = localDnsType,
|
||||||
detour = Global.DirectTag,
|
server = localDnsAddress
|
||||||
strategy = string.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom,
|
|
||||||
});
|
});
|
||||||
dns4Sbox.rules.Insert(0, new()
|
dns4Sbox.rules.Insert(0, new()
|
||||||
{
|
{
|
||||||
server = tag,
|
server = tag,
|
||||||
clash_mode = ERuleMode.Direct.ToString()
|
clash_mode = ERuleMode.Direct.ToString(),
|
||||||
|
strategy = string.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom
|
||||||
});
|
});
|
||||||
dns4Sbox.rules.Insert(0, new()
|
dns4Sbox.rules.Insert(0, new()
|
||||||
{
|
{
|
||||||
|
@ -1471,27 +1536,14 @@ public class CoreConfigSingboxService
|
||||||
clash_mode = ERuleMode.Global.ToString()
|
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
|
//Tun2SocksAddress
|
||||||
if (_config.TunModeItem.EnableTun && node?.ConfigType == EConfigType.SOCKS && Utils.IsDomain(node?.Sni))
|
if (_config.TunModeItem.EnableTun && node?.ConfigType == EConfigType.SOCKS && Utils.IsDomain(node?.Sni))
|
||||||
{
|
{
|
||||||
dns4Sbox.rules.Insert(0, new()
|
dns4Sbox.rules.Insert(0, new()
|
||||||
{
|
{
|
||||||
server = tag,
|
server = tag,
|
||||||
domain = [node?.Sni]
|
domain = [node?.Sni],
|
||||||
|
strategy = string.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue