|
|
|
@ -23,9 +23,33 @@ pub enum CheckDomainError { |
|
|
|
|
|
|
|
|
|
pub enum DNSRecord { |
|
|
|
|
A(net::Ipv4Addr), |
|
|
|
|
AAAA(net::Ipv6Addr), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl DNSRecord { |
|
|
|
|
async fn check_aaaa( |
|
|
|
|
client: &mut AsyncClient, |
|
|
|
|
domain: &trust_dns_client::rr::Name, |
|
|
|
|
addr: &net::Ipv6Addr, |
|
|
|
|
) -> Result<bool, unexpected::Error> { |
|
|
|
|
let response = client |
|
|
|
|
.query(domain.clone(), DNSClass::IN, RecordType::AAAA) |
|
|
|
|
.await |
|
|
|
|
.or_unexpected_while("querying A record")?; |
|
|
|
|
|
|
|
|
|
let records = response.answers(); |
|
|
|
|
|
|
|
|
|
if records.len() != 1 { |
|
|
|
|
return Ok(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if the single record isn't a AAAA, or it's not the target AAAA, then return false
|
|
|
|
|
match records[0].data() { |
|
|
|
|
Some(RData::AAAA(remote_addr)) if remote_addr == addr => Ok(true), |
|
|
|
|
_ => return Ok(false), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async fn check_a( |
|
|
|
|
client: &mut AsyncClient, |
|
|
|
|
domain: &trust_dns_client::rr::Name, |
|
|
|
@ -42,10 +66,9 @@ impl DNSRecord { |
|
|
|
|
return Ok(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if the single record isn't a A, or it's not the target A, then return
|
|
|
|
|
// TargetANAMENotSet
|
|
|
|
|
// if the single record isn't a A, or it's not the target A, then return false
|
|
|
|
|
match records[0].data() { |
|
|
|
|
Some(RData::A(remote_a)) if remote_a == addr => Ok(true), |
|
|
|
|
Some(RData::A(remote_addr)) if remote_addr == addr => Ok(true), |
|
|
|
|
_ => return Ok(false), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -57,6 +80,7 @@ impl DNSRecord { |
|
|
|
|
) -> Result<bool, unexpected::Error> { |
|
|
|
|
match self { |
|
|
|
|
Self::A(addr) => Self::check_a(client, domain, &addr).await, |
|
|
|
|
Self::AAAA(addr) => Self::check_aaaa(client, domain, &addr).await, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|