Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Apr 3, 2024
1 parent 1aef49e commit dc3f07e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
35 changes: 23 additions & 12 deletions v2rayN/v2rayN/Handler/CoreConfigSingbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,22 +653,30 @@ private int GenRoutingUserRule(RulesItem item, List<Rule4Sbox> rules)
var hasDomainIp = false;
if (item.domain?.Count > 0)
{
var countDomain = 0;
foreach (var it in item.domain)
{
ParseV2Domain(it, rule);
if (ParseV2Domain(it, rule)) countDomain++;
}
if (countDomain > 0)
{
rules.Add(rule);
hasDomainIp = true;
}
rules.Add(rule);
hasDomainIp = true;
}

if (item.ip?.Count > 0)
{
var countIp = 0;
foreach (var it in item.ip)
{
ParseV2Address(it, rule2);
if (ParseV2Address(it, rule2)) countIp++;
}
if (countIp > 0)
{
rules.Add(rule2);
hasDomainIp = true;
}
rules.Add(rule2);
hasDomainIp = true;
}

if (_config.tunModeItem.enableTun && item.process?.Count > 0)
Expand All @@ -678,7 +686,8 @@ private int GenRoutingUserRule(RulesItem item, List<Rule4Sbox> rules)
hasDomainIp = true;
}

if (!hasDomainIp)
if (!hasDomainIp
&& (rule.port != null || rule.port_range != null || rule.protocol != null || rule.inbound != null))
{
rules.Add(rule);
}
Expand All @@ -690,11 +699,11 @@ private int GenRoutingUserRule(RulesItem item, List<Rule4Sbox> rules)
return 0;
}

private void ParseV2Domain(string domain, Rule4Sbox rule)
private bool ParseV2Domain(string domain, Rule4Sbox rule)
{
if (domain.StartsWith("#") || domain.StartsWith("ext:") || domain.StartsWith("ext-domain:"))
{
return;
return false;
}
else if (domain.StartsWith("geosite:"))
{
Expand Down Expand Up @@ -728,17 +737,18 @@ private void ParseV2Domain(string domain, Rule4Sbox rule)
rule.domain_keyword ??= [];
rule.domain_keyword?.Add(domain);
}
return true;
}

private void ParseV2Address(string address, Rule4Sbox rule)
private bool ParseV2Address(string address, Rule4Sbox rule)
{
if (address.StartsWith("ext:") || address.StartsWith("ext-ip:"))
{
return;
return false;
}
else if (address.StartsWith("geoip:!"))
{
return;
return false;
}
else if (address.StartsWith("geoip:"))
{
Expand All @@ -750,6 +760,7 @@ private void ParseV2Address(string address, Rule4Sbox rule)
if (rule.ip_cidr is null) { rule.ip_cidr = new(); }
rule.ip_cidr?.Add(address);
}
return true;
}

private int GenDns(ProfileItem node, SingboxConfig singboxConfig)
Expand Down
14 changes: 7 additions & 7 deletions v2rayN/v2rayN/Models/V2rayConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,19 +389,19 @@ public class Routing4Ray
[Serializable]
public class RulesItem4Ray
{
public string type { get; set; }
public string? type { get; set; }

public string port { get; set; }
public string? port { get; set; }

public List<string> inboundTag { get; set; }
public List<string>? inboundTag { get; set; }

public string outboundTag { get; set; }
public string? outboundTag { get; set; }

public List<string> ip { get; set; }
public List<string>? ip { get; set; }

public List<string> domain { get; set; }
public List<string>? domain { get; set; }

public List<string> protocol { get; set; }
public List<string>? protocol { get; set; }
}

public class StreamSettings4Ray
Expand Down

0 comments on commit dc3f07e

Please sign in to comment.