summaryrefslogtreecommitdiff
path: root/vendor/github.com/miekg/dns/server.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2024-06-17 08:12:25 +0000
committerLibravatar GitHub <noreply@github.com>2024-06-17 08:12:25 +0000
commit3a01377bcc30105d11f5971b775c561d9ca71253 (patch)
treeb1862ce5771ac823c105a6a9543098814abd5dcb /vendor/github.com/miekg/dns/server.go
parent[chore]: Bump github.com/tdewolff/minify/v2 from 2.20.33 to 2.20.34 (#3017) (diff)
downloadgotosocial-3a01377bcc30105d11f5971b775c561d9ca71253.tar.xz
[chore]: Bump github.com/miekg/dns from 1.1.59 to 1.1.61 (#3014)
Diffstat (limited to 'vendor/github.com/miekg/dns/server.go')
-rw-r--r--vendor/github.com/miekg/dns/server.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/vendor/github.com/miekg/dns/server.go b/vendor/github.com/miekg/dns/server.go
index 0207d6da2..81580d1e5 100644
--- a/vendor/github.com/miekg/dns/server.go
+++ b/vendor/github.com/miekg/dns/server.go
@@ -188,6 +188,14 @@ type DecorateReader func(Reader) Reader
// Implementations should never return a nil Writer.
type DecorateWriter func(Writer) Writer
+// MsgInvalidFunc is a listener hook for observing incoming messages that were discarded
+// because they could not be parsed.
+// Every message that is read by a Reader will eventually be provided to the Handler,
+// rejected (or ignored) by the MsgAcceptFunc, or passed to this function.
+type MsgInvalidFunc func(m []byte, err error)
+
+func DefaultMsgInvalidFunc(m []byte, err error) {}
+
// A Server defines parameters for running an DNS server.
type Server struct {
// Address to listen on, ":dns" if empty.
@@ -233,6 +241,8 @@ type Server struct {
// AcceptMsgFunc will check the incoming message and will reject it early in the process.
// By default DefaultMsgAcceptFunc will be used.
MsgAcceptFunc MsgAcceptFunc
+ // MsgInvalidFunc is optional, will be called if a message is received but cannot be parsed.
+ MsgInvalidFunc MsgInvalidFunc
// Shutdown handling
lock sync.RWMutex
@@ -277,6 +287,9 @@ func (srv *Server) init() {
if srv.MsgAcceptFunc == nil {
srv.MsgAcceptFunc = DefaultMsgAcceptFunc
}
+ if srv.MsgInvalidFunc == nil {
+ srv.MsgInvalidFunc = DefaultMsgInvalidFunc
+ }
if srv.Handler == nil {
srv.Handler = DefaultServeMux
}
@@ -531,6 +544,7 @@ func (srv *Server) serveUDP(l net.PacketConn) error {
if cap(m) == srv.UDPSize {
srv.udpPool.Put(m[:srv.UDPSize])
}
+ srv.MsgInvalidFunc(m, ErrShortRead)
continue
}
wg.Add(1)
@@ -611,6 +625,7 @@ func (srv *Server) serveUDPPacket(wg *sync.WaitGroup, m []byte, u net.PacketConn
func (srv *Server) serveDNS(m []byte, w *response) {
dh, off, err := unpackMsgHdr(m, 0)
if err != nil {
+ srv.MsgInvalidFunc(m, err)
// Let client hang, they are sending crap; any reply can be used to amplify.
return
}
@@ -620,10 +635,12 @@ func (srv *Server) serveDNS(m []byte, w *response) {
switch action := srv.MsgAcceptFunc(dh); action {
case MsgAccept:
- if req.unpack(dh, m, off) == nil {
+ err := req.unpack(dh, m, off)
+ if err == nil {
break
}
+ srv.MsgInvalidFunc(m, err)
fallthrough
case MsgReject, MsgRejectNotImplemented:
opcode := req.Opcode