use builtin dns parser, added more tests, save a copy of txt record data
This commit is contained in:
parent
939fdc61cb
commit
8bcee50a54
|
@ -1,5 +1,5 @@
|
|||
use crate::socket::{Interface as MulticastInterface, MulticastOptions, MulticastSocket};
|
||||
use crate::Config;
|
||||
use crate::{Config, DnsPacket};
|
||||
use dns_parser::Packet;
|
||||
use log::{info, trace, warn};
|
||||
use nix::errno::Errno;
|
||||
|
@ -50,7 +50,7 @@ impl Mdns {
|
|||
|
||||
pub fn process_packet(&self, msg: crate::socket::Message) {
|
||||
// TODO: Generalize this to parse any type of supported packet
|
||||
let packet = Packet::parse(&msg.data).unwrap_or_else(|e| {
|
||||
let packet = DnsPacket::parse(&msg.data).unwrap_or_else(|e| {
|
||||
trace!("{:0x?}", msg.data);
|
||||
|
||||
panic!(
|
||||
|
|
|
@ -262,6 +262,86 @@ mod test {
|
|||
0x00, 0x00, 0x00, 0x68, 0x10, 0x85, 0xe5, 0x00, 0x00, 0x29, 0x04, 0xd0, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
],
|
||||
vec![
|
||||
0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x05, 0x5f,
|
||||
0x69, 0x70, 0x70, 0x73, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61,
|
||||
0x6c, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x13, 0x10, 0x45,
|
||||
0x70, 0x73, 0x6f, 0x6e, 0x4d, 0x32, 0x30, 0x35, 0x20, 0x40, 0x20, 0x63, 0x75, 0x70,
|
||||
0x73, 0xc0, 0x0c, 0xc0, 0x28, 0x00, 0x10, 0x80, 0x01, 0x00, 0x00, 0x11, 0x94, 0x01,
|
||||
0xc3, 0x09, 0x74, 0x78, 0x74, 0x76, 0x65, 0x72, 0x73, 0x3d, 0x31, 0x08, 0x71, 0x74,
|
||||
0x6f, 0x74, 0x61, 0x6c, 0x3d, 0x31, 0x15, 0x72, 0x70, 0x3d, 0x70, 0x72, 0x69, 0x6e,
|
||||
0x74, 0x65, 0x72, 0x73, 0x2f, 0x45, 0x70, 0x73, 0x6f, 0x6e, 0x4d, 0x32, 0x30, 0x35,
|
||||
0x5b, 0x74, 0x79, 0x3d, 0x45, 0x70, 0x73, 0x6f, 0x6e, 0x20, 0x4d, 0x32, 0x30, 0x35,
|
||||
0x20, 0x53, 0x65, 0x72, 0x69, 0x65, 0x73, 0x20, 0x2d, 0x20, 0x65, 0x70, 0x73, 0x6f,
|
||||
0x6e, 0x2d, 0x69, 0x6e, 0x6b, 0x6a, 0x65, 0x74, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74,
|
||||
0x65, 0x72, 0x20, 0x31, 0x2e, 0x30, 0x2e, 0x30, 0x2d, 0x31, 0x6c, 0x73, 0x62, 0x33,
|
||||
0x2e, 0x32, 0x20, 0x28, 0x53, 0x65, 0x69, 0x6b, 0x6f, 0x20, 0x45, 0x70, 0x73, 0x6f,
|
||||
0x6e, 0x20, 0x43, 0x6f, 0x72, 0x70, 0x6f, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20,
|
||||
0x4c, 0x53, 0x42, 0x20, 0x33, 0x2e, 0x32, 0x29, 0x33, 0x61, 0x64, 0x6d, 0x69, 0x6e,
|
||||
0x75, 0x72, 0x6c, 0x3d, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x63, 0x75,
|
||||
0x70, 0x73, 0x2e, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x2e, 0x3a, 0x36, 0x33, 0x31, 0x2f,
|
||||
0x70, 0x72, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x73, 0x2f, 0x45, 0x70, 0x73, 0x6f, 0x6e,
|
||||
0x4d, 0x32, 0x30, 0x35, 0x05, 0x6e, 0x6f, 0x74, 0x65, 0x3d, 0x0a, 0x70, 0x72, 0x69,
|
||||
0x6f, 0x72, 0x69, 0x74, 0x79, 0x3d, 0x30, 0x1f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63,
|
||||
0x74, 0x3d, 0x28, 0x57, 0x46, 0x2d, 0x4d, 0x31, 0x30, 0x33, 0x30, 0x2f, 0x4d, 0x31,
|
||||
0x35, 0x36, 0x30, 0x20, 0x53, 0x65, 0x72, 0x69, 0x65, 0x73, 0x29, 0x5a, 0x70, 0x64,
|
||||
0x6c, 0x3d, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f,
|
||||
0x70, 0x64, 0x66, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x2f, 0x70, 0x6f, 0x73, 0x74, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2c, 0x69,
|
||||
0x6d, 0x61, 0x67, 0x65, 0x2f, 0x6a, 0x70, 0x65, 0x67, 0x2c, 0x69, 0x6d, 0x61, 0x67,
|
||||
0x65, 0x2f, 0x70, 0x6e, 0x67, 0x2c, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x77,
|
||||
0x67, 0x2d, 0x72, 0x61, 0x73, 0x74, 0x65, 0x72, 0x2c, 0x69, 0x6d, 0x61, 0x67, 0x65,
|
||||
0x2f, 0x75, 0x72, 0x66, 0x29, 0x55, 0x55, 0x49, 0x44, 0x3d, 0x66, 0x37, 0x61, 0x65,
|
||||
0x33, 0x36, 0x37, 0x32, 0x2d, 0x30, 0x31, 0x38, 0x62, 0x2d, 0x33, 0x30, 0x30, 0x65,
|
||||
0x2d, 0x35, 0x64, 0x65, 0x64, 0x2d, 0x62, 0x66, 0x65, 0x35, 0x34, 0x33, 0x62, 0x32,
|
||||
0x62, 0x39, 0x63, 0x38, 0x07, 0x54, 0x4c, 0x53, 0x3d, 0x31, 0x2e, 0x32, 0x22, 0x55,
|
||||
0x52, 0x46, 0x3d, 0x56, 0x31, 0x2e, 0x34, 0x2c, 0x43, 0x50, 0x31, 0x2c, 0x57, 0x38,
|
||||
0x2c, 0x50, 0x51, 0x34, 0x2c, 0x4f, 0x46, 0x55, 0x30, 0x2c, 0x52, 0x53, 0x33, 0x30,
|
||||
0x30, 0x2c, 0x46, 0x4e, 0x33, 0x14, 0x6d, 0x6f, 0x70, 0x72, 0x69, 0x61, 0x2d, 0x63,
|
||||
0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x65, 0x64, 0x3d, 0x31, 0x2e, 0x33, 0x13, 0x70,
|
||||
0x72, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x30, 0x78,
|
||||
0x42, 0x30, 0x30, 0x36, 0xc0, 0x28, 0x00, 0x21, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78,
|
||||
0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x02, 0x77, 0x04, 0x63, 0x75, 0x70, 0x73, 0xc0,
|
||||
0x17, 0xc2, 0x1c, 0x00, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x04, 0x0a,
|
||||
0x00, 0x46, 0x07, 0x04, 0x5f, 0x69, 0x70, 0x70, 0xc0, 0x12, 0x00, 0x0c, 0x00, 0x01,
|
||||
0x00, 0x00, 0x11, 0x94, 0x00, 0x13, 0x10, 0x45, 0x70, 0x73, 0x6f, 0x6e, 0x4d, 0x32,
|
||||
0x30, 0x35, 0x20, 0x40, 0x20, 0x63, 0x75, 0x70, 0x73, 0xc2, 0x33, 0xc2, 0x44, 0x00,
|
||||
0x10, 0x80, 0x01, 0x00, 0x00, 0x11, 0x94, 0x01, 0xc3, 0x09, 0x74, 0x78, 0x74, 0x76,
|
||||
0x65, 0x72, 0x73, 0x3d, 0x31, 0x08, 0x71, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x3d, 0x31,
|
||||
0x15, 0x72, 0x70, 0x3d, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x73, 0x2f, 0x45,
|
||||
0x70, 0x73, 0x6f, 0x6e, 0x4d, 0x32, 0x30, 0x35, 0x5b, 0x74, 0x79, 0x3d, 0x45, 0x70,
|
||||
0x73, 0x6f, 0x6e, 0x20, 0x4d, 0x32, 0x30, 0x35, 0x20, 0x53, 0x65, 0x72, 0x69, 0x65,
|
||||
0x73, 0x20, 0x2d, 0x20, 0x65, 0x70, 0x73, 0x6f, 0x6e, 0x2d, 0x69, 0x6e, 0x6b, 0x6a,
|
||||
0x65, 0x74, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x20, 0x31, 0x2e, 0x30,
|
||||
0x2e, 0x30, 0x2d, 0x31, 0x6c, 0x73, 0x62, 0x33, 0x2e, 0x32, 0x20, 0x28, 0x53, 0x65,
|
||||
0x69, 0x6b, 0x6f, 0x20, 0x45, 0x70, 0x73, 0x6f, 0x6e, 0x20, 0x43, 0x6f, 0x72, 0x70,
|
||||
0x6f, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x4c, 0x53, 0x42, 0x20, 0x33, 0x2e,
|
||||
0x32, 0x29, 0x33, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x75, 0x72, 0x6c, 0x3d, 0x68, 0x74,
|
||||
0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x63, 0x75, 0x70, 0x73, 0x2e, 0x6c, 0x6f, 0x63,
|
||||
0x61, 0x6c, 0x2e, 0x3a, 0x36, 0x33, 0x31, 0x2f, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x65,
|
||||
0x72, 0x73, 0x2f, 0x45, 0x70, 0x73, 0x6f, 0x6e, 0x4d, 0x32, 0x30, 0x35, 0x05, 0x6e,
|
||||
0x6f, 0x74, 0x65, 0x3d, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x3d,
|
||||
0x30, 0x1f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x3d, 0x28, 0x57, 0x46, 0x2d,
|
||||
0x4d, 0x31, 0x30, 0x33, 0x30, 0x2f, 0x4d, 0x31, 0x35, 0x36, 0x30, 0x20, 0x53, 0x65,
|
||||
0x72, 0x69, 0x65, 0x73, 0x29, 0x5a, 0x70, 0x64, 0x6c, 0x3d, 0x61, 0x70, 0x70, 0x6c,
|
||||
0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x70, 0x64, 0x66, 0x2c, 0x61, 0x70,
|
||||
0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x70, 0x6f, 0x73, 0x74,
|
||||
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2c, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x6a,
|
||||
0x70, 0x65, 0x67, 0x2c, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67, 0x2c,
|
||||
0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x77, 0x67, 0x2d, 0x72, 0x61, 0x73, 0x74,
|
||||
0x65, 0x72, 0x2c, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x75, 0x72, 0x66, 0x29, 0x55,
|
||||
0x55, 0x49, 0x44, 0x3d, 0x66, 0x37, 0x61, 0x65, 0x33, 0x36, 0x37, 0x32, 0x2d, 0x30,
|
||||
0x31, 0x38, 0x62, 0x2d, 0x33, 0x30, 0x30, 0x65, 0x2d, 0x35, 0x64, 0x65, 0x64, 0x2d,
|
||||
0x62, 0x66, 0x65, 0x35, 0x34, 0x33, 0x62, 0x32, 0x62, 0x39, 0x63, 0x38, 0x07, 0x54,
|
||||
0x4c, 0x53, 0x3d, 0x31, 0x2e, 0x32, 0x22, 0x55, 0x52, 0x46, 0x3d, 0x56, 0x31, 0x2e,
|
||||
0x34, 0x2c, 0x43, 0x50, 0x31, 0x2c, 0x57, 0x38, 0x2c, 0x50, 0x51, 0x34, 0x2c, 0x4f,
|
||||
0x46, 0x55, 0x30, 0x2c, 0x52, 0x53, 0x33, 0x30, 0x30, 0x2c, 0x46, 0x4e, 0x33, 0x14,
|
||||
0x6d, 0x6f, 0x70, 0x72, 0x69, 0x61, 0x2d, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69,
|
||||
0x65, 0x64, 0x3d, 0x31, 0x2e, 0x33, 0x13, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x65, 0x72,
|
||||
0x2d, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x30, 0x78, 0x42, 0x30, 0x30, 0x36, 0xc2, 0x44,
|
||||
0x00, 0x21, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0x77, 0xc2, 0x1c,
|
||||
],
|
||||
];
|
||||
|
||||
for input in inputs.iter() {
|
||||
|
|
|
@ -5,6 +5,6 @@ pub struct Record {}
|
|||
|
||||
impl Record {
|
||||
pub fn parse(data: &[u8], original: &[u8]) -> Result<Self, ParserError> {
|
||||
Err(ParserError::UnexpectedEOP)
|
||||
Ok(Self {})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,13 @@ use crate::{ParserError, Qname};
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct Record {
|
||||
sets: Vec<Vec<u8>>,
|
||||
sets: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Record {
|
||||
pub fn parse(data: &[u8], original: &[u8]) -> Result<Self, ParserError> {
|
||||
Ok(Self { sets: vec![] })
|
||||
Ok(Self {
|
||||
sets: data.to_vec(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ impl ResourceRecord {
|
|||
if read + rdlength as usize > data.len() {
|
||||
return Err(ParserError::UnexpectedEOP);
|
||||
}
|
||||
|
||||
let rdata = RData::parse(rtype, &data[read..read + rdlength as usize], original)?;
|
||||
read += rdlength as usize;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ impl Default for MulticastOptions {
|
|||
fn default() -> Self {
|
||||
MulticastOptions {
|
||||
read_timeout: Duration::from_secs(1),
|
||||
buffer_size: 512,
|
||||
buffer_size: 4096,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user