"Fossies" - the Fresh Open Source Software Archive

Member "mattermost-server-6.0.1/vendor/github.com/miekg/dns/acceptfunc.go" (18 Oct 2021, 1927 Bytes) of package /linux/www/mattermost-server-6.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "acceptfunc.go": 5.37.1_vs_5.38.0.

    1 package dns
    2 
    3 // MsgAcceptFunc is used early in the server code to accept or reject a message with RcodeFormatError.
    4 // It returns a MsgAcceptAction to indicate what should happen with the message.
    5 type MsgAcceptFunc func(dh Header) MsgAcceptAction
    6 
    7 // DefaultMsgAcceptFunc checks the request and will reject if:
    8 //
    9 // * isn't a request (don't respond in that case)
   10 //
   11 // * opcode isn't OpcodeQuery or OpcodeNotify
   12 //
   13 // * Zero bit isn't zero
   14 //
   15 // * has more than 1 question in the question section
   16 //
   17 // * has more than 1 RR in the Answer section
   18 //
   19 // * has more than 0 RRs in the Authority section
   20 //
   21 // * has more than 2 RRs in the Additional section
   22 //
   23 var DefaultMsgAcceptFunc MsgAcceptFunc = defaultMsgAcceptFunc
   24 
   25 // MsgAcceptAction represents the action to be taken.
   26 type MsgAcceptAction int
   27 
   28 // Allowed returned values from a MsgAcceptFunc.
   29 const (
   30     MsgAccept               MsgAcceptAction = iota // Accept the message
   31     MsgReject                                      // Reject the message with a RcodeFormatError
   32     MsgIgnore                                      // Ignore the error and send nothing back.
   33     MsgRejectNotImplemented                        // Reject the message with a RcodeNotImplemented
   34 )
   35 
   36 func defaultMsgAcceptFunc(dh Header) MsgAcceptAction {
   37     if isResponse := dh.Bits&_QR != 0; isResponse {
   38         return MsgIgnore
   39     }
   40 
   41     // Don't allow dynamic updates, because then the sections can contain a whole bunch of RRs.
   42     opcode := int(dh.Bits>>11) & 0xF
   43     if opcode != OpcodeQuery && opcode != OpcodeNotify {
   44         return MsgRejectNotImplemented
   45     }
   46 
   47     if dh.Qdcount != 1 {
   48         return MsgReject
   49     }
   50     // NOTIFY requests can have a SOA in the ANSWER section. See RFC 1996 Section 3.7 and 3.11.
   51     if dh.Ancount > 1 {
   52         return MsgReject
   53     }
   54     // IXFR request could have one SOA RR in the NS section. See RFC 1995, section 3.
   55     if dh.Nscount > 1 {
   56         return MsgReject
   57     }
   58     if dh.Arcount > 2 {
   59         return MsgReject
   60     }
   61     return MsgAccept
   62 }