mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-26 13:06:58 +00:00
TUN inbound: Add autoSystemWfpBlockLeak on Windows (blocks "dns" and "misconfigtun" IPv4/IPv6 traffic leaks outside the TUN); Rename autoSystemDNS to autoSystemDnsToGateway on Linux (and change some behaviors) (#6853)
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>
This commit is contained in:
committed by
RPRX
co-authored by
Claude Opus 5.5
parent
0086362663
commit
1f304916bd
@@ -0,0 +1,32 @@
|
||||
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())
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package internet_test
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"testing"
|
||||
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
)
|
||||
|
||||
func TestSkipDNSServers(t *testing.T) {
|
||||
internet.SkipDNSServers([]netip.Addr{netip.MustParseAddr("::ffff:203.0.113.53"), netip.MustParseAddr("2001:db8::53")})
|
||||
t.Cleanup(func() { internet.SkipDNSServers(nil) })
|
||||
for address, want := range map[string]bool{
|
||||
"203.0.113.53:53": true,
|
||||
"[2001:db8::53]:53": true,
|
||||
"198.51.100.53:53": false,
|
||||
"localhost:53": false,
|
||||
} {
|
||||
if got := internet.IsSkippedDNSServer(address); got != want {
|
||||
t.Errorf("IsSkippedDNSServer(%q) = %v, want %v", address, got, want)
|
||||
}
|
||||
}
|
||||
internet.SkipDNSServers(nil)
|
||||
if internet.IsSkippedDNSServer("203.0.113.53:53") {
|
||||
t.Error("still skipped after SkipDNSServers(nil)")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user