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 support for Whitelist domains #172 #176

Merged
merged 1 commit into from
Oct 29, 2023
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
6 changes: 5 additions & 1 deletion src/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ impl<T: Debug> DomainMap<T> {
break;
}

domain = domain.base_name();
if domain.is_wildcard() {
domain = domain.base_name();
} else {
domain = domain.into_wildcard();
}
}

None
Expand Down
11 changes: 10 additions & 1 deletion src/config/parser/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl NomParser for Domain {
fn parse(input: &str) -> IResult<&str, Domain> {
let set = alphanumeric0;

let name = is_not(" \n\t\\/|\"#',!+*<>");
let name = is_not(" \n\t\\/|\"#',!+<>");

alt((
map(
Expand Down Expand Up @@ -47,4 +47,13 @@ mod test {
let (_, domain) = parse("xxx.集团 w").unwrap();
assert_eq!(domain, Domain::Name(Name::from_str("xxx.集团").unwrap()));
}

#[test]
fn test2() {
let n = Name::from_str(".").unwrap();
assert_eq!(n, Name::root());

let n = Name::from_str("*").unwrap();
assert!(n.is_wildcard());
}
}
22 changes: 22 additions & 0 deletions src/dns_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2115,6 +2115,8 @@ mod parse {

#[cfg(test)]
mod tests {
use std::str::FromStr;

use crate::libdns::resolver::config::Protocol;

use crate::config::{HttpsListener, ListenerAddress};
Expand Down Expand Up @@ -2441,6 +2443,26 @@ mod parse {
assert_eq!(domain_addr_rule.value, DomainAddress::IGNv6);
}

#[test]
fn test_config_address_whitelist_mode() {
let cfg = SmartDnsConfig::builder()
.with("address /google.com/-")
.with("address /*/#")
.build();

assert_eq!(
cfg.find_domain_rule(&Name::from_str("cloudflare.com").unwrap())
.and_then(|r| r.get(|n| n.address)),
Some(DomainAddress::SOA)
);

assert_eq!(
cfg.find_domain_rule(&Name::from_str("google.com").unwrap())
.and_then(|r| r.get(|n| n.address)),
Some(DomainAddress::IGN)
);
}

#[test]
fn test_config_nameserver() {
let mut cfg = SmartDnsConfig::builder();
Expand Down