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
|
||||
- (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
|
||||
- (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
|
||||
|
@ -80,7 +80,7 @@ fn build_message(query: Query, options: DnsRequestOptions) -> Message {
|
||||
.set_id(id)
|
||||
.set_message_type(MessageType::Query)
|
||||
.set_op_code(OpCode::Query)
|
||||
.set_recursion_desired(true);
|
||||
.set_recursion_desired(options.recursion_desired);
|
||||
|
||||
// Extended dns
|
||||
if options.use_edns {
|
||||
|
@ -25,18 +25,18 @@ pub struct DnsRequestOptions {
|
||||
// TODO: add EDNS options here?
|
||||
/// When true, will add EDNS options to the request.
|
||||
pub use_edns: bool,
|
||||
|
||||
/// Specifies maximum request depth for DNSSEC validation.
|
||||
pub max_request_depth: usize,
|
||||
/// set recursion desired (or not) for any requests
|
||||
pub recursion_desired: bool,
|
||||
}
|
||||
|
||||
impl Default for DnsRequestOptions {
|
||||
#[allow(deprecated)]
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
#[allow(deprecated)]
|
||||
DnsRequestOptions {
|
||||
max_request_depth: 26,
|
||||
expects_multiple_responses: false,
|
||||
use_edns: false,
|
||||
recursion_desired: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,9 @@
|
||||
|
||||
//! Structs for creating and using a AsyncResolver
|
||||
use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::net::IpAddr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use futures_util::{self, future};
|
||||
use proto::error::ProtoResult;
|
||||
use proto::op::Query;
|
||||
use proto::rr::domain::usage::ONION;
|
||||
@ -92,10 +90,7 @@ macro_rules! lookup_fn {
|
||||
}
|
||||
};
|
||||
|
||||
let mut request_opts = DnsRequestOptions::default();
|
||||
request_opts.use_edns = self.options.edns0;
|
||||
|
||||
self.inner_lookup(name, $r, request_opts).await
|
||||
self.inner_lookup(name, $r, self.request_options()).await
|
||||
}
|
||||
};
|
||||
($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`.
|
||||
pub async fn $p(&self, query: $t) -> Result<$l, ResolveError> {
|
||||
let name = Name::from(query);
|
||||
self.inner_lookup(name, $r, DnsRequestOptions::default())
|
||||
.await
|
||||
self.inner_lookup(name, $r, self.request_options()).await
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -265,6 +259,15 @@ impl<C: DnsHandle<Error = ResolveError>, P: ConnectionProvider<Conn = C>> AsyncR
|
||||
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
|
||||
///
|
||||
/// *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
|
||||
///
|
||||
// A future for the returned Lookup RData
|
||||
pub fn lookup<N: IntoName>(
|
||||
pub async fn lookup<N: IntoName>(
|
||||
&self,
|
||||
name: N,
|
||||
record_type: RecordType,
|
||||
options: DnsRequestOptions,
|
||||
) -> impl Future<Output = Result<Lookup, ResolveError>> + Send + Unpin + 'static {
|
||||
) -> Result<Lookup, ResolveError> {
|
||||
let name = match name.into_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);
|
||||
future::Either::Right(LookupFuture::lookup(
|
||||
names,
|
||||
record_type,
|
||||
options,
|
||||
self.client_cache.clone(),
|
||||
))
|
||||
self.inner_lookup(name, record_type, self.request_options())
|
||||
.await
|
||||
}
|
||||
|
||||
fn push_name(name: Name, names: &mut Vec<Name>) {
|
||||
@ -375,7 +372,10 @@ impl<C: DnsHandle<Error = ResolveError>, P: ConnectionProvider<Conn = C>> AsyncR
|
||||
where
|
||||
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.
|
||||
@ -430,7 +430,7 @@ impl<C: DnsHandle<Error = ResolveError>, P: ConnectionProvider<Conn = C>> AsyncR
|
||||
names,
|
||||
self.options.ip_strategy,
|
||||
self.client_cache.clone(),
|
||||
DnsRequestOptions::default(),
|
||||
self.request_options(),
|
||||
hosts,
|
||||
finally_ip_addr.and_then(Record::into_data),
|
||||
)
|
||||
|
@ -818,6 +818,10 @@ pub struct ResolverOpts {
|
||||
pub try_tcp_on_error: bool,
|
||||
/// The server ordering strategy that the resolver should use.
|
||||
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 {
|
||||
@ -847,6 +851,7 @@ impl Default for ResolverOpts {
|
||||
|
||||
try_tcp_on_error: false,
|
||||
server_ordering_strategy: ServerOrderingStrategy::default(),
|
||||
recursion_desired: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ use proto::rr::domain::TryParseIp;
|
||||
use proto::rr::IntoName;
|
||||
use proto::rr::RecordType;
|
||||
use tokio::runtime::{self, Runtime};
|
||||
use trust_dns_proto::xfer::DnsRequestOptions;
|
||||
|
||||
use crate::config::{ResolverConfig, ResolverOpts};
|
||||
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
|
||||
/// * `record_type` - type of record to lookup
|
||||
pub fn lookup<N: IntoName>(&self, name: N, record_type: RecordType) -> ResolveResult<Lookup> {
|
||||
let lookup = self
|
||||
.async_resolver
|
||||
.lookup(name, record_type, DnsRequestOptions::default());
|
||||
let lookup = self.async_resolver.lookup(name, record_type);
|
||||
self.runtime.lock()?.block_on(lookup)
|
||||
}
|
||||
|
||||
|
@ -131,10 +131,7 @@ impl Authority for ForwardAuthority {
|
||||
|
||||
debug!("forwarding lookup: {} {}", name, rtype);
|
||||
let name: LowerName = name.clone();
|
||||
let resolve = self
|
||||
.resolver
|
||||
.lookup(name, rtype, DnsRequestOptions::default())
|
||||
.await;
|
||||
let resolve = self.resolver.lookup(name, rtype).await;
|
||||
|
||||
resolve.map(ForwardLookup).map_err(LookupError::from)
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ use std::net::{IpAddr, SocketAddr};
|
||||
use clap::Parser;
|
||||
use console::style;
|
||||
|
||||
use trust_dns_proto::xfer::DnsRequestOptions;
|
||||
use trust_dns_resolver::config::{
|
||||
NameServerConfig, NameServerConfigGroup, Protocol, ResolverConfig, ResolverOpts,
|
||||
};
|
||||
@ -238,9 +237,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
lookup.into()
|
||||
} else {
|
||||
resolver
|
||||
.lookup(name.to_string(), ty, DnsRequestOptions::default())
|
||||
.await?
|
||||
resolver.lookup(name.to_string(), ty).await?
|
||||
};
|
||||
|
||||
// report response, TODO: better display of errors
|
||||
|
Loading…
Reference in New Issue
Block a user