Browse Source

Routing: consistent with domains key in DNS configuration (#502)

CalmLong 5 years ago
parent
commit
6858a7b0a7
2 changed files with 80 additions and 0 deletions
  1. 11 0
      infra/conf/router.go
  2. 69 0
      infra/conf/router_test.go

+ 11 - 0
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 {

+ 69 - 0
infra/conf/router_test.go

@@ -39,6 +39,14 @@ func TestRouterConfig(t *testing.T) {
 						},
 						{
 							"type": "field",
+							"domains": [
+								"v2fly.org",
+								"github.com"
+							],
+							"outboundTag": "direct"
+						},
+						{
+							"type": "field",
 							"ip": [
 								"10.0.0.0/8",
 								"::1/128"
@@ -88,6 +96,21 @@ func TestRouterConfig(t *testing.T) {
 						},
 					},
 					{
+						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{
 							{
 								Cidr: []*router.CIDR{
@@ -147,6 +170,14 @@ func TestRouterConfig(t *testing.T) {
 						},
 						{
 							"type": "field",
+							"domains": [
+								"v2fly.org",
+								"github.com"
+							],
+							"outboundTag": "direct"
+						},
+						{
+							"type": "field",
 							"ip": [
 								"10.0.0.0/8",
 								"::1/128"
@@ -176,6 +207,21 @@ func TestRouterConfig(t *testing.T) {
 						},
 					},
 					{
+						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{
 							{
 								Cidr: []*router.CIDR{
@@ -211,6 +257,14 @@ func TestRouterConfig(t *testing.T) {
 					},
 					{
 						"type": "field",
+						"domains": [
+							"v2fly.org",
+							"github.com"
+						],
+						"outboundTag": "direct"
+					},
+					{
+						"type": "field",
 						"ip": [
 							"10.0.0.0/8",
 							"::1/128"
@@ -239,6 +293,21 @@ func TestRouterConfig(t *testing.T) {
 						},
 					},
 					{
+						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{
 							{
 								Cidr: []*router.CIDR{