Skip to content

Commit

Permalink
Fixes #64: Add support for HTTPS query type (type 65)
Browse files Browse the repository at this point in the history
Summary:

I was getting 'query type 65 is invalid' errors parsing DNS packets
on my machine and this fixes it.

Test Plan:

Added a unit test that parses a wild packet... it works <shrug>
  • Loading branch information
capveg-netdebug committed Sep 22, 2023
1 parent 1912667 commit dc5c4a3
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub enum Type {
OPT = opt::Record::TYPE,
/// next secure record (RFC 4034, RFC 6762)
NSEC = nsec::Record::TYPE,
/// HTTPS parameters request
HTTPS = https::Record::TYPE,
}

/// The QTYPE value according to RFC 1035
Expand Down Expand Up @@ -95,6 +97,9 @@ pub enum QueryType {
MAILA = maila::Record::TYPE,
/// A request for all records
All = all::Record::TYPE,
/// A request for HTTPS records, see
/// https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-svcb-https-10
HTTPS = https::Record::TYPE,
}


Expand Down Expand Up @@ -218,6 +223,7 @@ impl QueryType {
ns::Record::TYPE => Ok(NS),
mf::Record::TYPE => Ok(MF),
cname::Record::TYPE => Ok(CNAME),
https::Record::TYPE => Ok(HTTPS),
soa::Record::TYPE => Ok(SOA),
mb::Record::TYPE => Ok(MB),
mg::Record::TYPE => Ok(MG),
Expand Down
82 changes: 82 additions & 0 deletions src/rdata/https.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use byteorder::{BigEndian, ByteOrder};
use {Error, Name};

#[derive(Debug, Clone, Copy)]
pub struct Record<'a> {
pub target: Name<'a>,
}

impl<'a> super::Record<'a> for Record<'a> {
const TYPE: isize = 65;

fn parse(rdata: &'a [u8], original: &'a [u8]) -> super::RDataResult<'a> {
if rdata.len() < 1 {
return Err(Error::WrongRdataLength);
}
let record = Record {
target: Name::scan(&rdata[0..], original)?,
};
Ok(super::RData::HTTPS(record))
}
}

#[cfg(test)]
mod test {

use Opcode::*;
use QueryClass as QC;
use QueryType as QT;
use ResponseCode::NoError;
use {Header, Packet};

#[test]
fn parse_response() {
// from wireshark
let response: [u8; 215] = [
0x21, 0x8b, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x06, 0x6d,
0x6f, 0x62, 0x69, 0x6c, 0x65, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x04, 0x64,
0x61, 0x74, 0x61, 0x09, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x03,
0x63, 0x6f, 0x6d, 0x00, 0x00, 0x41, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x05, 0x00, 0x01,
0x00, 0x00, 0x00, 0x6d, 0x00, 0x27, 0x06, 0x6d, 0x6f, 0x62, 0x69, 0x6c, 0x65, 0x06,
0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x04, 0x64, 0x61, 0x74, 0x61, 0x0e, 0x74, 0x72,
0x61, 0x66, 0x66, 0x69, 0x63, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x03, 0x6e,
0x65, 0x74, 0x00, 0xc0, 0x3e, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00,
0x29, 0x10, 0x6f, 0x6e, 0x65, 0x64, 0x73, 0x63, 0x6f, 0x6c, 0x70, 0x72, 0x64, 0x65,
0x75, 0x73, 0x30, 0x37, 0x06, 0x65, 0x61, 0x73, 0x74, 0x75, 0x73, 0x08, 0x63, 0x6c,
0x6f, 0x75, 0x64, 0x61, 0x70, 0x70, 0x05, 0x61, 0x7a, 0x75, 0x72, 0x65, 0xc0, 0x29,
0xc0, 0x82, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x31, 0x07, 0x6e,
0x73, 0x31, 0x2d, 0x32, 0x30, 0x31, 0x09, 0x61, 0x7a, 0x75, 0x72, 0x65, 0x2d, 0x64,
0x6e, 0x73, 0xc0, 0x29, 0x06, 0x6d, 0x73, 0x6e, 0x68, 0x73, 0x74, 0xc0, 0x1f, 0x00,
0x00, 0x27, 0x11, 0x00, 0x00, 0x03, 0x84, 0x00, 0x00, 0x01, 0x2c, 0x00, 0x09, 0x3a,
0x80, 0x00, 0x00, 0x00, 0x3c,
];

let packet = Packet::parse(&response).unwrap();
assert_eq!(
packet.header,
Header {
id: 0x218b,
query: false,
opcode: StandardQuery,
authoritative: false,
truncated: false,
recursion_desired: true,
recursion_available: true,
authenticated_data: false,
checking_disabled: false,
response_code: NoError,
questions: 1,
answers: 2,
nameservers: 1,
additional: 0,
}
);
assert_eq!(packet.questions.len(), 1);
assert_eq!(packet.questions[0].qtype, QT::HTTPS);
assert_eq!(packet.questions[0].qclass, QC::IN);
assert_eq!(
&packet.questions[0].qname.to_string()[..],
"mobile.events.data.microsoft.com"
);
}
}
4 changes: 4 additions & 0 deletions src/rdata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod all;
pub mod axfr;
pub mod cname;
pub mod hinfo;
pub mod https;
pub mod maila;
pub mod mailb;
pub mod mb;
Expand All @@ -31,6 +32,7 @@ use {Type, Error};
pub use self::a::Record as A;
pub use self::aaaa::Record as Aaaa;
pub use self::cname::Record as Cname;
pub use self::https::Record as Https;
pub use self::mx::Record as Mx;
pub use self::ns::Record as Ns;
pub use self::nsec::Record as Nsec;
Expand All @@ -48,6 +50,7 @@ pub enum RData<'a> {
A(A),
AAAA(Aaaa),
CNAME(Cname<'a>),
HTTPS(Https<'a>),
MX(Mx<'a>),
NS(Ns<'a>),
PTR(Ptr<'a>),
Expand Down Expand Up @@ -89,6 +92,7 @@ impl<'a> RData<'a> {
RData::A(..) => Type::A,
RData::AAAA(..) => Type::AAAA,
RData::CNAME(..) => Type::CNAME,
RData::HTTPS(..) => Type::HTTPS,
RData::NS(..) => Type::NS,
RData::MX(..) => Type::MX,
RData::PTR(..) => Type::PTR,
Expand Down

0 comments on commit dc5c4a3

Please sign in to comment.