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

当前 master branch 的 DNS 缓存有问题(缓存 TypeA 结果包含了 IPv6 地址) #1232

Closed
Mukou-Aoi opened this issue Aug 25, 2021 · 1 comment · Fixed by #1235
Closed

Comments

@Mukou-Aoi
Copy link

Mukou-Aoi commented Aug 25, 2021

master branch ( 编译时最新 commit 67cd3ac )

$ nslookup www.qq.com. 127.0.0.2
Server:  UnKnown
Address:  127.0.0.2

Non-authoritative answer:
Name:    www.qq.com
Addresses:  IPv6::1
          IPv6::2
          4.0.0.1

$ nslookup www.qq.com. 127.0.0.2
Server:  UnKnown
Address:  127.0.0.2

Non-authoritative answer:
Name:    www.qq.com
Addresses:  IPv6::1
          IPv6::2
          4.0.0.1
          IPv6::1
          IPv6::2

log

  [Debug] app/dns: domain www.qq.com will use DNS in order: [UDP:223.5.5.5:53]
  [Debug] app/dns: UDP:223.5.5.5:53 querying DNS for: www.qq.com.
  [Info] app/dns: UDP:223.5.5.5:53 got answer: www.qq.com. TypeA -> [4.0.0.1] 22.0012ms
  [Debug] app/dns: UDP:223.5.5.5:53 updating IP records for domain:www.qq.com.
  [Debug] app/dns: domain www.qq.com will use DNS in order: [UDP:223.5.5.5:53]
  [Debug] app/dns: UDP:223.5.5.5:53 querying DNS for: www.qq.com.
  [Info] app/dns: UDP:223.5.5.5:53 got answer: www.qq.com. TypeAAAA -> [[IPv6::1] [IPv6::2]] 21.0012ms
  [Debug] app/dns: UDP:223.5.5.5:53 updating IP records for domain:www.qq.com.
  [Debug] app/dns: domain www.qq.com will use DNS in order: [UDP:223.5.5.5:53]
  [Debug] app/dns: UDP:223.5.5.5:53 cache HIT www.qq.com -> [4.0.0.1 IPv6::1 IPv6::2]
  [Debug] app/dns: domain www.qq.com will use DNS in order: [UDP:223.5.5.5:53]
  [Debug] app/dns: UDP:223.5.5.5:53 cache HIT www.qq.com -> [IPv6::1 IPv6::2]
  [Debug] app/dns: domain www.qq.com will use DNS in order: [UDP:223.5.5.5:53]
- [Debug] app/dns: UDP:223.5.5.5:53 cache HIT www.qq.com -> [4.0.0.1 IPv6::1 IPv6::2]
  [Debug] app/dns: domain www.qq.com will use DNS in order: [UDP:223.5.5.5:53]
  [Debug] app/dns: UDP:223.5.5.5:53 cache HIT www.qq.com -> [IPv6::1 IPv6::2]

Release v4.41.1 (正常)

$ nslookup www.qq.com.
Server:  UnKnown
Address:  127.1.1.1

Non-authoritative answer:
Name:    www.qq.com
Addresses:  IPv6::1
          IPv6::2
          4.0.0.1

$ nslookup www.qq.com.
Server:  UnKnown
Address:  127.1.1.1

Non-authoritative answer:
Name:    www.qq.com
Addresses:  IPv6::1
          IPv6::2
          4.0.0.1

log(Release 4.41.1)

  [Debug] app/dns: domain www.qq.com will use DNS in order: [UDP:223.5.5.5:53]
  [Debug] app/dns: UDP:223.5.5.5:53 querying DNS for: www.qq.com.
  [Info] app/dns: UDP:223.5.5.5:53 got answer: www.qq.com. TypeA -> [4.0.0.1] 26.0015ms
  [Debug] app/dns: UDP:223.5.5.5:53 updating IP records for domain:www.qq.com.
  [Debug] app/dns: domain www.qq.com will use DNS in order: [UDP:223.5.5.5:53]
  [Debug] app/dns: UDP:223.5.5.5:53 querying DNS for: www.qq.com.
  [Info] app/dns: UDP:223.5.5.5:53 got answer: www.qq.com. TypeAAAA -> [[IPv6::2] [IPv6::1]] 25.0014ms
  [Debug] app/dns: UDP:223.5.5.5:53 updating IP records for domain:www.qq.com.
  [Debug] app/dns: domain www.qq.com will use DNS in order: [UDP:223.5.5.5:53]
+ [Debug] app/dns: UDP:223.5.5.5:53 cache HIT www.qq.com -> [4.0.0.1]
  [Debug] app/dns: domain www.qq.com will use DNS in order: [UDP:223.5.5.5:53]
  [Debug] app/dns: UDP:223.5.5.5:53 cache HIT www.qq.com -> [IPv6::2 IPv6::1]
@Mukou-Aoi Mukou-Aoi changed the title 当前 master branch 的 DNS 缓存有问题(缓存 IPv4 结果包含了 IPv6 地址?) 当前 master branch 的 DNS 缓存有问题(缓存 TypeA 结果包含了 IPv6 地址) Aug 26, 2021
@digglife
Copy link
Contributor

这应该是 PR #1183 引入的一个 Bug,涉及到所有协议的 nameserver。

fallthrough语句会导致无论 option.IPv6Enable 是真是假, IPv6 地址都会加入到 ips 里。

switch {
case option.IPv4Enable:
ips, err4 = record.A.getIPs()
fallthrough
case option.IPv6Enable:
ip6, err6 = record.AAAA.getIPs()
ips = append(ips, ip6...)
}

所以如果查询 AAAA 记录只会获取到 IPv6,但是查询 A 记录会同时获取到 v4 和 v6。我也能复现这个问题。

cc @Loyalsoldier

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