mirror of
https://github.com/coredns/coredns.git
synced 2025-11-02 02:03:13 -05:00
And make it actually work (#508)
This commit is contained in:
@@ -126,13 +126,7 @@ func (g *google) OnStartup(p *Proxy) error {
|
|||||||
|
|
||||||
new, err := g.bootstrapProxy.Lookup(state, g.endpoint, dns.TypeA)
|
new, err := g.bootstrapProxy.Lookup(state, g.endpoint, dns.TypeA)
|
||||||
|
|
||||||
oldUpstream := *p.Upstreams
|
var oldUpstream Upstream
|
||||||
oldFrom := ""
|
|
||||||
var oldEx Exchanger
|
|
||||||
if len(oldUpstream) > 0 {
|
|
||||||
oldFrom = oldUpstream[0].From()
|
|
||||||
oldEx = oldUpstream[0].Exchanger()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignore errors here, as we want to keep on trying.
|
// ignore errors here, as we want to keep on trying.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -143,8 +137,13 @@ func (g *google) OnStartup(p *Proxy) error {
|
|||||||
log.Printf("[WARNING] Failed to bootstrap A records %q: %s", g.endpoint, err)
|
log.Printf("[WARNING] Failed to bootstrap A records %q: %s", g.endpoint, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
up := newUpstream(addrs, oldFrom, oldEx)
|
if len(*p.Upstreams) > 0 {
|
||||||
p.Upstreams = &[]Upstream{up}
|
oldUpstream = (*p.Upstreams)[0]
|
||||||
|
up := newUpstream(addrs, oldUpstream.(*staticUpstream))
|
||||||
|
p.Upstreams = &[]Upstream{up}
|
||||||
|
} else {
|
||||||
|
log.Printf("[WARNING] Failed to bootstrap upstreams %q", g.endpoint)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -164,8 +163,11 @@ func (g *google) OnStartup(p *Proxy) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
up := newUpstream(addrs, oldFrom, oldEx)
|
// TODO(miek): can this actually happen?
|
||||||
p.Upstreams = &[]Upstream{up}
|
if oldUpstream != nil {
|
||||||
|
up := newUpstream(addrs, oldUpstream.(*staticUpstream))
|
||||||
|
p.Upstreams = &[]Upstream{up}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-g.quit:
|
case <-g.quit:
|
||||||
@@ -195,15 +197,17 @@ func extractAnswer(m *dns.Msg) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newUpstream returns an upstream initialized with hosts.
|
// newUpstream returns an upstream initialized with hosts.
|
||||||
func newUpstream(hosts []string, from string, ex Exchanger) Upstream {
|
func newUpstream(hosts []string, old *staticUpstream) Upstream {
|
||||||
upstream := &staticUpstream{
|
upstream := &staticUpstream{
|
||||||
from: from,
|
from: old.from,
|
||||||
Hosts: nil,
|
Hosts: nil,
|
||||||
Policy: &Random{},
|
Policy: &Random{},
|
||||||
Spray: nil,
|
Spray: nil,
|
||||||
FailTimeout: 10 * time.Second,
|
FailTimeout: 10 * time.Second,
|
||||||
MaxFails: 3,
|
MaxFails: 3,
|
||||||
ex: ex,
|
ex: old.ex,
|
||||||
|
WithoutPathPrefix: old.WithoutPathPrefix,
|
||||||
|
IgnoredSubDomains: old.IgnoredSubDomains,
|
||||||
}
|
}
|
||||||
|
|
||||||
upstream.Hosts = make([]*UpstreamHost, len(hosts))
|
upstream.Hosts = make([]*UpstreamHost, len(hosts))
|
||||||
|
|||||||
@@ -281,11 +281,11 @@ func (u *staticUpstream) Select() *UpstreamHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *staticUpstream) IsAllowedDomain(name string) bool {
|
func (u *staticUpstream) IsAllowedDomain(name string) bool {
|
||||||
for _, ignoredSubDomain := range u.IgnoredSubDomains {
|
if dns.Name(name) == dns.Name(u.From()) {
|
||||||
if dns.Name(name) == dns.Name(u.From()) {
|
return true
|
||||||
return true
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
for _, ignoredSubDomain := range u.IgnoredSubDomains {
|
||||||
if middleware.Name(ignoredSubDomain).Matches(name) {
|
if middleware.Name(ignoredSubDomain).Matches(name) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user