use new Types for A and AAAA record types
This commit is contained in:
parent
f9aa112580
commit
4a1c4fe2d1
@ -281,6 +281,7 @@ fn test_server_continues_on_bad_data_tcp() {
|
||||
#[cfg(feature = "resolver")]
|
||||
fn test_forward() {
|
||||
use server_harness::query_message;
|
||||
use trust_dns_proto::rr::rdata::A;
|
||||
|
||||
//env_logger::init();
|
||||
|
||||
@ -304,7 +305,7 @@ fn test_forward() {
|
||||
);
|
||||
assert_eq!(
|
||||
*response.answers()[0].data().and_then(RData::as_a).unwrap(),
|
||||
Ipv4Addr::new(93, 184, 216, 34)
|
||||
A::new(93, 184, 216, 34)
|
||||
);
|
||||
|
||||
// just tests that multiple queries work
|
||||
@ -326,7 +327,7 @@ fn test_forward() {
|
||||
);
|
||||
assert_eq!(
|
||||
*response.answers()[0].data().and_then(RData::as_a).unwrap(),
|
||||
Ipv4Addr::new(93, 184, 216, 34)
|
||||
A::new(93, 184, 216, 34)
|
||||
);
|
||||
assert!(!response.header().authoritative());
|
||||
})
|
||||
|
@ -4,7 +4,6 @@ use std::{
|
||||
env,
|
||||
io::{stdout, BufRead, BufReader, Write},
|
||||
mem,
|
||||
net::*,
|
||||
panic::{catch_unwind, UnwindSafe},
|
||||
process::{Command, Stdio},
|
||||
str::FromStr,
|
||||
@ -19,7 +18,7 @@ use tracing::{info, warn};
|
||||
use trust_dns_client::{client::*, proto::xfer::DnsResponse};
|
||||
#[cfg(feature = "dnssec")]
|
||||
use trust_dns_proto::rr::dnssec::*;
|
||||
use trust_dns_proto::rr::*;
|
||||
use trust_dns_proto::rr::{rdata::A, *};
|
||||
|
||||
#[cfg(feature = "dnssec")]
|
||||
use self::mut_message_client::MutMessageHandle;
|
||||
@ -250,7 +249,7 @@ pub fn query_a<C: ClientHandle>(io_loop: &mut Runtime, client: &mut C) {
|
||||
let record = &response.answers()[0];
|
||||
|
||||
if let Some(RData::A(ref address)) = record.data() {
|
||||
assert_eq!(address, &Ipv4Addr::new(127, 0, 0, 1))
|
||||
assert_eq!(address, &A::new(127, 0, 0, 1))
|
||||
} else {
|
||||
panic!("wrong RDATA")
|
||||
}
|
||||
|
@ -863,7 +863,7 @@ where
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use crate::rr::rdata::soa::SOA;
|
||||
use crate::rr::rdata::{A, SOA};
|
||||
use futures_util::stream::iter;
|
||||
use ClientStreamXfrState::*;
|
||||
|
||||
@ -880,8 +880,8 @@ mod tests {
|
||||
Record::from_rdata(Name::from_ascii("example.com.").unwrap(), 600, soa)
|
||||
}
|
||||
|
||||
fn a_record(ip: u32) -> Record {
|
||||
let a = RData::A(ip.into());
|
||||
fn a_record(ip: u8) -> Record {
|
||||
let a = RData::A(A::new(0, 0, 0, ip));
|
||||
Record::from_rdata(Name::from_ascii("www.example.com.").unwrap(), 600, a)
|
||||
}
|
||||
|
||||
@ -1086,7 +1086,6 @@ mod tests {
|
||||
use crate::proto::iocompat::AsyncIoTokioAsStd;
|
||||
use crate::rr::{DNSClass, Name, RData, RecordType};
|
||||
use crate::tcp::TcpClientStream;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::str::FromStr;
|
||||
use tokio::net::TcpStream as TokioTcpStream;
|
||||
|
||||
@ -1119,7 +1118,7 @@ mod tests {
|
||||
|
||||
// validate it's what we expected
|
||||
if let Some(RData::A(addr)) = message_returned.answers()[0].data() {
|
||||
assert_eq!(*addr, Ipv4Addr::new(93, 184, 216, 34));
|
||||
assert_eq!(*addr, A::new(93, 184, 216, 34));
|
||||
}
|
||||
|
||||
let message_parsed = Message::from_vec(&buffer)
|
||||
@ -1127,7 +1126,7 @@ mod tests {
|
||||
|
||||
// validate it's what we expected
|
||||
if let Some(RData::A(addr)) = message_parsed.answers()[0].data() {
|
||||
assert_eq!(*addr, Ipv4Addr::new(93, 184, 216, 34));
|
||||
assert_eq!(*addr, A::new(93, 184, 216, 34));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,7 @@
|
||||
//! # use trust_dns_client::udp::UdpClientConnection;
|
||||
//! use trust_dns_client::op::DnsResponse;
|
||||
//! use trust_dns_client::rr::{DNSClass, Name, RData, Record, RecordType};
|
||||
//! use trust_dns_client::rr::rdata::A;
|
||||
//! #
|
||||
//! # let address = "8.8.8.8:53".parse().unwrap();
|
||||
//! # let conn = UdpClientConnection::new(address).unwrap();
|
||||
@ -128,7 +129,7 @@
|
||||
//! // In order to access it we need to first check what type of record it is
|
||||
//! // In this case we are interested in A, IPv4 address
|
||||
//! if let Some(RData::A(ref ip)) = answers[0].data() {
|
||||
//! assert_eq!(*ip, Ipv4Addr::new(93, 184, 216, 34))
|
||||
//! assert_eq!(*ip, A::new(93, 184, 216, 34))
|
||||
//! } else {
|
||||
//! assert!(false, "unexpected result")
|
||||
//! }
|
||||
@ -160,7 +161,7 @@
|
||||
//! use trust_dns_client::rr::{Name, RData, Record, RecordType};
|
||||
//! use trust_dns_client::proto::rr::dnssec::{Algorithm, SigSigner, KeyPair};
|
||||
//! use trust_dns_client::op::ResponseCode;
|
||||
//! use trust_dns_client::rr::rdata::key::KEY;
|
||||
//! use trust_dns_client::rr::rdata::{A, key::KEY};
|
||||
//!
|
||||
//! # let address = "0.0.0.0:53".parse().unwrap();
|
||||
//! # let conn = UdpClientConnection::new(address).unwrap();
|
||||
@ -202,7 +203,7 @@
|
||||
//! let mut record = Record::with(Name::from_str("new.example.com").unwrap(),
|
||||
//! RecordType::A,
|
||||
//! Duration::minutes(5).whole_seconds() as u32);
|
||||
//! record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
//! record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
//!
|
||||
//! // the server must be authoritative for this zone
|
||||
//! let origin = Name::from_str("example.com.").unwrap();
|
||||
@ -231,6 +232,7 @@
|
||||
//! use trust_dns_client::client::{AsyncClient, ClientHandle};
|
||||
//! use trust_dns_client::proto::iocompat::AsyncIoTokioAsStd;
|
||||
//! use trust_dns_client::rr::{DNSClass, Name, RData, RecordType};
|
||||
//! use trust_dns_client::rr::rdata::A;
|
||||
//! use trust_dns_client::tcp::TcpClientStream;
|
||||
//!
|
||||
//! #[tokio::main]
|
||||
@ -264,7 +266,7 @@
|
||||
//!
|
||||
//! // validate it's what we expected
|
||||
//! if let Some(RData::A(addr)) = response.answers()[0].data() {
|
||||
//! assert_eq!(*addr, Ipv4Addr::new(93, 184, 216, 34));
|
||||
//! assert_eq!(*addr, A::new(93, 184, 216, 34));
|
||||
//! }
|
||||
//! }
|
||||
//! ```
|
||||
|
@ -527,7 +527,7 @@ impl Future for HttpsClientResponse {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr};
|
||||
use std::net::SocketAddr;
|
||||
use std::str::FromStr;
|
||||
|
||||
use rustls::KeyLogFile;
|
||||
@ -536,6 +536,7 @@ mod tests {
|
||||
|
||||
use crate::iocompat::AsyncIoTokioAsStd;
|
||||
use crate::op::{Message, Query, ResponseCode};
|
||||
use crate::rr::rdata::{A, AAAA};
|
||||
use crate::rr::{Name, RData, RecordType};
|
||||
use crate::xfer::{DnsRequestOptions, FirstAnswer};
|
||||
|
||||
@ -573,7 +574,7 @@ mod tests {
|
||||
.and_then(RData::as_a)
|
||||
.expect("Expected A record");
|
||||
|
||||
assert_eq!(addr, &Ipv4Addr::new(93, 184, 216, 34));
|
||||
assert_eq!(addr, &A::new(93, 184, 216, 34));
|
||||
|
||||
//
|
||||
// assert that the connection works for a second query
|
||||
@ -601,7 +602,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
addr,
|
||||
&Ipv6Addr::new(0x2606, 0x2800, 0x0220, 0x0001, 0x0248, 0x1893, 0x25c8, 0x1946)
|
||||
&AAAA::new(0x2606, 0x2800, 0x0220, 0x0001, 0x0248, 0x1893, 0x25c8, 0x1946)
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -639,7 +640,7 @@ mod tests {
|
||||
.and_then(RData::as_a)
|
||||
.expect("invalid response, expected A record");
|
||||
|
||||
assert_eq!(addr, &Ipv4Addr::new(93, 184, 216, 34));
|
||||
assert_eq!(addr, &A::new(93, 184, 216, 34));
|
||||
|
||||
//
|
||||
// assert that the connection works for a second query
|
||||
@ -663,7 +664,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
addr,
|
||||
&Ipv6Addr::new(0x2606, 0x2800, 0x0220, 0x0001, 0x0248, 0x1893, 0x25c8, 0x1946)
|
||||
&AAAA::new(0x2606, 0x2800, 0x0220, 0x0001, 0x0248, 0x1893, 0x25c8, 0x1946)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ pub trait TryParseIp {
|
||||
impl TryParseIp for str {
|
||||
fn try_parse_ip(&self) -> Option<RData> {
|
||||
match self.parse::<IpAddr>() {
|
||||
Ok(IpAddr::V4(ip4)) => Ok(RData::A(ip4)),
|
||||
Ok(IpAddr::V6(ip6)) => Ok(RData::AAAA(ip6)),
|
||||
Ok(IpAddr::V4(ip4)) => Ok(RData::A(ip4.into())),
|
||||
Ok(IpAddr::V6(ip6)) => Ok(RData::AAAA(ip6.into())),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
.ok()
|
||||
@ -54,12 +54,12 @@ fn test_try_parse_ip() {
|
||||
|
||||
assert_eq!(
|
||||
"127.0.0.1".try_parse_ip().expect("failed"),
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1))
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1).into())
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
"::1".try_parse_ip().expect("failed"),
|
||||
RData::AAAA(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1))
|
||||
RData::AAAA(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).into())
|
||||
);
|
||||
|
||||
assert!("example.com".try_parse_ip().is_none());
|
||||
|
@ -32,6 +32,10 @@
|
||||
//! ```
|
||||
|
||||
pub use std::net::Ipv4Addr;
|
||||
use std::{fmt, net::AddrParseError, ops::Deref, str};
|
||||
|
||||
#[cfg(feature = "serde-config")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
error::*,
|
||||
@ -39,7 +43,19 @@ use crate::{
|
||||
serialize::binary::*,
|
||||
};
|
||||
|
||||
impl RecordData for Ipv4Addr {
|
||||
/// The DNS A record type, an IPv4 address
|
||||
#[cfg_attr(feature = "serde-config", derive(Deserialize, Serialize))]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
pub struct A(pub Ipv4Addr);
|
||||
|
||||
impl A {
|
||||
/// Construct a new AAAA record with the 32 bits of IPv4 address
|
||||
pub const fn new(a: u8, b: u8, c: u8, d: u8) -> Self {
|
||||
Self(Ipv4Addr::new(a, b, c, d))
|
||||
}
|
||||
}
|
||||
|
||||
impl RecordData for A {
|
||||
fn try_from_rdata(data: RData) -> Result<Self, crate::rr::RData> {
|
||||
match data {
|
||||
RData::A(ipv4) => Ok(ipv4),
|
||||
@ -63,36 +79,93 @@ impl RecordData for Ipv4Addr {
|
||||
}
|
||||
}
|
||||
|
||||
impl BinEncodable for A {
|
||||
fn emit(&self, encoder: &mut BinEncoder<'_>) -> ProtoResult<()> {
|
||||
let segments = self.octets();
|
||||
|
||||
encoder.emit(segments[0])?;
|
||||
encoder.emit(segments[1])?;
|
||||
encoder.emit(segments[2])?;
|
||||
encoder.emit(segments[3])?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> BinDecodable<'r> for A {
|
||||
fn read(decoder: &mut BinDecoder<'r>) -> ProtoResult<Self> {
|
||||
// TODO: would this be more efficient as a single u32 read?
|
||||
Ok(Ipv4Addr::new(
|
||||
decoder.pop()?.unverified(/*valid as any u8*/),
|
||||
decoder.pop()?.unverified(/*valid as any u8*/),
|
||||
decoder.pop()?.unverified(/*valid as any u8*/),
|
||||
decoder.pop()?.unverified(/*valid as any u8*/),
|
||||
)
|
||||
.into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Read the RData from the given Decoder
|
||||
#[deprecated(note = "use the BinDecodable::read method instead")]
|
||||
pub fn read(decoder: &mut BinDecoder<'_>) -> ProtoResult<Ipv4Addr> {
|
||||
<Ipv4Addr as BinDecodable>::read(decoder)
|
||||
pub fn read(decoder: &mut BinDecoder<'_>) -> ProtoResult<A> {
|
||||
<A as BinDecodable>::read(decoder)
|
||||
}
|
||||
|
||||
/// Write the RData from the given Decoder
|
||||
#[deprecated(note = "use the BinEncodable::emit method instead")]
|
||||
pub fn emit(encoder: &mut BinEncoder<'_>, address: Ipv4Addr) -> ProtoResult<()> {
|
||||
BinEncodable::emit(&address, encoder)
|
||||
BinEncodable::emit(&A::from(address), encoder)
|
||||
}
|
||||
|
||||
impl From<Ipv4Addr> for A {
|
||||
fn from(a: Ipv4Addr) -> Self {
|
||||
Self(a)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<A> for Ipv4Addr {
|
||||
fn from(a: A) -> Self {
|
||||
a.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for A {
|
||||
type Target = Ipv4Addr;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for A {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl str::FromStr for A {
|
||||
type Err = AddrParseError;
|
||||
fn from_str(s: &str) -> Result<Self, AddrParseError> {
|
||||
Ipv4Addr::from_str(s).map(From::from)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod mytests {
|
||||
use std::net::Ipv4Addr;
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::*;
|
||||
use crate::serialize::binary::bin_tests::{test_emit_data_set, test_read_data_set};
|
||||
|
||||
fn get_data() -> Vec<(Ipv4Addr, Vec<u8>)> {
|
||||
fn get_data() -> Vec<(A, Vec<u8>)> {
|
||||
vec![
|
||||
(Ipv4Addr::from_str("0.0.0.0").unwrap(), vec![0, 0, 0, 0]), // base case
|
||||
(Ipv4Addr::from_str("1.0.0.0").unwrap(), vec![1, 0, 0, 0]),
|
||||
(Ipv4Addr::from_str("0.1.0.0").unwrap(), vec![0, 1, 0, 0]),
|
||||
(Ipv4Addr::from_str("0.0.1.0").unwrap(), vec![0, 0, 1, 0]),
|
||||
(Ipv4Addr::from_str("0.0.0.1").unwrap(), vec![0, 0, 0, 1]),
|
||||
(Ipv4Addr::from_str("127.0.0.1").unwrap(), vec![127, 0, 0, 1]),
|
||||
(A::from_str("0.0.0.0").unwrap(), vec![0, 0, 0, 0]), // base case
|
||||
(A::from_str("1.0.0.0").unwrap(), vec![1, 0, 0, 0]),
|
||||
(A::from_str("0.1.0.0").unwrap(), vec![0, 1, 0, 0]),
|
||||
(A::from_str("0.0.1.0").unwrap(), vec![0, 0, 1, 0]),
|
||||
(A::from_str("0.0.0.1").unwrap(), vec![0, 0, 0, 1]),
|
||||
(A::from_str("127.0.0.1").unwrap(), vec![127, 0, 0, 1]),
|
||||
(
|
||||
Ipv4Addr::from_str("192.168.64.32").unwrap(),
|
||||
A::from_str("192.168.64.32").unwrap(),
|
||||
vec![192, 168, 64, 32],
|
||||
),
|
||||
]
|
||||
@ -100,7 +173,7 @@ mod mytests {
|
||||
|
||||
#[test]
|
||||
fn test_parse() {
|
||||
test_read_data_set(get_data(), |ref mut d| Ipv4Addr::read(d));
|
||||
test_read_data_set(get_data(), |ref mut d| A::read(d));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -23,7 +23,11 @@
|
||||
//! resource record in network byte order (high-order byte first).
|
||||
//! ```
|
||||
|
||||
use std::net::Ipv6Addr;
|
||||
pub use std::net::Ipv6Addr;
|
||||
use std::{fmt, net::AddrParseError, ops::Deref, str};
|
||||
|
||||
#[cfg(feature = "serde-config")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
error::ProtoResult,
|
||||
@ -31,7 +35,20 @@ use crate::{
|
||||
serialize::binary::{BinDecodable, BinDecoder, BinEncodable, BinEncoder},
|
||||
};
|
||||
|
||||
impl RecordData for Ipv6Addr {
|
||||
/// The DNS AAAA record type, an IPv6 address
|
||||
#[cfg_attr(feature = "serde-config", derive(Deserialize, Serialize))]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
pub struct AAAA(pub Ipv6Addr);
|
||||
|
||||
impl AAAA {
|
||||
/// Construct a new AAAA record with the 128 bits of IPv6 address
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Self {
|
||||
Self(Ipv6Addr::new(a, b, c, d, e, f, g, h))
|
||||
}
|
||||
}
|
||||
|
||||
impl RecordData for AAAA {
|
||||
fn try_from_rdata(data: RData) -> Result<Self, crate::rr::RData> {
|
||||
match data {
|
||||
RData::AAAA(ipv4) => Ok(ipv4),
|
||||
@ -55,71 +72,136 @@ impl RecordData for Ipv6Addr {
|
||||
}
|
||||
}
|
||||
|
||||
impl BinEncodable for AAAA {
|
||||
fn emit(&self, encoder: &mut BinEncoder<'_>) -> ProtoResult<()> {
|
||||
let segments = self.segments();
|
||||
|
||||
// TODO: this might be more efficient as a single write of the array
|
||||
encoder.emit_u16(segments[0])?;
|
||||
encoder.emit_u16(segments[1])?;
|
||||
encoder.emit_u16(segments[2])?;
|
||||
encoder.emit_u16(segments[3])?;
|
||||
encoder.emit_u16(segments[4])?;
|
||||
encoder.emit_u16(segments[5])?;
|
||||
encoder.emit_u16(segments[6])?;
|
||||
encoder.emit_u16(segments[7])?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> BinDecodable<'r> for AAAA {
|
||||
fn read(decoder: &mut BinDecoder<'r>) -> ProtoResult<Self> {
|
||||
// TODO: would this be more efficient as two u64 reads?
|
||||
let a: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let b: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let c: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let d: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let e: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let f: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let g: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let h: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
|
||||
Ok(Ipv6Addr::new(a, b, c, d, e, f, g, h).into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Read the RData from the given Decoder
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
#[deprecated(note = "use the BinDecodable::read method instead")]
|
||||
pub fn read(decoder: &mut BinDecoder<'_>) -> ProtoResult<Ipv6Addr> {
|
||||
<Ipv6Addr as BinDecodable>::read(decoder)
|
||||
pub fn read(decoder: &mut BinDecoder<'_>) -> ProtoResult<AAAA> {
|
||||
<AAAA as BinDecodable>::read(decoder)
|
||||
}
|
||||
|
||||
/// Write the RData from the given Decoder
|
||||
#[deprecated(note = "use the BinEncodable::emit method instead")]
|
||||
pub fn emit(encoder: &mut BinEncoder<'_>, address: &Ipv6Addr) -> ProtoResult<()> {
|
||||
BinEncodable::emit(address, encoder)
|
||||
BinEncodable::emit(&AAAA::from(*address), encoder)
|
||||
}
|
||||
|
||||
impl From<Ipv6Addr> for AAAA {
|
||||
fn from(aaaa: Ipv6Addr) -> Self {
|
||||
Self(aaaa)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AAAA> for Ipv6Addr {
|
||||
fn from(aaaa: AAAA) -> Self {
|
||||
aaaa.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for AAAA {
|
||||
type Target = Ipv6Addr;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for AAAA {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl str::FromStr for AAAA {
|
||||
type Err = AddrParseError;
|
||||
fn from_str(s: &str) -> Result<Self, AddrParseError> {
|
||||
Ipv6Addr::from_str(s).map(From::from)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::net::Ipv6Addr;
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::*;
|
||||
use crate::serialize::binary::bin_tests::{test_emit_data_set, test_read_data_set};
|
||||
|
||||
fn get_data() -> Vec<(Ipv6Addr, Vec<u8>)> {
|
||||
fn get_data() -> Vec<(AAAA, Vec<u8>)> {
|
||||
vec![
|
||||
(
|
||||
Ipv6Addr::from_str("::").unwrap(),
|
||||
AAAA::from_str("::").unwrap(),
|
||||
vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
), // base case
|
||||
(
|
||||
Ipv6Addr::from_str("1::").unwrap(),
|
||||
AAAA::from_str("1::").unwrap(),
|
||||
vec![0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
),
|
||||
(
|
||||
Ipv6Addr::from_str("0:1::").unwrap(),
|
||||
AAAA::from_str("0:1::").unwrap(),
|
||||
vec![0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
),
|
||||
(
|
||||
Ipv6Addr::from_str("0:0:1::").unwrap(),
|
||||
AAAA::from_str("0:0:1::").unwrap(),
|
||||
vec![0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
),
|
||||
(
|
||||
Ipv6Addr::from_str("0:0:0:1::").unwrap(),
|
||||
AAAA::from_str("0:0:0:1::").unwrap(),
|
||||
vec![0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
),
|
||||
(
|
||||
Ipv6Addr::from_str("::1:0:0:0").unwrap(),
|
||||
AAAA::from_str("::1:0:0:0").unwrap(),
|
||||
vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
|
||||
),
|
||||
(
|
||||
Ipv6Addr::from_str("::1:0:0").unwrap(),
|
||||
AAAA::from_str("::1:0:0").unwrap(),
|
||||
vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
|
||||
),
|
||||
(
|
||||
Ipv6Addr::from_str("::1:0").unwrap(),
|
||||
AAAA::from_str("::1:0").unwrap(),
|
||||
vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
|
||||
),
|
||||
(
|
||||
Ipv6Addr::from_str("::1").unwrap(),
|
||||
AAAA::from_str("::1").unwrap(),
|
||||
vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
|
||||
),
|
||||
(
|
||||
Ipv6Addr::from_str("::127.0.0.1").unwrap(),
|
||||
AAAA::from_str("::127.0.0.1").unwrap(),
|
||||
vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1],
|
||||
),
|
||||
(
|
||||
Ipv6Addr::from_str("FF00::192.168.64.32").unwrap(),
|
||||
AAAA::from_str("FF00::192.168.64.32").unwrap(),
|
||||
vec![255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 168, 64, 32],
|
||||
),
|
||||
]
|
||||
@ -127,7 +209,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_read() {
|
||||
test_read_data_set(get_data(), |ref mut d| Ipv6Addr::read(d));
|
||||
test_read_data_set(get_data(), |ref mut d| AAAA::read(d));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -29,6 +29,8 @@ pub mod svcb;
|
||||
pub mod tlsa;
|
||||
pub mod txt;
|
||||
|
||||
pub use self::a::A;
|
||||
pub use self::aaaa::AAAA;
|
||||
pub use self::caa::CAA;
|
||||
pub use self::csync::CSYNC;
|
||||
pub use self::hinfo::HINFO;
|
||||
|
@ -12,8 +12,6 @@ use std::{
|
||||
cmp::{Ord, Ordering, PartialOrd},
|
||||
convert::TryFrom,
|
||||
fmt,
|
||||
net::Ipv4Addr,
|
||||
net::Ipv6Addr,
|
||||
};
|
||||
|
||||
#[cfg(feature = "serde-config")]
|
||||
@ -23,7 +21,10 @@ use enum_as_inner::EnumAsInner;
|
||||
|
||||
use crate::{
|
||||
error::{ProtoError, ProtoErrorKind, ProtoResult},
|
||||
rr::{Name, RData, RecordData, RecordDataDecodable, RecordType},
|
||||
rr::{
|
||||
rdata::{A, AAAA},
|
||||
Name, RData, RecordData, RecordDataDecodable, RecordType,
|
||||
},
|
||||
serialize::binary::{
|
||||
BinDecodable, BinDecoder, BinEncodable, BinEncoder, Restrict, RestrictedMath,
|
||||
},
|
||||
@ -401,7 +402,7 @@ pub enum SvcParamValue {
|
||||
/// or other geo-aware features and thereby degrade client performance.
|
||||
///
|
||||
/// see `IpHint`
|
||||
Ipv4Hint(IpHint<Ipv4Addr>),
|
||||
Ipv4Hint(IpHint<A>),
|
||||
/// ```text
|
||||
/// 6.3. "echconfig"
|
||||
///
|
||||
@ -424,7 +425,7 @@ pub enum SvcParamValue {
|
||||
/// ```
|
||||
EchConfig(EchConfig),
|
||||
/// See `IpHint`
|
||||
Ipv6Hint(IpHint<Ipv6Addr>),
|
||||
Ipv6Hint(IpHint<AAAA>),
|
||||
/// Unparsed network data. Refer to documents on the associated key value
|
||||
///
|
||||
/// This will be left as is when read off the wire, and encoded in bas64
|
||||
@ -469,9 +470,9 @@ impl SvcParamValue {
|
||||
let port = decoder.read_u16()?.unverified(/*all values are legal ports*/);
|
||||
Self::Port(port)
|
||||
}
|
||||
SvcParamKey::Ipv4Hint => Self::Ipv4Hint(IpHint::<Ipv4Addr>::read(&mut decoder)?),
|
||||
SvcParamKey::Ipv4Hint => Self::Ipv4Hint(IpHint::<A>::read(&mut decoder)?),
|
||||
SvcParamKey::EchConfig => Self::EchConfig(EchConfig::read(&mut decoder)?),
|
||||
SvcParamKey::Ipv6Hint => Self::Ipv6Hint(IpHint::<Ipv6Addr>::read(&mut decoder)?),
|
||||
SvcParamKey::Ipv6Hint => Self::Ipv6Hint(IpHint::<AAAA>::read(&mut decoder)?),
|
||||
SvcParamKey::Key(_) | SvcParamKey::Key65535 | SvcParamKey::Unknown(_) => {
|
||||
Self::Unknown(Unknown::read(&mut decoder)?)
|
||||
}
|
||||
|
@ -10,11 +10,7 @@
|
||||
|
||||
#[cfg(test)]
|
||||
use std::convert::From;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
fmt,
|
||||
net::{IpAddr, Ipv4Addr, Ipv6Addr},
|
||||
};
|
||||
use std::{cmp::Ordering, fmt, net::IpAddr};
|
||||
|
||||
#[cfg(feature = "serde-config")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -26,8 +22,8 @@ use crate::{
|
||||
error::{ProtoError, ProtoErrorKind, ProtoResult},
|
||||
rr::{
|
||||
rdata::{
|
||||
ANAME, CAA, CNAME, CSYNC, HINFO, HTTPS, MX, NAPTR, NS, NULL, OPENPGPKEY, OPT, PTR, SOA,
|
||||
SRV, SSHFP, SVCB, TLSA, TXT,
|
||||
A, AAAA, ANAME, CAA, CNAME, CSYNC, HINFO, HTTPS, MX, NAPTR, NS, NULL, OPENPGPKEY, OPT,
|
||||
PTR, SOA, SRV, SSHFP, SVCB, TLSA, TXT,
|
||||
},
|
||||
record_type::RecordType,
|
||||
RecordData, RecordDataDecodable,
|
||||
@ -86,7 +82,7 @@ pub enum RData {
|
||||
/// decimal numbers separated by dots without any embedded spaces (e.g.,
|
||||
/// "10.2.0.52" or "192.0.5.6").
|
||||
/// ```
|
||||
A(Ipv4Addr),
|
||||
A(A),
|
||||
|
||||
/// ```text
|
||||
/// -- RFC 1886 -- IPv6 DNS Extensions December 1995
|
||||
@ -96,7 +92,7 @@ pub enum RData {
|
||||
/// A 128 bit IPv6 address is encoded in the data portion of an AAAA
|
||||
/// resource record in network byte order (high-order byte first).
|
||||
/// ```
|
||||
AAAA(Ipv6Addr),
|
||||
AAAA(AAAA),
|
||||
|
||||
/// ```text
|
||||
/// 2. The ANAME resource record
|
||||
@ -746,8 +742,8 @@ impl RData {
|
||||
/// If this is an A or AAAA record type, then an IpAddr will be returned
|
||||
pub fn to_ip_addr(&self) -> Option<IpAddr> {
|
||||
match *self {
|
||||
Self::A(a) => Some(IpAddr::from(a)),
|
||||
Self::AAAA(aaaa) => Some(IpAddr::from(aaaa)),
|
||||
Self::A(a) => Some(IpAddr::from(a.0)),
|
||||
Self::AAAA(aaaa) => Some(IpAddr::from(aaaa.0)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -870,11 +866,11 @@ impl<'r> RecordDataDecodable<'r> for RData {
|
||||
let result = match record_type {
|
||||
RecordType::A => {
|
||||
trace!("reading A");
|
||||
Ipv4Addr::read_data(decoder, record_type, length).map(Self::A)
|
||||
A::read(decoder).map(Self::A)
|
||||
}
|
||||
RecordType::AAAA => {
|
||||
trace!("reading AAAA");
|
||||
Ipv6Addr::read_data(decoder, record_type, length).map(Self::AAAA)
|
||||
AAAA::read(decoder).map(Self::AAAA)
|
||||
}
|
||||
RecordType::ANAME => {
|
||||
trace!("reading ANAME");
|
||||
@ -1084,8 +1080,6 @@ impl Ord for RData {
|
||||
mod tests {
|
||||
#![allow(clippy::dbg_macro, clippy::print_stdout)]
|
||||
|
||||
use std::net::Ipv4Addr;
|
||||
use std::net::Ipv6Addr;
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::*;
|
||||
@ -1151,12 +1145,9 @@ mod tests {
|
||||
6, b'a', b'b', b'c', b'd', b'e', b'f', 3, b'g', b'h', b'i', 0, 1, b'j',
|
||||
],
|
||||
),
|
||||
(RData::A(A::from_str("0.0.0.0").unwrap()), vec![0, 0, 0, 0]),
|
||||
(
|
||||
RData::A(Ipv4Addr::from_str("0.0.0.0").unwrap()),
|
||||
vec![0, 0, 0, 0],
|
||||
),
|
||||
(
|
||||
RData::AAAA(Ipv6Addr::from_str("::").unwrap()),
|
||||
RData::AAAA(AAAA::from_str("::").unwrap()),
|
||||
vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
),
|
||||
(
|
||||
@ -1182,8 +1173,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_order() {
|
||||
let ordered: Vec<RData> = vec![
|
||||
RData::A(Ipv4Addr::from_str("0.0.0.0").unwrap()),
|
||||
RData::AAAA(Ipv6Addr::from_str("::").unwrap()),
|
||||
RData::A(A::from_str("0.0.0.0").unwrap()),
|
||||
RData::AAAA(AAAA::from_str("::").unwrap()),
|
||||
RData::SRV(SRV::new(
|
||||
1,
|
||||
2,
|
||||
@ -1230,8 +1221,8 @@ mod tests {
|
||||
"".to_string(),
|
||||
"j".to_string(),
|
||||
])),
|
||||
RData::A(Ipv4Addr::from_str("0.0.0.0").unwrap()),
|
||||
RData::AAAA(Ipv6Addr::from_str("::").unwrap()),
|
||||
RData::A(A::from_str("0.0.0.0").unwrap()),
|
||||
RData::AAAA(AAAA::from_str("::").unwrap()),
|
||||
RData::SRV(SRV::new(
|
||||
1,
|
||||
2,
|
||||
|
@ -842,11 +842,11 @@ mod tests {
|
||||
#![allow(clippy::dbg_macro, clippy::print_stdout)]
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::*;
|
||||
use crate::rr::dns_class::DNSClass;
|
||||
use crate::rr::rdata::A;
|
||||
use crate::rr::record_data::RData;
|
||||
use crate::rr::record_type::RecordType;
|
||||
use crate::rr::Name;
|
||||
@ -862,7 +862,7 @@ mod tests {
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_ttl(5)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(192, 168, 0, 1))));
|
||||
.set_data(Some(RData::A(A::new(192, 168, 0, 1))));
|
||||
|
||||
let mut vec_bytes: Vec<u8> = Vec::with_capacity(512);
|
||||
{
|
||||
@ -885,7 +885,7 @@ mod tests {
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_ttl(5)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(192, 168, 0, 1))));
|
||||
.set_data(Some(RData::A(A::new(192, 168, 0, 1))));
|
||||
|
||||
let mut greater_name = record.clone();
|
||||
greater_name.set_name(Name::from_str("zzz.example.com").unwrap());
|
||||
@ -897,7 +897,7 @@ mod tests {
|
||||
greater_class.set_dns_class(DNSClass::NONE);
|
||||
|
||||
let mut greater_rdata = record.clone();
|
||||
greater_rdata.set_data(Some(RData::A(Ipv4Addr::new(192, 168, 0, 255))));
|
||||
greater_rdata.set_data(Some(RData::A(A::new(192, 168, 0, 255))));
|
||||
|
||||
let compares = vec![
|
||||
(&record, &greater_name),
|
||||
|
@ -631,7 +631,7 @@ mod test {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(record_type)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24))))
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24).into())))
|
||||
.clone();
|
||||
|
||||
assert!(rr_set.insert(insert.clone(), 0));
|
||||
@ -649,7 +649,7 @@ mod test {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(record_type)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 25))))
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 25).into())))
|
||||
.clone();
|
||||
assert!(rr_set.insert(insert1.clone(), 0));
|
||||
assert_eq!(rr_set.records_without_rrsigs().count(), 2);
|
||||
@ -778,14 +778,14 @@ mod test {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(record_type)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24))))
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24).into())))
|
||||
.clone();
|
||||
let insert1 = Record::new()
|
||||
.set_name(name)
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(record_type)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 25))))
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 25).into())))
|
||||
.clone();
|
||||
|
||||
assert!(rr_set.insert(insert.clone(), 0));
|
||||
@ -952,7 +952,7 @@ mod test {
|
||||
.set_ttl(3600)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24))))
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24).into())))
|
||||
.clone();
|
||||
|
||||
let mut rrset = RecordSet::from(a);
|
||||
|
@ -11,8 +11,6 @@ mod decoder;
|
||||
mod encoder;
|
||||
mod restrict;
|
||||
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
|
||||
pub use self::decoder::{BinDecoder, DecodeError};
|
||||
pub use self::encoder::BinEncoder;
|
||||
pub use self::encoder::EncodeMode;
|
||||
@ -102,60 +100,3 @@ impl BinEncodable for Vec<u8> {
|
||||
encoder.emit_vec(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl BinEncodable for Ipv4Addr {
|
||||
fn emit(&self, encoder: &mut BinEncoder<'_>) -> ProtoResult<()> {
|
||||
let segments = self.octets();
|
||||
|
||||
encoder.emit(segments[0])?;
|
||||
encoder.emit(segments[1])?;
|
||||
encoder.emit(segments[2])?;
|
||||
encoder.emit(segments[3])?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> BinDecodable<'r> for Ipv4Addr {
|
||||
fn read(decoder: &mut BinDecoder<'r>) -> ProtoResult<Self> {
|
||||
// TODO: would this be more efficient as a single u32 read?
|
||||
Ok(Self::new(
|
||||
decoder.pop()?.unverified(/*valid as any u8*/),
|
||||
decoder.pop()?.unverified(/*valid as any u8*/),
|
||||
decoder.pop()?.unverified(/*valid as any u8*/),
|
||||
decoder.pop()?.unverified(/*valid as any u8*/),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl BinEncodable for Ipv6Addr {
|
||||
fn emit(&self, encoder: &mut BinEncoder<'_>) -> ProtoResult<()> {
|
||||
let segments = self.segments();
|
||||
|
||||
// TODO: this might be more efficient as a single write of the array
|
||||
encoder.emit_u16(segments[0])?;
|
||||
encoder.emit_u16(segments[1])?;
|
||||
encoder.emit_u16(segments[2])?;
|
||||
encoder.emit_u16(segments[3])?;
|
||||
encoder.emit_u16(segments[4])?;
|
||||
encoder.emit_u16(segments[5])?;
|
||||
encoder.emit_u16(segments[6])?;
|
||||
encoder.emit_u16(segments[7])?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> BinDecodable<'r> for Ipv6Addr {
|
||||
fn read(decoder: &mut BinDecoder<'r>) -> ProtoResult<Self> {
|
||||
// TODO: would this be more efficient as two u64 reads?
|
||||
let a: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let b: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let c: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let d: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let e: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let f: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let g: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
let h: u16 = decoder.read_u16()?.unverified(/*valid as any u16*/);
|
||||
|
||||
Ok(Self::new(a, b, c, d, e, f, g, h))
|
||||
}
|
||||
}
|
||||
|
@ -19,13 +19,16 @@
|
||||
use std::net::Ipv4Addr;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::serialize::txt::errors::{ParseError, ParseErrorKind, ParseResult};
|
||||
use crate::{
|
||||
rr::rdata::A,
|
||||
serialize::txt::errors::{ParseError, ParseErrorKind, ParseResult},
|
||||
};
|
||||
|
||||
/// Parse the RData from a set of Tokens
|
||||
pub(crate) fn parse<'i, I: Iterator<Item = &'i str>>(mut tokens: I) -> ParseResult<Ipv4Addr> {
|
||||
pub(crate) fn parse<'i, I: Iterator<Item = &'i str>>(mut tokens: I) -> ParseResult<A> {
|
||||
let address: Ipv4Addr = tokens
|
||||
.next()
|
||||
.ok_or_else(|| ParseError::from(ParseErrorKind::MissingToken("ipv4 address".to_string())))
|
||||
.and_then(|s| Ipv4Addr::from_str(s).map_err(Into::into))?;
|
||||
Ok(address)
|
||||
Ok(address.into())
|
||||
}
|
||||
|
@ -19,13 +19,16 @@
|
||||
use std::net::Ipv6Addr;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::serialize::txt::errors::{ParseError, ParseErrorKind, ParseResult};
|
||||
use crate::{
|
||||
rr::rdata::AAAA,
|
||||
serialize::txt::errors::{ParseError, ParseErrorKind, ParseResult},
|
||||
};
|
||||
|
||||
/// Parse the RData from a set of Tokens
|
||||
pub(crate) fn parse<'i, I: Iterator<Item = &'i str>>(mut tokens: I) -> ParseResult<Ipv6Addr> {
|
||||
pub(crate) fn parse<'i, I: Iterator<Item = &'i str>>(mut tokens: I) -> ParseResult<AAAA> {
|
||||
let address: Ipv6Addr = tokens
|
||||
.next()
|
||||
.ok_or_else(|| ParseError::from(ParseErrorKind::MissingToken("ipv6 address".to_string())))
|
||||
.and_then(|s| Ipv6Addr::from_str(s).map_err(Into::into))?;
|
||||
Ok(address)
|
||||
Ok(address.into())
|
||||
}
|
||||
|
@ -7,13 +7,13 @@
|
||||
|
||||
//! SVCB records in presentation format
|
||||
|
||||
use std::{
|
||||
net::{Ipv4Addr, Ipv6Addr},
|
||||
str::FromStr,
|
||||
};
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::{
|
||||
rr::{rdata::svcb::*, Name},
|
||||
rr::{
|
||||
rdata::{svcb::*, A, AAAA},
|
||||
Name,
|
||||
},
|
||||
serialize::txt::{
|
||||
errors::{ParseError, ParseErrorKind, ParseResult},
|
||||
Lexer, Token,
|
||||
@ -238,7 +238,7 @@ fn parse_ipv4_hint(value: Option<&str>) -> Result<SvcParamValue, ParseError> {
|
||||
ParseError::from(ParseErrorKind::Message("expected at least one ipv4 hint"))
|
||||
})?;
|
||||
|
||||
let hints = parse_list::<Ipv4Addr>(value)?;
|
||||
let hints = parse_list::<A>(value)?;
|
||||
Ok(SvcParamValue::Ipv4Hint(IpHint(hints)))
|
||||
}
|
||||
|
||||
@ -276,7 +276,7 @@ fn parse_ipv6_hint(value: Option<&str>) -> Result<SvcParamValue, ParseError> {
|
||||
ParseError::from(ParseErrorKind::Message("expected at least one ipv6 hint"))
|
||||
})?;
|
||||
|
||||
let hints = parse_list::<Ipv6Addr>(value)?;
|
||||
let hints = parse_list::<AAAA>(value)?;
|
||||
Ok(SvcParamValue::Ipv6Hint(IpHint(hints)))
|
||||
}
|
||||
|
||||
@ -371,10 +371,7 @@ mod tests {
|
||||
assert_eq!(SvcParamKey::Ipv4Hint, param.0);
|
||||
assert_eq!(
|
||||
param.1.as_ipv4_hint().expect("ipv4hint").0,
|
||||
&[
|
||||
Ipv4Addr::from([162, 159, 135, 79]),
|
||||
Ipv4Addr::from([162, 159, 136, 79])
|
||||
]
|
||||
&[A::new(162, 159, 135, 79), A::new(162, 159, 136, 79)]
|
||||
);
|
||||
|
||||
// echconfig
|
||||
@ -391,8 +388,8 @@ mod tests {
|
||||
assert_eq!(
|
||||
param.1.as_ipv6_hint().expect("ipv6hint").0,
|
||||
&[
|
||||
Ipv6Addr::from([0x2606, 0x4700, 0x7, 0, 0, 0, 0xa29f, 0x874f]),
|
||||
Ipv6Addr::from([0x2606, 0x4700, 0x7, 0, 0, 0, 0xa29f, 0x884f])
|
||||
AAAA::new(0x2606, 0x4700, 0x7, 0, 0, 0, 0xa29f, 0x874f),
|
||||
AAAA::new(0x2606, 0x4700, 0x7, 0, 0, 0, 0xa29f, 0x884f)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -553,7 +553,7 @@ mod test {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34).into())))
|
||||
.clone(),
|
||||
);
|
||||
(
|
||||
@ -625,16 +625,16 @@ mod test {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34).into())))
|
||||
.clone(),
|
||||
Record::new()
|
||||
.set_name(origin)
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::AAAA)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::AAAA(Ipv6Addr::new(
|
||||
0x2606, 0x2800, 0x220, 0x1, 0x248, 0x1893, 0x25c8, 0x1946,
|
||||
))))
|
||||
.set_data(Some(RData::AAAA(
|
||||
Ipv6Addr::new(0x2606, 0x2800, 0x220, 0x1, 0x248, 0x1893, 0x25c8, 0x1946).into(),
|
||||
)))
|
||||
.clone(),
|
||||
soa,
|
||||
]
|
||||
|
@ -647,7 +647,7 @@ impl NegativeType {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::op::{Message, Query, ResponseCode};
|
||||
use crate::rr::rdata::{CNAME, NS, SOA};
|
||||
use crate::rr::rdata::{A, CNAME, NS, SOA};
|
||||
use crate::rr::RData;
|
||||
use crate::rr::{Name, Record, RecordType};
|
||||
|
||||
@ -698,11 +698,11 @@ mod tests {
|
||||
}
|
||||
|
||||
fn ns1_a() -> Record {
|
||||
Record::from_rdata(xx(), 88640, RData::A([127, 0, 0, 2].into()))
|
||||
Record::from_rdata(xx(), 88640, RData::A(A::new(127, 0, 0, 2)))
|
||||
}
|
||||
|
||||
fn ns2_a() -> Record {
|
||||
Record::from_rdata(xx(), 88640, RData::A([127, 0, 0, 3].into()))
|
||||
Record::from_rdata(xx(), 88640, RData::A(A::new(127, 0, 0, 3)))
|
||||
}
|
||||
|
||||
fn soa() -> Record {
|
||||
@ -729,7 +729,7 @@ mod tests {
|
||||
message.add_answer(Record::from_rdata(
|
||||
Name::root(),
|
||||
88640,
|
||||
RData::A([127, 0, 0, 2].into()),
|
||||
RData::A(A::new(127, 0, 0, 2)),
|
||||
));
|
||||
|
||||
let response = DnsResponse::from_message(message).unwrap();
|
||||
|
@ -10,7 +10,6 @@
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
error::Error,
|
||||
net::{Ipv4Addr, Ipv6Addr},
|
||||
pin::Pin,
|
||||
sync::{
|
||||
atomic::{AtomicU8, Ordering},
|
||||
@ -33,7 +32,7 @@ use crate::{
|
||||
ResolverUsage, DEFAULT, INVALID, IN_ADDR_ARPA_127, IP6_ARPA_1, LOCAL,
|
||||
LOCALHOST as LOCALHOST_usage, ONION,
|
||||
},
|
||||
rdata::{CNAME, PTR, SOA},
|
||||
rdata::{A, AAAA, CNAME, PTR, SOA},
|
||||
resource::RecordRef,
|
||||
DNSClass, Name, RData, Record, RecordType,
|
||||
},
|
||||
@ -45,8 +44,8 @@ const MAX_QUERY_DEPTH: u8 = 8; // arbitrarily chosen number...
|
||||
|
||||
lazy_static! {
|
||||
static ref LOCALHOST: RData = RData::PTR(PTR(Name::from_ascii("localhost.").unwrap()));
|
||||
static ref LOCALHOST_V4: RData = RData::A(Ipv4Addr::new(127, 0, 0, 1));
|
||||
static ref LOCALHOST_V6: RData = RData::AAAA(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
|
||||
static ref LOCALHOST_V4: RData = RData::A(A::new(127, 0, 0, 1));
|
||||
static ref LOCALHOST_V6: RData = RData::AAAA(AAAA::new(0, 0, 0, 0, 0, 0, 0, 1));
|
||||
}
|
||||
|
||||
struct DepthTracker {
|
||||
@ -550,7 +549,7 @@ mod tests {
|
||||
Record::from_rdata(
|
||||
query.name().clone(),
|
||||
u32::max_value(),
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::A(A::new(127, 0, 0, 1)),
|
||||
),
|
||||
u32::max_value(),
|
||||
)],
|
||||
@ -570,7 +569,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
ips.iter().cloned().collect::<Vec<_>>(),
|
||||
vec![RData::A(Ipv4Addr::new(127, 0, 0, 1))]
|
||||
vec![RData::A(A::new(127, 0, 0, 1))]
|
||||
);
|
||||
}
|
||||
|
||||
@ -591,7 +590,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
ips.iter().cloned().collect::<Vec<_>>(),
|
||||
vec![RData::A(Ipv4Addr::new(127, 0, 0, 1))]
|
||||
vec![RData::A(A::new(127, 0, 0, 1))]
|
||||
);
|
||||
|
||||
// next should come from cache...
|
||||
@ -608,7 +607,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
ips.iter().cloned().collect::<Vec<_>>(),
|
||||
vec![RData::A(Ipv4Addr::new(127, 0, 0, 1))]
|
||||
vec![RData::A(A::new(127, 0, 0, 1))]
|
||||
);
|
||||
}
|
||||
|
||||
@ -739,12 +738,12 @@ mod tests {
|
||||
Record::from_rdata(
|
||||
Name::from_str("actual.example.com.").unwrap(),
|
||||
86400,
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::A(A::new(127, 0, 0, 1)),
|
||||
),
|
||||
Record::from_rdata(
|
||||
Name::from_str("actual.example.com.").unwrap(),
|
||||
86400,
|
||||
RData::AAAA(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)),
|
||||
RData::AAAA(AAAA::new(0, 0, 0, 0, 0, 0, 0, 1)),
|
||||
),
|
||||
]);
|
||||
|
||||
@ -774,8 +773,8 @@ mod tests {
|
||||
443,
|
||||
Name::from_str("www.example.com.").unwrap(),
|
||||
)),
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::AAAA(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)),
|
||||
RData::A(A::new(127, 0, 0, 1)),
|
||||
RData::AAAA(AAAA::new(0, 0, 0, 0, 0, 0, 0, 1)),
|
||||
]
|
||||
);
|
||||
}
|
||||
@ -843,12 +842,12 @@ mod tests {
|
||||
Record::from_rdata(
|
||||
Name::from_str("actual.example.com.").unwrap(),
|
||||
86400,
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::A(A::new(127, 0, 0, 1)),
|
||||
),
|
||||
Record::from_rdata(
|
||||
Name::from_str("actual.example.com.").unwrap(),
|
||||
86400,
|
||||
RData::AAAA(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)),
|
||||
RData::AAAA(AAAA::new(0, 0, 0, 0, 0, 0, 0, 1)),
|
||||
),
|
||||
]);
|
||||
|
||||
@ -870,8 +869,8 @@ mod tests {
|
||||
ips.iter().cloned().collect::<Vec<_>>(),
|
||||
vec![
|
||||
RData::NS(NS(Name::from_str("www.example.com.").unwrap())),
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::AAAA(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)),
|
||||
RData::A(A::new(127, 0, 0, 1)),
|
||||
RData::AAAA(AAAA::new(0, 0, 0, 0, 0, 0, 0, 1)),
|
||||
]
|
||||
);
|
||||
}
|
||||
@ -890,7 +889,7 @@ mod tests {
|
||||
message.insert_additionals(vec![Record::from_rdata(
|
||||
Name::from_str("actual.example.com.").unwrap(),
|
||||
second,
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::A(A::new(127, 0, 0, 1)),
|
||||
)]);
|
||||
|
||||
let records = CachingClient::handle_noerror(
|
||||
@ -1027,7 +1026,7 @@ mod tests {
|
||||
message.add_answer(Record::from_rdata(
|
||||
Name::from_str("www.example.local.").unwrap(),
|
||||
86400,
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::A(A::new(127, 0, 0, 1)),
|
||||
));
|
||||
|
||||
let client = mock(vec![
|
||||
|
@ -349,11 +349,11 @@ impl DnsLru {
|
||||
// see also the lookup_tests.rs in integration-tests crate
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::net::*;
|
||||
use std::str::FromStr;
|
||||
use std::time::*;
|
||||
|
||||
use proto::op::{Query, ResponseCode};
|
||||
use proto::rr::rdata::A;
|
||||
use proto::rr::{Name, RData, RecordType};
|
||||
|
||||
use super::*;
|
||||
@ -384,10 +384,10 @@ mod tests {
|
||||
let query = Query::query(name.clone(), RecordType::A);
|
||||
// record should have TTL of 1 second.
|
||||
let ips_ttl = vec![(
|
||||
Record::from_rdata(name.clone(), 1, RData::A(Ipv4Addr::new(127, 0, 0, 1))),
|
||||
Record::from_rdata(name.clone(), 1, RData::A(A::new(127, 0, 0, 1))),
|
||||
1,
|
||||
)];
|
||||
let ips = vec![RData::A(Ipv4Addr::new(127, 0, 0, 1))];
|
||||
let ips = vec![RData::A(A::new(127, 0, 0, 1))];
|
||||
|
||||
// configure the cache with a minimum TTL of 2 seconds.
|
||||
let ttls = TtlConfig {
|
||||
@ -404,7 +404,7 @@ mod tests {
|
||||
|
||||
// record should have TTL of 3 seconds.
|
||||
let ips_ttl = vec![(
|
||||
Record::from_rdata(name, 3, RData::A(Ipv4Addr::new(127, 0, 0, 1))),
|
||||
Record::from_rdata(name, 3, RData::A(A::new(127, 0, 0, 1))),
|
||||
3,
|
||||
)];
|
||||
|
||||
@ -474,10 +474,10 @@ mod tests {
|
||||
let query = Query::query(name.clone(), RecordType::A);
|
||||
// record should have TTL of 62 seconds.
|
||||
let ips_ttl = vec![(
|
||||
Record::from_rdata(name.clone(), 62, RData::A(Ipv4Addr::new(127, 0, 0, 1))),
|
||||
Record::from_rdata(name.clone(), 62, RData::A(A::new(127, 0, 0, 1))),
|
||||
62,
|
||||
)];
|
||||
let ips = vec![RData::A(Ipv4Addr::new(127, 0, 0, 1))];
|
||||
let ips = vec![RData::A(A::new(127, 0, 0, 1))];
|
||||
|
||||
// configure the cache with a maximum TTL of 60 seconds.
|
||||
let ttls = TtlConfig {
|
||||
@ -494,7 +494,7 @@ mod tests {
|
||||
|
||||
// record should have TTL of 59 seconds.
|
||||
let ips_ttl = vec![(
|
||||
Record::from_rdata(name, 59, RData::A(Ipv4Addr::new(127, 0, 0, 1))),
|
||||
Record::from_rdata(name, 59, RData::A(A::new(127, 0, 0, 1))),
|
||||
59,
|
||||
)];
|
||||
|
||||
@ -563,10 +563,10 @@ mod tests {
|
||||
let name = Name::from_str("www.example.com.").unwrap();
|
||||
let query = Query::query(name.clone(), RecordType::A);
|
||||
let ips_ttl = vec![(
|
||||
Record::from_rdata(name, 1, RData::A(Ipv4Addr::new(127, 0, 0, 1))),
|
||||
Record::from_rdata(name, 1, RData::A(A::new(127, 0, 0, 1))),
|
||||
1,
|
||||
)];
|
||||
let ips = vec![RData::A(Ipv4Addr::new(127, 0, 0, 1))];
|
||||
let ips = vec![RData::A(A::new(127, 0, 0, 1))];
|
||||
let lru = DnsLru::new(1, TtlConfig::default());
|
||||
|
||||
let rc_ips = lru.insert(query.clone(), ips_ttl, now);
|
||||
@ -584,17 +584,17 @@ mod tests {
|
||||
// TTL should be 1
|
||||
let ips_ttl = vec![
|
||||
(
|
||||
Record::from_rdata(name.clone(), 1, RData::A(Ipv4Addr::new(127, 0, 0, 1))),
|
||||
Record::from_rdata(name.clone(), 1, RData::A(A::new(127, 0, 0, 1))),
|
||||
1,
|
||||
),
|
||||
(
|
||||
Record::from_rdata(name, 2, RData::A(Ipv4Addr::new(127, 0, 0, 2))),
|
||||
Record::from_rdata(name, 2, RData::A(A::new(127, 0, 0, 2))),
|
||||
2,
|
||||
),
|
||||
];
|
||||
let ips = vec![
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 2)),
|
||||
RData::A(A::new(127, 0, 0, 1)),
|
||||
RData::A(A::new(127, 0, 0, 2)),
|
||||
];
|
||||
let lru = DnsLru::new(1, TtlConfig::default());
|
||||
|
||||
@ -620,17 +620,17 @@ mod tests {
|
||||
// TTL should be 1
|
||||
let ips_ttl = vec![
|
||||
(
|
||||
Record::from_rdata(name.clone(), 1, RData::A(Ipv4Addr::new(127, 0, 0, 1))),
|
||||
Record::from_rdata(name.clone(), 1, RData::A(A::new(127, 0, 0, 1))),
|
||||
1,
|
||||
),
|
||||
(
|
||||
Record::from_rdata(name, 2, RData::A(Ipv4Addr::new(127, 0, 0, 2))),
|
||||
Record::from_rdata(name, 2, RData::A(A::new(127, 0, 0, 2))),
|
||||
2,
|
||||
),
|
||||
];
|
||||
let ips = vec![
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 2)),
|
||||
RData::A(A::new(127, 0, 0, 1)),
|
||||
RData::A(A::new(127, 0, 0, 2)),
|
||||
];
|
||||
|
||||
// this cache should override the TTL of 1 seconds with the configured
|
||||
@ -680,17 +680,17 @@ mod tests {
|
||||
// TTL should be 500
|
||||
let ips_ttl = vec![
|
||||
(
|
||||
Record::from_rdata(name.clone(), 400, RData::A(Ipv4Addr::new(127, 0, 0, 1))),
|
||||
Record::from_rdata(name.clone(), 400, RData::A(A::new(127, 0, 0, 1))),
|
||||
400,
|
||||
),
|
||||
(
|
||||
Record::from_rdata(name, 500, RData::A(Ipv4Addr::new(127, 0, 0, 2))),
|
||||
Record::from_rdata(name, 500, RData::A(A::new(127, 0, 0, 2))),
|
||||
500,
|
||||
),
|
||||
];
|
||||
let ips = vec![
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 2)),
|
||||
RData::A(A::new(127, 0, 0, 1)),
|
||||
RData::A(A::new(127, 0, 0, 2)),
|
||||
];
|
||||
|
||||
// this cache should override the TTL of 500 seconds with the configured
|
||||
|
@ -205,7 +205,7 @@ mod tests {
|
||||
.map(ToOwned::to_owned)
|
||||
.collect::<Vec<RData>>();
|
||||
|
||||
assert_eq!(rdatas, vec![RData::A(Ipv4Addr::new(127, 0, 0, 1))]);
|
||||
assert_eq!(rdatas, vec![RData::A(Ipv4Addr::new(127, 0, 0, 1).into())]);
|
||||
|
||||
let rdatas = hosts
|
||||
.lookup_static_host(&Query::query(name, RecordType::AAAA))
|
||||
@ -216,7 +216,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
rdatas,
|
||||
vec![RData::AAAA(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1))]
|
||||
vec![RData::AAAA(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).into())]
|
||||
);
|
||||
|
||||
let name = Name::from_str("broadcasthost").unwrap();
|
||||
@ -226,7 +226,10 @@ mod tests {
|
||||
.iter()
|
||||
.map(ToOwned::to_owned)
|
||||
.collect::<Vec<RData>>();
|
||||
assert_eq!(rdatas, vec![RData::A(Ipv4Addr::new(255, 255, 255, 255))]);
|
||||
assert_eq!(
|
||||
rdatas,
|
||||
vec![RData::A(Ipv4Addr::new(255, 255, 255, 255).into())]
|
||||
);
|
||||
|
||||
let name = Name::from_str("example.com").unwrap();
|
||||
let rdatas = hosts
|
||||
@ -235,7 +238,7 @@ mod tests {
|
||||
.iter()
|
||||
.map(ToOwned::to_owned)
|
||||
.collect::<Vec<RData>>();
|
||||
assert_eq!(rdatas, vec![RData::A(Ipv4Addr::new(10, 0, 1, 102))]);
|
||||
assert_eq!(rdatas, vec![RData::A(Ipv4Addr::new(10, 0, 1, 102).into())]);
|
||||
|
||||
let name = Name::from_str("a.example.com").unwrap();
|
||||
let rdatas = hosts
|
||||
@ -244,7 +247,7 @@ mod tests {
|
||||
.iter()
|
||||
.map(ToOwned::to_owned)
|
||||
.collect::<Vec<RData>>();
|
||||
assert_eq!(rdatas, vec![RData::A(Ipv4Addr::new(10, 0, 1, 111))]);
|
||||
assert_eq!(rdatas, vec![RData::A(Ipv4Addr::new(10, 0, 1, 111).into())]);
|
||||
|
||||
let name = Name::from_str("b.example.com").unwrap();
|
||||
let rdatas = hosts
|
||||
@ -253,6 +256,6 @@ mod tests {
|
||||
.iter()
|
||||
.map(ToOwned::to_owned)
|
||||
.collect::<Vec<RData>>();
|
||||
assert_eq!(rdatas, vec![RData::A(Ipv4Addr::new(10, 0, 1, 111))]);
|
||||
assert_eq!(rdatas, vec![RData::A(Ipv4Addr::new(10, 0, 1, 111).into())]);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
use std::{
|
||||
cmp::min,
|
||||
error::Error,
|
||||
net::{Ipv4Addr, Ipv6Addr},
|
||||
pin::Pin,
|
||||
slice::Iter,
|
||||
sync::Arc,
|
||||
@ -34,7 +33,7 @@ use crate::{
|
||||
error::ProtoError,
|
||||
op::Query,
|
||||
rr::{
|
||||
rdata::{self, NS, PTR},
|
||||
rdata::{self, A, AAAA, NS, PTR},
|
||||
Name, RData, Record, RecordType,
|
||||
},
|
||||
xfer::{DnsRequest, DnsRequestOptions, DnsResponse},
|
||||
@ -494,19 +493,13 @@ lookup_type!(
|
||||
RData::PTR,
|
||||
PTR
|
||||
);
|
||||
lookup_type!(
|
||||
Ipv4Lookup,
|
||||
Ipv4LookupIter,
|
||||
Ipv4LookupIntoIter,
|
||||
RData::A,
|
||||
Ipv4Addr
|
||||
);
|
||||
lookup_type!(Ipv4Lookup, Ipv4LookupIter, Ipv4LookupIntoIter, RData::A, A);
|
||||
lookup_type!(
|
||||
Ipv6Lookup,
|
||||
Ipv6LookupIter,
|
||||
Ipv6LookupIntoIter,
|
||||
RData::AAAA,
|
||||
Ipv6Addr
|
||||
AAAA
|
||||
);
|
||||
lookup_type!(
|
||||
MxLookup,
|
||||
@ -577,7 +570,7 @@ pub mod tests {
|
||||
message.insert_answers(vec![Record::from_rdata(
|
||||
Name::root(),
|
||||
86400,
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::A(A::new(127, 0, 0, 1)),
|
||||
)]);
|
||||
|
||||
let resp = DnsResponse::from_message(message).unwrap();
|
||||
@ -695,25 +688,19 @@ pub mod tests {
|
||||
Record::from_rdata(
|
||||
Name::from_str("www.example.com.").unwrap(),
|
||||
80,
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::A(A::new(127, 0, 0, 1)),
|
||||
),
|
||||
Record::from_rdata(
|
||||
Name::from_str("www.example.com.").unwrap(),
|
||||
80,
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 2)),
|
||||
RData::A(A::new(127, 0, 0, 2)),
|
||||
),
|
||||
]),
|
||||
index: 0,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
lookup.next().unwrap(),
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1))
|
||||
);
|
||||
assert_eq!(
|
||||
lookup.next().unwrap(),
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 2))
|
||||
);
|
||||
assert_eq!(lookup.next().unwrap(), RData::A(A::new(127, 0, 0, 1)));
|
||||
assert_eq!(lookup.next().unwrap(), RData::A(A::new(127, 0, 0, 2)));
|
||||
assert_eq!(lookup.next(), None);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
//! At it's heart LookupIp uses Lookup for performing all lookups. It is unlike other standard lookups in that there are customizations around A and AAAA resolutions.
|
||||
|
||||
use std::error::Error;
|
||||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll};
|
||||
@ -82,8 +82,8 @@ impl<'i> Iterator for LookupIpIter<'i> {
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let iter: &mut _ = &mut self.0;
|
||||
iter.filter_map(|rdata| match *rdata {
|
||||
RData::A(ip) => Some(IpAddr::from(ip)),
|
||||
RData::AAAA(ip) => Some(IpAddr::from(ip)),
|
||||
RData::A(ip) => Some(IpAddr::from(Ipv4Addr::from(ip))),
|
||||
RData::AAAA(ip) => Some(IpAddr::from(Ipv6Addr::from(ip))),
|
||||
_ => None,
|
||||
})
|
||||
.next()
|
||||
@ -110,8 +110,8 @@ impl Iterator for LookupIpIntoIter {
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let iter: &mut _ = &mut self.0;
|
||||
iter.filter_map(|rdata| match rdata {
|
||||
RData::A(ip) => Some(IpAddr::from(ip)),
|
||||
RData::AAAA(ip) => Some(IpAddr::from(ip)),
|
||||
RData::A(ip) => Some(IpAddr::from(Ipv4Addr::from(ip))),
|
||||
RData::AAAA(ip) => Some(IpAddr::from(Ipv6Addr::from(ip))),
|
||||
_ => None,
|
||||
})
|
||||
.next()
|
||||
@ -487,7 +487,7 @@ pub mod tests {
|
||||
message.insert_answers(vec![Record::from_rdata(
|
||||
Name::root(),
|
||||
86400,
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
RData::A(Ipv4Addr::new(127, 0, 0, 1).into()),
|
||||
)]);
|
||||
|
||||
let resp = DnsResponse::from_message(message).unwrap();
|
||||
@ -501,7 +501,7 @@ pub mod tests {
|
||||
message.insert_answers(vec![Record::from_rdata(
|
||||
Name::root(),
|
||||
86400,
|
||||
RData::AAAA(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)),
|
||||
RData::AAAA(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).into()),
|
||||
)]);
|
||||
|
||||
let resp = DnsResponse::from_message(message).unwrap();
|
||||
|
@ -597,7 +597,7 @@ mod tests {
|
||||
.data()
|
||||
.and_then(RData::as_a)
|
||||
.expect("no a record available"),
|
||||
Ipv4Addr::new(93, 184, 216, 34)
|
||||
Ipv4Addr::new(93, 184, 216, 34).into()
|
||||
);
|
||||
|
||||
assert!(
|
||||
@ -621,7 +621,7 @@ mod tests {
|
||||
.data()
|
||||
.and_then(RData::as_aaaa)
|
||||
.expect("no aaaa record available"),
|
||||
Ipv6Addr::new(0x2606, 0x2800, 0x0220, 0x0001, 0x0248, 0x1893, 0x25c8, 0x1946)
|
||||
Ipv6Addr::new(0x2606, 0x2800, 0x0220, 0x0001, 0x0248, 0x1893, 0x25c8, 0x1946).into()
|
||||
);
|
||||
|
||||
assert!(
|
||||
|
@ -267,7 +267,7 @@ mod tests {
|
||||
let answer = Record::new()
|
||||
.set_record_type(RecordType::A)
|
||||
.set_name(Name::from_str("www.example.com.").unwrap())
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34).into())))
|
||||
.set_dns_class(DNSClass::NONE)
|
||||
.clone();
|
||||
|
||||
@ -304,7 +304,7 @@ mod tests {
|
||||
let answer = Record::new()
|
||||
.set_record_type(RecordType::A)
|
||||
.set_name(Name::from_str("www.example.com.").unwrap())
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34).into())))
|
||||
.set_dns_class(DNSClass::NONE)
|
||||
.clone();
|
||||
|
||||
|
@ -348,10 +348,9 @@ impl DnssecAuthority for FileAuthority {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::net::Ipv4Addr;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::proto::rr::RData;
|
||||
use crate::proto::rr::{rdata::A, RData};
|
||||
use futures_executor::block_on;
|
||||
|
||||
use super::*;
|
||||
@ -391,7 +390,7 @@ mod tests {
|
||||
.expect("A record not found in authority")
|
||||
.data()
|
||||
{
|
||||
Some(RData::A(ip)) => assert_eq!(Ipv4Addr::new(127, 0, 0, 1), *ip),
|
||||
Some(RData::A(ip)) => assert_eq!(A::new(127, 0, 0, 1), *ip),
|
||||
_ => panic!("wrong rdata type returned"),
|
||||
}
|
||||
|
||||
@ -409,7 +408,7 @@ mod tests {
|
||||
.expect("A record not found in authority")
|
||||
.data()
|
||||
{
|
||||
Some(RData::A(ip)) => assert_eq!(Ipv4Addr::new(127, 0, 0, 5), *ip),
|
||||
Some(RData::A(ip)) => assert_eq!(A::new(127, 0, 0, 5), *ip),
|
||||
_ => panic!("wrong rdata type returned"),
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,10 @@ use futures_executor::block_on;
|
||||
|
||||
use trust_dns_proto::{
|
||||
op::{Header, Message, Query, ResponseCode},
|
||||
rr::{Name, RData, Record, RecordType},
|
||||
rr::{
|
||||
rdata::{A as A4, AAAA},
|
||||
Name, RData, Record, RecordType,
|
||||
},
|
||||
serialize::binary::BinDecodable,
|
||||
};
|
||||
use trust_dns_server::authority::{
|
||||
@ -36,7 +39,7 @@ pub fn test_a_lookup<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.data()
|
||||
.and_then(RData::as_a)
|
||||
{
|
||||
Some(ip) => assert_eq!(Ipv4Addr::new(127, 0, 0, 1), *ip),
|
||||
Some(ip) => assert_eq!(A4::new(127, 0, 0, 1), *ip),
|
||||
_ => panic!("wrong rdata type returned"),
|
||||
}
|
||||
}
|
||||
@ -110,7 +113,7 @@ pub fn test_ns_lookup<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.data()
|
||||
.and_then(RData::as_a)
|
||||
.expect("Not an A record");
|
||||
assert_eq!(Ipv4Addr::new(127, 0, 0, 2), *a);
|
||||
assert_eq!(A4::new(127, 0, 0, 2), *a);
|
||||
}
|
||||
|
||||
pub fn test_mx<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
@ -158,7 +161,7 @@ pub fn test_mx<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.data()
|
||||
.and_then(RData::as_a)
|
||||
.expect("Not an A record");
|
||||
assert_eq!(Ipv4Addr::new(127, 0, 0, 1), *a);
|
||||
assert_eq!(A4::new(127, 0, 0, 1), *a);
|
||||
|
||||
let aaaa = additionals
|
||||
.next()
|
||||
@ -166,7 +169,7 @@ pub fn test_mx<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.data()
|
||||
.and_then(RData::as_aaaa)
|
||||
.expect("Not an AAAA record");
|
||||
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), *aaaa);
|
||||
assert_eq!(AAAA::new(0, 0, 0, 0, 0, 0, 0, 1), *aaaa);
|
||||
}
|
||||
|
||||
pub fn test_mx_to_null<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
@ -258,7 +261,7 @@ pub fn test_cname_alias<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.data()
|
||||
.and_then(RData::as_a)
|
||||
.expect("Not an A record");
|
||||
assert_eq!(Ipv4Addr::new(127, 0, 0, 1), *a);
|
||||
assert_eq!(A4::new(127, 0, 0, 1), *a);
|
||||
}
|
||||
|
||||
pub fn test_cname_chain<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
@ -308,7 +311,7 @@ pub fn test_cname_chain<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.data()
|
||||
.and_then(RData::as_a)
|
||||
.expect("Not an A record");
|
||||
assert_eq!(Ipv4Addr::new(127, 0, 0, 1), *a);
|
||||
assert_eq!(A4::new(127, 0, 0, 1), *a);
|
||||
}
|
||||
|
||||
/// In this the ANAME , should, return A and AAAA records in additional section
|
||||
@ -345,7 +348,7 @@ pub fn test_aname<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.and_then(Record::data)
|
||||
.and_then(RData::as_a)
|
||||
.expect("A not found");
|
||||
assert_eq!(Ipv4Addr::new(127, 0, 0, 1), *a);
|
||||
assert_eq!(A4::new(127, 0, 0, 1), *a);
|
||||
|
||||
let aaaa = additionals
|
||||
.iter()
|
||||
@ -353,7 +356,7 @@ pub fn test_aname<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.and_then(Record::data)
|
||||
.and_then(RData::as_aaaa)
|
||||
.expect("AAAA not found");
|
||||
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), *aaaa);
|
||||
assert_eq!(AAAA::new(0, 0, 0, 0, 0, 0, 0, 1), *aaaa);
|
||||
}
|
||||
|
||||
/// In this test the A record that the ANAME resolves to should be returned as the answer,
|
||||
@ -380,7 +383,7 @@ pub fn test_aname_a_lookup<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.expect("No A answer");
|
||||
|
||||
let a = a.and_then(RData::as_a).expect("Not an A record");
|
||||
assert_eq!(Ipv4Addr::new(127, 0, 0, 1), *a);
|
||||
assert_eq!(A4::new(127, 0, 0, 1), *a);
|
||||
assert_eq!(Name::from_str("example.com.").unwrap(), *name);
|
||||
|
||||
// check that additionals contain the info
|
||||
@ -422,7 +425,7 @@ pub fn test_aname_chain<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.expect("Not an A record");
|
||||
|
||||
let a = a.and_then(RData::as_a).expect("Not an A record");
|
||||
assert_eq!(Ipv4Addr::new(127, 0, 0, 1), *a);
|
||||
assert_eq!(A4::new(127, 0, 0, 1), *a);
|
||||
assert_eq!(Name::from_str("aname-chain.example.com.").unwrap(), *name);
|
||||
|
||||
// the name should match the lookup, not the A records
|
||||
@ -451,7 +454,7 @@ pub fn test_aname_chain<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.data()
|
||||
.and_then(RData::as_a)
|
||||
.expect("Not an A record");
|
||||
assert_eq!(Ipv4Addr::new(127, 0, 0, 1), *a);
|
||||
assert_eq!(A4::new(127, 0, 0, 1), *a);
|
||||
}
|
||||
|
||||
pub fn test_update_errors<A: Authority<Lookup = AuthLookup>>(mut authority: A) {
|
||||
@ -488,7 +491,7 @@ pub fn test_dots_in_name<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.data()
|
||||
.and_then(RData::as_a)
|
||||
.expect("wrong rdata type returned"),
|
||||
Ipv4Addr::new(127, 0, 0, 3)
|
||||
A4::new(127, 0, 0, 3)
|
||||
);
|
||||
|
||||
// the rest should all be NameExists
|
||||
@ -642,7 +645,7 @@ pub fn test_wildcard_chain<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.data()
|
||||
.and_then(RData::as_a)
|
||||
.expect("Not an A record");
|
||||
assert_eq!(Ipv4Addr::new(127, 0, 0, 1), *a);
|
||||
assert_eq!(A4::new(127, 0, 0, 1), *a);
|
||||
}
|
||||
|
||||
pub fn test_srv<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
@ -691,7 +694,7 @@ pub fn test_srv<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.data()
|
||||
.and_then(RData::as_a)
|
||||
.expect("Not an A record");
|
||||
assert_eq!(Ipv4Addr::new(127, 0, 0, 1), *a);
|
||||
assert_eq!(A4::new(127, 0, 0, 1), *a);
|
||||
|
||||
let aaaa = additionals
|
||||
.next()
|
||||
@ -699,7 +702,7 @@ pub fn test_srv<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
.data()
|
||||
.and_then(RData::as_aaaa)
|
||||
.expect("Not an AAAA record");
|
||||
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), *aaaa);
|
||||
assert_eq!(AAAA::new(0, 0, 0, 0, 0, 0, 0, 1), *aaaa);
|
||||
}
|
||||
|
||||
pub fn test_invalid_lookup<A: Authority<Lookup = AuthLookup>>(authority: A) {
|
||||
|
@ -11,7 +11,10 @@ use futures_executor::block_on;
|
||||
use trust_dns_proto::{
|
||||
op::{update_message, Header, Message, Query, ResponseCode},
|
||||
rr::dnssec::{Algorithm, SigSigner, SupportedAlgorithms, Verifier},
|
||||
rr::{DNSClass, Name, RData, Record, RecordSet, RecordType},
|
||||
rr::{
|
||||
rdata::{A as A4, AAAA},
|
||||
DNSClass, Name, RData, Record, RecordSet, RecordType,
|
||||
},
|
||||
serialize::binary::{BinDecodable, BinEncodable},
|
||||
};
|
||||
use trust_dns_server::{
|
||||
@ -44,7 +47,7 @@ pub fn test_create<A: Authority<Lookup = AuthLookup>>(mut authority: A, keys: &[
|
||||
.append_name(&name)
|
||||
.unwrap();
|
||||
|
||||
let record = Record::from_rdata(name.clone(), 8, RData::A(Ipv4Addr::new(127, 0, 0, 10)));
|
||||
let record = Record::from_rdata(name.clone(), 8, RData::A(A4::new(127, 0, 0, 10)));
|
||||
let message = update_message::create(
|
||||
record.clone().into(),
|
||||
Name::from_str("example.com.").unwrap(),
|
||||
@ -68,7 +71,7 @@ pub fn test_create<A: Authority<Lookup = AuthLookup>>(mut authority: A, keys: &[
|
||||
.expect("A record not found in authority")
|
||||
.data()
|
||||
{
|
||||
Some(RData::A(ip)) => assert_eq!(Ipv4Addr::new(127, 0, 0, 10), *ip),
|
||||
Some(RData::A(ip)) => assert_eq!(A4::new(127, 0, 0, 10), *ip),
|
||||
_ => panic!("wrong rdata type returned"),
|
||||
}
|
||||
|
||||
@ -91,11 +94,11 @@ pub fn test_create_multi<A: Authority<Lookup = AuthLookup>>(mut authority: A, ke
|
||||
.unwrap();
|
||||
// create a record
|
||||
let mut record = Record::with(name.clone(), RecordType::A, 8);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A4::new(100, 10, 100, 10))));
|
||||
let record = record;
|
||||
|
||||
let mut record2 = record.clone();
|
||||
record2.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 11))));
|
||||
record2.set_data(Some(RData::A(A4::new(100, 10, 100, 11))));
|
||||
let record2 = record2;
|
||||
|
||||
let mut rrset = RecordSet::from(record.clone());
|
||||
@ -138,7 +141,7 @@ pub fn test_append<A: Authority<Lookup = AuthLookup>>(mut authority: A, keys: &[
|
||||
|
||||
// append a record
|
||||
let mut record = Record::with(name.clone(), RecordType::A, 8);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A4::new(100, 10, 100, 10))));
|
||||
|
||||
// first check the must_exist option
|
||||
let mut message = update_message::append(
|
||||
@ -177,7 +180,7 @@ pub fn test_append<A: Authority<Lookup = AuthLookup>>(mut authority: A, keys: &[
|
||||
|
||||
// will fail if already set and not the same value.
|
||||
let mut record2 = record.clone();
|
||||
record2.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record2.set_data(Some(RData::A(A4::new(101, 11, 101, 11))));
|
||||
|
||||
let message = update_message::append(
|
||||
record2.clone().into(),
|
||||
@ -238,7 +241,7 @@ pub fn test_append_multi<A: Authority<Lookup = AuthLookup>>(mut authority: A, ke
|
||||
|
||||
// append a record
|
||||
let mut record = Record::with(name.clone(), RecordType::A, 8);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A4::new(100, 10, 100, 10))));
|
||||
|
||||
// next append to a non-existent RRset
|
||||
let message = update_message::append(
|
||||
@ -251,9 +254,9 @@ pub fn test_append_multi<A: Authority<Lookup = AuthLookup>>(mut authority: A, ke
|
||||
|
||||
// will fail if already set and not the same value.
|
||||
let mut record2 = record.clone();
|
||||
record2.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record2.set_data(Some(RData::A(A4::new(101, 11, 101, 11))));
|
||||
let mut record3 = record.clone();
|
||||
record3.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 12))));
|
||||
record3.set_data(Some(RData::A(A4::new(101, 11, 101, 12))));
|
||||
|
||||
// build the append set
|
||||
let mut rrset = RecordSet::from(record2.clone());
|
||||
@ -324,7 +327,7 @@ pub fn test_compare_and_swap<A: Authority<Lookup = AuthLookup>>(
|
||||
|
||||
// create a record
|
||||
let mut record = Record::with(name.clone(), RecordType::A, 8);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A4::new(100, 10, 100, 10))));
|
||||
let record = record;
|
||||
|
||||
let message = update_message::create(
|
||||
@ -336,7 +339,7 @@ pub fn test_compare_and_swap<A: Authority<Lookup = AuthLookup>>(
|
||||
|
||||
let current = record;
|
||||
let mut new = current.clone();
|
||||
new.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
new.set_data(Some(RData::A(A4::new(101, 11, 101, 11))));
|
||||
let new = new;
|
||||
|
||||
let message = update_message::compare_and_swap(
|
||||
@ -363,7 +366,7 @@ pub fn test_compare_and_swap<A: Authority<Lookup = AuthLookup>>(
|
||||
|
||||
// check the it fails if tried again.
|
||||
let mut not = new.clone();
|
||||
not.set_data(Some(RData::A(Ipv4Addr::new(102, 12, 102, 12))));
|
||||
not.set_data(Some(RData::A(A4::new(102, 12, 102, 12))));
|
||||
let not = not;
|
||||
|
||||
let message = update_message::compare_and_swap(
|
||||
@ -408,10 +411,10 @@ pub fn test_compare_and_swap_multi<A: Authority<Lookup = AuthLookup>>(
|
||||
let mut current = RecordSet::with_ttl(name.clone(), RecordType::A, 8);
|
||||
|
||||
let current1 = current
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 100, 10)))
|
||||
.new_record(&RData::A(A4::new(100, 10, 100, 10)))
|
||||
.clone();
|
||||
let current2 = current
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 100, 11)))
|
||||
.new_record(&RData::A(A4::new(100, 10, 100, 11)))
|
||||
.clone();
|
||||
let current = current;
|
||||
|
||||
@ -424,12 +427,8 @@ pub fn test_compare_and_swap_multi<A: Authority<Lookup = AuthLookup>>(
|
||||
|
||||
let mut new =
|
||||
RecordSet::with_ttl(current.name().clone(), current.record_type(), current.ttl());
|
||||
let new1 = new
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 101, 10)))
|
||||
.clone();
|
||||
let new2 = new
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 101, 11)))
|
||||
.clone();
|
||||
let new1 = new.new_record(&RData::A(A4::new(100, 10, 101, 10))).clone();
|
||||
let new2 = new.new_record(&RData::A(A4::new(100, 10, 101, 11))).clone();
|
||||
let new = new;
|
||||
|
||||
let mut message = update_message::compare_and_swap(
|
||||
@ -458,7 +457,7 @@ pub fn test_compare_and_swap_multi<A: Authority<Lookup = AuthLookup>>(
|
||||
|
||||
// check the it fails if tried again.
|
||||
let mut not = new1.clone();
|
||||
not.set_data(Some(RData::A(Ipv4Addr::new(102, 12, 102, 12))));
|
||||
not.set_data(Some(RData::A(A4::new(102, 12, 102, 12))));
|
||||
let not = not;
|
||||
|
||||
let message = update_message::compare_and_swap(
|
||||
@ -501,7 +500,7 @@ pub fn test_delete_by_rdata<A: Authority<Lookup = AuthLookup>>(
|
||||
|
||||
// append a record
|
||||
let mut record1 = Record::with(name.clone(), RecordType::A, 8);
|
||||
record1.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record1.set_data(Some(RData::A(A4::new(100, 10, 100, 10))));
|
||||
|
||||
// first check the must_exist option
|
||||
let mut message = update_message::delete_by_rdata(
|
||||
@ -520,7 +519,7 @@ pub fn test_delete_by_rdata<A: Authority<Lookup = AuthLookup>>(
|
||||
assert!(update_authority(message, key, &mut authority).expect("delete_by_rdata failed"));
|
||||
|
||||
let mut record2 = record1.clone();
|
||||
record2.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record2.set_data(Some(RData::A(A4::new(101, 11, 101, 11))));
|
||||
let message = update_message::append(
|
||||
record2.clone().into(),
|
||||
Name::from_str("example.com.").unwrap(),
|
||||
@ -567,16 +566,16 @@ pub fn test_delete_by_rdata_multi<A: Authority<Lookup = AuthLookup>>(
|
||||
let mut rrset = RecordSet::with_ttl(name.clone(), RecordType::A, 8);
|
||||
|
||||
let record1 = rrset
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 100, 10)))
|
||||
.new_record(&RData::A(A4::new(100, 10, 100, 10)))
|
||||
.clone();
|
||||
let record2 = rrset
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 100, 11)))
|
||||
.new_record(&RData::A(A4::new(100, 10, 100, 11)))
|
||||
.clone();
|
||||
let record3 = rrset
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 100, 12)))
|
||||
.new_record(&RData::A(A4::new(100, 10, 100, 12)))
|
||||
.clone();
|
||||
let record4 = rrset
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 100, 13)))
|
||||
.new_record(&RData::A(A4::new(100, 10, 100, 13)))
|
||||
.clone();
|
||||
let rrset = rrset;
|
||||
|
||||
@ -644,7 +643,7 @@ pub fn test_delete_rrset<A: Authority<Lookup = AuthLookup>>(mut authority: A, ke
|
||||
|
||||
// append a record
|
||||
let mut record = Record::with(name.clone(), RecordType::A, 8);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A4::new(100, 10, 100, 10))));
|
||||
|
||||
// first check the must_exist option
|
||||
let message = update_message::delete_rrset(
|
||||
@ -663,7 +662,7 @@ pub fn test_delete_rrset<A: Authority<Lookup = AuthLookup>>(mut authority: A, ke
|
||||
assert!(update_authority(message, key, &mut authority).expect("create failed"));
|
||||
|
||||
let mut record = record.clone();
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record.set_data(Some(RData::A(A4::new(101, 11, 101, 11))));
|
||||
let message = update_message::append(
|
||||
record.clone().into(),
|
||||
Name::from_str("example.com.").unwrap(),
|
||||
@ -707,7 +706,7 @@ pub fn test_delete_all<A: Authority<Lookup = AuthLookup>>(mut authority: A, keys
|
||||
|
||||
// append a record
|
||||
let mut record = Record::with(name.clone(), RecordType::A, 8);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A4::new(100, 10, 100, 10))));
|
||||
|
||||
// first check the must_exist option
|
||||
let message = update_message::delete_all(
|
||||
@ -728,7 +727,7 @@ pub fn test_delete_all<A: Authority<Lookup = AuthLookup>>(mut authority: A, keys
|
||||
|
||||
let mut record = record.clone();
|
||||
record.set_rr_type(RecordType::AAAA);
|
||||
record.set_data(Some(RData::AAAA(Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8))));
|
||||
record.set_data(Some(RData::AAAA(AAAA::new(1, 2, 3, 4, 5, 6, 7, 8))));
|
||||
let message = update_message::create(
|
||||
record.clone().into(),
|
||||
Name::from_str("example.com.").unwrap(),
|
||||
|
@ -33,5 +33,5 @@ fn test_lookup() {
|
||||
.data()
|
||||
.and_then(RData::as_a)
|
||||
.expect("not an A record");
|
||||
assert_eq!(*address, Ipv4Addr::new(93, 184, 216, 34));
|
||||
assert_eq!(*address, Ipv4Addr::new(93, 184, 216, 34).into());
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
#![cfg(feature = "sqlite")]
|
||||
|
||||
use std::net::*;
|
||||
use std::str::FromStr;
|
||||
|
||||
use rusqlite::*;
|
||||
|
||||
use trust_dns_proto::rr::*;
|
||||
use trust_dns_proto::rr::{rdata::A, *};
|
||||
use trust_dns_server::store::sqlite::persistence::CURRENT_VERSION;
|
||||
use trust_dns_server::store::sqlite::Journal;
|
||||
|
||||
@ -36,7 +35,7 @@ fn create_test_journal() -> (Record, Journal) {
|
||||
let mut record = Record::new();
|
||||
record.set_name(www);
|
||||
record.set_rr_type(RecordType::A);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::from_str("127.0.0.1").unwrap())));
|
||||
record.set_data(Some(RData::A(A::from_str("127.0.0.1").unwrap())));
|
||||
|
||||
// test that this message can be inserted
|
||||
let conn = Connection::open_in_memory().expect("could not create in memory DB");
|
||||
@ -47,7 +46,7 @@ fn create_test_journal() -> (Record, Journal) {
|
||||
journal.insert_record(0, &record).unwrap();
|
||||
|
||||
// insert another...
|
||||
record.set_data(Some(RData::A(Ipv4Addr::from_str("127.0.1.1").unwrap())));
|
||||
record.set_data(Some(RData::A(A::from_str("127.0.1.1").unwrap())));
|
||||
journal.insert_record(0, &record).unwrap();
|
||||
|
||||
(record, journal)
|
||||
@ -62,7 +61,7 @@ fn test_insert_and_select_record() {
|
||||
.select_record(0)
|
||||
.expect("persistence error")
|
||||
.expect("none");
|
||||
record.set_data(Some(RData::A(Ipv4Addr::from_str("127.0.0.1").unwrap())));
|
||||
record.set_data(Some(RData::A(A::from_str("127.0.0.1").unwrap())));
|
||||
assert_eq!(journal_record, record);
|
||||
|
||||
// test another
|
||||
@ -70,7 +69,7 @@ fn test_insert_and_select_record() {
|
||||
.select_record(row_id + 1)
|
||||
.expect("persistence error")
|
||||
.expect("none");
|
||||
record.set_data(Some(RData::A(Ipv4Addr::from_str("127.0.1.1").unwrap())));
|
||||
record.set_data(Some(RData::A(A::from_str("127.0.1.1").unwrap())));
|
||||
assert_eq!(journal_record, record);
|
||||
|
||||
// check that we get nothing for id over row_id
|
||||
@ -87,11 +86,11 @@ fn test_iterator() {
|
||||
let mut iter = journal.iter();
|
||||
|
||||
assert_eq!(
|
||||
record.set_data(Some(RData::A(Ipv4Addr::from_str("127.0.0.1").unwrap()))),
|
||||
record.set_data(Some(RData::A(A::from_str("127.0.0.1").unwrap()))),
|
||||
&iter.next().unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
record.set_data(Some(RData::A(Ipv4Addr::from_str("127.0.1.1").unwrap()))),
|
||||
record.set_data(Some(RData::A(A::from_str("127.0.1.1").unwrap()))),
|
||||
&iter.next().unwrap()
|
||||
);
|
||||
assert_eq!(None, iter.next());
|
||||
|
@ -1,9 +1,8 @@
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
use std::str::FromStr;
|
||||
|
||||
use futures_executor::block_on;
|
||||
|
||||
use trust_dns_proto::rr::rdata::tlsa::*;
|
||||
use trust_dns_proto::rr::rdata::{tlsa::*, A, AAAA};
|
||||
use trust_dns_proto::rr::*;
|
||||
use trust_dns_proto::serialize::txt::*;
|
||||
use trust_dns_server::authority::{Authority, LookupOptions, ZoneType};
|
||||
@ -207,7 +206,7 @@ tech. 3600 in soa ns0.centralnic.net. hostmaster.centralnic.ne
|
||||
assert_eq!(DNSClass::IN, a_record.dns_class());
|
||||
assert_eq!(RecordType::A, a_record.record_type());
|
||||
if let Some(RData::A(ref address)) = a_record.data() {
|
||||
assert_eq!(&Ipv4Addr::new(26u8, 3u8, 0u8, 103u8), address);
|
||||
assert_eq!(&A::new(26u8, 3u8, 0u8, 103u8), address);
|
||||
} else {
|
||||
panic!("Not an A record!!!") // valid panic, test code
|
||||
}
|
||||
@ -225,10 +224,7 @@ tech. 3600 in soa ns0.centralnic.net. hostmaster.centralnic.ne
|
||||
.unwrap();
|
||||
assert_eq!(&Name::from_str("aaaa.isi.edu").unwrap(), aaaa_record.name());
|
||||
if let Some(RData::AAAA(ref address)) = aaaa_record.data() {
|
||||
assert_eq!(
|
||||
&Ipv6Addr::from_str("4321:0:1:2:3:4:567:89ab").unwrap(),
|
||||
address
|
||||
);
|
||||
assert_eq!(&AAAA::from_str("4321:0:1:2:3:4:567:89ab").unwrap(), address);
|
||||
} else {
|
||||
panic!("Not a AAAA record!!!") // valid panic, test code
|
||||
}
|
||||
@ -250,7 +246,7 @@ tech. 3600 in soa ns0.centralnic.net. hostmaster.centralnic.ne
|
||||
);
|
||||
assert_eq!(70, short_record.ttl());
|
||||
if let Some(RData::A(ref address)) = short_record.data() {
|
||||
assert_eq!(&Ipv4Addr::new(26u8, 3u8, 0u8, 104u8), address);
|
||||
assert_eq!(&A::new(26u8, 3u8, 0u8, 104u8), address);
|
||||
} else {
|
||||
panic!("Not an A record!!!") // valid panic, test code
|
||||
}
|
||||
@ -352,7 +348,7 @@ tech. 3600 in soa ns0.centralnic.net. hostmaster.centralnic.ne
|
||||
idna_record.name()
|
||||
);
|
||||
if let Some(RData::A(ref address)) = idna_record.data() {
|
||||
assert_eq!(&Ipv4Addr::new(192u8, 0u8, 2u8, 1u8), address);
|
||||
assert_eq!(&A::new(192u8, 0u8, 2u8, 1u8), address);
|
||||
} else {
|
||||
panic!("Not an A record!!!") // valid panic, test code
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ use trust_dns_compatibility::named_process;
|
||||
#[test]
|
||||
#[allow(unused)]
|
||||
fn test_get() {
|
||||
use trust_dns_client::rr::rdata::A;
|
||||
|
||||
let (process, port) = named_process();
|
||||
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), port);
|
||||
let conn = UdpClientConnection::new(socket).unwrap();
|
||||
@ -50,7 +52,7 @@ fn test_get() {
|
||||
|
||||
let rdata = result.answers()[0].data();
|
||||
if let Some(RData::A(address)) = rdata {
|
||||
assert_eq!(address, &Ipv4Addr::new(127, 0, 0, 1));
|
||||
assert_eq!(address, &A::new(127, 0, 0, 1));
|
||||
} else {
|
||||
panic!("RData::A wasn't here");
|
||||
}
|
||||
@ -92,6 +94,8 @@ where
|
||||
#[test]
|
||||
#[allow(unused)]
|
||||
fn test_create() {
|
||||
use trust_dns_client::rr::rdata::A;
|
||||
|
||||
let (process, port) = named_process();
|
||||
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), port);
|
||||
let conn = UdpClientConnection::new(socket).unwrap();
|
||||
@ -105,7 +109,7 @@ fn test_create() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
let result = client
|
||||
.create(record.clone(), origin.clone())
|
||||
@ -127,7 +131,7 @@ fn test_create() {
|
||||
|
||||
// will fail if already set and not the same value.
|
||||
let mut record = record;
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
|
||||
let result = client.create(record, origin).expect("create failed");
|
||||
assert_eq!(result.response_code(), ResponseCode::YXRRSet);
|
||||
|
@ -50,6 +50,8 @@ where
|
||||
#[cfg(not(feature = "none"))]
|
||||
#[test]
|
||||
fn test_create() {
|
||||
use trust_dns_client::rr::rdata::A;
|
||||
|
||||
let (_process, port) = named_process();
|
||||
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), port);
|
||||
let conn = UdpClientConnection::new(socket).unwrap();
|
||||
@ -63,7 +65,7 @@ fn test_create() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
let result = client
|
||||
.create(record.clone(), origin.clone())
|
||||
@ -85,7 +87,7 @@ fn test_create() {
|
||||
|
||||
// will fail if already set and not the same value.
|
||||
let mut record = record;
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
|
||||
let result = client.create(record, origin).expect("create failed");
|
||||
assert_eq!(result.response_code(), ResponseCode::YXRRSet);
|
||||
|
@ -38,6 +38,8 @@ macro_rules! assert_serial {
|
||||
#[test]
|
||||
#[allow(unused)]
|
||||
fn test_zone_transfer() {
|
||||
use trust_dns_client::rr::rdata::A;
|
||||
|
||||
let (process, port) = named_process();
|
||||
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), port);
|
||||
let conn = TcpClientConnection::new(socket).unwrap();
|
||||
@ -75,7 +77,7 @@ fn test_zone_transfer() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
client.create(record, name.clone()).expect("create failed");
|
||||
|
||||
|
@ -88,7 +88,7 @@ pub fn create_example() -> InMemoryAuthority {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 34))))
|
||||
.clone(),
|
||||
0,
|
||||
);
|
||||
@ -100,7 +100,7 @@ pub fn create_example() -> InMemoryAuthority {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::AAAA)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::AAAA(Ipv6Addr::new(
|
||||
.set_data(Some(RData::AAAA(AAAA::new(
|
||||
0x2606, 0x2800, 0x220, 0x1, 0x248, 0x1893, 0x25c8, 0x1946,
|
||||
))))
|
||||
.clone(),
|
||||
@ -143,7 +143,7 @@ pub fn create_example() -> InMemoryAuthority {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 34))))
|
||||
.clone(),
|
||||
0,
|
||||
);
|
||||
@ -155,7 +155,7 @@ pub fn create_example() -> InMemoryAuthority {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::AAAA)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::AAAA(Ipv6Addr::new(
|
||||
.set_data(Some(RData::AAAA(AAAA::new(
|
||||
0x2606, 0x2800, 0x220, 0x1, 0x248, 0x1893, 0x25c8, 0x1946,
|
||||
))))
|
||||
.clone(),
|
||||
|
@ -220,7 +220,7 @@ pub fn cname_record(name: Name, cname: Name) -> Record {
|
||||
}
|
||||
|
||||
pub fn v4_record(name: Name, ip: Ipv4Addr) -> Record {
|
||||
Record::from_rdata(name, 86400, RData::A(ip))
|
||||
Record::from_rdata(name, 86400, RData::A(ip.into()))
|
||||
}
|
||||
|
||||
pub fn soa_record(name: Name, mname: Name) -> Record {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::{net::*, str::FromStr, sync::Arc};
|
||||
use std::{str::FromStr, sync::Arc};
|
||||
|
||||
use trust_dns_client::{
|
||||
op::*,
|
||||
@ -74,7 +74,7 @@ pub fn create_test() -> InMemoryAuthority {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(94, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(A::new(94, 184, 216, 34))))
|
||||
.clone(),
|
||||
0,
|
||||
);
|
||||
@ -84,7 +84,7 @@ pub fn create_test() -> InMemoryAuthority {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::AAAA)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::AAAA(Ipv6Addr::new(
|
||||
.set_data(Some(RData::AAAA(AAAA::new(
|
||||
0x2606, 0x2800, 0x220, 0x1, 0x248, 0x1893, 0x25c8, 0x1946,
|
||||
))))
|
||||
.clone(),
|
||||
@ -98,7 +98,7 @@ pub fn create_test() -> InMemoryAuthority {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(94, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(A::new(94, 184, 216, 34))))
|
||||
.clone(),
|
||||
0,
|
||||
);
|
||||
@ -108,7 +108,7 @@ pub fn create_test() -> InMemoryAuthority {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::AAAA)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::AAAA(Ipv6Addr::new(
|
||||
.set_data(Some(RData::AAAA(AAAA::new(
|
||||
0x2606, 0x2800, 0x220, 0x1, 0x248, 0x1893, 0x25c8, 0x1946,
|
||||
))))
|
||||
.clone(),
|
||||
@ -157,7 +157,7 @@ async fn test_catalog_lookup() {
|
||||
assert_eq!(answers.first().unwrap().record_type(), RecordType::A);
|
||||
assert_eq!(
|
||||
answers.first().unwrap().data().unwrap(),
|
||||
&RData::A(Ipv4Addr::new(93, 184, 216, 34))
|
||||
&RData::A(A::new(93, 184, 216, 34))
|
||||
);
|
||||
|
||||
let ns = result.name_servers();
|
||||
@ -191,7 +191,7 @@ async fn test_catalog_lookup() {
|
||||
assert_eq!(answers.first().unwrap().record_type(), RecordType::A);
|
||||
assert_eq!(
|
||||
answers.first().unwrap().data().unwrap(),
|
||||
&RData::A(Ipv4Addr::new(94, 184, 216, 34))
|
||||
&RData::A(A::new(94, 184, 216, 34))
|
||||
);
|
||||
}
|
||||
|
||||
@ -443,14 +443,14 @@ async fn test_axfr() {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(94, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(A::new(94, 184, 216, 34))))
|
||||
.clone(),
|
||||
Record::new()
|
||||
.set_name(origin.clone().into())
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::AAAA)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::AAAA(Ipv6Addr::new(
|
||||
.set_data(Some(RData::AAAA(AAAA::new(
|
||||
0x2606, 0x2800, 0x220, 0x1, 0x248, 0x1893, 0x25c8, 0x1946,
|
||||
))))
|
||||
.clone(),
|
||||
@ -459,14 +459,14 @@ async fn test_axfr() {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(94, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(A::new(94, 184, 216, 34))))
|
||||
.clone(),
|
||||
Record::new()
|
||||
.set_name(www_name)
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::AAAA)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::AAAA(Ipv6Addr::new(
|
||||
.set_data(Some(RData::AAAA(AAAA::new(
|
||||
0x2606, 0x2800, 0x220, 0x1, 0x248, 0x1893, 0x25c8, 0x1946,
|
||||
))))
|
||||
.clone(),
|
||||
@ -576,7 +576,7 @@ async fn test_cname_additionals() {
|
||||
assert_eq!(additionals.first().unwrap().record_type(), RecordType::A);
|
||||
assert_eq!(
|
||||
additionals.first().unwrap().data().unwrap(),
|
||||
&RData::A(Ipv4Addr::new(93, 184, 216, 34))
|
||||
&RData::A(A::new(93, 184, 216, 34))
|
||||
);
|
||||
}
|
||||
|
||||
@ -636,6 +636,6 @@ async fn test_multiple_cname_additionals() {
|
||||
assert_eq!(additionals.last().unwrap().record_type(), RecordType::A);
|
||||
assert_eq!(
|
||||
additionals.last().unwrap().data().unwrap(),
|
||||
&RData::A(Ipv4Addr::new(93, 184, 216, 34))
|
||||
&RData::A(A::new(93, 184, 216, 34))
|
||||
);
|
||||
}
|
||||
|
@ -19,7 +19,10 @@ use trust_dns_client::{
|
||||
error::ClientErrorKind,
|
||||
op::{Edns, Message, MessageType, OpCode, Query, ResponseCode},
|
||||
rr::{
|
||||
rdata::opt::{EdnsCode, EdnsOption},
|
||||
rdata::{
|
||||
opt::{EdnsCode, EdnsOption},
|
||||
A,
|
||||
},
|
||||
DNSClass, Name, RData, RecordSet, RecordType,
|
||||
},
|
||||
tcp::TcpClientStream,
|
||||
@ -189,7 +192,7 @@ fn test_query(client: &mut AsyncClient) -> impl Future<Output = ()> {
|
||||
assert_eq!(record.dns_class(), DNSClass::IN);
|
||||
|
||||
if let RData::A(ref address) = record.data().unwrap() {
|
||||
assert_eq!(address, &Ipv4Addr::new(93, 184, 216, 34))
|
||||
assert_eq!(address, &A::new(93, 184, 216, 34))
|
||||
} else {
|
||||
panic!();
|
||||
}
|
||||
@ -248,7 +251,7 @@ fn test_query_edns(client: &mut AsyncClient) -> impl Future<Output = ()> {
|
||||
&EdnsOption::Subnet("1.2.0.0/16".parse().unwrap())
|
||||
);
|
||||
if let RData::A(ref address) = *record.data().unwrap() {
|
||||
assert_eq!(address, &Ipv4Addr::new(93, 184, 216, 34))
|
||||
assert_eq!(address, &A::new(93, 184, 216, 34))
|
||||
} else {
|
||||
panic!();
|
||||
}
|
||||
@ -346,7 +349,7 @@ fn test_create() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
let record = record;
|
||||
|
||||
let result = io_loop
|
||||
@ -373,7 +376,7 @@ fn test_create() {
|
||||
|
||||
// will fail if already set and not the same value.
|
||||
let mut record = record;
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
|
||||
let result = io_loop
|
||||
.block_on(client.create(record, origin))
|
||||
@ -394,11 +397,11 @@ fn test_create_multi() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
let record = record;
|
||||
|
||||
let mut record2 = record.clone();
|
||||
record2.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 11))));
|
||||
record2.set_data(Some(RData::A(A::new(100, 10, 100, 11))));
|
||||
let record2 = record2;
|
||||
|
||||
let mut rrset = RecordSet::from(record.clone());
|
||||
@ -431,7 +434,7 @@ fn test_create_multi() {
|
||||
|
||||
// will fail if already set and not the same value.
|
||||
let mut record = record;
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 12))));
|
||||
record.set_data(Some(RData::A(A::new(101, 11, 101, 12))));
|
||||
|
||||
let result = io_loop
|
||||
.block_on(client.create(record, origin))
|
||||
@ -452,7 +455,7 @@ fn test_append() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
let record = record;
|
||||
|
||||
// first check the must_exist option
|
||||
@ -481,7 +484,7 @@ fn test_append() {
|
||||
|
||||
// will fail if already set and not the same value.
|
||||
let mut record2 = record.clone();
|
||||
record2.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record2.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
let record2 = record2;
|
||||
|
||||
let result = io_loop
|
||||
@ -532,7 +535,7 @@ fn test_append_multi() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
// first check the must_exist option
|
||||
let result = io_loop
|
||||
@ -560,9 +563,9 @@ fn test_append_multi() {
|
||||
|
||||
// will fail if already set and not the same value.
|
||||
let mut record2 = record.clone();
|
||||
record2.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record2.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
let mut record3 = record.clone();
|
||||
record3.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 12))));
|
||||
record3.set_data(Some(RData::A(A::new(101, 11, 101, 12))));
|
||||
|
||||
// build the append set
|
||||
let mut rrset = RecordSet::from(record2.clone());
|
||||
@ -618,7 +621,7 @@ fn test_compare_and_swap() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
let record = record;
|
||||
|
||||
let result = io_loop
|
||||
@ -628,7 +631,7 @@ fn test_compare_and_swap() {
|
||||
|
||||
let current = record;
|
||||
let mut new = current.clone();
|
||||
new.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
new.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
let new = new;
|
||||
|
||||
let result = io_loop
|
||||
@ -646,7 +649,7 @@ fn test_compare_and_swap() {
|
||||
|
||||
// check the it fails if tried again.
|
||||
let mut not = new.clone();
|
||||
not.set_data(Some(RData::A(Ipv4Addr::new(102, 12, 102, 12))));
|
||||
not.set_data(Some(RData::A(A::new(102, 12, 102, 12))));
|
||||
let not = not;
|
||||
|
||||
let result = io_loop
|
||||
@ -678,10 +681,10 @@ fn test_compare_and_swap_multi() {
|
||||
);
|
||||
|
||||
let current1 = current
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 100, 10)))
|
||||
.new_record(&RData::A(A::new(100, 10, 100, 10)))
|
||||
.clone();
|
||||
let current2 = current
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 100, 11)))
|
||||
.new_record(&RData::A(A::new(100, 10, 100, 11)))
|
||||
.clone();
|
||||
let current = current;
|
||||
|
||||
@ -691,12 +694,8 @@ fn test_compare_and_swap_multi() {
|
||||
assert_eq!(result.response_code(), ResponseCode::NoError);
|
||||
|
||||
let mut new = RecordSet::with_ttl(current.name().clone(), current.record_type(), current.ttl());
|
||||
let new1 = new
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 101, 10)))
|
||||
.clone();
|
||||
let new2 = new
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 101, 11)))
|
||||
.clone();
|
||||
let new1 = new.new_record(&RData::A(A::new(100, 10, 101, 10))).clone();
|
||||
let new2 = new.new_record(&RData::A(A::new(100, 10, 101, 11))).clone();
|
||||
let new = new;
|
||||
|
||||
let result = io_loop
|
||||
@ -716,7 +715,7 @@ fn test_compare_and_swap_multi() {
|
||||
|
||||
// check the it fails if tried again.
|
||||
let mut not = new1.clone();
|
||||
not.set_data(Some(RData::A(Ipv4Addr::new(102, 12, 102, 12))));
|
||||
not.set_data(Some(RData::A(A::new(102, 12, 102, 12))));
|
||||
let not = not;
|
||||
|
||||
let result = io_loop
|
||||
@ -746,7 +745,7 @@ fn test_delete_by_rdata() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record1.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record1.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
// first check the must_exist option
|
||||
let result = io_loop
|
||||
@ -761,7 +760,7 @@ fn test_delete_by_rdata() {
|
||||
assert_eq!(result.response_code(), ResponseCode::NoError);
|
||||
|
||||
let mut record2 = record1.clone();
|
||||
record2.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record2.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
let result = io_loop
|
||||
.block_on(client.append(record2.clone(), origin.clone(), true))
|
||||
.expect("create failed");
|
||||
@ -800,16 +799,16 @@ fn test_delete_by_rdata_multi() {
|
||||
);
|
||||
|
||||
let record1 = rrset
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 100, 10)))
|
||||
.new_record(&RData::A(A::new(100, 10, 100, 10)))
|
||||
.clone();
|
||||
let record2 = rrset
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 100, 11)))
|
||||
.new_record(&RData::A(A::new(100, 10, 100, 11)))
|
||||
.clone();
|
||||
let record3 = rrset
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 100, 12)))
|
||||
.new_record(&RData::A(A::new(100, 10, 100, 12)))
|
||||
.clone();
|
||||
let record4 = rrset
|
||||
.new_record(&RData::A(Ipv4Addr::new(100, 10, 100, 13)))
|
||||
.new_record(&RData::A(A::new(100, 10, 100, 13)))
|
||||
.clone();
|
||||
let rrset = rrset;
|
||||
|
||||
@ -875,7 +874,7 @@ fn test_delete_rrset() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
// first check the must_exist option
|
||||
let result = io_loop
|
||||
@ -890,7 +889,7 @@ fn test_delete_rrset() {
|
||||
assert_eq!(result.response_code(), ResponseCode::NoError);
|
||||
|
||||
let mut record = record;
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
let result = io_loop
|
||||
.block_on(client.append(record.clone(), origin.clone(), true))
|
||||
.expect("create failed");
|
||||
@ -916,6 +915,8 @@ fn test_delete_rrset() {
|
||||
#[cfg(all(feature = "dnssec", feature = "sqlite"))]
|
||||
#[test]
|
||||
fn test_delete_all() {
|
||||
use trust_dns_proto::rr::rdata::AAAA;
|
||||
|
||||
let io_loop = Runtime::new().unwrap();
|
||||
let ((mut client, bg), origin) = io_loop.block_on(create_sig0_ready_client());
|
||||
trust_dns_proto::spawn_bg(&io_loop, bg);
|
||||
@ -926,7 +927,7 @@ fn test_delete_all() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
// first check the must_exist option
|
||||
let result = io_loop
|
||||
@ -942,7 +943,7 @@ fn test_delete_all() {
|
||||
|
||||
let mut record = record;
|
||||
record.set_rr_type(RecordType::AAAA);
|
||||
record.set_data(Some(RData::AAAA(Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8))));
|
||||
record.set_data(Some(RData::AAAA(AAAA::new(1, 2, 3, 4, 5, 6, 7, 8))));
|
||||
let result = io_loop
|
||||
.block_on(client.create(record.clone(), origin.clone()))
|
||||
.expect("create failed");
|
||||
|
@ -25,7 +25,7 @@ use trust_dns_proto::error::ProtoError;
|
||||
use trust_dns_proto::op::*;
|
||||
#[cfg(feature = "dnssec")]
|
||||
use trust_dns_proto::rr::Record;
|
||||
use trust_dns_proto::rr::{DNSClass, Name, RData, RecordType};
|
||||
use trust_dns_proto::rr::{rdata::A, DNSClass, Name, RData, RecordType};
|
||||
use trust_dns_proto::xfer::{DnsMultiplexer, DnsMultiplexerConnect};
|
||||
use trust_dns_server::authority::{Authority, Catalog};
|
||||
|
||||
@ -126,7 +126,7 @@ where
|
||||
assert_eq!(record.dns_class(), DNSClass::IN);
|
||||
|
||||
if let RData::A(ref address) = *record.data().unwrap() {
|
||||
assert_eq!(address, &Ipv4Addr::new(93, 184, 216, 34))
|
||||
assert_eq!(address, &A::new(93, 184, 216, 34))
|
||||
} else {
|
||||
panic!();
|
||||
}
|
||||
@ -184,7 +184,7 @@ where
|
||||
);
|
||||
|
||||
if let RData::A(ref address) = *record.data().unwrap() {
|
||||
assert_eq!(address, &Ipv4Addr::new(93, 184, 216, 34))
|
||||
assert_eq!(address, &A::new(93, 184, 216, 34))
|
||||
} else {
|
||||
panic!();
|
||||
}
|
||||
@ -243,7 +243,7 @@ where
|
||||
assert_eq!(record.dns_class(), DNSClass::IN);
|
||||
|
||||
if let RData::A(ref address) = *record.data().unwrap() {
|
||||
assert_eq!(address, &Ipv4Addr::new(93, 184, 216, 34))
|
||||
assert_eq!(address, &A::new(93, 184, 216, 34))
|
||||
} else {
|
||||
panic!();
|
||||
}
|
||||
@ -495,7 +495,7 @@ fn test_create() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
let result = client
|
||||
.create(record.clone(), origin.clone())
|
||||
@ -517,7 +517,7 @@ fn test_create() {
|
||||
|
||||
// will fail if already set and not the same value.
|
||||
let mut record = record;
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
|
||||
let result = client.create(record, origin).expect("create failed");
|
||||
assert_eq!(result.response_code(), ResponseCode::YXRRSet);
|
||||
@ -535,7 +535,7 @@ fn test_append() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
// first check the must_exist option
|
||||
let result = client
|
||||
@ -559,7 +559,7 @@ fn test_append() {
|
||||
|
||||
// will fail if already set and not the same value.
|
||||
let mut record = record;
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
|
||||
let result = client
|
||||
.append(record.clone(), origin.clone(), true)
|
||||
@ -576,7 +576,7 @@ fn test_append() {
|
||||
.answers()
|
||||
.iter()
|
||||
.any(|rr| if let RData::A(ip) = *rr.data().unwrap() {
|
||||
ip == Ipv4Addr::new(100, 10, 100, 10)
|
||||
ip == A::new(100, 10, 100, 10)
|
||||
} else {
|
||||
false
|
||||
}));
|
||||
@ -584,7 +584,7 @@ fn test_append() {
|
||||
.answers()
|
||||
.iter()
|
||||
.any(|rr| if let RData::A(ip) = rr.data().unwrap() {
|
||||
*ip == Ipv4Addr::new(101, 11, 101, 11)
|
||||
*ip == A::new(101, 11, 101, 11)
|
||||
} else {
|
||||
false
|
||||
}));
|
||||
@ -614,7 +614,7 @@ fn test_compare_and_swap() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
let result = client
|
||||
.create(record.clone(), origin.clone())
|
||||
@ -623,7 +623,7 @@ fn test_compare_and_swap() {
|
||||
|
||||
let current = record;
|
||||
let mut new = current.clone();
|
||||
new.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
new.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
|
||||
let result = client
|
||||
.compare_and_swap(current.clone(), new.clone(), origin.clone())
|
||||
@ -639,14 +639,14 @@ fn test_compare_and_swap() {
|
||||
.answers()
|
||||
.iter()
|
||||
.any(|rr| if let RData::A(ip) = rr.data().unwrap() {
|
||||
*ip == Ipv4Addr::new(101, 11, 101, 11)
|
||||
*ip == A::new(101, 11, 101, 11)
|
||||
} else {
|
||||
false
|
||||
}));
|
||||
|
||||
// check the it fails if tried again.
|
||||
let mut new = new;
|
||||
new.set_data(Some(RData::A(Ipv4Addr::new(102, 12, 102, 12))));
|
||||
new.set_data(Some(RData::A(A::new(102, 12, 102, 12))));
|
||||
|
||||
let result = client
|
||||
.compare_and_swap(current, new.clone(), origin)
|
||||
@ -662,7 +662,7 @@ fn test_compare_and_swap() {
|
||||
.answers()
|
||||
.iter()
|
||||
.any(|rr| if let RData::A(ip) = rr.data().unwrap() {
|
||||
*ip == Ipv4Addr::new(101, 11, 101, 11)
|
||||
*ip == A::new(101, 11, 101, 11)
|
||||
} else {
|
||||
false
|
||||
}));
|
||||
@ -680,7 +680,7 @@ fn test_delete_by_rdata() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
// first check the must_exist option
|
||||
let result = client
|
||||
@ -695,7 +695,7 @@ fn test_delete_by_rdata() {
|
||||
assert_eq!(result.response_code(), ResponseCode::NoError);
|
||||
|
||||
let mut record = record;
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
let result = client
|
||||
.append(record.clone(), origin.clone(), true)
|
||||
.expect("create failed");
|
||||
@ -716,7 +716,7 @@ fn test_delete_by_rdata() {
|
||||
.answers()
|
||||
.iter()
|
||||
.any(|rr| if let RData::A(ip) = rr.data().unwrap() {
|
||||
*ip == Ipv4Addr::new(100, 10, 100, 10)
|
||||
*ip == A::new(100, 10, 100, 10)
|
||||
} else {
|
||||
false
|
||||
}));
|
||||
@ -734,7 +734,7 @@ fn test_delete_rrset() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
// first check the must_exist option
|
||||
let result = client
|
||||
@ -749,7 +749,7 @@ fn test_delete_rrset() {
|
||||
assert_eq!(result.response_code(), ResponseCode::NoError);
|
||||
|
||||
let mut record = record;
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(101, 11, 101, 11))));
|
||||
record.set_data(Some(RData::A(A::new(101, 11, 101, 11))));
|
||||
let result = client
|
||||
.append(record.clone(), origin.clone(), true)
|
||||
.expect("create failed");
|
||||
@ -771,6 +771,8 @@ fn test_delete_rrset() {
|
||||
#[cfg(all(feature = "dnssec", feature = "sqlite"))]
|
||||
#[test]
|
||||
fn test_delete_all() {
|
||||
use trust_dns_proto::rr::rdata::AAAA;
|
||||
|
||||
let catalog = Catalog::new();
|
||||
let (client, origin) = create_sig0_ready_client(catalog);
|
||||
|
||||
@ -780,7 +782,7 @@ fn test_delete_all() {
|
||||
RecordType::A,
|
||||
Duration::minutes(5).whole_seconds() as u32,
|
||||
);
|
||||
record.set_data(Some(RData::A(Ipv4Addr::new(100, 10, 100, 10))));
|
||||
record.set_data(Some(RData::A(A::new(100, 10, 100, 10))));
|
||||
|
||||
// first check the must_exist option
|
||||
let result = client
|
||||
@ -796,7 +798,7 @@ fn test_delete_all() {
|
||||
|
||||
let mut record = record;
|
||||
record.set_rr_type(RecordType::AAAA);
|
||||
record.set_data(Some(RData::AAAA(Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8))));
|
||||
record.set_data(Some(RData::AAAA(AAAA::new(1, 2, 3, 4, 5, 6, 7, 8))));
|
||||
let result = client
|
||||
.create(record.clone(), origin.clone())
|
||||
.expect("create failed");
|
||||
|
@ -15,6 +15,7 @@ use trust_dns_client::tcp::TcpClientStream;
|
||||
use trust_dns_proto::iocompat::AsyncIoTokioAsStd;
|
||||
use trust_dns_proto::op::ResponseCode;
|
||||
use trust_dns_proto::rr::dnssec::TrustAnchor;
|
||||
use trust_dns_proto::rr::rdata::A;
|
||||
use trust_dns_proto::rr::Name;
|
||||
use trust_dns_proto::rr::{DNSClass, RData, RecordType};
|
||||
use trust_dns_proto::udp::{UdpClientConnect, UdpClientStream};
|
||||
@ -63,7 +64,7 @@ where
|
||||
assert_eq!(record.dns_class(), DNSClass::IN);
|
||||
|
||||
if let RData::A(ref address) = *record.data().unwrap() {
|
||||
assert_eq!(address, &Ipv4Addr::new(93, 184, 216, 34))
|
||||
assert_eq!(address, &A::new(93, 184, 216, 34))
|
||||
} else {
|
||||
panic!();
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use tokio::runtime::Runtime;
|
||||
|
||||
use trust_dns_proto::{
|
||||
op::{NoopMessageFinalizer, Query},
|
||||
rr::{DNSClass, Name, RData, Record, RecordType},
|
||||
rr::{rdata::A, DNSClass, Name, RData, Record, RecordType},
|
||||
xfer::{DnsExchange, DnsMultiplexer, DnsResponse},
|
||||
TokioTime,
|
||||
};
|
||||
@ -51,7 +51,7 @@ fn test_lookup() {
|
||||
|
||||
assert_eq!(
|
||||
*lookup.iter().next().unwrap(),
|
||||
RData::A(Ipv4Addr::new(93, 184, 216, 34))
|
||||
RData::A(A::new(93, 184, 216, 34))
|
||||
);
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ fn test_lookup_hosts() {
|
||||
let record = Record::from_rdata(
|
||||
Name::from_str("www.example.com.").unwrap(),
|
||||
86400,
|
||||
RData::A(Ipv4Addr::new(10, 0, 1, 104)),
|
||||
RData::A(A::new(10, 0, 1, 104)),
|
||||
);
|
||||
hosts.insert(
|
||||
Name::from_str("www.example.com.").unwrap(),
|
||||
@ -105,7 +105,7 @@ fn create_ip_like_example() -> InMemoryAuthority {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(198, 51, 100, 35))))
|
||||
.set_data(Some(RData::A(A::new(198, 51, 100, 35))))
|
||||
.clone(),
|
||||
0,
|
||||
);
|
||||
@ -133,7 +133,7 @@ fn test_lookup_ipv4_like() {
|
||||
CachingClient::new(0, client, false),
|
||||
Default::default(),
|
||||
Some(Arc::new(Hosts::default())),
|
||||
Some(RData::A(Ipv4Addr::new(1, 2, 3, 4))),
|
||||
Some(RData::A(A::new(1, 2, 3, 4))),
|
||||
);
|
||||
let lookup = io_loop.block_on(lookup).unwrap();
|
||||
|
||||
@ -163,7 +163,7 @@ fn test_lookup_ipv4_like_fall_through() {
|
||||
CachingClient::new(0, client, false),
|
||||
Default::default(),
|
||||
Some(Arc::new(Hosts::default())),
|
||||
Some(RData::A(Ipv4Addr::new(198, 51, 100, 35))),
|
||||
Some(RData::A(A::new(198, 51, 100, 35))),
|
||||
);
|
||||
let lookup = io_loop.block_on(lookup).unwrap();
|
||||
|
||||
@ -196,7 +196,7 @@ fn test_mock_lookup() {
|
||||
|
||||
assert_eq!(
|
||||
*lookup.iter().next().unwrap(),
|
||||
RData::A(Ipv4Addr::new(93, 184, 216, 34))
|
||||
RData::A(A::new(93, 184, 216, 34))
|
||||
);
|
||||
}
|
||||
|
||||
@ -227,7 +227,7 @@ fn test_cname_lookup() {
|
||||
|
||||
assert_eq!(
|
||||
*lookup.iter().next().unwrap(),
|
||||
RData::A(Ipv4Addr::new(93, 184, 216, 34))
|
||||
RData::A(A::new(93, 184, 216, 34))
|
||||
);
|
||||
}
|
||||
|
||||
@ -263,10 +263,7 @@ fn test_cname_lookup_preserve() {
|
||||
|
||||
let mut iter = lookup.iter();
|
||||
assert_eq!(iter.next().unwrap(), cname_record.data().unwrap());
|
||||
assert_eq!(
|
||||
*iter.next().unwrap(),
|
||||
RData::A(Ipv4Addr::new(93, 184, 216, 34))
|
||||
);
|
||||
assert_eq!(*iter.next().unwrap(), RData::A(A::new(93, 184, 216, 34)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -303,7 +300,7 @@ fn test_chained_cname_lookup() {
|
||||
|
||||
assert_eq!(
|
||||
*lookup.iter().next().unwrap(),
|
||||
RData::A(Ipv4Addr::new(93, 184, 216, 34))
|
||||
RData::A(A::new(93, 184, 216, 34))
|
||||
);
|
||||
}
|
||||
|
||||
@ -346,10 +343,7 @@ fn test_chained_cname_lookup_preserve() {
|
||||
|
||||
let mut iter = lookup.iter();
|
||||
assert_eq!(iter.next().unwrap(), cname_record.data().unwrap());
|
||||
assert_eq!(
|
||||
*iter.next().unwrap(),
|
||||
RData::A(Ipv4Addr::new(93, 184, 216, 34))
|
||||
);
|
||||
assert_eq!(*iter.next().unwrap(), RData::A(A::new(93, 184, 216, 34)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -448,6 +442,6 @@ fn test_max_chained_lookup_depth() {
|
||||
|
||||
assert_eq!(
|
||||
*lookup.iter().next().unwrap(),
|
||||
RData::A(Ipv4Addr::new(93, 184, 216, 34))
|
||||
RData::A(A::new(93, 184, 216, 34))
|
||||
);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ use trust_dns_client::rr::*;
|
||||
use trust_dns_client::tcp::TcpClientConnection;
|
||||
use trust_dns_client::udp::UdpClientConnection;
|
||||
use trust_dns_proto::error::ProtoError;
|
||||
use trust_dns_proto::rr::rdata::A;
|
||||
use trust_dns_proto::xfer::DnsRequestSender;
|
||||
|
||||
use trust_dns_server::authority::{Authority, Catalog};
|
||||
@ -315,7 +316,7 @@ where
|
||||
assert_eq!(record.dns_class(), DNSClass::IN);
|
||||
|
||||
if let RData::A(ref address) = *record.data().unwrap() {
|
||||
assert_eq!(address, &Ipv4Addr::new(93, 184, 216, 34))
|
||||
assert_eq!(address, &A::new(93, 184, 216, 34))
|
||||
} else {
|
||||
panic!();
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#![cfg(feature = "sqlite")]
|
||||
|
||||
use std::net::*;
|
||||
use std::str::FromStr;
|
||||
|
||||
use rusqlite::*;
|
||||
@ -53,10 +52,7 @@ async fn test_search() {
|
||||
let record = result.iter().next().unwrap();
|
||||
assert_eq!(record.record_type(), RecordType::A);
|
||||
assert_eq!(record.dns_class(), DNSClass::IN);
|
||||
assert_eq!(
|
||||
record.data().unwrap(),
|
||||
&RData::A(Ipv4Addr::new(93, 184, 216, 34))
|
||||
);
|
||||
assert_eq!(record.data().unwrap(), &RData::A(A::new(93, 184, 216, 34)));
|
||||
} else {
|
||||
panic!("expected a result"); // valid panic, in test
|
||||
}
|
||||
@ -86,10 +82,7 @@ async fn test_search_www() {
|
||||
let record = result.iter().next().unwrap();
|
||||
assert_eq!(record.record_type(), RecordType::A);
|
||||
assert_eq!(record.dns_class(), DNSClass::IN);
|
||||
assert_eq!(
|
||||
record.data().unwrap(),
|
||||
&RData::A(Ipv4Addr::new(93, 184, 216, 34))
|
||||
);
|
||||
assert_eq!(record.data().unwrap(), &RData::A(A::new(93, 184, 216, 34)));
|
||||
} else {
|
||||
panic!("expected a result"); // valid panic, in test
|
||||
}
|
||||
@ -206,7 +199,7 @@ async fn test_authority() {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 34))))
|
||||
.clone()
|
||||
);
|
||||
}
|
||||
@ -376,7 +369,7 @@ async fn test_prerequisites() {
|
||||
.set_ttl(0)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 34))))
|
||||
.clone()])
|
||||
.await
|
||||
.is_ok());
|
||||
@ -388,7 +381,7 @@ async fn test_prerequisites() {
|
||||
.set_ttl(0)
|
||||
.set_dns_class(DNSClass::CH)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 34))))
|
||||
.clone()],)
|
||||
.await,
|
||||
Err(ResponseCode::FormErr)
|
||||
@ -401,7 +394,7 @@ async fn test_prerequisites() {
|
||||
.set_ttl(0)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 24))))
|
||||
.clone()],)
|
||||
.await,
|
||||
Err(ResponseCode::NXRRSet)
|
||||
@ -414,7 +407,7 @@ async fn test_prerequisites() {
|
||||
.set_ttl(0)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 24))))
|
||||
.clone()],)
|
||||
.await,
|
||||
Err(ResponseCode::NXRRSet)
|
||||
@ -435,7 +428,7 @@ async fn test_pre_scan() {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 24))))
|
||||
.clone()],)
|
||||
.await,
|
||||
Err(ResponseCode::NotZone)
|
||||
@ -483,7 +476,7 @@ async fn test_pre_scan() {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 24))))
|
||||
.clone()])
|
||||
.await
|
||||
.is_ok());
|
||||
@ -505,7 +498,7 @@ async fn test_pre_scan() {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::ANY)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 24))))
|
||||
.clone()],)
|
||||
.await,
|
||||
Err(ResponseCode::FormErr)
|
||||
@ -517,7 +510,7 @@ async fn test_pre_scan() {
|
||||
.set_ttl(0)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::ANY)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 24))))
|
||||
.clone()],)
|
||||
.await,
|
||||
Err(ResponseCode::FormErr)
|
||||
@ -631,7 +624,7 @@ async fn test_pre_scan() {
|
||||
.set_ttl(0)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::NONE)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 24))))
|
||||
.clone()])
|
||||
.await
|
||||
.is_ok());
|
||||
@ -672,14 +665,14 @@ async fn test_update() {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 34))))
|
||||
.clone(),
|
||||
Record::new()
|
||||
.set_name(www_name.clone())
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::AAAA)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::AAAA(Ipv6Addr::new(
|
||||
.set_data(Some(RData::AAAA(AAAA::new(
|
||||
0x2606, 0x2800, 0x220, 0x1, 0x248, 0x1893, 0x25c8, 0x1946,
|
||||
))))
|
||||
.clone(),
|
||||
@ -723,7 +716,7 @@ async fn test_update() {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 24))))
|
||||
.clone()];
|
||||
assert!(authority
|
||||
.update_records(add_record, true,)
|
||||
@ -749,7 +742,7 @@ async fn test_update() {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(10, 0, 0, 1))))
|
||||
.set_data(Some(RData::A(A::new(10, 0, 0, 1))))
|
||||
.clone()];
|
||||
assert!(authority
|
||||
.update_records(add_www_record, true,)
|
||||
@ -784,7 +777,7 @@ async fn test_update() {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::NONE)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 24))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 24))))
|
||||
.clone()];
|
||||
assert!(authority
|
||||
.update_records(del_record, true,)
|
||||
@ -807,7 +800,7 @@ async fn test_update() {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::A)
|
||||
.set_dns_class(DNSClass::NONE)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(10, 0, 0, 1))))
|
||||
.set_data(Some(RData::A(A::new(10, 0, 0, 1))))
|
||||
.clone()];
|
||||
assert!(authority
|
||||
.update_records(del_record, true,)
|
||||
@ -858,7 +851,7 @@ async fn test_update() {
|
||||
.set_ttl(86400)
|
||||
.set_rr_type(RecordType::AAAA)
|
||||
.set_dns_class(DNSClass::IN)
|
||||
.set_data(Some(RData::AAAA(Ipv6Addr::new(
|
||||
.set_data(Some(RData::AAAA(AAAA::new(
|
||||
0x2606, 0x2800, 0x220, 0x1, 0x248, 0x1893, 0x25c8, 0x1946,
|
||||
))))
|
||||
.clone(),
|
||||
@ -1008,12 +1001,12 @@ async fn test_journal() {
|
||||
let new_record = Record::new()
|
||||
.set_name(new_name.clone())
|
||||
.set_record_type(RecordType::A)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(10, 11, 12, 13))))
|
||||
.set_data(Some(RData::A(A::new(10, 11, 12, 13))))
|
||||
.clone();
|
||||
let delete_record = Record::new()
|
||||
.set_name(delete_name.clone())
|
||||
.set_record_type(RecordType::A)
|
||||
.set_data(Some(RData::A(Ipv4Addr::new(93, 184, 216, 34))))
|
||||
.set_data(Some(RData::A(A::new(93, 184, 216, 34))))
|
||||
.set_dns_class(DNSClass::NONE)
|
||||
.clone();
|
||||
authority
|
||||
|
Loading…
Reference in New Issue
Block a user