mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-30 01:34:08 +00:00
Fix negative rules
This commit is contained in:
parent
1760a92507
commit
9714f70ed5
1 changed files with 44 additions and 13 deletions
|
|
@ -329,6 +329,46 @@ public partial class CoreConfigSingboxService
|
||||||
if (item.Ip?.Count > 0)
|
if (item.Ip?.Count > 0)
|
||||||
{
|
{
|
||||||
var countIp = 0;
|
var countIp = 0;
|
||||||
|
var negativeIpList = item.Ip.Where(it => it.StartsWith('!')).ToList();
|
||||||
|
if (negativeIpList.Count > 0)
|
||||||
|
{
|
||||||
|
var positiveIpList = item.Ip.Except(negativeIpList).ToList();
|
||||||
|
var positiveRule = rule2;
|
||||||
|
positiveRule = JsonUtils.DeepCopy(rule2);
|
||||||
|
positiveRule.outbound = null;
|
||||||
|
positiveRule.action = null;
|
||||||
|
foreach (var it in positiveIpList)
|
||||||
|
{
|
||||||
|
if (ParseV2Address(it, positiveRule))
|
||||||
|
{
|
||||||
|
countIp++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var negativeRule = new Rule4Sbox();
|
||||||
|
foreach (var it in negativeIpList)
|
||||||
|
{
|
||||||
|
// Remove first '!' and trim spaces
|
||||||
|
var ip = it[1..].Trim();
|
||||||
|
if (ParseV2Address(ip, negativeRule))
|
||||||
|
{
|
||||||
|
countIp++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
negativeRule.invert = true;
|
||||||
|
rule2 = new Rule4Sbox()
|
||||||
|
{
|
||||||
|
outbound = rule2.outbound,
|
||||||
|
action = rule2.action,
|
||||||
|
type = "logical",
|
||||||
|
mode = "or",
|
||||||
|
rules = [
|
||||||
|
positiveRule,
|
||||||
|
negativeRule
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
foreach (var it in item.Ip)
|
foreach (var it in item.Ip)
|
||||||
{
|
{
|
||||||
if (ParseV2Address(it, rule2))
|
if (ParseV2Address(it, rule2))
|
||||||
|
|
@ -336,6 +376,7 @@ public partial class CoreConfigSingboxService
|
||||||
countIp++;
|
countIp++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (countIp > 0)
|
if (countIp > 0)
|
||||||
{
|
{
|
||||||
rules.Add(rule2);
|
rules.Add(rule2);
|
||||||
|
|
@ -459,16 +500,6 @@ public partial class CoreConfigSingboxService
|
||||||
rule.geoip ??= [];
|
rule.geoip ??= [];
|
||||||
rule.geoip?.Add(address[Global.GeoIPPrefix.Length..]);
|
rule.geoip?.Add(address[Global.GeoIPPrefix.Length..]);
|
||||||
}
|
}
|
||||||
else if (address.Equals($"{Global.GeoIPPrefix}!private"))
|
|
||||||
{
|
|
||||||
rule.ip_is_private = false;
|
|
||||||
}
|
|
||||||
else if (address.StartsWith($"{Global.GeoIPPrefix}!"))
|
|
||||||
{
|
|
||||||
rule.geoip ??= [];
|
|
||||||
rule.geoip?.Add(address.Substring($"{Global.GeoIPPrefix}!".Length));
|
|
||||||
rule.invert = true;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rule.ip_cidr ??= [];
|
rule.ip_cidr ??= [];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue