mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 01:03:54 +00:00
upgrade hickory-dns to 0.26.0
fix zone test
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
use crate::dns::config::DNS_SUPPORTED_PROTOCOLS;
|
||||
use crate::proto;
|
||||
use crate::proto::utils::RepeatedMessageModel;
|
||||
use anyhow::{Error, anyhow};
|
||||
use hickory_proto::xfer::Protocol;
|
||||
use hickory_resolver::config::{NameServerConfig, NameServerConfigGroup};
|
||||
use hickory_net::xfer::Protocol;
|
||||
use hickory_resolver::config::{ConnectionConfig, NameServerConfig};
|
||||
use serde::de::IntoDeserializer;
|
||||
use serde::{Deserialize, de};
|
||||
use serde_with::{DeserializeFromStr, SerializeDisplay};
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::str::FromStr;
|
||||
use url::Url;
|
||||
use url::{Host, Url};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, SerializeDisplay, DeserializeFromStr)]
|
||||
pub struct NameServerAddr {
|
||||
@@ -18,15 +19,22 @@ pub struct NameServerAddr {
|
||||
|
||||
impl From<NameServerAddr> for NameServerConfig {
|
||||
fn from(value: NameServerAddr) -> Self {
|
||||
Self::new(value.addr, value.protocol)
|
||||
let mut config = match value.protocol {
|
||||
Protocol::Udp => ConnectionConfig::udp(),
|
||||
Protocol::Tcp => ConnectionConfig::tcp(),
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
config.port = value.addr.port();
|
||||
Self::new(value.addr.ip(), true, vec![config])
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&NameServerConfig> for NameServerAddr {
|
||||
fn from(value: &NameServerConfig) -> Self {
|
||||
let connection = value.connections.first().unwrap();
|
||||
Self {
|
||||
protocol: value.protocol,
|
||||
addr: value.socket_addr,
|
||||
protocol: connection.protocol.to_protocol(),
|
||||
addr: SocketAddr::new(value.ip, connection.port),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,29 +70,23 @@ impl TryFrom<&Url> for NameServerAddr {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: &Url) -> Result<Self, Self::Error> {
|
||||
let scheme = value.scheme();
|
||||
let protocol = *DNS_SUPPORTED_PROTOCOLS
|
||||
.iter()
|
||||
.find(|p| p.to_string() == scheme)
|
||||
.ok_or(anyhow!("unsupported scheme: {}", scheme))?;
|
||||
let addr = value.host_str().ok_or(anyhow!("host not found"))?;
|
||||
let addr = addr
|
||||
.trim_start_matches('[')
|
||||
.trim_end_matches(']')
|
||||
.parse::<IpAddr>()
|
||||
.map_err(|e| anyhow!("invalid ip address '{}': {}", addr, e))?;
|
||||
let port = if let Some(port) = value.port() {
|
||||
port
|
||||
} else {
|
||||
match protocol {
|
||||
Protocol::Udp | Protocol::Tcp => 53,
|
||||
_ => return Err(anyhow!("port not found")),
|
||||
let protocol = Protocol::deserialize(value.scheme().into_deserializer()).map_err(
|
||||
|e: de::value::Error| anyhow!("invalid protocol '{}': {}", value.scheme(), e),
|
||||
)?;
|
||||
let port = value
|
||||
.port()
|
||||
.or_else(|| matches!(protocol, Protocol::Udp | Protocol::Tcp).then_some(53))
|
||||
.ok_or_else(|| anyhow!("port not found"))?;
|
||||
let ip = match value.host().ok_or(anyhow!("host not found"))? {
|
||||
Host::Domain(_) => {
|
||||
return Err(anyhow!("unsupported host: {}", value.host_str().unwrap()));
|
||||
}
|
||||
Host::Ipv4(ip) => ip.into(),
|
||||
Host::Ipv6(ip) => ip.into(),
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
protocol,
|
||||
addr: SocketAddr::new(addr, port),
|
||||
addr: SocketAddr::new(ip, port),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -125,20 +127,3 @@ impl Display for NameServerAddr {
|
||||
}
|
||||
|
||||
pub type NameServerAddrGroup = RepeatedMessageModel<NameServerAddr>;
|
||||
|
||||
impl From<NameServerAddrGroup> for NameServerConfigGroup {
|
||||
fn from(value: NameServerAddrGroup) -> Self {
|
||||
value.into_iter().map(Into::into).collect::<Vec<_>>().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NameServerConfigGroup> for NameServerAddrGroup {
|
||||
fn from(value: NameServerConfigGroup) -> Self {
|
||||
value
|
||||
.into_inner()
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
use crate::utils::BoxExt;
|
||||
use delegate::delegate;
|
||||
use derive_more::{Deref, DerefMut, From};
|
||||
use hickory_proto::rr::{LowerName, RecordType};
|
||||
use hickory_server::authority::{
|
||||
Authority, AuthorityObject, LookupControlFlow, LookupObject, LookupOptions, MessageRequest,
|
||||
UpdateResult, ZoneType,
|
||||
};
|
||||
use hickory_server::server::RequestInfo;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub type ArcAuthority = Arc<dyn AuthorityObject>;
|
||||
|
||||
#[derive(From, Deref, DerefMut)]
|
||||
pub struct ChainedAuthority<A>(A)
|
||||
where
|
||||
A: Authority,
|
||||
A::Lookup: LookupObject + 'static;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<A> Authority for ChainedAuthority<A>
|
||||
where
|
||||
A: Authority,
|
||||
A::Lookup: LookupObject + 'static,
|
||||
{
|
||||
type Lookup = A::Lookup;
|
||||
|
||||
delegate! {
|
||||
to self.0 {
|
||||
fn zone_type(&self) -> ZoneType;
|
||||
fn is_axfr_allowed(&self) -> bool;
|
||||
fn origin(&self) -> &LowerName;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
async fn update(&self, update: &MessageRequest) -> UpdateResult<bool> {
|
||||
self.0.update(update).await
|
||||
}
|
||||
#[inline]
|
||||
async fn lookup(
|
||||
&self,
|
||||
name: &LowerName,
|
||||
rtype: RecordType,
|
||||
lookup_options: LookupOptions,
|
||||
) -> LookupControlFlow<Self::Lookup> {
|
||||
self.0.lookup(name, rtype, lookup_options).await
|
||||
}
|
||||
#[inline]
|
||||
async fn consult(
|
||||
&self,
|
||||
name: &LowerName,
|
||||
rtype: RecordType,
|
||||
lookup_options: LookupOptions,
|
||||
last_result: LookupControlFlow<Box<dyn LookupObject>>,
|
||||
) -> LookupControlFlow<Box<dyn LookupObject>> {
|
||||
if let Some(Ok(l)) = last_result.map_result() {
|
||||
LookupControlFlow::Break(Ok(l))
|
||||
} else {
|
||||
self.0
|
||||
.lookup(name, rtype, lookup_options)
|
||||
.await
|
||||
.map(|l| l.boxed() as _)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
async fn search(
|
||||
&self,
|
||||
request_info: RequestInfo<'_>,
|
||||
lookup_options: LookupOptions,
|
||||
) -> LookupControlFlow<Self::Lookup> {
|
||||
self.0.search(request_info, lookup_options).await
|
||||
}
|
||||
#[inline]
|
||||
async fn get_nsec_records(
|
||||
&self,
|
||||
name: &LowerName,
|
||||
lookup_options: LookupOptions,
|
||||
) -> LookupControlFlow<Self::Lookup> {
|
||||
self.0.get_nsec_records(name, lookup_options).await
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@ use hickory_proto::rr::LowerName;
|
||||
use idna::AsciiDenyList;
|
||||
|
||||
pub mod addr;
|
||||
pub mod authority;
|
||||
pub mod dirty;
|
||||
pub mod response;
|
||||
pub mod zone_handler;
|
||||
|
||||
pub fn sanitize(name: &str) -> String {
|
||||
let dot = name.ends_with('.');
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use hickory_net::NetError;
|
||||
use hickory_proto::rr::Record;
|
||||
use hickory_proto::serialize::binary::BinEncoder;
|
||||
use hickory_server::authority::MessageResponse;
|
||||
use hickory_server::server::{ResponseHandler, ResponseInfo};
|
||||
use hickory_server::zone_handler::MessageResponse;
|
||||
use parking_lot::Mutex;
|
||||
use std::io;
|
||||
use std::sync::Arc;
|
||||
|
||||
// ResponseWrapper for serializing DNS responses into a byte buffer.
|
||||
@@ -41,11 +41,11 @@ impl ResponseHandler for ResponseHandle {
|
||||
impl RecordIter<'r>,
|
||||
impl RecordIter<'r>,
|
||||
>,
|
||||
) -> io::Result<ResponseInfo> {
|
||||
let max_size = if let Some(edns) = response.get_edns() {
|
||||
) -> Result<ResponseInfo, NetError> {
|
||||
let max_size = if let Some(edns) = response.edns() {
|
||||
edns.max_payload()
|
||||
} else {
|
||||
hickory_proto::udp::MAX_RECEIVE_BUFFER_SIZE as u16
|
||||
hickory_net::udp::MAX_RECEIVE_BUFFER_SIZE as u16
|
||||
};
|
||||
|
||||
let mut inner = self.inner.lock();
|
||||
@@ -54,6 +54,6 @@ impl ResponseHandler for ResponseHandle {
|
||||
encoder.set_max_size(max_size);
|
||||
response
|
||||
.destructive_emit(&mut encoder)
|
||||
.map_err(io::Error::other)
|
||||
.map_err(NetError::Proto)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
use delegate::delegate;
|
||||
use derive_more::{Deref, DerefMut, From};
|
||||
use hickory_proto::op::ResponseCode;
|
||||
use hickory_proto::rr::{LowerName, RecordType, TSigResponseContext};
|
||||
use hickory_server::server::{Request, RequestInfo};
|
||||
use hickory_server::zone_handler::{
|
||||
AuthLookup, AxfrPolicy, LookupControlFlow, LookupOptions, ZoneHandler, ZoneType,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub type ArcZoneHandler = Arc<dyn ZoneHandler>;
|
||||
|
||||
#[derive(From, Deref, DerefMut)]
|
||||
pub struct ChainedZoneHandler<H>(H)
|
||||
where
|
||||
H: ZoneHandler;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<H> ZoneHandler for ChainedZoneHandler<H>
|
||||
where
|
||||
H: ZoneHandler,
|
||||
{
|
||||
delegate! {
|
||||
to self.0 {
|
||||
fn zone_type(&self) -> ZoneType;
|
||||
fn axfr_policy(&self) -> AxfrPolicy;
|
||||
fn origin(&self) -> &LowerName;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
async fn update(
|
||||
&self,
|
||||
update: &Request,
|
||||
now: u64,
|
||||
) -> (Result<bool, ResponseCode>, Option<TSigResponseContext>) {
|
||||
self.0.update(update, now).await
|
||||
}
|
||||
#[inline]
|
||||
async fn lookup(
|
||||
&self,
|
||||
name: &LowerName,
|
||||
rtype: RecordType,
|
||||
request_info: Option<&RequestInfo<'_>>,
|
||||
lookup_options: LookupOptions,
|
||||
) -> LookupControlFlow<AuthLookup> {
|
||||
self.0
|
||||
.lookup(name, rtype, request_info, lookup_options)
|
||||
.await
|
||||
}
|
||||
#[inline]
|
||||
async fn consult(
|
||||
&self,
|
||||
name: &LowerName,
|
||||
rtype: RecordType,
|
||||
request_info: Option<&RequestInfo<'_>>,
|
||||
lookup_options: LookupOptions,
|
||||
last_result: LookupControlFlow<AuthLookup>,
|
||||
) -> (LookupControlFlow<AuthLookup>, Option<TSigResponseContext>) {
|
||||
let result = if let Some(Ok(l)) = last_result.map_result() {
|
||||
LookupControlFlow::Break(Ok(l))
|
||||
} else {
|
||||
self.0
|
||||
.lookup(name, rtype, request_info, lookup_options)
|
||||
.await
|
||||
};
|
||||
(result, None)
|
||||
}
|
||||
#[inline]
|
||||
async fn search(
|
||||
&self,
|
||||
request: &Request,
|
||||
lookup_options: LookupOptions,
|
||||
) -> (LookupControlFlow<AuthLookup>, Option<TSigResponseContext>) {
|
||||
self.0.search(request, lookup_options).await
|
||||
}
|
||||
#[inline]
|
||||
async fn nsec_records(
|
||||
&self,
|
||||
name: &LowerName,
|
||||
lookup_options: LookupOptions,
|
||||
) -> LookupControlFlow<AuthLookup> {
|
||||
self.0.nsec_records(name, lookup_options).await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user