From f7f1d2ab429bff408ff021d5d40fcc14e0d49b51 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 26 Feb 2012 21:33:50 +0100 Subject: [PATCH] Add listenAndServerTsig function --- client.go | 4 +++- server.go | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 22e7a9d8..f41086aa 100644 --- a/client.go +++ b/client.go @@ -7,6 +7,8 @@ package dns // setup for server - a HANDLER function that gets run // when the query returns. +// TsigStatus here too? TODO + import ( "io" "net" @@ -38,7 +40,7 @@ type reply struct { tsigTimersOnly bool } -// A Request is a incoming message from a Client +// A Request is a incoming message from a Client. type Request struct { Request *Msg Addr string diff --git a/server.go b/server.go index 2cc3d788..e5b4122d 100644 --- a/server.go +++ b/server.go @@ -12,6 +12,12 @@ import ( "time" ) +const ( + TsigNone = iota // No Tsig attached to the message + TsigVerified // Tisg seen and verified + TsigBad // Tisg seen but failed to verify +) + type Handler interface { ServeDNS(w ResponseWriter, r *Msg) // IP based ACL mapping. The contains the string representation @@ -23,6 +29,8 @@ type Handler interface { type ResponseWriter interface { // RemoteAddr returns the net.Addr of the client that sent the current request. RemoteAddr() net.Addr + // Return the status of the Tsig (TsigNone, TsigVerified or TsigBad) + TsigStatus() int // Write writes a reply back to the client. Write([]byte) (int, error) } @@ -85,6 +93,15 @@ func ListenAndServe(addr string, network string, handler Handler) error { return server.ListenAndServe() } +// Start a server on addresss and network speficied. Use the tsig +// secrets for Tsig validation. +// Invoke handler for any incoming queries. +func ListenAndServeTsig(addr string, network string, handler Handler, tsig map[string]string) error { + server := &Server{Addr: addr, Net: network, Handler: handler, TsigSecret: tsig} + return server.ListenAndServe() +} + + func (mux *ServeMux) match(zone string) Handler { var h Handler var n = 0 @@ -352,3 +369,8 @@ func (w *response) Write(data []byte) (n int, err error) { // RemoteAddr implements the ResponseWriter.RemoteAddr method func (w *response) RemoteAddr() net.Addr { return w.conn.remoteAddr } + +// TsigStatus implements the ResponseWriter.TsigStatus method +func (w *response) TsigStatus() int { + return TsigNone +}