"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "server.go" between
dns-1.1.45.tar.gz and dns-1.1.46.tar.gz

About: GO DNS implements a DNS library in Go.

server.go  (dns-1.1.45):server.go  (dns-1.1.46)
skipping to change at line 74 skipping to change at line 74
type ConnectionStater interface { type ConnectionStater interface {
ConnectionState() *tls.ConnectionState ConnectionState() *tls.ConnectionState
} }
type response struct { type response struct {
closed bool // connection has been closed closed bool // connection has been closed
hijacked bool // connection has been hijacked by handler hijacked bool // connection has been hijacked by handler
tsigTimersOnly bool tsigTimersOnly bool
tsigStatus error tsigStatus error
tsigRequestMAC string tsigRequestMAC string
tsigSecret map[string]string // the tsig secrets tsigProvider TsigProvider
udp net.PacketConn // i/o connection if UDP was used udp net.PacketConn // i/o connection if UDP was used
tcp net.Conn // i/o connection if TCP was used tcp net.Conn // i/o connection if TCP was used
udpSession *SessionUDP // oob data to get egress interface righ udpSession *SessionUDP // oob data to get egress interface right
t pcSession net.Addr // address to use when writing to a generic
pcSession net.Addr // address to use when writing to a gene net.PacketConn
ric net.PacketConn writer Writer // writer to output the raw DNS bits
writer Writer // writer to output the raw DNS bits
} }
// handleRefused returns a HandlerFunc that returns REFUSED for every request it gets. // handleRefused returns a HandlerFunc that returns REFUSED for every request it gets.
func handleRefused(w ResponseWriter, r *Msg) { func handleRefused(w ResponseWriter, r *Msg) {
m := new(Msg) m := new(Msg)
m.SetRcode(r, RcodeRefused) m.SetRcode(r, RcodeRefused)
w.WriteMsg(m) w.WriteMsg(m)
} }
// HandleFailed returns a HandlerFunc that returns SERVFAIL for every request it gets. // HandleFailed returns a HandlerFunc that returns SERVFAIL for every request it gets.
skipping to change at line 214 skipping to change at line 214
Handler Handler Handler Handler
// Default buffer size to use to read incoming UDP messages. If not set // Default buffer size to use to read incoming UDP messages. If not set
// it defaults to MinMsgSize (512 B). // it defaults to MinMsgSize (512 B).
UDPSize int UDPSize int
// The net.Conn.SetReadTimeout value for new connections, defaults to 2 * time.Second. // The net.Conn.SetReadTimeout value for new connections, defaults to 2 * time.Second.
ReadTimeout time.Duration ReadTimeout time.Duration
// The net.Conn.SetWriteTimeout value for new connections, defaults to 2 * time.Second. // The net.Conn.SetWriteTimeout value for new connections, defaults to 2 * time.Second.
WriteTimeout time.Duration WriteTimeout time.Duration
// TCP idle timeout for multiple queries, if nil, defaults to 8 * time.Se cond (RFC 5966). // TCP idle timeout for multiple queries, if nil, defaults to 8 * time.Se cond (RFC 5966).
IdleTimeout func() time.Duration IdleTimeout func() time.Duration
// An implementation of the TsigProvider interface. If defined it replace
s TsigSecret and is used for all TSIG operations.
TsigProvider TsigProvider
// Secret(s) for Tsig map[<zonename>]<base64 secret>. The zonename must b e in canonical form (lowercase, fqdn, see RFC 4034 Section 6.2). // Secret(s) for Tsig map[<zonename>]<base64 secret>. The zonename must b e in canonical form (lowercase, fqdn, see RFC 4034 Section 6.2).
TsigSecret map[string]string TsigSecret map[string]string
// If NotifyStartedFunc is set it is called once the server has started l istening. // If NotifyStartedFunc is set it is called once the server has started l istening.
NotifyStartedFunc func() NotifyStartedFunc func()
// DecorateReader is optional, allows customization of the process that r eads raw DNS messages. // DecorateReader is optional, allows customization of the process that r eads raw DNS messages.
DecorateReader DecorateReader DecorateReader DecorateReader
// DecorateWriter is optional, allows customization of the process that w rites raw DNS messages. // DecorateWriter is optional, allows customization of the process that w rites raw DNS messages.
DecorateWriter DecorateWriter DecorateWriter DecorateWriter
// Maximum number of TCP queries before we close the socket. Default is m axTCPQueries (unlimited if -1). // Maximum number of TCP queries before we close the socket. Default is m axTCPQueries (unlimited if -1).
MaxTCPQueries int MaxTCPQueries int
skipping to change at line 241 skipping to change at line 243
// Shutdown handling // Shutdown handling
lock sync.RWMutex lock sync.RWMutex
started bool started bool
shutdown chan struct{} shutdown chan struct{}
conns map[net.Conn]struct{} conns map[net.Conn]struct{}
// A pool for UDP message buffers. // A pool for UDP message buffers.
udpPool sync.Pool udpPool sync.Pool
} }
func (srv *Server) tsigProvider() TsigProvider {
if srv.TsigProvider != nil {
return srv.TsigProvider
}
if srv.TsigSecret != nil {
return tsigSecretProvider(srv.TsigSecret)
}
return nil
}
func (srv *Server) isStarted() bool { func (srv *Server) isStarted() bool {
srv.lock.RLock() srv.lock.RLock()
started := srv.started started := srv.started
srv.lock.RUnlock() srv.lock.RUnlock()
return started return started
} }
func makeUDPBuffer(size int) func() interface{} { func makeUDPBuffer(size int) func() interface{} {
return func() interface{} { return func() interface{} {
return make([]byte, size) return make([]byte, size)
skipping to change at line 529 skipping to change at line 541
} }
wg.Add(1) wg.Add(1)
go srv.serveUDPPacket(&wg, m, l, sUDP, sPC) go srv.serveUDPPacket(&wg, m, l, sUDP, sPC)
} }
return nil return nil
} }
// Serve a new TCP connection. // Serve a new TCP connection.
func (srv *Server) serveTCPConn(wg *sync.WaitGroup, rw net.Conn) { func (srv *Server) serveTCPConn(wg *sync.WaitGroup, rw net.Conn) {
w := &response{tsigSecret: srv.TsigSecret, tcp: rw} w := &response{tsigProvider: srv.tsigProvider(), tcp: rw}
if srv.DecorateWriter != nil { if srv.DecorateWriter != nil {
w.writer = srv.DecorateWriter(w) w.writer = srv.DecorateWriter(w)
} else { } else {
w.writer = w w.writer = w
} }
reader := Reader(defaultReader{srv}) reader := Reader(defaultReader{srv})
if srv.DecorateReader != nil { if srv.DecorateReader != nil {
reader = srv.DecorateReader(reader) reader = srv.DecorateReader(reader)
} }
skipping to change at line 584 skipping to change at line 596
srv.lock.Lock() srv.lock.Lock()
delete(srv.conns, w.tcp) delete(srv.conns, w.tcp)
srv.lock.Unlock() srv.lock.Unlock()
wg.Done() wg.Done()
} }
// Serve a new UDP request. // Serve a new UDP request.
func (srv *Server) serveUDPPacket(wg *sync.WaitGroup, m []byte, u net.PacketConn , udpSession *SessionUDP, pcSession net.Addr) { func (srv *Server) serveUDPPacket(wg *sync.WaitGroup, m []byte, u net.PacketConn , udpSession *SessionUDP, pcSession net.Addr) {
w := &response{tsigSecret: srv.TsigSecret, udp: u, udpSession: udpSession , pcSession: pcSession} w := &response{tsigProvider: srv.tsigProvider(), udp: u, udpSession: udpS ession, pcSession: pcSession}
if srv.DecorateWriter != nil { if srv.DecorateWriter != nil {
w.writer = srv.DecorateWriter(w) w.writer = srv.DecorateWriter(w)
} else { } else {
w.writer = w w.writer = w
} }
srv.serveDNS(m, w) srv.serveDNS(m, w)
wg.Done() wg.Done()
} }
skipping to change at line 635 skipping to change at line 647
fallthrough fallthrough
case MsgIgnore: case MsgIgnore:
if w.udp != nil && cap(m) == srv.UDPSize { if w.udp != nil && cap(m) == srv.UDPSize {
srv.udpPool.Put(m[:srv.UDPSize]) srv.udpPool.Put(m[:srv.UDPSize])
} }
return return
} }
w.tsigStatus = nil w.tsigStatus = nil
if w.tsigSecret != nil { if w.tsigProvider != nil {
if t := req.IsTsig(); t != nil { if t := req.IsTsig(); t != nil {
if secret, ok := w.tsigSecret[t.Hdr.Name]; ok { w.tsigStatus = tsigVerifyProvider(m, w.tsigProvider, "",
w.tsigStatus = TsigVerify(m, secret, "", false) false)
} else {
w.tsigStatus = ErrSecret
}
w.tsigTimersOnly = false w.tsigTimersOnly = false
w.tsigRequestMAC = req.Extra[len(req.Extra)-1].(*TSIG).MA C w.tsigRequestMAC = t.MAC
} }
} }
if w.udp != nil && cap(m) == srv.UDPSize { if w.udp != nil && cap(m) == srv.UDPSize {
srv.udpPool.Put(m[:srv.UDPSize]) srv.udpPool.Put(m[:srv.UDPSize])
} }
srv.Handler.ServeDNS(w, req) // Writes back to the client srv.Handler.ServeDNS(w, req) // Writes back to the client
} }
skipping to change at line 721 skipping to change at line 729
return m, addr, nil return m, addr, nil
} }
// WriteMsg implements the ResponseWriter.WriteMsg method. // WriteMsg implements the ResponseWriter.WriteMsg method.
func (w *response) WriteMsg(m *Msg) (err error) { func (w *response) WriteMsg(m *Msg) (err error) {
if w.closed { if w.closed {
return &Error{err: "WriteMsg called after Close"} return &Error{err: "WriteMsg called after Close"}
} }
var data []byte var data []byte
if w.tsigSecret != nil { // if no secrets, dont check for the tsig (which is a longer check) if w.tsigProvider != nil { // if no provider, dont check for the tsig (wh ich is a longer check)
if t := m.IsTsig(); t != nil { if t := m.IsTsig(); t != nil {
data, w.tsigRequestMAC, err = TsigGenerate(m, w.tsigSecre t[t.Hdr.Name], w.tsigRequestMAC, w.tsigTimersOnly) data, w.tsigRequestMAC, err = tsigGenerateProvider(m, w.t sigProvider, w.tsigRequestMAC, w.tsigTimersOnly)
if err != nil { if err != nil {
return err return err
} }
_, err = w.writer.Write(data) _, err = w.writer.Write(data)
return err return err
} }
} }
data, err = m.Pack() data, err = m.Pack()
if err != nil { if err != nil {
return err return err
 End of changes. 10 change blocks. 
19 lines changed or deleted 28 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)