Migrating to singbox 1.12 support

This commit is contained in:
DHR60 2025-04-07 19:24:30 +08:00
parent 7384fb3d31
commit 1d2aa70fe9
4 changed files with 86 additions and 39 deletions

View file

@ -134,6 +134,7 @@ public class Outbound4Sbox
public HyObfs4Sbox? obfs { get; set; }
public List<string>? outbounds { get; set; }
public bool? interrupt_exist_connections { get; set; }
public Rule4Sbox? domain_resolver { get; set; }
}
public class Endpoints4Sbox
@ -220,12 +221,12 @@ public class HyObfs4Sbox
public class Server4Sbox
{
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? 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

View file

@ -2,19 +2,16 @@
"servers": [
{
"tag": "remote",
"address": "tcp://8.8.8.8",
"type": "tcp",
"server": "8.8.8.8",
"strategy": "prefer_ipv4",
"detour": "proxy"
},
{
"tag": "local",
"address": "223.5.5.5",
"strategy": "prefer_ipv4",
"detour": "direct"
},
{
"tag": "block",
"address": "rcode://success"
"type": "udp",
"server": "223.5.5.5",
"strategy": "prefer_ipv4"
}
],
"rules": [

View file

@ -2,19 +2,16 @@
"servers": [
{
"tag": "remote",
"address": "tcp://8.8.8.8",
"type": "tcp",
"server": "8.8.8.8",
"strategy": "prefer_ipv4",
"detour": "proxy"
},
{
"tag": "local",
"address": "223.5.5.5",
"strategy": "prefer_ipv4",
"detour": "direct"
},
{
"tag": "block",
"address": "rcode://success"
"type": "udp",
"server": "223.5.5.5",
"strategy": "prefer_ipv4"
}
],
"rules": [

View file

@ -2,6 +2,7 @@ using System.Data;
using System.Net;
using System.Net.NetworkInformation;
using DynamicData;
using ServiceLib.Models;
namespace ServiceLib.Services.CoreConfig;
@ -635,6 +636,16 @@ public class CoreConfigSingboxService
outbound.server_port = node.Port;
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)
{
case EConfigType.VMess:
@ -1292,17 +1303,71 @@ public class CoreConfigSingboxService
dns4Sbox.rules ??= [];
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()
{
tag = tag,
address = string.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.SingboxDomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress,
detour = Global.DirectTag,
strategy = string.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom,
type = localDnsType,
server = localDnsAddress
});
dns4Sbox.rules.Insert(0, new()
{
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()
{
@ -1310,27 +1375,14 @@ public class CoreConfigSingboxService
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]
domain = [node?.Sni],
strategy = string.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom
});
}