mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-02-09 01:59:16 +08:00
Enable dns-relay only for Android
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,3 +11,4 @@ Cargo.lock
|
||||
/*.json
|
||||
/restart.sh
|
||||
/udp_echo_server.py
|
||||
/.idea
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -881,13 +881,13 @@ pub struct Config {
|
||||
/// Path for local DNS resolver, only for Android
|
||||
pub local_dns_path: Option<String>,
|
||||
/// Interanl DNS's bind address
|
||||
#[cfg(feature = "dns-relay")]
|
||||
#[cfg(target_os = "android")]
|
||||
pub dns_relay_addr: Option<SocketAddr>,
|
||||
/// Local DNS's address
|
||||
#[cfg(feature = "dns-relay")]
|
||||
#[cfg(target_os = "android")]
|
||||
pub local_dns_addr: Option<SocketAddr>,
|
||||
/// Remote DNS's address
|
||||
#[cfg(feature = "dns-relay")]
|
||||
#[cfg(target_os = "android")]
|
||||
pub remote_dns_addr: Option<SocketAddr>,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<LruCache<IpAddr, String>>,
|
||||
}
|
||||
|
||||
@@ -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::<IpAddr, String>::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) => {
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user