all: add UpstreamConfig.VerifyDomain

So the self-check process is only done for ControlD upstream, and can be
distinguished between .com and .dev resolvers.
This commit is contained in:
Cuong Manh Le
2023-05-26 21:33:24 +07:00
committed by Cuong Manh Le
parent 54e63ccf9b
commit 8fda856e24
4 changed files with 76 additions and 9 deletions
+28 -1
View File
@@ -29,9 +29,19 @@ const (
IpStackV4 = "v4"
IpStackV6 = "v6"
IpStackSplit = "split"
controlDComDomain = "controld.com"
controlDNetDomain = "controld.net"
controlDDevDomain = "controld.dev"
)
var controldParentDomains = []string{"controld.com", "controld.net", "controld.dev"}
var (
controldParentDomains = []string{controlDComDomain, controlDNetDomain, controlDDevDomain}
controldVerifiedDomain = map[string]string{
controlDComDomain: "verify.controld.com",
controlDDevDomain: "verify.controld.dev",
}
)
// SetConfigName set the config name that ctrld will look for.
// DEPRECATED: use SetConfigNameWithPath instead.
@@ -201,6 +211,23 @@ func (uc *UpstreamConfig) Init() {
}
}
// VerifyDomain returns the domain name that could be resolved by the upstream endpoint.
// It returns empty for non-ControlD upstream endpoint.
func (uc *UpstreamConfig) VerifyDomain() string {
domain := uc.Domain
if domain == "" {
if u, err := url.Parse(uc.Endpoint); err == nil {
domain = u.Hostname()
}
}
for _, parent := range controldParentDomains {
if dns.IsSubDomain(parent, domain) {
return controldVerifiedDomain[parent]
}
}
return ""
}
// UpstreamSendClientInfo reports whether the upstream is
// configured to send client info to Control D DNS server.
//