mirror of
https://github.com/miekg/dns.git
synced 2025-10-10 17:31:01 +02:00
Add listenAndServerTsig function
This commit is contained in:
parent
7981d35886
commit
f7f1d2ab42
@ -7,6 +7,8 @@ package dns
|
|||||||
// setup for server - a HANDLER function that gets run
|
// setup for server - a HANDLER function that gets run
|
||||||
// when the query returns.
|
// when the query returns.
|
||||||
|
|
||||||
|
// TsigStatus here too? TODO
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
@ -38,7 +40,7 @@ type reply struct {
|
|||||||
tsigTimersOnly bool
|
tsigTimersOnly bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Request is a incoming message from a Client
|
// A Request is a incoming message from a Client.
|
||||||
type Request struct {
|
type Request struct {
|
||||||
Request *Msg
|
Request *Msg
|
||||||
Addr string
|
Addr string
|
||||||
|
22
server.go
22
server.go
@ -12,6 +12,12 @@ import (
|
|||||||
"time"
|
"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 {
|
type Handler interface {
|
||||||
ServeDNS(w ResponseWriter, r *Msg)
|
ServeDNS(w ResponseWriter, r *Msg)
|
||||||
// IP based ACL mapping. The contains the string representation
|
// IP based ACL mapping. The contains the string representation
|
||||||
@ -23,6 +29,8 @@ type Handler interface {
|
|||||||
type ResponseWriter interface {
|
type ResponseWriter interface {
|
||||||
// RemoteAddr returns the net.Addr of the client that sent the current request.
|
// RemoteAddr returns the net.Addr of the client that sent the current request.
|
||||||
RemoteAddr() net.Addr
|
RemoteAddr() net.Addr
|
||||||
|
// Return the status of the Tsig (TsigNone, TsigVerified or TsigBad)
|
||||||
|
TsigStatus() int
|
||||||
// Write writes a reply back to the client.
|
// Write writes a reply back to the client.
|
||||||
Write([]byte) (int, error)
|
Write([]byte) (int, error)
|
||||||
}
|
}
|
||||||
@ -85,6 +93,15 @@ func ListenAndServe(addr string, network string, handler Handler) error {
|
|||||||
return server.ListenAndServe()
|
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 {
|
func (mux *ServeMux) match(zone string) Handler {
|
||||||
var h Handler
|
var h Handler
|
||||||
var n = 0
|
var n = 0
|
||||||
@ -352,3 +369,8 @@ func (w *response) Write(data []byte) (n int, err error) {
|
|||||||
|
|
||||||
// RemoteAddr implements the ResponseWriter.RemoteAddr method
|
// RemoteAddr implements the ResponseWriter.RemoteAddr method
|
||||||
func (w *response) RemoteAddr() net.Addr { return w.conn.remoteAddr }
|
func (w *response) RemoteAddr() net.Addr { return w.conn.remoteAddr }
|
||||||
|
|
||||||
|
// TsigStatus implements the ResponseWriter.TsigStatus method
|
||||||
|
func (w *response) TsigStatus() int {
|
||||||
|
return TsigNone
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user