remove DnsRequestOptions from AsyncResolver::lookup
This commit is contained in:
parent
0ef848fff3
commit
a89cde5393
@ -54,6 +54,7 @@ All notes should be prepended with the location of the change, e.g. `(proto)` or
|
|||||||
|
|
||||||
- (util) openssl is no longer default enabled in trust-dns-utils, bins marked as required as necessary #1644
|
- (util) openssl is no longer default enabled in trust-dns-utils, bins marked as required as necessary #1644
|
||||||
- (proto) deprecate outdated dnssec algorithms #1640
|
- (proto) deprecate outdated dnssec algorithms #1640
|
||||||
|
- (resolver) *BREAKING* removed `DnsRequestOptions` parameter from `AsyncResolver::lookup`, this is derived from `ResolverOpts`
|
||||||
- (server) pass RequestInfo into Authority on search #1620
|
- (server) pass RequestInfo into Authority on search #1620
|
||||||
- (proto) SSHFP: Ed448 is assigned algorithm 6 in RFC 8709 #1604
|
- (proto) SSHFP: Ed448 is assigned algorithm 6 in RFC 8709 #1604
|
||||||
- (resolver) Do not retry the same name server on a negative response (@peterthejohnston) #1589
|
- (resolver) Do not retry the same name server on a negative response (@peterthejohnston) #1589
|
||||||
|
@ -80,7 +80,7 @@ fn build_message(query: Query, options: DnsRequestOptions) -> Message {
|
|||||||
.set_id(id)
|
.set_id(id)
|
||||||
.set_message_type(MessageType::Query)
|
.set_message_type(MessageType::Query)
|
||||||
.set_op_code(OpCode::Query)
|
.set_op_code(OpCode::Query)
|
||||||
.set_recursion_desired(true);
|
.set_recursion_desired(options.recursion_desired);
|
||||||
|
|
||||||
// Extended dns
|
// Extended dns
|
||||||
if options.use_edns {
|
if options.use_edns {
|
||||||
|
@ -25,18 +25,18 @@ pub struct DnsRequestOptions {
|
|||||||
// TODO: add EDNS options here?
|
// TODO: add EDNS options here?
|
||||||
/// When true, will add EDNS options to the request.
|
/// When true, will add EDNS options to the request.
|
||||||
pub use_edns: bool,
|
pub use_edns: bool,
|
||||||
|
/// set recursion desired (or not) for any requests
|
||||||
/// Specifies maximum request depth for DNSSEC validation.
|
pub recursion_desired: bool,
|
||||||
pub max_request_depth: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DnsRequestOptions {
|
impl Default for DnsRequestOptions {
|
||||||
#[allow(deprecated)]
|
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
#[allow(deprecated)]
|
||||||
|
DnsRequestOptions {
|
||||||
max_request_depth: 26,
|
max_request_depth: 26,
|
||||||
expects_multiple_responses: false,
|
expects_multiple_responses: false,
|
||||||
use_edns: false,
|
use_edns: false,
|
||||||
|
recursion_desired: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,9 @@
|
|||||||
|
|
||||||
//! Structs for creating and using a AsyncResolver
|
//! Structs for creating and using a AsyncResolver
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::future::Future;
|
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use futures_util::{self, future};
|
|
||||||
use proto::error::ProtoResult;
|
use proto::error::ProtoResult;
|
||||||
use proto::op::Query;
|
use proto::op::Query;
|
||||||
use proto::rr::domain::usage::ONION;
|
use proto::rr::domain::usage::ONION;
|
||||||
@ -92,10 +90,7 @@ macro_rules! lookup_fn {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut request_opts = DnsRequestOptions::default();
|
self.inner_lookup(name, $r, self.request_options()).await
|
||||||
request_opts.use_edns = self.options.edns0;
|
|
||||||
|
|
||||||
self.inner_lookup(name, $r, request_opts).await
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($p:ident, $l:ty, $r:path, $t:ty) => {
|
($p:ident, $l:ty, $r:path, $t:ty) => {
|
||||||
@ -106,8 +101,7 @@ macro_rules! lookup_fn {
|
|||||||
/// * `query` - a type which can be converted to `Name` via `From`.
|
/// * `query` - a type which can be converted to `Name` via `From`.
|
||||||
pub async fn $p(&self, query: $t) -> Result<$l, ResolveError> {
|
pub async fn $p(&self, query: $t) -> Result<$l, ResolveError> {
|
||||||
let name = Name::from(query);
|
let name = Name::from(query);
|
||||||
self.inner_lookup(name, $r, DnsRequestOptions::default())
|
self.inner_lookup(name, $r, self.request_options()).await
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -265,6 +259,15 @@ impl<C: DnsHandle<Error = ResolveError>, P: ConnectionProvider<Conn = C>> AsyncR
|
|||||||
Self::new_with_conn(config, options, conn_provider)
|
Self::new_with_conn(config, options, conn_provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Per request options based on the ResolverOpts
|
||||||
|
pub(crate) fn request_options(&self) -> DnsRequestOptions {
|
||||||
|
let mut request_opts = DnsRequestOptions::default();
|
||||||
|
request_opts.recursion_desired = self.options.recursion_desired;
|
||||||
|
request_opts.use_edns = self.options.edns0;
|
||||||
|
|
||||||
|
request_opts
|
||||||
|
}
|
||||||
|
|
||||||
/// Generic lookup for any RecordType
|
/// Generic lookup for any RecordType
|
||||||
///
|
///
|
||||||
/// *WARNING* this interface may change in the future, see if one of the specializations would be better.
|
/// *WARNING* this interface may change in the future, see if one of the specializations would be better.
|
||||||
@ -277,24 +280,18 @@ impl<C: DnsHandle<Error = ResolveError>, P: ConnectionProvider<Conn = C>> AsyncR
|
|||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
// A future for the returned Lookup RData
|
// A future for the returned Lookup RData
|
||||||
pub fn lookup<N: IntoName>(
|
pub async fn lookup<N: IntoName>(
|
||||||
&self,
|
&self,
|
||||||
name: N,
|
name: N,
|
||||||
record_type: RecordType,
|
record_type: RecordType,
|
||||||
options: DnsRequestOptions,
|
) -> Result<Lookup, ResolveError> {
|
||||||
) -> impl Future<Output = Result<Lookup, ResolveError>> + Send + Unpin + 'static {
|
|
||||||
let name = match name.into_name() {
|
let name = match name.into_name() {
|
||||||
Ok(name) => name,
|
Ok(name) => name,
|
||||||
Err(err) => return future::Either::Left(future::err(err.into())),
|
Err(err) => return Err(err.into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let names = self.build_names(name);
|
self.inner_lookup(name, record_type, self.request_options())
|
||||||
future::Either::Right(LookupFuture::lookup(
|
.await
|
||||||
names,
|
|
||||||
record_type,
|
|
||||||
options,
|
|
||||||
self.client_cache.clone(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_name(name: Name, names: &mut Vec<Name>) {
|
fn push_name(name: Name, names: &mut Vec<Name>) {
|
||||||
@ -375,7 +372,10 @@ impl<C: DnsHandle<Error = ResolveError>, P: ConnectionProvider<Conn = C>> AsyncR
|
|||||||
where
|
where
|
||||||
L: From<Lookup> + Send + 'static,
|
L: From<Lookup> + Send + 'static,
|
||||||
{
|
{
|
||||||
self.lookup(name, record_type, options).await.map(L::from)
|
let names = self.build_names(name);
|
||||||
|
LookupFuture::lookup(names, record_type, options, self.client_cache.clone())
|
||||||
|
.await
|
||||||
|
.map(L::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Performs a dual-stack DNS lookup for the IP for the given hostname.
|
/// Performs a dual-stack DNS lookup for the IP for the given hostname.
|
||||||
@ -430,7 +430,7 @@ impl<C: DnsHandle<Error = ResolveError>, P: ConnectionProvider<Conn = C>> AsyncR
|
|||||||
names,
|
names,
|
||||||
self.options.ip_strategy,
|
self.options.ip_strategy,
|
||||||
self.client_cache.clone(),
|
self.client_cache.clone(),
|
||||||
DnsRequestOptions::default(),
|
self.request_options(),
|
||||||
hosts,
|
hosts,
|
||||||
finally_ip_addr.and_then(Record::into_data),
|
finally_ip_addr.and_then(Record::into_data),
|
||||||
)
|
)
|
||||||
|
@ -818,6 +818,10 @@ pub struct ResolverOpts {
|
|||||||
pub try_tcp_on_error: bool,
|
pub try_tcp_on_error: bool,
|
||||||
/// The server ordering strategy that the resolver should use.
|
/// The server ordering strategy that the resolver should use.
|
||||||
pub server_ordering_strategy: ServerOrderingStrategy,
|
pub server_ordering_strategy: ServerOrderingStrategy,
|
||||||
|
/// Request upstream recursive resolvers to not perform any recursion.
|
||||||
|
///
|
||||||
|
/// This is true by default, disabling this is useful for requesting single records, but may prevent successful resolution.
|
||||||
|
pub recursion_desired: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ResolverOpts {
|
impl Default for ResolverOpts {
|
||||||
@ -847,6 +851,7 @@ impl Default for ResolverOpts {
|
|||||||
|
|
||||||
try_tcp_on_error: false,
|
try_tcp_on_error: false,
|
||||||
server_ordering_strategy: ServerOrderingStrategy::default(),
|
server_ordering_strategy: ServerOrderingStrategy::default(),
|
||||||
|
recursion_desired: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ use proto::rr::domain::TryParseIp;
|
|||||||
use proto::rr::IntoName;
|
use proto::rr::IntoName;
|
||||||
use proto::rr::RecordType;
|
use proto::rr::RecordType;
|
||||||
use tokio::runtime::{self, Runtime};
|
use tokio::runtime::{self, Runtime};
|
||||||
use trust_dns_proto::xfer::DnsRequestOptions;
|
|
||||||
|
|
||||||
use crate::config::{ResolverConfig, ResolverOpts};
|
use crate::config::{ResolverConfig, ResolverOpts};
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
@ -129,9 +128,7 @@ impl Resolver {
|
|||||||
/// * `name` - name of the record to lookup, if name is not a valid domain name, an error will be returned
|
/// * `name` - name of the record to lookup, if name is not a valid domain name, an error will be returned
|
||||||
/// * `record_type` - type of record to lookup
|
/// * `record_type` - type of record to lookup
|
||||||
pub fn lookup<N: IntoName>(&self, name: N, record_type: RecordType) -> ResolveResult<Lookup> {
|
pub fn lookup<N: IntoName>(&self, name: N, record_type: RecordType) -> ResolveResult<Lookup> {
|
||||||
let lookup = self
|
let lookup = self.async_resolver.lookup(name, record_type);
|
||||||
.async_resolver
|
|
||||||
.lookup(name, record_type, DnsRequestOptions::default());
|
|
||||||
self.runtime.lock()?.block_on(lookup)
|
self.runtime.lock()?.block_on(lookup)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,10 +131,7 @@ impl Authority for ForwardAuthority {
|
|||||||
|
|
||||||
debug!("forwarding lookup: {} {}", name, rtype);
|
debug!("forwarding lookup: {} {}", name, rtype);
|
||||||
let name: LowerName = name.clone();
|
let name: LowerName = name.clone();
|
||||||
let resolve = self
|
let resolve = self.resolver.lookup(name, rtype).await;
|
||||||
.resolver
|
|
||||||
.lookup(name, rtype, DnsRequestOptions::default())
|
|
||||||
.await;
|
|
||||||
|
|
||||||
resolve.map(ForwardLookup).map_err(LookupError::from)
|
resolve.map(ForwardLookup).map_err(LookupError::from)
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ use std::net::{IpAddr, SocketAddr};
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use console::style;
|
use console::style;
|
||||||
|
|
||||||
use trust_dns_proto::xfer::DnsRequestOptions;
|
|
||||||
use trust_dns_resolver::config::{
|
use trust_dns_resolver::config::{
|
||||||
NameServerConfig, NameServerConfigGroup, Protocol, ResolverConfig, ResolverOpts,
|
NameServerConfig, NameServerConfigGroup, Protocol, ResolverConfig, ResolverOpts,
|
||||||
};
|
};
|
||||||
@ -238,9 +237,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
lookup.into()
|
lookup.into()
|
||||||
} else {
|
} else {
|
||||||
resolver
|
resolver.lookup(name.to_string(), ty).await?
|
||||||
.lookup(name.to_string(), ty, DnsRequestOptions::default())
|
|
||||||
.await?
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// report response, TODO: better display of errors
|
// report response, TODO: better display of errors
|
||||||
|
Loading…
Reference in New Issue
Block a user