Skip to content

Commit

Permalink
Extend MandatoryMiddlewareSvc with an RFC 9619 check for opcode QUERY…
Browse files Browse the repository at this point in the history
… with QDCOUNT > 1. (#365)
  • Loading branch information
ximon18 authored Oct 2, 2024
1 parent 38cbb13 commit a354121
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/net/server/middleware/mandatory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ pub const MINIMUM_RESPONSE_BYTE_LEN: u16 = 512;
/// |--------|---------|
/// | [1035] | TBD |
/// | [2181] | TBD |
/// | [9619] | TBD |
///
/// [1035]: https://datatracker.ietf.org/doc/html/rfc1035
/// [2181]: https://datatracker.ietf.org/doc/html/rfc2181
/// [9619]: https://datatracker.ietf.org/doc/html/rfc9619
#[derive(Clone, Debug)]
pub struct MandatoryMiddlewareSvc<RequestOctets, NextSvc, RequestMeta> {
/// The upstream [`Service`] to pass requests to and receive responses
Expand Down Expand Up @@ -203,12 +205,29 @@ where
// "Therefore IQUERY is now obsolete, and name servers SHOULD return
// a "Not Implemented" error when an IQUERY request is received."
if self.strict && msg.header().opcode() == Opcode::IQUERY {
debug!("RFC 3425 violation: request opcode IQUERY is obsolete.");
return ControlFlow::Break(mk_error_response(
msg,
OptRcode::NOTIMP,
));
}

// https://datatracker.ietf.org/doc/html/rfc9619#section-4
// 4. Updates to RFC 1035
// ...
// "A DNS message with OPCODE = 0 and QDCOUNT > 1 MUST be treated as
// an incorrectly formatted message. The value of the RCODE
// parameter in the response message MUST be set to 1 (FORMERR)."
if self.strict
&& msg.header().opcode() == Opcode::QUERY
&& msg.header_counts().qdcount() > 1
{
debug!(
"RFC 3425 3 violation: request opcode IQUERY is obsolete."
"RFC 9619 violation: request opcode QUERY with QDCOUNT > 1."
);
return ControlFlow::Break(mk_error_response(
msg,
OptRcode::NOTIMP,
OptRcode::FORMERR,
));
}

Expand Down

0 comments on commit a354121

Please sign in to comment.