mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-09-04 13:36:35 +02:00
macOS intercept mode fails totally on networks that provide no usable IPv4 DNS (e.g. IPv6-only iPhone tethering with 464XLAT): the pf ruleset blocks all outbound IPv6 port 53, and with no IPv4 DNS configured mDNSResponder emits no DNS packets at all, so pf has nothing to intercept while the Control D upstream stays provably healthy. When network-change recovery discovers no usable IPv4 DNS on the default-route service, set 127.0.0.1 as that service DNS so macOS can emit queries that land directly on the listener. The entry is removed when the network regains IPv4 DNS and on intercept shutdown; networks that provide IPv4 DNS are never modified. Runs on the already-debounced recovery path so interface flaps do not churn networksetup. Also fix the canceled-recovery state leak: the cancellation early return never reset recoveryBypass/recoveryRunning, so a flap burst ending in a canceled recovery left the daemon in bypass forever with the DNS watchdog disabled. Cleanup is generation-gated so a superseded recovery never clears state owned by its successor.
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package ctrld
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseDHCPOptionNameservers(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
output string
|
|
want []string
|
|
}{
|
|
{"single", "192.168.10.1\n", []string{"192.168.10.1"}},
|
|
{"multiple", "192.168.10.1\n1.1.1.1\n", []string{"192.168.10.1", "1.1.1.1"}},
|
|
{"deduplicate and reject invalid", "192.168.10.1 999.1.1.1 192.168.10.1", []string{"192.168.10.1"}},
|
|
{"empty", "", nil},
|
|
}
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if got := parseDHCPOptionNameservers([]byte(tc.output)); !slices.Equal(got, tc.want) {
|
|
t.Fatalf("parseDHCPOptionNameservers() = %v, want %v", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseDHCPPacketNameservers(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
output string
|
|
want []string
|
|
}{
|
|
{
|
|
name: "macos singular ip_mult",
|
|
output: `op = BOOTREPLY
|
|
` +
|
|
`yiaddr = 192.168.10.155
|
|
` +
|
|
`domain_name_server (ip_mult): {192.168.10.1, 1.1.1.1}
|
|
` +
|
|
`server_identifier (ip): 192.168.10.1
|
|
`,
|
|
want: []string{"192.168.10.1", "1.1.1.1"},
|
|
},
|
|
{
|
|
name: "legacy plural equals",
|
|
output: "domain_name_servers = 192.168.1.1 8.8.8.8;\n",
|
|
want: []string{"192.168.1.1", "8.8.8.8"},
|
|
},
|
|
{
|
|
name: "packet addresses without option are ignored",
|
|
output: "yiaddr = 192.168.10.155\nserver_identifier (ip): 192.168.10.1\n",
|
|
want: nil,
|
|
},
|
|
}
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if got := parseDHCPPacketNameservers([]byte(tc.output)); !slices.Equal(got, tc.want) {
|
|
t.Fatalf("parseDHCPPacketNameservers() = %v, want %v", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|