mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-16 13:17:19 +02:00
ff14fc8ac9
When IPv6 is available locally but the selected IPv6 DoH endpoint is unroutable (e.g. dialing [2606:1a40::22]:443 returns "no route to host" while IPv4 stays usable), ctrld re-bootstrapped and re-dialed the endpoint every ~2s. A weekend soak produced ~46.7k "no route to host" lines, with the dial/health-check loop dominating the log during bad windows. Add bounded backoff/suppression for network-unreachable endpoints at two levels: - ParallelDialer (internal/net): track dial addresses that fail with ENETUNREACH/EHOSTUNREACH and skip them for an exponentially growing, bounded window (5s -> 60s). A successful dial clears the entry immediately, so recovery is preserved when the route returns. When every candidate is suppressed the dial fails fast and quietly instead of hammering known-unroutable addresses. - Upstream recovery loop (cmd/cli): demote unreachable check failures to debug and back off the retry cadence (2s -> 60s) for an unreachable streak; any other failure resets to the base cadence. The new IsUnreachable classifier lives in internal/net and is reused by cmd/cli's errNetworkError, so the unreachable-errno matching has a single definition. Note the explicit winsock constants (10051/10065) are required on Windows: syscall.ENETUNREACH/EHOSTUNREACH are Go's portable "invented" values and never equal the raw WSA codes a failing connect surfaces. Suppression and backoff are always bounded, so IPv6 is never disabled until restart and recovers on its own once the route is back. Split-stack selection and the #549 macOS intercept recovery work are untouched. Adds unit tests for the classifier, the dialer's suppression tracker, and the recovery backoff schedule.
123 lines
3.6 KiB
Go
123 lines
3.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"sync/atomic"
|
|
"testing"
|
|
|
|
"github.com/Control-D-Inc/ctrld"
|
|
)
|
|
|
|
func withVPNDNSSettlingEnabled(t *testing.T) {
|
|
t.Helper()
|
|
old := vpnDNSSettlingEnabled
|
|
vpnDNSSettlingEnabled = true
|
|
t.Cleanup(func() { vpnDNSSettlingEnabled = old })
|
|
}
|
|
|
|
func TestVPNDNSRefreshSkipsConcurrentDuplicate(t *testing.T) {
|
|
m := newVPNDNSManager(&mainLog, nil)
|
|
started := make(chan struct{})
|
|
release := make(chan struct{})
|
|
done := make(chan struct{})
|
|
var once sync.Once
|
|
var calls atomic.Int32
|
|
|
|
m.discoverVPNDNS = func(context.Context) []ctrld.VPNDNSConfig {
|
|
calls.Add(1)
|
|
once.Do(func() { close(started) })
|
|
<-release
|
|
return nil
|
|
}
|
|
|
|
go func() {
|
|
defer close(done)
|
|
m.Refresh(context.Background(), true)
|
|
}()
|
|
|
|
<-started
|
|
m.Refresh(context.Background(), true)
|
|
close(release)
|
|
<-done
|
|
|
|
if calls.Load() != 1 {
|
|
t.Fatalf("expected overlapping refresh to be skipped, got %d discovery calls", calls.Load())
|
|
}
|
|
}
|
|
|
|
func TestVPNDNSRefreshRetainsStateForOneGuardedEmptyDiscovery(t *testing.T) {
|
|
withVPNDNSSettlingEnabled(t)
|
|
var gotExemptions []vpnDNSExemption
|
|
m := newVPNDNSManager(&mainLog, func(exemptions []vpnDNSExemption) error {
|
|
gotExemptions = exemptions
|
|
return nil
|
|
})
|
|
m.discoverVPNDNS = func(context.Context) []ctrld.VPNDNSConfig { return nil }
|
|
m.configs = []ctrld.VPNDNSConfig{{
|
|
InterfaceName: "Ethernet 6",
|
|
Servers: []string{"10.25.37.21", "10.25.37.22"},
|
|
}}
|
|
m.domainlessServers = []string{"10.25.37.21", "10.25.37.22"}
|
|
|
|
m.Refresh(context.Background(), true)
|
|
|
|
if got := m.DomainlessServers(); len(got) != 2 {
|
|
t.Fatalf("expected retained domainless servers, got %v", got)
|
|
}
|
|
if len(gotExemptions) != 2 {
|
|
t.Fatalf("expected retained exemptions to be re-applied, got %v", gotExemptions)
|
|
}
|
|
if !m.retainedAfterEmptyDiscovery {
|
|
t.Fatal("expected empty discovery retention to be marked")
|
|
}
|
|
}
|
|
|
|
func TestVPNDNSRefreshClearsOnSecondGuardedEmptyDiscovery(t *testing.T) {
|
|
withVPNDNSSettlingEnabled(t)
|
|
var gotExemptions []vpnDNSExemption
|
|
m := newVPNDNSManager(&mainLog, func(exemptions []vpnDNSExemption) error {
|
|
gotExemptions = exemptions
|
|
return nil
|
|
})
|
|
m.discoverVPNDNS = func(context.Context) []ctrld.VPNDNSConfig { return nil }
|
|
m.configs = []ctrld.VPNDNSConfig{{
|
|
InterfaceName: "Ethernet 6",
|
|
Servers: []string{"10.25.37.21"},
|
|
}}
|
|
m.domainlessServers = []string{"10.25.37.21"}
|
|
m.retainedAfterEmptyDiscovery = true
|
|
|
|
m.Refresh(context.Background(), true)
|
|
|
|
if got := m.DomainlessServers(); len(got) != 0 {
|
|
t.Fatalf("expected domainless servers to be cleared on second empty discovery, got %v", got)
|
|
}
|
|
if len(gotExemptions) != 0 {
|
|
t.Fatalf("expected empty exemptions after clearing stale state, got %v", gotExemptions)
|
|
}
|
|
if m.retainedAfterEmptyDiscovery {
|
|
t.Fatal("expected retained empty-discovery marker to be cleared with stale state")
|
|
}
|
|
}
|
|
|
|
func TestVPNDNSTransportFailureSuppressesFallbackOnlyWhileRetainingState(t *testing.T) {
|
|
withVPNDNSSettlingEnabled(t)
|
|
m := newVPNDNSManager(&mainLog, nil)
|
|
m.domainlessServers = []string{"10.25.37.21"}
|
|
|
|
if m.ShouldFailClosedAfterVPNDNSTransportFailure("splunk.aws.arena.net.", []string{"10.25.37.21"}) {
|
|
t.Fatal("did not expect transport failure to suppress OS fallback outside retained empty-discovery state")
|
|
}
|
|
|
|
m.retainedAfterEmptyDiscovery = true
|
|
if !m.ShouldFailClosedAfterVPNDNSTransportFailure("splunk.aws.arena.net.", []string{"10.25.37.21"}) {
|
|
t.Fatal("expected transport failure to suppress OS fallback while retained state is active")
|
|
}
|
|
|
|
m.VPNDNSReachable()
|
|
if m.retainedAfterEmptyDiscovery {
|
|
t.Fatal("expected reachable DNS response to clear retained empty-discovery state")
|
|
}
|
|
}
|