Closed yvvw closed 4 months ago
最近遇到了一点问题 https://github.com/xiaorouji/openwrt-passwall/issues/2960 我比较好奇的是,为什么 Sing-Box DNS 的响应会比 dns2tcp/Xray DNS 大很多?
Sing-Box DNS
root@OpenWrt:~# dig www.youtube.com -p 15353
;; Truncated, retrying in TCP mode.
; <<>> DiG 9.18.24 <<>> www.youtube.com -p 15353
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48655
;; flags: qr rd ra; QUERY: 1, ANSWER: 17, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; MBZ: 0x0072, udp: 1232
;; QUESTION SECTION:
;www.youtube.com. IN A
;; ANSWER SECTION:
www.youtube.com. 114 IN CNAME youtube-ui.l.google.com.
youtube-ui.l.google.com. 114 IN A 172.217.25.14
youtube-ui.l.google.com. 114 IN A 142.250.66.46
youtube-ui.l.google.com. 114 IN A 142.250.66.110
youtube-ui.l.google.com. 114 IN A 142.250.204.110
youtube-ui.l.google.com. 114 IN A 142.250.66.78
youtube-ui.l.google.com. 114 IN A 142.250.207.78
youtube-ui.l.google.com. 114 IN A 172.217.24.238
youtube-ui.l.google.com. 114 IN A 142.250.204.46
youtube-ui.l.google.com. 114 IN A 172.217.27.46
youtube-ui.l.google.com. 114 IN A 172.217.24.110
youtube-ui.l.google.com. 114 IN A 142.250.204.78
youtube-ui.l.google.com. 114 IN A 142.250.199.78
youtube-ui.l.google.com. 114 IN A 142.251.222.206
youtube-ui.l.google.com. 114 IN A 142.250.66.142
youtube-ui.l.google.com. 114 IN A 172.217.31.14
youtube-ui.l.google.com. 114 IN A 172.217.27.14
;; Query time: 29 msec
;; SERVER: 127.0.0.1#15353(127.0.0.1) (TCP)
;; WHEN: Sat Feb 24 02:05:13 CST 2024
;; MSG SIZE rcvd: 720
dns2tcp
root@OpenWrt:~# dig www.youtube.com -p 15353
; <<>> DiG 9.18.24 <<>> www.youtube.com -p 15353
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7423
;; flags: qr rd ra; QUERY: 1, ANSWER: 17, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;www.youtube.com. IN A
;; ANSWER SECTION:
www.youtube.com. 86 IN CNAME youtube-ui.l.google.com.
youtube-ui.l.google.com. 86 IN A 142.250.204.142
youtube-ui.l.google.com. 86 IN A 142.250.204.46
youtube-ui.l.google.com. 86 IN A 172.217.24.78
youtube-ui.l.google.com. 86 IN A 142.250.204.78
youtube-ui.l.google.com. 86 IN A 216.58.200.238
youtube-ui.l.google.com. 86 IN A 172.217.27.46
youtube-ui.l.google.com. 86 IN A 142.250.204.110
youtube-ui.l.google.com. 86 IN A 142.251.220.46
youtube-ui.l.google.com. 86 IN A 172.217.31.14
youtube-ui.l.google.com. 86 IN A 172.217.25.14
youtube-ui.l.google.com. 86 IN A 172.217.24.238
youtube-ui.l.google.com. 86 IN A 172.217.27.14
youtube-ui.l.google.com. 86 IN A 172.217.24.110
youtube-ui.l.google.com. 86 IN A 216.58.203.78
youtube-ui.l.google.com. 86 IN A 142.251.220.14
youtube-ui.l.google.com. 86 IN A 142.250.199.78
;; Query time: 59 msec
;; SERVER: 127.0.0.1#15353(127.0.0.1) (UDP)
;; WHEN: Sat Feb 24 02:17:57 CST 2024
;; MSG SIZE rcvd: 334
Xray DNS
root@OpenWrt:~# dig www.youtube.com -p 15353
; <<>> DiG 9.18.24 <<>> www.youtube.com -p 15353
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13693
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 16, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.youtube.com. IN A
;; ANSWER SECTION:
www.youtube.com. 600 IN A 142.250.199.78
www.youtube.com. 600 IN A 172.217.24.238
www.youtube.com. 600 IN A 172.217.24.78
www.youtube.com. 600 IN A 142.250.204.110
www.youtube.com. 600 IN A 142.250.204.46
www.youtube.com. 600 IN A 142.250.207.78
www.youtube.com. 600 IN A 142.250.204.78
www.youtube.com. 600 IN A 172.217.27.46
www.youtube.com. 600 IN A 172.217.31.14
www.youtube.com. 600 IN A 142.250.204.142
www.youtube.com. 600 IN A 172.217.24.110
www.youtube.com. 600 IN A 216.58.200.238
www.youtube.com. 600 IN A 172.217.25.14
www.youtube.com. 600 IN A 216.58.203.78
www.youtube.com. 600 IN A 172.217.27.14
www.youtube.com. 600 IN A 142.250.66.142
;; Query time: 0 msec
;; SERVER: 127.0.0.1#15353(127.0.0.1) (UDP)
;; WHEN: Sat Feb 24 14:46:15 CST 2024
;; MSG SIZE rcvd: 289
@mm11253 sing-box没有对dns响应体进行压缩,可能出于性能考虑,目前还没选项进行设置,还在等开发者回复 https://github.com/SagerNet/sing-box/pull/1442
@mm11253 sing-box没有对dns响应体进行压缩,可能出于性能考虑,目前还没选项进行设置,还在等开发者回复 #1442
引用隔壁 ChinaDNS-NG 作者的回复 https://github.com/zfl9/chinadns-ng/issues/144#issuecomment-1962291623
拒绝连接是因为 chinadns-ng 目前还没实施 tcp 监听。用 zig 重写的 1.0/2.0 版本已经加入 tcp 支持了。
结合你引用的几个 issue 推测,有这几方面的原因:
所以压缩还是有必要的吧
Still in Todo.
https://www.rfc-editor.org/rfc/rfc2671 https://www.rfc-editor.org/rfc/rfc1035
I gotcha, but I reckon compressing the response takes precedence over customizing the UDP buffer size.
应已在最新版本修复。
Most DNS related issues had been fixed. but DNS response still not compressed by default? Even when the request buffer size larger than 512 bytes it should try to get the response under 512 bytes. The 512 bytes guarantees the DNS packets can be reassembled if fragmented in the transit.
The first one from dnsmasq which is also hijacked by singbox.
root@sam46:~# kdig www.youtube.com
;; ->>HEADER<<- opcode: QUERY; status: NOERROR; id: 43430
;; Flags: qr rd ra; QUERY: 1; ANSWER: 17; AUTHORITY: 0; ADDITIONAL: 0
;; QUESTION SECTION:
;; www.youtube.com. IN A
;; ANSWER SECTION:
www.youtube.com. 1794 IN CNAME youtube-ui.l.google.com.
youtube-ui.l.google.com. 1794 IN A 64.233.170.93
youtube-ui.l.google.com. 1794 IN A 64.233.170.190
youtube-ui.l.google.com. 1794 IN A 142.251.175.190
youtube-ui.l.google.com. 1794 IN A 142.251.175.91
youtube-ui.l.google.com. 1794 IN A 142.251.175.136
youtube-ui.l.google.com. 1794 IN A 142.251.175.93
youtube-ui.l.google.com. 1794 IN A 74.125.24.190
youtube-ui.l.google.com. 1794 IN A 74.125.24.93
youtube-ui.l.google.com. 1794 IN A 74.125.24.136
youtube-ui.l.google.com. 1794 IN A 74.125.130.136
youtube-ui.l.google.com. 1794 IN A 74.125.68.136
youtube-ui.l.google.com. 1794 IN A 74.125.68.190
youtube-ui.l.google.com. 1794 IN A 74.125.68.93
youtube-ui.l.google.com. 1794 IN A 74.125.68.91
youtube-ui.l.google.com. 1794 IN A 64.233.170.91
youtube-ui.l.google.com. 1794 IN A 64.233.170.136
;; Received 326 B
;; Time 2024-02-29 17:41:50 WITA
;; From 127.0.0.1@53(UDP) in 0.6 ms
root@sam46:~# kdig www.youtube.com @1.1.1.1
;; ->>HEADER<<- opcode: QUERY; status: NOERROR; id: 23934
;; Flags: qr rd ra; QUERY: 1; ANSWER: 17; AUTHORITY: 0; ADDITIONAL: 0
;; QUESTION SECTION:
;; www.youtube.com. IN A
;; ANSWER SECTION:
www.youtube.com. 300 IN CNAME youtube-ui.l.google.com.
youtube-ui.l.google.com. 300 IN A 64.233.170.91
youtube-ui.l.google.com. 300 IN A 64.233.170.136
youtube-ui.l.google.com. 300 IN A 64.233.170.93
youtube-ui.l.google.com. 300 IN A 64.233.170.190
youtube-ui.l.google.com. 300 IN A 142.251.175.190
youtube-ui.l.google.com. 300 IN A 142.251.175.91
youtube-ui.l.google.com. 300 IN A 142.251.175.136
youtube-ui.l.google.com. 300 IN A 142.251.175.93
youtube-ui.l.google.com. 300 IN A 74.125.24.190
youtube-ui.l.google.com. 300 IN A 74.125.24.93
youtube-ui.l.google.com. 300 IN A 74.125.24.136
youtube-ui.l.google.com. 300 IN A 74.125.130.136
youtube-ui.l.google.com. 300 IN A 74.125.68.136
youtube-ui.l.google.com. 300 IN A 74.125.68.190
youtube-ui.l.google.com. 300 IN A 74.125.68.93
youtube-ui.l.google.com. 300 IN A 74.125.68.91
;; Received 709 B
;; Time 2024-02-29 17:41:57 WITA
;; From 1.1.1.1@53(UDP) in 150.9 ms
Looking at popular DNS solution like blocky and adguardhome it force enable compression. Maybe we should follow that?
diff --git a/client_truncate.go b/client_truncate.go
index a0b4afd..90cf3dd 100644
--- a/client_truncate.go
+++ b/client_truncate.go
@@ -14,6 +14,7 @@ func TruncateDNSMessage(request *dns.Msg, response *dns.Msg, frontHeadroom int)
}
}
response.Truncate(maxLen)
+ response.Compress = true
buffer := buf.NewSize(frontHeadroom + 1 + maxLen)
buffer.Resize(frontHeadroom, 0)
rawMessage, err := response.PackBuffer(buffer.FreeBytes())
https://github.com/MetaCubeX/mihomo/blob/7eb16a098a92e43c4a8871c0103d670462252bbc/dns/server.go#L35
这种情况不是应该用TCP重传吗?为啥要改UDP响应?
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days
Operating system
Linux
System version
openwrt 23.05
Installation type
Original sing-box Command Line
If you are using a graphical client, please provide the version of the client.
No response
Version
Description
在 17aebc5 对 cn-beijing-data.aliyundrive.net 这类响应超出 512B 的域名进行修复后,又出现 api.aliyundrive.com 连续AAAA记录,最后一个A类记录IP信息,由于sing-box DNS响应没有进行压缩,导致这类地址被截断后拿不到ip信息。我猜测压缩会影响处理性能,但又觉得能正确处理更重要些,是否可以在超出限制的情况下尝试压缩再去截取那。
Reproduction
如上
Logs
No response
Integrity requirements