diff --git a/infra/conf/router.go b/infra/conf/router.go index 80afcde33..78f289bfd 100644 --- a/infra/conf/router.go +++ b/infra/conf/router.go @@ -396,6 +396,7 @@ func parseFieldRule(msg json.RawMessage) (*router.RoutingRule, error) { type RawFieldRule struct { RouterRule Domain *StringList `json:"domain"` + Domains *StringList `json:"domains"` IP *StringList `json:"ip"` Port *PortList `json:"port"` Network *NetworkList `json:"network"` @@ -436,6 +437,16 @@ func parseFieldRule(msg json.RawMessage) (*router.RoutingRule, error) { } } + if rawFieldRule.Domains != nil { + for _, domain := range *rawFieldRule.Domains { + rules, err := parseDomainRule(domain) + if err != nil { + return nil, newError("failed to parse domain rule: ", domain).Base(err) + } + rule.Domain = append(rule.Domain, rules...) + } + } + if rawFieldRule.IP != nil { geoipList, err := toCidrList(*rawFieldRule.IP) if err != nil { diff --git a/infra/conf/router_test.go b/infra/conf/router_test.go index ac4284dc8..5f2cb24b6 100644 --- a/infra/conf/router_test.go +++ b/infra/conf/router_test.go @@ -37,6 +37,14 @@ func TestRouterConfig(t *testing.T) { ], "outboundTag": "direct" }, + { + "type": "field", + "domains": [ + "v2fly.org", + "github.com" + ], + "outboundTag": "direct" + }, { "type": "field", "ip": [ @@ -87,6 +95,21 @@ func TestRouterConfig(t *testing.T) { Tag: "direct", }, }, + { + Domain: []*router.Domain{ + { + Type: router.Domain_Plain, + Value: "v2fly.org", + }, + { + Type: router.Domain_Plain, + Value: "github.com", + }, + }, + TargetTag: &router.RoutingRule_Tag{ + Tag: "direct", + }, + }, { Geoip: []*router.GeoIP{ { @@ -145,6 +168,14 @@ func TestRouterConfig(t *testing.T) { ], "outboundTag": "direct" }, + { + "type": "field", + "domains": [ + "v2fly.org", + "github.com" + ], + "outboundTag": "direct" + }, { "type": "field", "ip": [ @@ -175,6 +206,21 @@ func TestRouterConfig(t *testing.T) { Tag: "direct", }, }, + { + Domain: []*router.Domain{ + { + Type: router.Domain_Plain, + Value: "v2fly.org", + }, + { + Type: router.Domain_Plain, + Value: "github.com", + }, + }, + TargetTag: &router.RoutingRule_Tag{ + Tag: "direct", + }, + }, { Geoip: []*router.GeoIP{ { @@ -209,6 +255,14 @@ func TestRouterConfig(t *testing.T) { ], "outboundTag": "direct" }, + { + "type": "field", + "domains": [ + "v2fly.org", + "github.com" + ], + "outboundTag": "direct" + }, { "type": "field", "ip": [ @@ -238,6 +292,21 @@ func TestRouterConfig(t *testing.T) { Tag: "direct", }, }, + { + Domain: []*router.Domain{ + { + Type: router.Domain_Plain, + Value: "v2fly.org", + }, + { + Type: router.Domain_Plain, + Value: "github.com", + }, + }, + TargetTag: &router.RoutingRule_Tag{ + Tag: "direct", + }, + }, { Geoip: []*router.GeoIP{ {