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.
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package ctrld
|
|
|
|
import (
|
|
"net"
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
func parseDHCPOptionNameservers(output []byte) []string {
|
|
return parseIPv4Nameservers(string(output))
|
|
}
|
|
|
|
func parseDHCPPacketNameservers(output []byte) []string {
|
|
for _, line := range strings.Split(string(output), "\n") {
|
|
field := strings.TrimSpace(line)
|
|
if strings.HasPrefix(field, "domain_name_server ") ||
|
|
strings.HasPrefix(field, "domain_name_server:") ||
|
|
strings.HasPrefix(field, "domain_name_servers ") ||
|
|
strings.HasPrefix(field, "domain_name_servers:") {
|
|
return parseIPv4Nameservers(field)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func parseIPv4Nameservers(value string) []string {
|
|
seen := make(map[string]struct{})
|
|
var nameservers []string
|
|
for _, token := range strings.FieldsFunc(value, func(r rune) bool {
|
|
return r != '.' && !unicode.IsDigit(r)
|
|
}) {
|
|
ip := net.ParseIP(token)
|
|
if ip == nil || ip.To4() == nil {
|
|
continue
|
|
}
|
|
ns := ip.String()
|
|
if _, ok := seen[ns]; ok {
|
|
continue
|
|
}
|
|
seen[ns] = struct{}{}
|
|
nameservers = append(nameservers, ns)
|
|
}
|
|
return nameservers
|
|
}
|