Skip to content

Commit

Permalink
Merge pull request #344 from parkma99/main
Browse files Browse the repository at this point in the history
add "Deny All" Dns Resolver
  • Loading branch information
GlenDC authored Oct 25, 2024
2 parents 45848f3 + 655e369 commit e0b2f57
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
35 changes: 35 additions & 0 deletions rama-dns/src/deny_all.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::DnsResolver;
use rama_net::address::Domain;
use rama_utils::macros::error::static_str_error;
use std::net::{Ipv4Addr, Ipv6Addr};

#[derive(Debug, Clone, Default)]
#[non_exhaustive]
/// a [`DnsResolver`] implementation which
/// denies all incoming DNS requests with a [`DnsDeniedError`].
pub struct DenyAllDns;

impl DenyAllDns {
#[inline]
/// Create a new [`Default`] [`DenyAllDns`].
pub fn new() -> Self {
Self::default()
}
}

static_str_error! {
#[doc = "Dns denied"]
pub struct DnsDeniedError;
}

impl DnsResolver for DenyAllDns {
type Error = DnsDeniedError;

async fn ipv4_lookup(&self, _domain: Domain) -> Result<Vec<Ipv4Addr>, Self::Error> {
Err(DnsDeniedError)
}

async fn ipv6_lookup(&self, _domain: Domain) -> Result<Vec<Ipv6Addr>, Self::Error> {
Err(DnsDeniedError)
}
}
4 changes: 4 additions & 0 deletions rama-dns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ pub use hickory::HickoryDns;
mod in_memory;
#[doc(inline)]
pub use in_memory::{DnsOverwrite, DomainNotMappedErr, InMemoryDns};

mod deny_all;
#[doc(inline)]
pub use deny_all::{DenyAllDns, DnsDeniedError};

0 comments on commit e0b2f57

Please sign in to comment.