zone: move chained authority to utils, rewrite authority creation

This commit is contained in:
Luna Yao
2026-02-19 16:26:13 +01:00
parent 77ccd7dbc9
commit a6bec0fa6f
2 changed files with 129 additions and 117 deletions
+91 -1
View File
@@ -1,7 +1,13 @@
use anyhow::{anyhow, Error};
use hickory_proto::rr::LowerName;
use derive_more::{Deref, DerefMut};
use hickory_proto::rr::{LowerName, RecordType};
use hickory_proto::xfer::Protocol;
use hickory_resolver::config::NameServerConfig;
use hickory_server::authority::{
Authority, LookupControlFlow, LookupObject, LookupOptions, MessageRequest, UpdateResult,
ZoneType,
};
use hickory_server::server::RequestInfo;
use idna::AsciiDenyList;
use serde_with::{DeserializeFromStr, SerializeDisplay};
use std::fmt::{Display, Formatter};
@@ -121,3 +127,87 @@ impl Display for NameServerAddr {
f.write_str(Url::from(self).as_str())
}
}
#[derive(Deref, DerefMut)]
pub struct ChainedAuthority<A>(pub(super) A)
where
A: Authority,
A::Lookup: LookupObject + 'static;
impl<A> From<A> for ChainedAuthority<A>
where
A: Authority,
A::Lookup: LookupObject + 'static,
{
fn from(value: A) -> Self {
Self(value)
}
}
#[async_trait::async_trait]
impl<A> Authority for ChainedAuthority<A>
where
A: Authority,
A::Lookup: LookupObject + 'static,
{
type Lookup = A::Lookup;
#[inline]
fn zone_type(&self) -> ZoneType {
self.0.zone_type()
}
#[inline]
fn is_axfr_allowed(&self) -> bool {
self.0.is_axfr_allowed()
}
#[inline]
async fn update(&self, update: &MessageRequest) -> UpdateResult<bool> {
self.0.update(update).await
}
#[inline]
fn origin(&self) -> &LowerName {
self.0.origin()
}
#[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| Box::new(l) 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
}
}