Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/router/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ func TestServiceTestRoute(t *testing.T) {
TargetTag: &router.RoutingRule_Tag{Tag: "out"},
},
{
Domain: []*router.Domain{{Type: router.Domain_Domain, Value: "com"}},
Domain: &router.GeoSite{Domain: []*router.Domain{{Type: router.Domain_Domain, Value: "com"}}},
TargetTag: &router.RoutingRule_Tag{Tag: "out"},
},
{
SourceGeoip: []*router.GeoIP{{CountryCode: "private", Cidr: []*router.CIDR{{Ip: []byte{127, 0, 0, 0}, Prefix: 8}}}},
SourceGeoip: &router.GeoIPList{Entry: []*router.GeoIP{{CountryCode: "private", Cidr: []*router.CIDR{{Ip: []byte{127, 0, 0, 0}, Prefix: 8}}}}},
TargetTag: &router.RoutingRule_Tag{Tag: "out"},
},
{
Expand Down
71 changes: 39 additions & 32 deletions app/router/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strconv"
"testing"

"github.com/xtls/xray-core/app/router"
. "github.com/xtls/xray-core/app/router"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/errors"
Expand Down Expand Up @@ -45,18 +46,20 @@ func TestRoutingRule(t *testing.T) {
}{
{
rule: &RoutingRule{
Domain: []*Domain{
{
Value: "example.com",
Type: Domain_Plain,
},
{
Value: "google.com",
Type: Domain_Domain,
},
{
Value: "^facebook\\.com$",
Type: Domain_Regex,
Domain: &router.GeoSite{
Domain: []*Domain{
{
Value: "example.com",
Type: Domain_Plain,
},
{
Value: "google.com",
Type: Domain_Domain,
},
{
Value: "^facebook\\.com$",
Type: Domain_Regex,
},
},
},
},
Expand Down Expand Up @@ -93,20 +96,22 @@ func TestRoutingRule(t *testing.T) {
},
{
rule: &RoutingRule{
Geoip: []*GeoIP{
{
Cidr: []*CIDR{
{
Ip: []byte{8, 8, 8, 8},
Prefix: 32,
},
{
Ip: []byte{8, 8, 8, 8},
Prefix: 32,
},
{
Ip: net.ParseAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334").IP(),
Prefix: 128,
Geoip: &router.GeoIPList{
Entry: []*GeoIP{
{
Cidr: []*CIDR{
{
Ip: []byte{8, 8, 8, 8},
Prefix: 32,
},
{
Ip: []byte{8, 8, 8, 8},
Prefix: 32,
},
{
Ip: net.ParseAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334").IP(),
Prefix: 128,
},
},
},
},
Expand All @@ -133,12 +138,14 @@ func TestRoutingRule(t *testing.T) {
},
{
rule: &RoutingRule{
SourceGeoip: []*GeoIP{
{
Cidr: []*CIDR{
{
Ip: []byte{192, 168, 0, 0},
Prefix: 16,
SourceGeoip: &router.GeoIPList{
Entry: []*GeoIP{
{
Cidr: []*CIDR{
{
Ip: []byte{192, 168, 0, 0},
Prefix: 16,
},
},
},
},
Expand Down
18 changes: 9 additions & 9 deletions app/router/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,37 @@ func (rr *RoutingRule) BuildCondition() (Condition, error) {
conds.Add(&AttributeMatcher{configuredKeys})
}

if len(rr.Geoip) > 0 {
cond, err := NewIPMatcher(rr.Geoip, MatcherAsType_Target)
if rr.Geoip != nil && len(rr.Geoip.Entry) > 0 {
cond, err := NewIPMatcher(rr.Geoip.Entry, MatcherAsType_Target)
if err != nil {
return nil, err
}
conds.Add(cond)
}

if len(rr.SourceGeoip) > 0 {
cond, err := NewIPMatcher(rr.SourceGeoip, MatcherAsType_Source)
if rr.SourceGeoip != nil && len(rr.SourceGeoip.Entry) > 0 {
cond, err := NewIPMatcher(rr.SourceGeoip.Entry, MatcherAsType_Source)
if err != nil {
return nil, err
}
conds.Add(cond)
}

if len(rr.LocalGeoip) > 0 {
cond, err := NewIPMatcher(rr.LocalGeoip, MatcherAsType_Local)
if rr.LocalGeoip != nil && len(rr.LocalGeoip.Entry) > 0 {
cond, err := NewIPMatcher(rr.LocalGeoip.Entry, MatcherAsType_Local)
if err != nil {
return nil, err
}
conds.Add(cond)
errors.LogWarning(context.Background(), "Due to some limitations, in UDP connections, localIP is always equal to listen interface IP, so \"localIP\" rule condition does not work properly on UDP inbound connections that listen on all interfaces")
}

if len(rr.Domain) > 0 {
matcher, err := NewMphMatcherGroup(rr.Domain)
if rr.Domain != nil && len(rr.Domain.Domain) > 0 {
matcher, err := NewMphMatcherGroup(rr.Domain.Domain)
if err != nil {
return nil, errors.New("failed to build domain condition with MphDomainMatcher").Base(err)
}
errors.LogDebug(context.Background(), "MphDomainMatcher is enabled for ", len(rr.Domain), " domain rule(s)")
errors.LogDebug(context.Background(), "MphDomainMatcher is enabled for ", len(rr.Domain.Domain), " domain rule(s)")
conds.Add(matcher)
}

Expand Down
Loading