mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
On Linux the module's upstream, bootstrap and health-check sockets carry SO_MARK 0x80, which the transparent-proxy rules exempt. Windows and macOS have no mark: once a TUN holds the default route, those sockets would send the module's own queries into the TUN, where the core's port-53 interception hands them straight back to the module. The module config gains egress_interface; when set, every dialer created by newMarkedDnsClient binds to it with IP_UNICAST_IF / IPV6_UNICAST_IF on Windows and IP_BOUND_IF / IPV6_BOUND_IF on macOS. Unset, the dialers are unchanged, and Linux keeps the mark. The darwin and windows tests dial through the dialer and read the option back; they run on those platforms. The interface lookup itself is tested everywhere.
33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
//go:build !windows
|
|
|
|
package dns
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// On Unix, markedDialer() sets Dialer.Control so every socket created by the
|
|
// dialer carries SO_MARK=0x80 (the fwmark that makes iptables skip the DNS
|
|
// redirect rules). Without Control the upstream queries would be hijacked
|
|
// back into this module — an infinite loop and unbounded memory growth.
|
|
// Windows and macOS have no SO_MARK; their Control binds the socket to the
|
|
// egress interface instead (IP_UNICAST_IF, IP_BOUND_IF), so these
|
|
// assertions are platform-specific and live in a !windows file.
|
|
func TestMarkedDnsClientHasControl(t *testing.T) {
|
|
udpClient := newMarkedDnsClient("udp")
|
|
if udpClient.Dialer == nil {
|
|
t.Fatal("Dialer is nil")
|
|
}
|
|
if udpClient.Dialer.Control == nil {
|
|
t.Error("Dialer.Control is nil — UDP sockets would not carry SO_MARK=0x80 and queries could loop back into the DNS module")
|
|
}
|
|
|
|
tcpClient := newMarkedDnsClient("tcp")
|
|
if tcpClient.Dialer == nil {
|
|
t.Fatal("Dialer is nil")
|
|
}
|
|
if tcpClient.Dialer.Control == nil {
|
|
t.Error("Dialer.Control is nil — TCP sockets would not carry SO_MARK=0x80")
|
|
}
|
|
}
|