1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

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

This commit is contained in:
CalmLong 2020-12-11 21:16:52 +08:00 committed by GitHub
parent 0dcd6ee838
commit 6858a7b0a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 80 additions and 0 deletions

View File

@ -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 {

View File

@ -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{
{