add version.server and version.bind

This commit is contained in:
Miek Gieben 2012-09-03 13:56:43 +02:00
parent c8a588fabb
commit c03a914cec
3 changed files with 46 additions and 2 deletions

View File

@ -160,6 +160,8 @@ func main() {
dns.HandleFunc(".", handleReflect)
dns.HandleFunc("authors.bind.", dns.HandleAuthors)
dns.HandleFunc("authors.server.", dns.HandleAuthors)
dns.HandleFunc("version.bind.", dns.HandleVersion)
dns.HandleFunc("version.server.", dns.HandleVersion)
go serve("tcp", name, secret)
go serve("udp", name, secret)
sig := make(chan os.Signal)

View File

@ -56,6 +56,8 @@ func ExampleToDs(zone string) {
// queries.
func ExampleAuthors() {
// ... server setup is out of scope ...
// Register the handle funcs.
HandleFunc("authors.bind.", HandleAuthors)
HandleFunc("authors.server.", HandleAuthors)

View File

@ -73,6 +73,9 @@ var DefaultServeMux = NewServeMux()
// Authors is a list of authors that helped create or make Go DNS better.
var Authors = []string{ "Miek Gieben", "Ask Bjorn Hansen", "Dave Cheney", "Dusty Wilson", "Peter van Dijk"}
// Version holds the current version.
var Version = "Go DNS"
// The HandlerFunc type is an adapter to allow the use of
// ordinary functions as DNS handlers. If f is a function
// with the appropriate signature, HandlerFunc(f) is a
@ -95,7 +98,14 @@ func HandleFailed(w ResponseWriter, r *Msg) {
// AuthorHandler returns a HandlerFunc that returns the authors
// of Go DNS for 'authors.bind' or 'authors.server' queries in the
// CHAOS Class.
// CHAOS Class. Note with
//
// HandleFunc("authors.bind.", HandleAuthors)
//
// The handler is registered for all DNS classes, thereby potentially
// hijacking the authors.bind. zone in the IN class. If you need the
// authors.bind zone to exist in the IN class, you need to register
// some other handler, check the class in there and then call HandleAuthors.
func HandleAuthors(w ResponseWriter, r *Msg) {
if len(r.Question) != 1 {
HandleFailed(w, r)
@ -109,7 +119,6 @@ func HandleAuthors(w ResponseWriter, r *Msg) {
HandleFailed(w, r)
return
}
// primary author
m := new(Msg)
m.SetReply(r)
for _, author := range Authors {
@ -119,8 +128,39 @@ func HandleAuthors(w ResponseWriter, r *Msg) {
w.Write(m)
}
// VersionHandler returns a HandlerFunc that returns the version
// of Go DNS for 'version.bind' or 'version.server' queries in the
// CHAOS Class. Note with
//
// HandleFunc("version.bind.", HandleVersion)
//
// The handler is registered for all DNS classes, thereby potentially
// hijacking the version.bind. zone in the IN class. If you need the
// version.bind zone to exist in the IN class, you need to register
// some other handler, check the class in there and then call HandleVersion.
func HandleVersion(w ResponseWriter, r *Msg) {
if len(r.Question) != 1 {
HandleFailed(w, r)
return
}
if r.Question[0].Qtype != ClassCHAOS && r.Question[0].Qtype != TypeTXT {
HandleFailed(w, r)
return
}
if r.Question[0].Name != "version.server." && r.Question[0].Name != "version.bind." {
HandleFailed(w, r)
return
}
m := new(Msg)
m.SetReply(r)
h := RR_Header{r.Question[0].Name, TypeTXT, ClassCHAOS, 0, 0}
m.Answer = append(m.Answer, &RR_TXT{h, []string{Version}})
w.Write(m)
}
func authorHandler() Handler { return HandlerFunc(HandleAuthors) }
func failedHandler() Handler { return HandlerFunc(HandleFailed) }
func versionHandler() Handler { return HandlerFunc(HandleVersion) }
// Start a server on addresss and network speficied. Invoke handler
// for any incoming queries.