mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-10 13:20:33 +02:00
Ignoring RFC 1918 addresses for ControlD upstream
This commit is contained in:
@@ -343,9 +343,23 @@ func (uc *UpstreamConfig) SetupBootstrapIP() {
|
|||||||
// SetupBootstrapIP manually find all available IPs of the upstream.
|
// SetupBootstrapIP manually find all available IPs of the upstream.
|
||||||
// The first usable IP will be used as bootstrap IP of the upstream.
|
// The first usable IP will be used as bootstrap IP of the upstream.
|
||||||
func (uc *UpstreamConfig) setupBootstrapIP(withBootstrapDNS bool) {
|
func (uc *UpstreamConfig) setupBootstrapIP(withBootstrapDNS bool) {
|
||||||
b := backoff.NewBackoff("setupBootstrapIP", func(format string, args ...any) {}, 2*time.Second)
|
b := backoff.NewBackoff("setupBootstrapIP", func(format string, args ...any) {}, 10*time.Second)
|
||||||
|
isControlD := uc.isControlD()
|
||||||
for {
|
for {
|
||||||
uc.bootstrapIPs = lookupIP(uc.Domain, uc.Timeout, withBootstrapDNS)
|
uc.bootstrapIPs = lookupIP(uc.Domain, uc.Timeout, withBootstrapDNS)
|
||||||
|
// For ControlD upstream, the bootstrap IPs could not be RFC 1918 addresses,
|
||||||
|
// filtering them out here to prevent weird behavior.
|
||||||
|
if isControlD {
|
||||||
|
n := 0
|
||||||
|
for _, ip := range uc.bootstrapIPs {
|
||||||
|
netIP := net.ParseIP(ip)
|
||||||
|
if netIP != nil && !netIP.IsPrivate() {
|
||||||
|
uc.bootstrapIPs[n] = ip
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uc.bootstrapIPs = uc.bootstrapIPs[:n]
|
||||||
|
}
|
||||||
if len(uc.bootstrapIPs) > 0 {
|
if len(uc.bootstrapIPs) > 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -177,12 +177,12 @@ func lookupIP(domain string, timeout int, withBootstrapDNS bool) (ips []string)
|
|||||||
ipFromRecord := func(record dns.RR, target string) string {
|
ipFromRecord := func(record dns.RR, target string) string {
|
||||||
switch ar := record.(type) {
|
switch ar := record.(type) {
|
||||||
case *dns.A:
|
case *dns.A:
|
||||||
if ar.Hdr.Name != target {
|
if ar.Hdr.Name != target || len(ar.A) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return ar.A.String()
|
return ar.A.String()
|
||||||
case *dns.AAAA:
|
case *dns.AAAA:
|
||||||
if ar.Hdr.Name != target {
|
if ar.Hdr.Name != target || len(ar.AAAA) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return ar.AAAA.String()
|
return ar.AAAA.String()
|
||||||
|
|||||||
Reference in New Issue
Block a user