Compare commits

..

2 commits

Author SHA1 Message Date
2dust
89d6af8fc9 Added global constants such as IPIfNonMatch
Some checks are pending
release Linux / build (Release) (push) Waiting to run
release macOS / build (Release) (push) Waiting to run
release Windows desktop (Avalonia UI) / build (Release) (push) Waiting to run
release Windows / build (Release) (push) Waiting to run
2025-08-14 20:18:22 +08:00
DHR60
dcc9c9fa14
Fixes DNS (#7757)
* Adds properties

* Adds DNS routing
2025-08-14 17:32:48 +08:00
7 changed files with 61 additions and 12 deletions

View file

@ -48,6 +48,7 @@ public class Global
public const string ProxyTag = "proxy";
public const string DirectTag = "direct";
public const string BlockTag = "block";
public const string DnsTag = "dns-module";
public const string StreamSecurity = "tls";
public const string StreamSecurityReality = "reality";
public const string Loopback = "127.0.0.1";
@ -56,6 +57,9 @@ public class Global
public const string HttpsProtocol = "https://";
public const string SocksProtocol = "socks://";
public const string Socks5Protocol = "socks5://";
public const string AsIs = "AsIs";
public const string IPIfNonMatch = "IPIfNonMatch";
public const string IPOnDemand = "IPOnDemand";
public const string UserEMail = "t@t.tt";
public const string AutoRunRegPath = @"Software\Microsoft\Windows\CurrentVersion\Run";
@ -287,9 +291,9 @@ public class Global
public static readonly List<string> DomainStrategies =
[
"AsIs",
"IPIfNonMatch",
"IPOnDemand"
AsIs,
IPIfNonMatch,
IPOnDemand
];
public static readonly List<string> DomainStrategies4Singbox =

View file

@ -2262,6 +2262,7 @@ public class ConfigHandler
return 0;
}
public static async Task<int> SaveFullConfigTemplate(Config config, FullConfigTemplateItem item)
{
if (item == null)

View file

@ -203,8 +203,15 @@ public class Response4Ray
public class Dns4Ray
{
public Dictionary<string, List<string>>? hosts { get; set; }
public Dictionary<string, object>? hosts { get; set; }
public List<object> servers { get; set; }
public string? clientIp { get; set; }
public string? queryStrategy { get; set; }
public bool? disableCache { get; set; }
public bool? disableFallback { get; set; }
public bool? disableFallbackIfMatch { get; set; }
public bool? useSystemHosts { get; set; }
public string? tag { get; set; }
}
public class DnsServer4Ray
@ -214,6 +221,12 @@ public class DnsServer4Ray
public bool? skipFallback { get; set; }
public List<string>? expectedIPs { get; set; }
public List<string>? unexpectedIPs { get; set; }
public string? clientIp { get; set; }
public string? queryStrategy { get; set; }
public int? timeoutMs { get; set; }
public bool? disableCache { get; set; }
public bool? finalQuery { get; set; }
public string? tag { get; set; }
}
public class Routing4Ray

View file

@ -1329,7 +1329,7 @@ public class CoreConfigSingboxService
action = "resolve",
strategy = domainStrategy
};
if (_config.RoutingBasicItem.DomainStrategy == "IPOnDemand")
if (_config.RoutingBasicItem.DomainStrategy == Global.IPOnDemand)
{
singboxConfig.route.rules.Add(resolveRule);
}
@ -1351,7 +1351,7 @@ public class CoreConfigSingboxService
}
}
}
if (_config.RoutingBasicItem.DomainStrategy == "IPIfNonMatch")
if (_config.RoutingBasicItem.DomainStrategy == Global.IPIfNonMatch)
{
singboxConfig.route.rules.Add(resolveRule);
foreach (var item2 in ipRules)

View file

@ -177,7 +177,7 @@ public class CoreConfigV2rayService
rule.balancerTag = balancer.tag;
}
}
if (v2rayConfig.routing.domainStrategy == "IPIfNonMatch")
if (v2rayConfig.routing.domainStrategy == Global.IPIfNonMatch)
{
v2rayConfig.routing.rules.Add(new()
{
@ -1143,7 +1143,21 @@ public class CoreConfigV2rayService
var item = await AppHandler.Instance.GetDNSItem(ECoreType.Xray);
if (item != null && item.Enabled == true)
{
return await GenDnsCompatible(node, v2rayConfig);
var result = await GenDnsCompatible(node, v2rayConfig);
if (v2rayConfig.routing.domainStrategy == Global.IPIfNonMatch)
{
// DNS routing
v2rayConfig.dns.tag = Global.DnsTag;
v2rayConfig.routing.rules.Add(new RulesItem4Ray
{
type = "field",
inboundTag = new List<string> { Global.DnsTag },
outboundTag = Global.ProxyTag,
});
}
return result;
}
var simpleDNSItem = _config.SimpleDNSItem;
var domainStrategy4Freedom = simpleDNSItem?.RayStrategy4Freedom;
@ -1164,6 +1178,18 @@ public class CoreConfigV2rayService
await GenDnsServers(node, v2rayConfig, simpleDNSItem);
await GenDnsHosts(v2rayConfig, simpleDNSItem);
if (v2rayConfig.routing.domainStrategy == Global.IPIfNonMatch)
{
// DNS routing
v2rayConfig.dns.tag = Global.DnsTag;
v2rayConfig.routing.rules.Add(new RulesItem4Ray
{
type = "field",
inboundTag = new List<string> { Global.DnsTag },
outboundTag = Global.ProxyTag,
});
}
}
catch (Exception ex)
{
@ -1340,10 +1366,13 @@ public class CoreConfigV2rayService
return await Task.FromResult(0);
}
v2rayConfig.dns ??= new Dns4Ray();
v2rayConfig.dns.hosts ??= new Dictionary<string, List<string>>();
v2rayConfig.dns.hosts ??= new Dictionary<string, object>();
if (simpleDNSItem.AddCommonHosts == true)
{
v2rayConfig.dns.hosts = Global.PredefinedHosts;
v2rayConfig.dns.hosts = Global.PredefinedHosts.ToDictionary(
kvp => kvp.Key,
kvp => (object)kvp.Value
);
}
if (simpleDNSItem.UseSystemHosts == true)

View file

@ -1,12 +1,13 @@
using System.Reactive;
using DynamicData.Binding;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
namespace ServiceLib.ViewModels;
public class FullConfigTemplateViewModel : MyReactiveObject
{
#region Reactive
[Reactive]
public bool EnableFullConfigTemplate4Ray { get; set; }
@ -35,6 +36,7 @@ public class FullConfigTemplateViewModel : MyReactiveObject
public string ProxyDetour4Singbox { get; set; }
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
#endregion Reactive
public FullConfigTemplateViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
@ -48,6 +50,7 @@ public class FullConfigTemplateViewModel : MyReactiveObject
_ = Init();
}
private async Task Init()
{
var item = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.Xray);

View file

@ -1246,4 +1246,3 @@
</TabControl>
</DockPanel>
</base:WindowBase>