mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
faster check in field rule
This commit is contained in:
parent
dc69dfb3e1
commit
f6c486327f
@ -59,6 +59,7 @@ func (this *FieldRule) Apply(dest v2net.Destination) bool {
|
||||
for _, domain := range *this.Domain {
|
||||
if strings.Contains(address.Domain(), domain) {
|
||||
foundMatch = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !foundMatch {
|
||||
@ -74,6 +75,7 @@ func (this *FieldRule) Apply(dest v2net.Destination) bool {
|
||||
for _, ipnet := range this.IP {
|
||||
if ipnet.Contains(address.IP()) {
|
||||
foundMatch = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !foundMatch {
|
||||
|
@ -65,6 +65,19 @@ func TestIPMatching(t *testing.T) {
|
||||
assert.Bool(rule.Apply(dest)).IsTrue()
|
||||
}
|
||||
|
||||
func TestIPListMatching(t *testing.T) {
|
||||
assert := unit.Assert(t)
|
||||
|
||||
rawJson := `{
|
||||
"type": "field",
|
||||
"ip": ["10.0.0.0/8", "192.168.0.0/16"],
|
||||
"tag": "test"
|
||||
}`
|
||||
rule := parseRule([]byte(rawJson))
|
||||
dest := v2net.NewTCPDestination(v2net.IPAddress([]byte{192, 168, 1, 1}, 80))
|
||||
assert.Bool(rule.Apply(dest)).IsTrue()
|
||||
}
|
||||
|
||||
func TestPortNotMatching(t *testing.T) {
|
||||
assert := unit.Assert(t)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user