mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-19 13:42:24 +00:00
Migrating to singbox 1.12 support
This commit is contained in:
parent
7384fb3d31
commit
1d2aa70fe9
4 changed files with 86 additions and 39 deletions
|
@ -134,6 +134,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 +221,12 @@ 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? 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
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
@ -635,6 +636,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:
|
||||||
|
@ -1292,17 +1303,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()
|
||||||
{
|
{
|
||||||
|
@ -1310,27 +1375,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 a new issue