Feature: add support for dns search domains (#2597)
This commit is contained in:
@ -69,6 +69,7 @@ type DNS struct {
|
||||
FakeIPRange *fakeip.Pool
|
||||
Hosts *trie.DomainTrie
|
||||
NameServerPolicy map[string]dns.NameServer
|
||||
SearchDomains []string
|
||||
}
|
||||
|
||||
// FallbackFilter config
|
||||
@ -117,6 +118,7 @@ type RawDNS struct {
|
||||
FakeIPFilter []string `yaml:"fake-ip-filter"`
|
||||
DefaultNameserver []string `yaml:"default-nameserver"`
|
||||
NameServerPolicy map[string]string `yaml:"nameserver-policy"`
|
||||
SearchDomains []string `yaml:"search-domains"`
|
||||
}
|
||||
|
||||
type RawFallbackFilter struct {
|
||||
@ -702,6 +704,18 @@ func parseDNS(rawCfg *RawConfig, hosts *trie.DomainTrie) (*DNS, error) {
|
||||
dnsCfg.Hosts = hosts
|
||||
}
|
||||
|
||||
if len(cfg.SearchDomains) != 0 {
|
||||
for _, domain := range cfg.SearchDomains {
|
||||
if strings.HasPrefix(domain, ".") || strings.HasSuffix(domain, ".") {
|
||||
return nil, errors.New("search domains should not start or end with '.'")
|
||||
}
|
||||
if strings.Contains(domain, ":") {
|
||||
return nil, errors.New("search domains are for ipv4 only and should not contain ports")
|
||||
}
|
||||
}
|
||||
dnsCfg.SearchDomains = cfg.SearchDomains
|
||||
}
|
||||
|
||||
return dnsCfg, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user