mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-07-14 01:57:32 +08:00
Make PWD dns recursive
This commit is contained in:
parent
b6e44d93bc
commit
5f647d7fba
44
api.go
44
api.go
@ -4,6 +4,7 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -165,9 +166,44 @@ func handleDnsRequest(w dns.ResponseWriter, r *dns.Msg) {
|
|||||||
w.WriteMsg(m)
|
w.WriteMsg(m)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
// we have no information about this and we are not a recursive dns server, so we just fail so the client can fallback to the next dns server it has configured
|
if len(r.Question) > 0 {
|
||||||
w.Close()
|
question := r.Question[0].Name
|
||||||
// dns.HandleFailed(w, r)
|
ips, err := net.LookupIP(question)
|
||||||
return
|
if err != nil {
|
||||||
|
// we have no information about this and we are not a recursive dns server, so we just fail so the client can fallback to the next dns server it has configured
|
||||||
|
w.Close()
|
||||||
|
// dns.HandleFailed(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Printf("Not a PWD host. Looking up [%s] got [%s]\n", question, ips)
|
||||||
|
m := new(dns.Msg)
|
||||||
|
m.SetReply(r)
|
||||||
|
m.Authoritative = true
|
||||||
|
m.RecursionAvailable = true
|
||||||
|
for _, ip := range ips {
|
||||||
|
ipv4 := ip.To4()
|
||||||
|
if ipv4 == nil {
|
||||||
|
a, err := dns.NewRR(fmt.Sprintf("%s 60 IN AAAA %s", question, ip.String()))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
m.Answer = append(m.Answer, a)
|
||||||
|
} else {
|
||||||
|
a, err := dns.NewRR(fmt.Sprintf("%s 60 IN A %s", question, ipv4.String()))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
m.Answer = append(m.Answer, a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.WriteMsg(m)
|
||||||
|
return
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// we have no information about this and we are not a recursive dns server, so we just fail so the client can fallback to the next dns server it has configured
|
||||||
|
w.Close()
|
||||||
|
// dns.HandleFailed(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user