diff --git a/.gitignore b/.gitignore index c1d37946..35b46d70 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ Cargo.lock /*.json /restart.sh /udp_echo_server.py +/.idea diff --git a/Cargo.toml b/Cargo.toml index 528d48b6..052c02da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,6 @@ camellia-cfb = ["openssl"] single-threaded = [] trust-dns = ["trust-dns-resolver"] openssl-vendored = ["openssl/vendored"] -dns-relay = ["trust-dns-proto"] [dependencies] log = "0.4" @@ -79,7 +78,6 @@ url = "2.1" byte_string = "1.0" libsodium-sys = { version = "0.2", optional = true } miscreant = { version = "0.5", optional = true } -trust-dns-proto = { version = "0.19", optional = true} trust-dns-resolver = { version = "0.19", features = ["dns-over-rustls", "dns-over-https-rustls"], optional = true } hkdf = "0.8" hmac = "0.7" @@ -109,6 +107,7 @@ winapi = { version = "0.3", features = ["mswsock", "winsock2"] } [target.'cfg(target_os = "android")'.dependencies] sendfd = "0.3" +trust-dns-proto = "0.19" # Just for the ioctl call macro [target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies] diff --git a/src/bin/local.rs b/src/bin/local.rs index d7188349..9a1c59ca 100644 --- a/src/bin/local.rs +++ b/src/bin/local.rs @@ -149,7 +149,7 @@ fn main() { ); } - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] { app = app .arg( @@ -168,7 +168,7 @@ fn main() { ) .arg( Arg::with_name("DNS_RELAY_ADDR") - .long("dns-realy") + .long("dns-relay") .takes_value(true) .default_value("127.0.0.1:5450") .help("Specify the address of DNS relay (only for Android)"), @@ -235,7 +235,7 @@ fn main() { } } - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] { use std::net::SocketAddr; diff --git a/src/config.rs b/src/config.rs index c2d1b24c..a698736c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -881,13 +881,13 @@ pub struct Config { /// Path for local DNS resolver, only for Android pub local_dns_path: Option, /// Interanl DNS's bind address - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] pub dns_relay_addr: Option, /// Local DNS's address - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] pub local_dns_addr: Option, /// Remote DNS's address - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] pub remote_dns_addr: Option, } @@ -972,11 +972,11 @@ impl Config { stat_path: None, protect_path: None, local_dns_path: None, - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] dns_relay_addr: None, - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] local_dns_addr: None, - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] remote_dns_addr: None, } } diff --git a/src/context.rs b/src/context.rs index 36688bdb..9f9a3f8b 100644 --- a/src/context.rs +++ b/src/context.rs @@ -9,10 +9,10 @@ use std::{ }, }; -#[cfg(feature = "dns-relay")] +#[cfg(target_os = "android")] use std::net::IpAddr; -#[cfg(feature = "dns-relay")] +#[cfg(target_os = "android")] use lru_time_cache::LruCache; use bloomfilter::Bloom; @@ -166,7 +166,7 @@ pub struct Context { local_flow_statistic: ServerFlowStatistic, // For DNS relay's ACL domain name reverse lookup - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] reverse_lookup_cache: Mutex>, } @@ -177,7 +177,7 @@ impl Context { /// Create a non-shared Context fn new(config: Config, server_state: SharedServerState) -> Context { let nonce_ppbloom = Mutex::new(PingPongBloom::new(config.config_type)); - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] let reverse_lookup_cache = Mutex::new(LruCache::::with_capacity(8192)); Context { @@ -186,7 +186,7 @@ impl Context { server_running: AtomicBool::new(true), nonce_ppbloom, local_flow_statistic: ServerFlowStatistic::new(), - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] reverse_lookup_cache, } } @@ -283,7 +283,7 @@ impl Context { } /// Add a record to the reverse lookup cache - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] pub fn add_to_reverse_lookup_cache(&self, addr: IpAddr, qname: String) { let mut reverse_lookup_cache = self.reverse_lookup_cache.lock(); reverse_lookup_cache.insert(addr, qname); @@ -295,7 +295,7 @@ impl Context { // Proxy everything by default None => false, Some(ref a) => { - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] { match *target { Address::SocketAddress(ref saddr) => { diff --git a/src/relay/local.rs b/src/relay/local.rs index ef0a0fea..799ca9bb 100644 --- a/src/relay/local.rs +++ b/src/relay/local.rs @@ -13,7 +13,7 @@ use crate::{ relay::{tcprelay::local::run as run_tcp, udprelay::local::run as run_udp, utils::set_nofile}, }; -#[cfg(feature = "dns-relay")] +#[cfg(target_os = "android")] use crate::relay::dnsrelay::run as run_dns_relay; /// Relay server running under local environment. @@ -99,7 +99,7 @@ pub async fn run(mut config: Config, rt: Handle) -> io::Result<()> { vf.push(udp_fut.boxed()); } - #[cfg(feature = "dns-relay")] + #[cfg(target_os = "android")] { // For Android's local resolver let dns_relay = run_dns_relay(context.clone()); diff --git a/src/relay/mod.rs b/src/relay/mod.rs index f5f9fce5..5825d7a8 100644 --- a/src/relay/mod.rs +++ b/src/relay/mod.rs @@ -1,6 +1,6 @@ //! Relay server in local and server side implementations. -#[cfg(feature = "dns-relay")] +#[cfg(target_os = "android")] pub mod dnsrelay; pub(crate) mod dns_resolver; pub(crate) mod flow; diff --git a/src/relay/tcprelay/sys/unix/linux.rs b/src/relay/tcprelay/sys/unix/linux.rs index e659d9fb..bb0d592e 100644 --- a/src/relay/tcprelay/sys/unix/linux.rs +++ b/src/relay/tcprelay/sys/unix/linux.rs @@ -43,7 +43,7 @@ impl TcpStreamRedirExt for TcpStream { RedirType::Netfilter => get_original_destination_addr(self), RedirType::TProxy => { // For TPROXY, uses getsockname() to retrieve original destination address - self.local_addr()? + self.local_addr() } _ => unreachable!("not supported tcp transparent proxy type"), }