Skip to content

Commit

Permalink
v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zyj committed Sep 26, 2023
1 parent 13b1eb9 commit d31bc7f
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 73 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ jobs:
strategy:
matrix:
target:
#- mips-unknown-linux-musl
- mips-unknown-linux-musl
# - mipsel-unknown-linux-musl
- x86_64-unknown-linux-musl
# - i686-unknown-linux-musl
- aarch64-unknown-linux-musl
# - arm-unknown-linux-musleabi
# - armv7-unknown-linux-musleabihf
- x86_64-pc-windows-gnu
- x86_64-unknown-freebsd
steps:
- name: checkout
uses: actions/checkout@v3
Expand All @@ -30,7 +31,7 @@ jobs:

- name: install deps
run: |
sudo apt update && sudo apt install llvm-dev libclang-dev clang libssl-dev pkg-config protobuf-compiler make libssl-dev -y
sudo apt update && sudo apt install llvm-dev libclang-dev clang libssl-dev pkg-config protobuf-compiler make -y
- name: install cross
run: |
Expand Down Expand Up @@ -73,6 +74,8 @@ jobs:
include:
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
runs-on: ${{ matrix.os }}
steps:
- name: checkout
Expand All @@ -92,7 +95,8 @@ jobs:
run: |
export CFG_COMMIT_HASH=`git log --pretty=format:'%h' -n 1`
export CFG_COMMIT_DATE=`git log --format="%ci" -n 1`
cargo build --release --target ${{ matrix.target }}
rustup target add ${{ matrix.target }}
SDKROOT=$(xcrun -sdk macosx14.0 --show-sdk-path) MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx14.0 --show-sdk-platform-version) cargo build --release --target ${{ matrix.target }}
- name: rename and compress artifacts
run: |
Expand Down Expand Up @@ -141,14 +145,16 @@ jobs:
matrix:
target:
- x86_64-apple-darwin
#- mips-unknown-linux-musl
- aarch64-apple-darwin
- mips-unknown-linux-musl
# - mipsel-unknown-linux-musl
- x86_64-unknown-linux-musl
# - i686-unknown-linux-musl
- aarch64-unknown-linux-musl
# - arm-unknown-linux-musleabi
# - armv7-unknown-linux-musleabihf
- x86_64-pc-windows-gnu
- x86_64-unknown-freebsd
steps:
- name: download upload url
uses: actions/download-artifact@v2
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.1.1

* fixed mips build error

# 0.1.0

* First version
Expand Down
33 changes: 22 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yadns"
version = "0.1.0"
version = "0.1.1"
authors = ["zyj"]
edition = "2021"

Expand Down Expand Up @@ -30,6 +30,7 @@ publicsuffix = "2.2.3"

[target.'cfg(any(target_arch = "mips", target_arch = "mips64"))'.dependencies]
trust-dns-resolver = { version = "0.23.0", default-features = false, features = ["dns-over-openssl"] }
openssl = { version = "0.10", features = ["vendored"] }

[target.'cfg(not(any(target_arch = "mips", target_arch = "mips64")))'.dependencies]
trust-dns-resolver = { version = "0.23.0", default-features = false, features = ["dns-over-https-rustls"] }
Expand Down
15 changes: 3 additions & 12 deletions src/filter.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::{
config::{RequestRule, ResponseRule, RuleAction},
resolver::RecursiveResolver,
APPCONFIG, STDERR,
};
use slog::debug;
use std::sync::Arc;
use trust_dns_proto::{op::LowerQuery, rr::RecordType};
use trust_dns_resolver::lookup::Lookup;

Expand Down Expand Up @@ -69,7 +67,7 @@ pub fn check_response(domain: &str, upstream_name: &str, resp: &Lookup) -> RuleA
.unwrap_or(RuleAction::Accept)
}

pub fn resolvers(query: &LowerQuery) -> Vec<(&str, Arc<RecursiveResolver>)> {
pub fn resolvers(query: &LowerQuery) -> Vec<&str> {
let name = query.name().to_string();

let check_type = |rule: &RequestRule| {
Expand All @@ -86,18 +84,11 @@ pub fn resolvers(query: &LowerQuery) -> Vec<(&str, Arc<RecursiveResolver>)> {

if let Some(rule) = rule {
debug!(STDERR, "Query {} matches rule {:?}", name, rule);
rule.upstreams
.iter()
.filter_map(|u| APPCONFIG.resolvers.get(u).map(|v| (u.as_str(), v.clone())))
.collect()
rule.upstreams.iter().map(String::as_str).collect()
} else {
debug!(STDERR, "No rule matches for {}. Use defaults.", name);
// If no rule matches, use defaults
APPCONFIG
.defaults
.iter()
.filter_map(|u| APPCONFIG.resolvers.get(u).map(|v| (u.as_str(), v.clone())))
.collect()
APPCONFIG.defaults.iter().map(String::as_str).collect()
}
}

Expand Down
17 changes: 5 additions & 12 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ use futures::{
Future, FutureExt, TryFutureExt,
};
use slog::{debug, error};
use std::{
pin::Pin,
sync::{
atomic::{AtomicU64, Ordering},
Arc,
},
};
use std::pin::Pin;
use trust_dns_resolver::{error::ResolveError, lookup::Lookup};
use trust_dns_server::{
authority::MessageResponseBuilder,
Expand All @@ -32,15 +26,14 @@ pub enum Error {
/// DNS Request Handler
#[derive(Clone)]
pub struct Handler {
/// Request counter, incremented on every successful request.
pub counter: Arc<AtomicU64>,
//pub counter: Arc<AtomicU64>,
}

impl Handler {
/// Create new handler from command-line options.
pub fn new() -> Self {
Handler {
counter: Arc::new(AtomicU64::new(0)),
// counter: Arc::new(AtomicU64::new(0)),
}
}

Expand All @@ -50,15 +43,15 @@ impl Handler {
request: &Request,
mut responder: R,
) -> Result<ResponseInfo, Error> {
self.counter.fetch_add(1, Ordering::SeqCst);
//self.counter.fetch_add(1, Ordering::SeqCst);
let builder = MessageResponseBuilder::from_message_request(request);
let mut header = Header::response_from_request(request.header());
header.set_authoritative(true);

let resolvers = filter::resolvers(request.query());
let tasks: Vec<_> = resolvers
.into_iter()
.map(|(name, _)| {
.map(|name| {
let domain1 = request.query().name().to_string().to_owned();
let domain2 = request.query().name().to_string().to_owned();
let query_type = request.query().query_type().to_owned();
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ where
}
}

// Wait for #47338 to be stable
trait Transpose {
type Output;
fn transpose(self) -> Self::Output;
Expand Down
46 changes: 14 additions & 32 deletions src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,52 +27,34 @@ impl RecursiveResolver {

pub fn udp_resolver(address: &SocketAddr) -> RecursiveResolver {
let mut resolver_config = ResolverConfig::new();
resolver_config.add_name_server(NameServerConfig {
socket_addr: *address,
protocol: Protocol::Udp,
tls_dns_name: None,
trust_negative_responses: true,
tls_config: None,
bind_addr: None,
});
resolver_config.add_name_server(NameServerConfig::new(*address, Protocol::Udp));
RecursiveResolver::new(resolver_config)
}

pub fn tcp_resolver(address: &SocketAddr) -> RecursiveResolver {
let mut resolver_config = ResolverConfig::new();
resolver_config.add_name_server(NameServerConfig {
socket_addr: *address,
protocol: Protocol::Tcp,
tls_dns_name: None,
trust_negative_responses: true,
tls_config: None,
bind_addr: None,
});
resolver_config.add_name_server(NameServerConfig::new(*address, Protocol::Tcp));
RecursiveResolver::new(resolver_config)
}

pub fn tls_resolver(address: &SocketAddr, tls_host: &String) -> RecursiveResolver {
let mut resolver_config = ResolverConfig::new();
resolver_config.add_name_server(NameServerConfig {
socket_addr: *address,
protocol: Protocol::Tls,
tls_dns_name: Some(tls_host.to_owned()),
trust_negative_responses: true,
tls_config: None,
bind_addr: None,
});
let mut name_server_config = NameServerConfig::new(*address, Protocol::Tls);
name_server_config.tls_dns_name = Some(tls_host.to_owned());
resolver_config.add_name_server(name_server_config);
RecursiveResolver::new(resolver_config)
}

#[cfg(not(any(target_arch = "mips", target_arch = "mips64")))]
pub fn https_resolver(address: &SocketAddr, tls_host: &String) -> RecursiveResolver {
let mut resolver_config = ResolverConfig::new();
resolver_config.add_name_server(NameServerConfig {
socket_addr: *address,
protocol: Protocol::Https,
tls_dns_name: Some(tls_host.to_owned()),
trust_negative_responses: true,
tls_config: None,
bind_addr: None,
});
let mut name_server_config = NameServerConfig::new(*address, Protocol::Https);
name_server_config.tls_dns_name = Some(tls_host.to_owned());
resolver_config.add_name_server(name_server_config);
RecursiveResolver::new(resolver_config)
}

#[cfg(any(target_arch = "mips", target_arch = "mips64"))]
pub fn https_resolver(address: &SocketAddr, tls_host: &String) -> RecursiveResolver {
tls_resolver(address, tls_host)
}

0 comments on commit d31bc7f

Please sign in to comment.