| 1 | package dnsscip-go gomod github.com/miekg/dns . `github.com/miekg/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 MsgAcceptFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgAcceptFunc# func(dh Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Header#) MsgAcceptActionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/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 | // * does not have exactly 1 question in the question section |
| 14 | // |
| 15 | // * has more than 1 RR in the Answer section |
| 16 | // |
| 17 | // * has more than 0 RRs in the Authority section |
| 18 | // |
| 19 | // * has more than 2 RRs in the Additional section |
| 20 | var DefaultMsgAcceptFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DefaultMsgAcceptFunc. MsgAcceptFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgAcceptFunc# = defaultMsgAcceptFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultMsgAcceptFunc(). |
| 21 | |
| 22 | // MsgAcceptAction represents the action to be taken. |
| 23 | type MsgAcceptActionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgAcceptAction# int |
| 24 | |
| 25 | // Allowed returned values from a MsgAcceptFunc. |
| 26 | const ( |
| 27 | MsgAcceptscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgAccept. MsgAcceptActionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgAcceptAction# = iota // Accept the message |
| 28 | MsgRejectscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgReject. // Reject the message with a RcodeFormatError |
| 29 | MsgIgnorescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgIgnore. // Ignore the error and send nothing back. |
| 30 | MsgRejectNotImplementedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgRejectNotImplemented. // Reject the message with a RcodeNotImplemented |
| 31 | ) |
| 32 | |
| 33 | func defaultMsgAcceptFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultMsgAcceptFunc().(dh Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Header#) MsgAcceptActionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgAcceptAction# { |
| 34 | if isResponse := dh.Bitsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Header#Bits.&_QRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/_QR. != 0; isResponse { |
| 35 | return MsgIgnorescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgIgnore. |
| 36 | } |
| 37 | |
| 38 | // Don't allow dynamic updates, because then the sections can contain a whole bunch of RRs. |
| 39 | opcode := int(dh.Bitsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Header#Bits.>>11) & 0xF |
| 40 | if opcode != OpcodeQueryscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/OpcodeQuery. && opcode != OpcodeNotifyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/OpcodeNotify. { |
| 41 | return MsgRejectNotImplementedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgRejectNotImplemented. |
| 42 | } |
| 43 | |
| 44 | if dh.Qdcountscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Header#Qdcount. != 1 { |
| 45 | return MsgRejectscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgReject. |
| 46 | } |
| 47 | // NOTIFY requests can have a SOA in the ANSWER section. See RFC 1996 Section 3.7 and 3.11. |
| 48 | if dh.Ancountscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Header#Ancount. > 1 { |
| 49 | return MsgRejectscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgReject. |
| 50 | } |
| 51 | // IXFR request could have one SOA RR in the NS section. See RFC 1995, section 3. |
| 52 | if dh.Nscountscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Header#Nscount. > 1 { |
| 53 | return MsgRejectscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgReject. |
| 54 | } |
| 55 | if dh.Arcountscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Header#Arcount. > 2 { |
| 56 | return MsgRejectscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgReject. |
| 57 | } |
| 58 | return MsgAcceptscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgAccept. |
| 59 | } |