Skip to content

Commit

Permalink
Source external DNS queries from container namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Santhosh Manohar <[email protected]>
  • Loading branch information
Santhosh Manohar committed Mar 2, 2016
1 parent 9994ce1 commit 6c9014d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 15 additions & 4 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,26 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
for i := 0; i < num; i++ {
log.Debugf("Querying ext dns %s:%s for %s[%d]", w.LocalAddr().Network(), r.extDNS[i], name, query.Question[0].Qtype)

c := &dns.Client{Net: w.LocalAddr().Network()}
addr := fmt.Sprintf("%s:%d", r.extDNS[i], 53)
var extConn net.Conn
r.sb.execFunc(func() {
addr := fmt.Sprintf("%s:%d", r.extDNS[i], 53)
extConn, r.err = net.Dial(w.LocalAddr().Network(), addr)
})

if r.err != nil {
continue
}

co := &dns.Conn{Conn: extConn}
co.WriteMsg(query)
resp, err = co.ReadMsg()
co.Close()

resp, _, err = c.Exchange(query, addr)
if err == nil {
resp.Compress = true
break
}
log.Errorf("external resolution failed, %s", err)
log.Debugf("external resolution failed, %s", err)
}
if resp == nil {
return
Expand Down
4 changes: 4 additions & 0 deletions sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ func (sb *sandbox) ResolveIP(ip string) string {
return svc
}

func (sb *sandbox) execFunc(f func()) {
sb.osSbox.InvokeFunc(f)
}

func (sb *sandbox) ResolveName(name string) net.IP {
var ip net.IP

Expand Down

0 comments on commit 6c9014d

Please sign in to comment.