2026-03-04 16:41:54 -05:00
|
|
|
package resolver
|
|
|
|
|
|
2026-03-04 17:03:30 -05:00
|
|
|
import "ekdns/platform"
|
2026-03-04 16:41:54 -05:00
|
|
|
|
|
|
|
|
// BuildResolverPool constructs the ordered list of DNS resolver addresses for
|
|
|
|
|
// the given ServerMode and discovered NetworkInfo.
|
|
|
|
|
//
|
|
|
|
|
// Modes:
|
|
|
|
|
// - "default" → local DNS servers + bootstrap resolvers (deduplicated, local first)
|
|
|
|
|
// - "local" → only the local DNS servers from NetworkInfo.DNSServers
|
|
|
|
|
// - "gateway" → only NetworkInfo.Gateway
|
|
|
|
|
// - "explicit" → only ServerMode.ExplicitAddr
|
|
|
|
|
//
|
|
|
|
|
// Returns nil for unknown modes. Callers should validate that the pool is
|
|
|
|
|
// non-empty before proceeding (e.g. gateway mode with no discovered gateway).
|
|
|
|
|
func BuildResolverPool(mode ServerMode, info platform.NetworkInfo) []string {
|
|
|
|
|
switch mode.Mode {
|
|
|
|
|
case "default":
|
|
|
|
|
seen := make(map[string]bool, len(info.DNSServers)+len(BootstrapResolvers))
|
|
|
|
|
pool := make([]string, 0, len(info.DNSServers)+len(BootstrapResolvers))
|
|
|
|
|
|
|
|
|
|
for _, r := range info.DNSServers {
|
|
|
|
|
if !seen[r] {
|
|
|
|
|
seen[r] = true
|
|
|
|
|
pool = append(pool, r)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, r := range BootstrapResolvers {
|
|
|
|
|
if !seen[r] {
|
|
|
|
|
seen[r] = true
|
|
|
|
|
pool = append(pool, r)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return pool
|
|
|
|
|
|
|
|
|
|
case "local":
|
|
|
|
|
return info.DNSServers
|
|
|
|
|
|
|
|
|
|
case "gateway":
|
|
|
|
|
return []string{info.Gateway}
|
|
|
|
|
|
|
|
|
|
case "explicit":
|
|
|
|
|
return []string{mode.ExplicitAddr}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|