Skip to content

Commit dc5c4a3

Browse files
Fixes #64: Add support for HTTPS query type (type 65)
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>
1 parent 1912667 commit dc5c4a3

3 files changed

Lines changed: 92 additions & 0 deletions

File tree

src/enums.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub enum Type {
4545
OPT = opt::Record::TYPE,
4646
/// next secure record (RFC 4034, RFC 6762)
4747
NSEC = nsec::Record::TYPE,
48+
/// HTTPS parameters request
49+
HTTPS = https::Record::TYPE,
4850
}
4951

5052
/// The QTYPE value according to RFC 1035
@@ -95,6 +97,9 @@ pub enum QueryType {
9597
MAILA = maila::Record::TYPE,
9698
/// A request for all records
9799
All = all::Record::TYPE,
100+
/// A request for HTTPS records, see
101+
/// https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-svcb-https-10
102+
HTTPS = https::Record::TYPE,
98103
}
99104

100105

@@ -218,6 +223,7 @@ impl QueryType {
218223
ns::Record::TYPE => Ok(NS),
219224
mf::Record::TYPE => Ok(MF),
220225
cname::Record::TYPE => Ok(CNAME),
226+
https::Record::TYPE => Ok(HTTPS),
221227
soa::Record::TYPE => Ok(SOA),
222228
mb::Record::TYPE => Ok(MB),
223229
mg::Record::TYPE => Ok(MG),

src/rdata/https.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
use byteorder::{BigEndian, ByteOrder};
2+
use {Error, Name};
3+
4+
#[derive(Debug, Clone, Copy)]
5+
pub struct Record<'a> {
6+
pub target: Name<'a>,
7+
}
8+
9+
impl<'a> super::Record<'a> for Record<'a> {
10+
const TYPE: isize = 65;
11+
12+
fn parse(rdata: &'a [u8], original: &'a [u8]) -> super::RDataResult<'a> {
13+
if rdata.len() < 1 {
14+
return Err(Error::WrongRdataLength);
15+
}
16+
let record = Record {
17+
target: Name::scan(&rdata[0..], original)?,
18+
};
19+
Ok(super::RData::HTTPS(record))
20+
}
21+
}
22+
23+
#[cfg(test)]
24+
mod test {
25+
26+
use Opcode::*;
27+
use QueryClass as QC;
28+
use QueryType as QT;
29+
use ResponseCode::NoError;
30+
use {Header, Packet};
31+
32+
#[test]
33+
fn parse_response() {
34+
// from wireshark
35+
let response: [u8; 215] = [
36+
0x21, 0x8b, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x06, 0x6d,
37+
0x6f, 0x62, 0x69, 0x6c, 0x65, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x04, 0x64,
38+
0x61, 0x74, 0x61, 0x09, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x03,
39+
0x63, 0x6f, 0x6d, 0x00, 0x00, 0x41, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x05, 0x00, 0x01,
40+
0x00, 0x00, 0x00, 0x6d, 0x00, 0x27, 0x06, 0x6d, 0x6f, 0x62, 0x69, 0x6c, 0x65, 0x06,
41+
0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x04, 0x64, 0x61, 0x74, 0x61, 0x0e, 0x74, 0x72,
42+
0x61, 0x66, 0x66, 0x69, 0x63, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x03, 0x6e,
43+
0x65, 0x74, 0x00, 0xc0, 0x3e, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00,
44+
0x29, 0x10, 0x6f, 0x6e, 0x65, 0x64, 0x73, 0x63, 0x6f, 0x6c, 0x70, 0x72, 0x64, 0x65,
45+
0x75, 0x73, 0x30, 0x37, 0x06, 0x65, 0x61, 0x73, 0x74, 0x75, 0x73, 0x08, 0x63, 0x6c,
46+
0x6f, 0x75, 0x64, 0x61, 0x70, 0x70, 0x05, 0x61, 0x7a, 0x75, 0x72, 0x65, 0xc0, 0x29,
47+
0xc0, 0x82, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x31, 0x07, 0x6e,
48+
0x73, 0x31, 0x2d, 0x32, 0x30, 0x31, 0x09, 0x61, 0x7a, 0x75, 0x72, 0x65, 0x2d, 0x64,
49+
0x6e, 0x73, 0xc0, 0x29, 0x06, 0x6d, 0x73, 0x6e, 0x68, 0x73, 0x74, 0xc0, 0x1f, 0x00,
50+
0x00, 0x27, 0x11, 0x00, 0x00, 0x03, 0x84, 0x00, 0x00, 0x01, 0x2c, 0x00, 0x09, 0x3a,
51+
0x80, 0x00, 0x00, 0x00, 0x3c,
52+
];
53+
54+
let packet = Packet::parse(&response).unwrap();
55+
assert_eq!(
56+
packet.header,
57+
Header {
58+
id: 0x218b,
59+
query: false,
60+
opcode: StandardQuery,
61+
authoritative: false,
62+
truncated: false,
63+
recursion_desired: true,
64+
recursion_available: true,
65+
authenticated_data: false,
66+
checking_disabled: false,
67+
response_code: NoError,
68+
questions: 1,
69+
answers: 2,
70+
nameservers: 1,
71+
additional: 0,
72+
}
73+
);
74+
assert_eq!(packet.questions.len(), 1);
75+
assert_eq!(packet.questions[0].qtype, QT::HTTPS);
76+
assert_eq!(packet.questions[0].qclass, QC::IN);
77+
assert_eq!(
78+
&packet.questions[0].qname.to_string()[..],
79+
"mobile.events.data.microsoft.com"
80+
);
81+
}
82+
}

src/rdata/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub mod all;
88
pub mod axfr;
99
pub mod cname;
1010
pub mod hinfo;
11+
pub mod https;
1112
pub mod maila;
1213
pub mod mailb;
1314
pub mod mb;
@@ -31,6 +32,7 @@ use {Type, Error};
3132
pub use self::a::Record as A;
3233
pub use self::aaaa::Record as Aaaa;
3334
pub use self::cname::Record as Cname;
35+
pub use self::https::Record as Https;
3436
pub use self::mx::Record as Mx;
3537
pub use self::ns::Record as Ns;
3638
pub use self::nsec::Record as Nsec;
@@ -48,6 +50,7 @@ pub enum RData<'a> {
4850
A(A),
4951
AAAA(Aaaa),
5052
CNAME(Cname<'a>),
53+
HTTPS(Https<'a>),
5154
MX(Mx<'a>),
5255
NS(Ns<'a>),
5356
PTR(Ptr<'a>),
@@ -89,6 +92,7 @@ impl<'a> RData<'a> {
8992
RData::A(..) => Type::A,
9093
RData::AAAA(..) => Type::AAAA,
9194
RData::CNAME(..) => Type::CNAME,
95+
RData::HTTPS(..) => Type::HTTPS,
9296
RData::NS(..) => Type::NS,
9397
RData::MX(..) => Type::MX,
9498
RData::PTR(..) => Type::PTR,

0 commit comments

Comments
 (0)