mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
Allowing bootstrap IPs for ControlD sub-domains
So protocol which uses sub-domain like doq/dot could be bootstrap in case of no DNS available.
This commit is contained in:
committed by
Cuong Manh Le
parent
7dfb77228f
commit
8d6ea91f35
@@ -446,7 +446,7 @@ func (uc *UpstreamConfig) SetupBootstrapIP() {
|
|||||||
uc.bootstrapIPs = uc.bootstrapIPs[:n]
|
uc.bootstrapIPs = uc.bootstrapIPs[:n]
|
||||||
if len(uc.bootstrapIPs) == 0 {
|
if len(uc.bootstrapIPs) == 0 {
|
||||||
uc.bootstrapIPs = bootstrapIPsFromControlDDomain(uc.Domain)
|
uc.bootstrapIPs = bootstrapIPsFromControlDDomain(uc.Domain)
|
||||||
ProxyLogger.Load().Warn().Msgf("no bootstrap IPs found for %q, fallback to direct IPs", uc.Domain)
|
ProxyLogger.Load().Warn().Msgf("no record found for %q, lookup from direct IP table", uc.Domain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(uc.bootstrapIPs) > 0 {
|
if len(uc.bootstrapIPs) > 0 {
|
||||||
@@ -951,14 +951,14 @@ func (uc *UpstreamConfig) String() string {
|
|||||||
|
|
||||||
// bootstrapIPsFromControlDDomain returns bootstrap IPs for ControlD domain.
|
// bootstrapIPsFromControlDDomain returns bootstrap IPs for ControlD domain.
|
||||||
func bootstrapIPsFromControlDDomain(domain string) []string {
|
func bootstrapIPsFromControlDDomain(domain string) []string {
|
||||||
switch domain {
|
switch {
|
||||||
case PremiumDnsDomain:
|
case dns.IsSubDomain(PremiumDnsDomain, domain):
|
||||||
return []string{PremiumDNSBoostrapIP, PremiumDNSBoostrapIPv6}
|
return []string{PremiumDNSBoostrapIP, PremiumDNSBoostrapIPv6}
|
||||||
case FreeDnsDomain:
|
case dns.IsSubDomain(FreeDnsDomain, domain):
|
||||||
return []string{FreeDNSBoostrapIP, FreeDNSBoostrapIPv6}
|
return []string{FreeDNSBoostrapIP, FreeDNSBoostrapIPv6}
|
||||||
case premiumDnsDomainDev:
|
case dns.IsSubDomain(premiumDnsDomainDev, domain):
|
||||||
return []string{premiumDNSBoostrapIP, premiumDNSBoostrapIPv6}
|
return []string{premiumDNSBoostrapIP, premiumDNSBoostrapIPv6}
|
||||||
case freeDnsDomainDev:
|
case dns.IsSubDomain(freeDnsDomainDev, domain):
|
||||||
return []string{freeDNSBoostrapIP, freeDNSBoostrapIPv6}
|
return []string{freeDNSBoostrapIP, freeDNSBoostrapIPv6}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+34
-11
@@ -8,19 +8,42 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestUpstreamConfig_SetupBootstrapIP(t *testing.T) {
|
func TestUpstreamConfig_SetupBootstrapIP(t *testing.T) {
|
||||||
uc := &UpstreamConfig{
|
tests := []struct {
|
||||||
Name: "test",
|
name string
|
||||||
Type: ResolverTypeDOH,
|
uc *UpstreamConfig
|
||||||
Endpoint: "https://freedns.controld.com/p2",
|
}{
|
||||||
Timeout: 5000,
|
{
|
||||||
|
name: "doh/doh3",
|
||||||
|
uc: &UpstreamConfig{
|
||||||
|
Name: "doh",
|
||||||
|
Type: ResolverTypeDOH,
|
||||||
|
Endpoint: "https://freedns.controld.com/p2",
|
||||||
|
Timeout: 5000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "doq/dot",
|
||||||
|
uc: &UpstreamConfig{
|
||||||
|
Name: "dot",
|
||||||
|
Type: ResolverTypeDOT,
|
||||||
|
Endpoint: "p2.freedns.controld.com",
|
||||||
|
Timeout: 5000,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
uc.Init()
|
for _, tc := range tests {
|
||||||
uc.SetupBootstrapIP()
|
tc := tc
|
||||||
if len(uc.bootstrapIPs) == 0 {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
t.Log(defaultNameservers())
|
t.Parallel()
|
||||||
t.Fatal("could not bootstrap ip without bootstrap DNS")
|
tc.uc.Init()
|
||||||
|
tc.uc.SetupBootstrapIP()
|
||||||
|
if len(tc.uc.bootstrapIPs) == 0 {
|
||||||
|
t.Log(defaultNameservers())
|
||||||
|
t.Fatalf("could not bootstrap ip: %s", tc.uc.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
t.Log(uc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpstreamConfig_Init(t *testing.T) {
|
func TestUpstreamConfig_Init(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user