Add listenAndServerTsig function

This commit is contained in:
Miek Gieben 2012-02-26 21:33:50 +01:00
parent 7981d35886
commit f7f1d2ab42
2 changed files with 25 additions and 1 deletions

View File

@ -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

View File

@ -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
}