Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Resolve unqualified domains in the weave.local domain.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wilkie committed Jul 14, 2015
1 parent 932687a commit d46301c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions nameserver/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ func (d *DNSServer) handleLocal(defaultMaxResponseSize int) func(dns.ResponseWri
return
}

hostname := req.Question[0].Name
hostname := dns.Fqdn(req.Question[0].Name)
if strings.Count(hostname, ".") == 1 {
hostname = hostname + d.domain
}

addrs := d.ns.Lookup(hostname)

response := dns.Msg{}
Expand All @@ -139,7 +143,7 @@ func (d *DNSServer) handleLocal(defaultMaxResponseSize int) func(dns.ResponseWri
response.Answer = make([]dns.RR, len(addrs))

header := dns.RR_Header{
Name: hostname,
Name: req.Question[0].Name,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: d.ttl,
Expand Down Expand Up @@ -214,21 +218,22 @@ func (d *DNSServer) handleRecursive(client *dns.Client, defaultMaxResponseSize i
d.ns.debugf("recursive request: %+v", *req)

// Resolve unqualified names locally
name := dns.Fqdn(req.Question[0].Name)
if strings.Count(name, ".") == 1 {
req.Question[0].Name = name + d.domain
d.handleLocal(defaultMaxResponseSize)(w, req)
return
if len(req.Question) == 1 && req.Question[0].Qtype == dns.TypeA {
hostname := dns.Fqdn(req.Question[0].Name)
if strings.Count(hostname, ".") == 1 {
d.handleLocal(defaultMaxResponseSize)(w, req)
return
}
}

for _, server := range d.upstream.Servers {
response, _, err := client.Exchange(req, fmt.Sprintf("%s:%s", server, d.upstream.Port))
if err != nil || response == nil {
d.ns.debugf("network error trying %s (%s)", server, err)
d.ns.debugf("error trying %s: %v", server, err)
continue
}
if response.Rcode != dns.RcodeSuccess && !response.Authoritative {
d.ns.debugf("network error trying %s (%s)", server, err)
d.ns.debugf("non-authoritative error trying %s: %v", server, response.Rcode)
continue
}
d.ns.debugf("response: %+v", response)
Expand Down
2 changes: 1 addition & 1 deletion test/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ echo " prefetch test images"
for HOST in $HOSTS; do
docker_on $HOST load -i ../weave.tar
DANGLING_IMAGES="$(docker_on $HOST images -q -f dangling=true)"
[ -n "$DANGLING_IMAGES" ] && docker_on $HOST rmi $DANGLING_IMAGES
[ -n "$DANGLING_IMAGES" ] && docker_on $HOST rmi $DANGLING_IMAGES || true
run_on $HOST mkdir -p bin
upload_executable $HOST ../bin/docker-ns
upload_executable $HOST ../weave
Expand Down

0 comments on commit d46301c

Please sign in to comment.