-
Notifications
You must be signed in to change notification settings - Fork 45
Update hickory-dns monorepo to 0.25.2 #8391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ca8ed8a
ebd5d7e
7560b14
2d1f80d
481a28e
3dd7c99
83dc4ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,11 @@ | |
use anyhow::Context; | ||
use anyhow::anyhow; | ||
use futures::FutureExt; | ||
use hickory_resolver::TokioAsyncResolver; | ||
use hickory_resolver::TokioResolver; | ||
use hickory_resolver::config::{ | ||
NameServerConfig, Protocol, ResolverConfig, ResolverOpts, | ||
NameServerConfig, ResolverConfig, ResolverOpts, | ||
}; | ||
use hickory_resolver::name_server::TokioConnectionProvider; | ||
use std::net::SocketAddr; | ||
use std::sync::Arc; | ||
use thiserror::Error; | ||
|
@@ -29,32 +30,35 @@ progenitor::generate_api!( | |
/// for Nexus. This is often useful when trying to connect with Nexus using | ||
/// TLS, since you need to come in via the DNS name to do that. | ||
/// | ||
/// This is a thin wrapper around `TokioAsyncResolver` | ||
/// This is a thin wrapper around `TokioResolver` | ||
pub struct CustomDnsResolver { | ||
dns_addr: SocketAddr, | ||
// The lifetime constraints on the `Resolve` trait make it hard to avoid an | ||
// Arc here. | ||
resolver: Arc<TokioAsyncResolver>, | ||
resolver: Arc<TokioResolver>, | ||
} | ||
|
||
impl CustomDnsResolver { | ||
/// Make a new custom resolver that uses the DNS server at the specified | ||
/// address | ||
pub fn new(dns_addr: SocketAddr) -> anyhow::Result<CustomDnsResolver> { | ||
let mut resolver_config = ResolverConfig::new(); | ||
resolver_config.add_name_server(NameServerConfig { | ||
socket_addr: dns_addr, | ||
protocol: Protocol::Udp, | ||
tls_dns_name: None, | ||
trust_negative_responses: false, | ||
bind_addr: None, | ||
}); | ||
resolver_config.add_name_server(NameServerConfig::new( | ||
dns_addr, | ||
hickory_resolver::proto::xfer::Protocol::Udp, | ||
)); | ||
Comment on lines
+46
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kind of funny but fine: now that our internal answers are authoritative it'd be a difference if we queried all internal name servers, but even then trusting negative answers seems fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooops... that is a kinds of funny. Nice catch |
||
let mut resolver_opts = ResolverOpts::default(); | ||
// Enable edns for potentially larger records | ||
resolver_opts.edns0 = true; | ||
|
||
let resolver = | ||
Arc::new(TokioAsyncResolver::tokio(resolver_config, resolver_opts)); | ||
let resolver = Arc::new( | ||
TokioResolver::builder_with_config( | ||
resolver_config, | ||
TokioConnectionProvider::default(), | ||
) | ||
.with_options(resolver_opts) | ||
.build(), | ||
); | ||
Ok(CustomDnsResolver { dns_addr, resolver }) | ||
} | ||
|
||
|
@@ -63,8 +67,8 @@ impl CustomDnsResolver { | |
self.dns_addr | ||
} | ||
|
||
/// Returns the underlying `TokioAsyncResolver | ||
pub fn resolver(&self) -> &TokioAsyncResolver { | ||
/// Returns the underlying `TokioResolver` | ||
pub fn resolver(&self) -> &TokioResolver { | ||
&self.resolver | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ use hickory_proto::op::ResponseCode; | |
use hickory_proto::rr::RData; | ||
use hickory_proto::rr::Record; | ||
use hickory_proto::rr::RecordType; | ||
use hickory_proto::rr::rdata::NS; | ||
use hickory_proto::rr::rdata::SRV; | ||
use hickory_proto::serialize::binary::BinDecodable; | ||
use hickory_proto::serialize::binary::BinDecoder; | ||
|
@@ -224,19 +225,11 @@ fn dns_record_to_record( | |
) -> Result<Record, RequestError> { | ||
match record { | ||
DnsRecord::A(addr) => { | ||
let mut a = Record::new(); | ||
a.set_name(name.clone()) | ||
.set_rr_type(RecordType::A) | ||
.set_data(Some(RData::A((*addr).into()))); | ||
Ok(a) | ||
Ok(Record::from_rdata(name.clone(), 0, RData::A((*addr).into()))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice. i'd wondered why |
||
} | ||
|
||
DnsRecord::Aaaa(addr) => { | ||
let mut aaaa = Record::new(); | ||
aaaa.set_name(name.clone()) | ||
.set_rr_type(RecordType::AAAA) | ||
.set_data(Some(RData::AAAA((*addr).into()))); | ||
Ok(aaaa) | ||
Ok(Record::from_rdata(name.clone(), 0, RData::AAAA((*addr).into()))) | ||
} | ||
|
||
DnsRecord::Srv(Srv { prio, weight, port, target }) => { | ||
|
@@ -247,11 +240,11 @@ fn dns_record_to_record( | |
error | ||
)) | ||
})?; | ||
let mut srv = Record::new(); | ||
srv.set_name(name.clone()).set_rr_type(RecordType::SRV).set_data( | ||
Some(RData::SRV(SRV::new(*prio, *weight, *port, tgt))), | ||
); | ||
Ok(srv) | ||
Ok(Record::from_rdata( | ||
name.clone(), | ||
0, | ||
RData::SRV(SRV::new(*prio, *weight, *port, tgt)), | ||
)) | ||
} | ||
|
||
DnsRecord::Ns(nsdname) => { | ||
|
@@ -262,12 +255,7 @@ fn dns_record_to_record( | |
error | ||
)) | ||
})?; | ||
let mut ns = Record::new(); | ||
use hickory_proto::rr::rdata::NS; | ||
ns.set_name(name.clone()) | ||
.set_rr_type(RecordType::NS) | ||
.set_data(Some(RData::NS(NS(nsdname)))); | ||
Ok(ns) | ||
Ok(Record::from_rdata(name.clone(), 0, RData::NS(NS(nsdname)))) | ||
} | ||
} | ||
} | ||
|
@@ -287,9 +275,27 @@ async fn handle_dns_message( | |
// have to decide if the error is authoritative. | ||
header.set_authoritative(true); | ||
|
||
let query = mr.query(); | ||
let query = match mr.queries() { | ||
[] => { | ||
// A request with no queries could be legitimate (such as RFC 7873's Server Cookie | ||
// query), but we won't look enough to find out because we don't support that. | ||
return Err(RequestError::ServFail(anyhow!( | ||
"request with no query?" | ||
))); | ||
} | ||
[query] => query, | ||
_ => { | ||
// A request that is a query (opcode 0) with more than one question | ||
// is invalid according to RFC 9619. We don't currently check that | ||
// the opcode is actually QUERY, but even for other opcodes we don't | ||
// support more than one question. | ||
return Err(RequestError::ServFail(anyhow!( | ||
"request with too many queries" | ||
))); | ||
} | ||
}; | ||
let name = query.original().name().clone(); | ||
let answer = store.query(mr)?; | ||
let answer = store.query(query)?; | ||
let rb = MessageResponseBuilder::from_message_request(mr); | ||
let mut additional_records = vec![]; | ||
|
||
|
@@ -315,29 +321,22 @@ async fn handle_dns_message( | |
if name_records.is_empty() { | ||
return Err(RequestError::NxDomain(answer.queried_fqdn())); | ||
} | ||
|
||
let response_records = name_records | ||
.into_iter() | ||
.filter(|record| { | ||
let ty = query.query_type(); | ||
if ty == RecordType::ANY { | ||
return true; | ||
} | ||
|
||
match (ty, record.data()) { | ||
(RecordType::A, Some(RData::A(_))) => true, | ||
(RecordType::AAAA, Some(RData::AAAA(_))) => true, | ||
(RecordType::SRV, Some(RData::SRV(_))) => true, | ||
(RecordType::NS, Some(RData::NS(_))) => true, | ||
(RecordType::SOA, Some(RData::SOA(_))) => true, | ||
_ => false, | ||
} | ||
.filter(|record| match (query.query_type(), record.data()) { | ||
(RecordType::ANY, _) => true, | ||
(RecordType::A, RData::A(_)) => true, | ||
(RecordType::AAAA, RData::AAAA(_)) => true, | ||
(RecordType::SRV, RData::SRV(_)) => true, | ||
(RecordType::NS, RData::NS(_)) => true, | ||
(RecordType::SOA, RData::SOA(_)) => true, | ||
_ => false, | ||
}) | ||
.map(|record| { | ||
// DNS allows for the server to return additional records that | ||
// weren't explicitly asked for by the client but that the server | ||
// expects the client will want. SRV and NS records both use names | ||
// for their referents (rather than IP addresses dierctly). If | ||
// for their referents (rather than IP addresses directly). If | ||
// someone has queried for one of those kinds of records, they'll | ||
// almost certainly be needing the IP addresses that go with them as | ||
// well. We opportunistically attempt to resolve the target here and | ||
|
@@ -346,8 +345,8 @@ async fn handle_dns_message( | |
// NOTE: we only do this one-layer deep. If the target of a SRV or | ||
// NS is a CNAME instead of A/AAAA directly, it will be lost here. | ||
let additionals_target = match record.data() { | ||
Some(RData::SRV(srv)) => Some(srv.target()), | ||
Some(RData::NS(ns)) => Some(&ns.0), | ||
RData::SRV(srv) => Some(srv.target()), | ||
RData::NS(ns) => Some(&ns.0), | ||
_ => None, | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, i see, the synchronous Hickory resolver is just gone gone (PR 2515 over there) and names shifted accordingly. good for them!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everyone loves async