403 lines
7.5 KiB
Rust
403 lines
7.5 KiB
Rust
|
use bytes::Bytes;
|
||
|
use ser::DnsPacketData;
|
||
|
use common_types::*;
|
||
|
use std::net::{Ipv4Addr, Ipv6Addr};
|
||
|
|
||
|
// unless otherwise documented, class should probably be IN (0x0001)
|
||
|
|
||
|
// class IN
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct A {
|
||
|
addr: Ipv4Addr,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct NS {
|
||
|
nsdname: DnsCompressedName,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct MD {
|
||
|
madname: DnsCompressedName,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct MF {
|
||
|
madname: DnsCompressedName,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct CNAME {
|
||
|
cname: DnsCompressedName,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct SOA {
|
||
|
mname: DnsCompressedName,
|
||
|
rname: DnsCompressedName,
|
||
|
serial: u32,
|
||
|
refresh: u32,
|
||
|
retry: u32,
|
||
|
expire: u32,
|
||
|
minimum: u32,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct MB {
|
||
|
madname: DnsCompressedName,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct MG {
|
||
|
mgmname: DnsCompressedName,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct MR {
|
||
|
newname: DnsCompressedName,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct NULL {
|
||
|
anything: RemainingText,
|
||
|
}
|
||
|
|
||
|
// class IN
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct WKS {
|
||
|
address: Ipv4Addr,
|
||
|
protocol: u8,
|
||
|
bitmap: RemainingText,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct PTR {
|
||
|
ptrdname: DnsCompressedName,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct HINFO {
|
||
|
cpu: ShortText,
|
||
|
os: ShortText,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct MINFO {
|
||
|
rmailbx: DnsCompressedName,
|
||
|
emailbx: DnsCompressedName,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct MX {
|
||
|
preference: u16,
|
||
|
mxname: DnsCompressedName,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct TXT {
|
||
|
text: LongText,
|
||
|
}
|
||
|
|
||
|
// end of RFC 1035: no DnsCompressedName below!
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct RP {
|
||
|
mbox: DnsName,
|
||
|
txt: DnsName,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct AFSDB {
|
||
|
subtype: u16,
|
||
|
hostname: DnsName,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
// pub struct X25;
|
||
|
|
||
|
// class independent
|
||
|
// pub struct ISDN;
|
||
|
|
||
|
// class independent
|
||
|
// pub struct RT;
|
||
|
|
||
|
// pub struct NSAP;
|
||
|
// pub struct NSAP_PTR;
|
||
|
// pub struct SIG;
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct KEY {
|
||
|
flags: u16,
|
||
|
protocol: u8,
|
||
|
algorithm: u8,
|
||
|
certificate: RemainingText,
|
||
|
}
|
||
|
|
||
|
// pub struct PX;
|
||
|
// pub struct GPOS;
|
||
|
|
||
|
// class IN
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct AAAA {
|
||
|
addr: Ipv6Addr,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, RRData)]
|
||
|
pub enum LOC {
|
||
|
Version0(LOC0),
|
||
|
UnknownVersion{
|
||
|
version: u8,
|
||
|
data: RemainingText
|
||
|
},
|
||
|
}
|
||
|
|
||
|
impl DnsPacketData for LOC {
|
||
|
fn deserialize(data: &mut ::std::io::Cursor<Bytes>) -> ::errors::Result<Self> {
|
||
|
let version: u8 = DnsPacketData::deserialize(data)?;
|
||
|
if 0 == version {
|
||
|
Ok(LOC::Version0(DnsPacketData::deserialize(data)?))
|
||
|
} else {
|
||
|
Ok(LOC::UnknownVersion{
|
||
|
version: version,
|
||
|
data: DnsPacketData::deserialize(data)?,
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[derive(Clone, Debug, DnsPacketData)]
|
||
|
pub struct LOC0 {
|
||
|
size: u8,
|
||
|
horizontal_precision: u8,
|
||
|
vertical_precision: u8,
|
||
|
latitude: u32,
|
||
|
longitude: u32,
|
||
|
altitude: u32,
|
||
|
}
|
||
|
|
||
|
// pub struct NXT;
|
||
|
// pub struct EID;
|
||
|
// pub struct NIMLOC;
|
||
|
|
||
|
// class IN
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct SRV {
|
||
|
preference: u16,
|
||
|
weight: u16,
|
||
|
port: u16,
|
||
|
target: DnsName,
|
||
|
}
|
||
|
|
||
|
// pub struct ATMA;
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct NAPTR {
|
||
|
order: u16,
|
||
|
preference: u16,
|
||
|
flags: ShortText,
|
||
|
service: ShortText,
|
||
|
regexp: ShortText,
|
||
|
replacement: DnsName,
|
||
|
}
|
||
|
|
||
|
// class IN
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct KX {
|
||
|
preference: u16,
|
||
|
exchanger: DnsName,
|
||
|
}
|
||
|
|
||
|
// class ??
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct CERT {
|
||
|
cert_type: u16,
|
||
|
key_tag: u16,
|
||
|
algorithm: u8,
|
||
|
certificate: RemainingText,
|
||
|
}
|
||
|
|
||
|
// pub struct A6;
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct DNAME {
|
||
|
target: DnsName,
|
||
|
}
|
||
|
|
||
|
// pub struct SINK;
|
||
|
|
||
|
// OPT should be decoded at "transport level", abuses ttl and class
|
||
|
// fields too.
|
||
|
// pub struct OPT;
|
||
|
|
||
|
// pub struct APL;
|
||
|
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct DS {
|
||
|
key_tag: u16,
|
||
|
algorithm: u8,
|
||
|
digest_type: u8,
|
||
|
digest: HexRemainingBlob,
|
||
|
}
|
||
|
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct SSHFP {
|
||
|
algorithm: u8,
|
||
|
fingerprint_type: u8,
|
||
|
fingerprint: HexRemainingBlob,
|
||
|
}
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct IPSECKEY;
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct RRSIG {
|
||
|
rr_type: Type,
|
||
|
algorithm: u8,
|
||
|
labels: u8,
|
||
|
original_ttl: u32,
|
||
|
signature_expiration: u32,
|
||
|
signature_inception: u32,
|
||
|
key_tag: u16,
|
||
|
signers_name: DnsName,
|
||
|
signature: RemainingText,
|
||
|
}
|
||
|
|
||
|
#[derive(Clone, Debug, DnsPacketData)]
|
||
|
pub struct NsecTypeBitmap {
|
||
|
types: RemainingText, // TODO: actually parse it
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct NSEC {
|
||
|
next: DnsName,
|
||
|
bitmap: NsecTypeBitmap,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct DNSKEY {
|
||
|
flags: u16,
|
||
|
protocol: u8,
|
||
|
algorithm: u8,
|
||
|
public_key: RemainingText,
|
||
|
}
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct DHCID;
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct NSEC3 {
|
||
|
hash_algorithm: u8,
|
||
|
flags: u8,
|
||
|
iterations: u16,
|
||
|
salt: HexShortBlob,
|
||
|
next_hashed: Base32ShortBlob,
|
||
|
bitmap: NsecTypeBitmap,
|
||
|
}
|
||
|
|
||
|
// class independent
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct NSEC3PARAM {
|
||
|
hash_algorithm: u8,
|
||
|
flags: u8,
|
||
|
iterations: u16,
|
||
|
salt: HexShortBlob,
|
||
|
}
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct TLSA;
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct SMIMEA;
|
||
|
|
||
|
// pub struct HIP;
|
||
|
// pub struct NINFO;
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct RKEY;
|
||
|
|
||
|
// pub struct TALINK;
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct CDS;
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct CDNSKEY;
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct OPENPGPKEY;
|
||
|
|
||
|
// pub struct CSYNC;
|
||
|
|
||
|
#[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
pub struct SPF {
|
||
|
text: LongText,
|
||
|
}
|
||
|
|
||
|
// pub struct UINFO;
|
||
|
// pub struct UID;
|
||
|
// pub struct GID;
|
||
|
// pub struct UNSPEC;
|
||
|
// pub struct NID;
|
||
|
// pub struct L32;
|
||
|
// pub struct L64;
|
||
|
// pub struct LP;
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct EUI48;
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct EUI64;
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct TKEY;
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct TSIG;
|
||
|
|
||
|
// pub struct IXFR; // qtype only?
|
||
|
// pub struct AXFR; // qtype only?
|
||
|
// pub struct MAILB; // qtype only?
|
||
|
// pub struct MAILA; // qtype only?
|
||
|
// pub struct ANY; // qtype only?
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct URI;
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct CAA;
|
||
|
|
||
|
// pub struct AVC;
|
||
|
// pub struct DOA;
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct DLV;
|
||
|
|
||
|
// pub struct ADDR;
|
||
|
|
||
|
// #[derive(Clone, Debug, DnsPacketData, RRData)]
|
||
|
// pub struct ALIAS;
|