mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
fix routing config on source IP
This commit is contained in:
parent
d343cb1ee6
commit
2e0d54fd4c
@ -152,7 +152,7 @@ func parseFieldRule(msg json.RawMessage) (*router.RoutingRule, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rawFieldRule.SourceIP != nil {
|
if rawFieldRule.SourceIP != nil {
|
||||||
for _, ip := range *rawFieldRule.IP {
|
for _, ip := range *rawFieldRule.SourceIP {
|
||||||
ipRule := parseIP(ip)
|
ipRule := parseIP(ip)
|
||||||
if ipRule != nil {
|
if ipRule != nil {
|
||||||
rule.SourceCidr = append(rule.SourceCidr, ipRule)
|
rule.SourceCidr = append(rule.SourceCidr, ipRule)
|
||||||
|
@ -135,3 +135,31 @@ func TestIPRule(t *testing.T) {
|
|||||||
Destination: v2net.TCPDestination(v2net.IPAddress([]byte{192, 0, 0, 1}), 80),
|
Destination: v2net.TCPDestination(v2net.IPAddress([]byte{192, 0, 0, 1}), 80),
|
||||||
})).IsTrue()
|
})).IsTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSourceIPRule(t *testing.T) {
|
||||||
|
assert := assert.On(t)
|
||||||
|
|
||||||
|
rule := ParseRule([]byte(`{
|
||||||
|
"type": "field",
|
||||||
|
"source": [
|
||||||
|
"10.0.0.0/8",
|
||||||
|
"192.0.0.0/24"
|
||||||
|
],
|
||||||
|
"outboundTag": "direct"
|
||||||
|
}`))
|
||||||
|
assert.Pointer(rule).IsNotNil()
|
||||||
|
cond, err := rule.BuildCondition()
|
||||||
|
assert.Error(err).IsNil()
|
||||||
|
assert.Bool(cond.Apply(&proxy.SessionInfo{
|
||||||
|
Source: v2net.TCPDestination(v2net.DomainAddress("www.ooxx.com"), 80),
|
||||||
|
})).IsFalse()
|
||||||
|
assert.Bool(cond.Apply(&proxy.SessionInfo{
|
||||||
|
Source: v2net.TCPDestination(v2net.IPAddress([]byte{10, 0, 0, 1}), 80),
|
||||||
|
})).IsTrue()
|
||||||
|
assert.Bool(cond.Apply(&proxy.SessionInfo{
|
||||||
|
Source: v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80),
|
||||||
|
})).IsFalse()
|
||||||
|
assert.Bool(cond.Apply(&proxy.SessionInfo{
|
||||||
|
Source: v2net.TCPDestination(v2net.IPAddress([]byte{192, 0, 0, 1}), 80),
|
||||||
|
})).IsTrue()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user