mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
Ignore local addresses for OS resolver
Otherwise, DNS loop may be triggered if requests are forwarded from ctrld to OS resolver.
This commit is contained in:
committed by
Cuong Manh Le
parent
e88372fc8c
commit
cb14992ddc
@@ -58,7 +58,16 @@ func defaultNameservers() []string {
|
|||||||
// calling this function.
|
// calling this function.
|
||||||
func InitializeOsResolver() []string {
|
func InitializeOsResolver() []string {
|
||||||
or.nameservers = or.nameservers[:0]
|
or.nameservers = or.nameservers[:0]
|
||||||
|
// Ignore local addresses to prevent loop.
|
||||||
|
regularIPs, loopbackIPs, _ := netmon.LocalAddresses()
|
||||||
|
machineIPsMap := make(map[string]struct{}, len(regularIPs))
|
||||||
|
for _, v := range slices.Concat(regularIPs, loopbackIPs) {
|
||||||
|
machineIPsMap[net.JoinHostPort(v.String(), "53")] = struct{}{}
|
||||||
|
}
|
||||||
for _, ns := range defaultNameservers() {
|
for _, ns := range defaultNameservers() {
|
||||||
|
if _, ok := machineIPsMap[ns]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if testNameserver(ns) {
|
if testNameserver(ns) {
|
||||||
or.nameservers = append(or.nameservers, ns)
|
or.nameservers = append(or.nameservers, ns)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user