use core::ops::Deref;
use once_cell::sync::Lazy;
use crate::rr::domain::Name;
pub static DEFAULT: Lazy<ZoneUsage> = Lazy::new(ZoneUsage::default);
static ARPA: Lazy<Name> = Lazy::new(|| Name::from_ascii("arpa.").unwrap());
pub static IN_ADDR_ARPA: Lazy<Name> = Lazy::new(|| {
Name::from_ascii("in-addr")
.unwrap()
.append_domain(&ARPA)
.unwrap()
});
pub static IP6_ARPA: Lazy<Name> = Lazy::new(|| {
Name::from_ascii("ip6")
.unwrap()
.append_domain(&ARPA)
.unwrap()
});
pub static LOCALHOST: Lazy<ZoneUsage> =
Lazy::new(|| ZoneUsage::localhost(Name::from_ascii("localhost.").unwrap()));
pub static IN_ADDR_ARPA_127: Lazy<ZoneUsage> = Lazy::new(|| {
ZoneUsage::localhost(
Name::from_ascii("127")
.unwrap()
.append_domain(&IN_ADDR_ARPA)
.unwrap(),
)
});
pub static IP6_ARPA_1: Lazy<ZoneUsage> = Lazy::new(|| {
ZoneUsage::localhost(
Name::from_ascii("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0")
.unwrap()
.append_domain(&IP6_ARPA)
.unwrap(),
)
});
pub static LOCAL: Lazy<ZoneUsage> =
Lazy::new(|| ZoneUsage::local(Name::from_ascii("local.").unwrap()));
pub static IN_ADDR_ARPA_169_254: Lazy<ZoneUsage> = Lazy::new(|| {
ZoneUsage::local(
Name::from_ascii("254.169")
.unwrap()
.append_domain(&IN_ADDR_ARPA)
.unwrap(),
)
});
pub static IP6_ARPA_FE_8: Lazy<ZoneUsage> = Lazy::new(|| {
ZoneUsage::local(
Name::from_ascii("8.e.f")
.unwrap()
.append_domain(&IP6_ARPA)
.unwrap(),
)
});
pub static IP6_ARPA_FE_9: Lazy<ZoneUsage> = Lazy::new(|| {
ZoneUsage::local(
Name::from_ascii("9.e.f")
.unwrap()
.append_domain(&IP6_ARPA)
.unwrap(),
)
});
pub static IP6_ARPA_FE_B: Lazy<ZoneUsage> = Lazy::new(|| {
ZoneUsage::local(
Name::from_ascii("b.e.f")
.unwrap()
.append_domain(&IP6_ARPA)
.unwrap(),
)
});
pub static INVALID: Lazy<ZoneUsage> =
Lazy::new(|| ZoneUsage::invalid(Name::from_ascii("invalid.").unwrap()));
pub static ONION: Lazy<ZoneUsage> = Lazy::new(|| ZoneUsage {
user: UserUsage::Normal, app: AppUsage::Normal, ..ZoneUsage::invalid(Name::from_ascii("onion.").unwrap())
});
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum UserUsage {
Normal,
Loopback,
LinkLocal,
NxDomain,
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum AppUsage {
Normal,
Loopback,
LinkLocal,
NxDomain,
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum ResolverUsage {
Normal,
Loopback,
LinkLocal,
NxDomain,
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum CacheUsage {
NonRecursive,
NxDomain,
Loopback,
Normal,
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum AuthUsage {
Local,
NxDomain,
Loopback,
Normal,
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum OpUsage {
Normal,
Loopback,
NxDomain,
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum RegistryUsage {
Normal,
Reserved,
}
pub struct ZoneUsage {
name: Name,
user: UserUsage,
app: AppUsage,
resolver: ResolverUsage,
cache: CacheUsage,
auth: AuthUsage,
op: OpUsage,
registry: RegistryUsage,
}
impl ZoneUsage {
#[allow(clippy::too_many_arguments)]
pub fn new(
name: Name,
user: UserUsage,
app: AppUsage,
resolver: ResolverUsage,
cache: CacheUsage,
auth: AuthUsage,
op: OpUsage,
registry: RegistryUsage,
) -> Self {
Self {
name,
user,
app,
resolver,
cache,
auth,
op,
registry,
}
}
pub fn reverse(name: Name) -> Self {
Self::new(
name,
UserUsage::Normal,
AppUsage::Normal,
ResolverUsage::Normal,
CacheUsage::NonRecursive,
AuthUsage::Local,
OpUsage::Normal,
RegistryUsage::Reserved,
)
}
pub fn test(name: Name) -> Self {
Self::new(
name,
UserUsage::Normal,
AppUsage::Normal,
ResolverUsage::Normal,
CacheUsage::NonRecursive,
AuthUsage::Local,
OpUsage::Normal,
RegistryUsage::Reserved,
)
}
pub fn localhost(name: Name) -> Self {
Self::new(
name,
UserUsage::Loopback,
AppUsage::Loopback,
ResolverUsage::Loopback,
CacheUsage::Loopback,
AuthUsage::Loopback,
OpUsage::Loopback,
RegistryUsage::Reserved,
)
}
pub fn local(name: Name) -> Self {
Self::new(
name,
UserUsage::LinkLocal,
AppUsage::LinkLocal,
ResolverUsage::LinkLocal,
CacheUsage::Normal,
AuthUsage::Local,
OpUsage::Normal,
RegistryUsage::Reserved,
)
}
pub fn invalid(name: Name) -> Self {
Self::new(
name,
UserUsage::NxDomain,
AppUsage::NxDomain,
ResolverUsage::NxDomain,
CacheUsage::NxDomain,
AuthUsage::NxDomain,
OpUsage::NxDomain,
RegistryUsage::Reserved,
)
}
pub fn example(name: Name) -> Self {
Self::new(
name,
UserUsage::Normal,
AppUsage::Normal,
ResolverUsage::Normal,
CacheUsage::Normal,
AuthUsage::Normal,
OpUsage::Normal,
RegistryUsage::Reserved,
)
}
pub fn name(&self) -> &Name {
&self.name
}
pub fn user(&self) -> UserUsage {
self.user
}
pub fn app(&self) -> AppUsage {
self.app
}
pub fn resolver(&self) -> ResolverUsage {
self.resolver
}
pub fn cache(&self) -> CacheUsage {
self.cache
}
pub fn auth(&self) -> AuthUsage {
self.auth
}
pub fn op(&self) -> OpUsage {
self.op
}
pub fn registry(&self) -> RegistryUsage {
self.registry
}
}
impl Default for ZoneUsage {
fn default() -> Self {
Self::new(
Name::root(),
UserUsage::Normal,
AppUsage::Normal,
ResolverUsage::Normal,
CacheUsage::Normal,
AuthUsage::Normal,
OpUsage::Normal,
RegistryUsage::Normal,
)
}
}
impl Deref for ZoneUsage {
type Target = Name;
fn deref(&self) -> &Self::Target {
&self.name
}
}