Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS servers with same tag in a SINGLE configuration file got unexpected merged #2981

Open
povsister opened this issue Apr 19, 2024 · 5 comments · May be fixed by #3005
Open

DNS servers with same tag in a SINGLE configuration file got unexpected merged #2981

povsister opened this issue Apr 19, 2024 · 5 comments · May be fixed by #3005

Comments

@povsister
Copy link

What version of V2Ray are you using?

master build
V2Ray 5.15.1 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.22.2 linux/amd64)

What's your scenario of using V2Ray?

Not related

What problems have you encountered?

Multiple DNS servers with same tag in a single configuration file are unexpected merged into one, with all domain rules merged together, and the last server's address & settings taken effect.

What's your expectation?

According to documentation here, same-tag-merging in slices should only take effect on inbounds and outbounds.
so DNS servers with same tag in a single configuration file should be all preserved.

Please attach your configuration here

What I typed in v4 configuration:

{
// omitted

  "dns": {
    "queryStrategy": "UseIPv4",
    "fallbackStrategy": "disabled-if-any-match",
    "domainMatcher": "mph",
    "servers": [
      {
         "address": "aaa.bbb.ccc.ddd", // DNS from ISP
         "port": 53,
         "domains": [
           "geosite:cn"
         ],
         "tag": "dns-domestic"
      },
      {
         "address": "114.114.114.114", // 114 public DNS as backup
         "port": 53,
         "domains": [
           "geosite:cn"
         ],
         "tag": "dns-domestic",
      },
      {
         "address": "https://1.1.1.1/dns-query", // Cloudflare DoH as default fallback
         "tag": "dns-international",
      }
    ]
  },
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "domainMatcher": "mph",
    "rules": [
      // omitted
      {
        "type": "field",
        "inboundTag": "dns-domestic",
        "outboundTag": "direct"   // always direct sent domestic site DNS queries
      },
      {
        "type": "field",
        "inboundTag": "dns-international",
        "outboundTag": "proxy"  // proxy international cf DoH queries
      }
      // omitted
    ]
  }

// omitted
}

What I actually got after configuration parsed:

{
// omitted

  "dns": {
    "queryStrategy": "UseIPv4",
    "fallbackStrategy": "disabled-if-any-match",
    "domainMatcher": "mph",
    "servers": [
      {
         "address": "114.114.114.114", // got overwritten by the last one
         "port": 53,
         "domains": [
           "geosite:cn",
           "geosite:cn"  // Yes, it even has the same domain rule repeated twice
         ],
         "tag": "dns-domestic",
      },
      {
         "address": "https://1.1.1.1/dns-query", // Cloudflare DoH as default fallback
         "tag": "dns-international",
      }
    ]
  },
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "domainMatcher": "mph",
    "rules": [
      // omitted
      {
        "type": "field",
        "inboundTag": "dns-domestic",
        "outboundTag": "direct"   // always direct send domestic site DNS queries
      },
      {
        "type": "field",
        "inboundTag": "dns-international",
        "outboundTag": "proxy"  // proxy international cf DoH queries
      }
      // omitted
    ]
  }

// omitted
}
@Vigilans
Copy link
Contributor

Vigilans commented May 6, 2024

What I actually got after configuration parsed:

What are your reproduction steps for What I actually got after configuration parsed? How is the second configuration generated/printed?

@povsister
Copy link
Author

What are your reproduction steps for What I actually got after configuration parsed? How is the second configuration generated/printed?

The actual effective configuration is exported by adding stdout print code before+after config load.
It can also be verified by adding some print code during config build.

From what I have seen, the issue reported here can be easily reproduced with v4 JSON config format.
Other config formats are not tested.

@Vigilans
Copy link
Contributor

Vigilans commented May 6, 2024

@povsister Can reproduce with v2ray convert.

However, dns tags do not work this way. The tag is only used for routing, and not participating in DNS server selection. It should be more like a bug with the parsing logic of v2ray convert, rather than the DNS itself.

Can you check whether you can get expected behavior without any sorts of merging, just run with the config as-is?

@povsister
Copy link
Author

However, dns tags do not work this way. The tag is only used for routing, and not participating in DNS server selection.

I know exactly what i am doing.
I have two domestic DNS servers(one as primary and one as backup) with same rules/tags configured within the DNS server list, and I am intending to identitify and direct send domestic DNS traffic.

I have read the code of DNS processing, and I am sure those 2 domestic servers will be used in sequence for domestic sites.

it should be more like a bug with the parsing logic of v2ray convert, rather than the DNS itself.

I agree with that, too.
As I have mentioned the "merging" behaviour referred in documentation, I don't think the same-tag-merging shoud be applied to DNS configurations.

Can you check whether you can get expected behavior without any sorts of merging, just run with the config as-is?

I am using a workaround right now, by configuring different tag on different servers.
It works as expected now.
For example:

{
// omitted

  "dns": {
    "queryStrategy": "UseIPv4",
    "fallbackStrategy": "disabled-if-any-match",
    "domainMatcher": "mph",
    "servers": [
      {
         "address": "aaa.bbb.ccc.ddd", // DNS from ISP
         "port": 53,
         "domains": [
           "geosite:cn"
         ],
         "tag": "dns-domestic"
      },
      {
         "address": "114.114.114.114", // 114 public DNS as backup
         "port": 53,
         "domains": [
           "geosite:cn"
         ],
         "tag": "dns-domestic-backup", //  <- WORKAROUND HERE
      },
      {
         "address": "https://1.1.1.1/dns-query", // Cloudflare DoH as default fallback
         "tag": "dns-international",
      }
    ]
  },
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "domainMatcher": "mph",
    "rules": [
      // omitted
      {
        "type": "field",
        "inboundTag": ["dns-domestic", "dns-domestic-backup"], // <- Don't forget to add tag here.
        "outboundTag": "direct"   // always direct sent domestic site DNS queries
      },
      {
        "type": "field",
        "inboundTag": "dns-international",
        "outboundTag": "proxy"  // proxy international cf DoH queries
      }
      // omitted
    ]
  }

// omitted
}

@Vigilans
Copy link
Contributor

Vigilans commented May 6, 2024

See it. I would seek some time to look into the code and propose a fix for it.

@Vigilans Vigilans linked a pull request May 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants