mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-07 08:13:39 +00:00
https://github.com/XTLS/Xray-core/pull/6853#issuecomment-5899791359 https://github.com/XTLS/Xray-core/pull/6853#issuecomment-5901287980 https://github.com/XTLS/Xray-core/pull/6853#issuecomment-5903680113 https://github.com/XTLS/Xray-core/pull/6853#issuecomment-5904123488 https://github.com/XTLS/Xray-core/pull/6853#issuecomment-5904647772 https://github.com/XTLS/Xray-core/pull/6853#issuecomment-5905047424 Fixes https://github.com/XTLS/Xray-core/issues/6454#issuecomment-5863800676 --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
952 B
Go
33 lines
952 B
Go
package internet
|
|
|
|
import (
|
|
"net/netip"
|
|
"slices"
|
|
"sync/atomic"
|
|
)
|
|
|
|
var skippedDNSServers atomic.Pointer[[]netip.Addr]
|
|
|
|
// SkipDNSServers has the queries Xray sends to the system's DNS servers on its
|
|
// own, like those of localdns, skip servers until it is called again. The DNS
|
|
// servers of a TUN are only meant for what goes through it: queried by Xray
|
|
// itself they lead back into it, or nowhere.
|
|
func SkipDNSServers(servers []netip.Addr) {
|
|
skipped := make([]netip.Addr, len(servers))
|
|
for i, server := range servers {
|
|
skipped[i] = server.Unmap()
|
|
}
|
|
skippedDNSServers.Store(&skipped)
|
|
}
|
|
|
|
// IsSkippedDNSServer reports whether address, a DNS server as host:port, is to
|
|
// be skipped, see SkipDNSServers.
|
|
func IsSkippedDNSServer(address string) bool {
|
|
skipped := skippedDNSServers.Load()
|
|
if skipped == nil {
|
|
return false
|
|
}
|
|
server, err := netip.ParseAddrPort(address)
|
|
return err == nil && slices.Contains(*skipped, server.Addr().Unmap())
|
|
}
|