Skip to content
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

add "Deny All" Dns Resolver #344

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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};