mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-02-09 01:59:16 +08:00
Refine local DNS relay configurations
- Renamed local-dns-relay feature to local-dns - sslocal DNS relay cmd options become --dns-addr --local-dns-addr --remote-dns-addr - sslocal accepts --protocol dns to start standalone DNS resolver - Hide local-tunnel specific configuration fields if feature disabled
This commit is contained in:
@@ -64,8 +64,7 @@ dns-over-https = ["trust-dns", "trust-dns-resolver/dns-over-https-rustls"]
|
||||
# by enabling this feature will try to build or use prebuilt OpenSSL libraries
|
||||
openssl-vendored = ["native-tls/vendored", "openssl/vendored"]
|
||||
# Enable DNS-relay
|
||||
# Currently is only used in Android
|
||||
local-dns-relay = ["trust-dns-proto"]
|
||||
local-dns = ["trust-dns-proto"]
|
||||
# Enable client flow statistic report
|
||||
# Currently is only used in Android
|
||||
local-flow-stat = []
|
||||
|
||||
@@ -50,9 +50,9 @@ function build() {
|
||||
|
||||
RELEASE_DIR="target/${TARGET}/release"
|
||||
|
||||
EXTRA_FEATURES=""
|
||||
EXTRA_FEATURES="local-dns"
|
||||
if [[ "$TARGET" == *"-linux-"* || "$TARGET" == *"-darwin" ]]; then
|
||||
EXTRA_FEATURES="local-redir"
|
||||
EXTRA_FEATURES+=" local-redir"
|
||||
fi
|
||||
|
||||
EXTRA_FLAG=""
|
||||
@@ -60,7 +60,7 @@ function build() {
|
||||
# This is because `ring` doesn't support MIPS
|
||||
# https://github.com/shadowsocks/shadowsocks-rust/issues/273
|
||||
# https://github.com/briansmith/ring/issues/562
|
||||
EXTRA_FEATURES="sodium rc4 aes-cfb aes-ctr local-http local-http-native-tls local-tunnel local-socks4 local-redir"
|
||||
EXTRA_FEATURES="sodium rc4 aes-cfb aes-ctr local-http local-http-native-tls local-tunnel local-socks4 local-redir local-dns"
|
||||
EXTRA_FLAG="--no-default-features"
|
||||
fi
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ const AVAILABLE_PROTOCOLS: &[&str] = &[
|
||||
"tunnel",
|
||||
#[cfg(feature = "local-redir")]
|
||||
"redir",
|
||||
#[cfg(feature = "local-dns")]
|
||||
"dns",
|
||||
];
|
||||
|
||||
fn main() {
|
||||
@@ -77,8 +79,6 @@ fn main() {
|
||||
(@group SERVER_CONFIG =>
|
||||
(@attributes +multiple arg[SERVER_ADDR URL]))
|
||||
|
||||
(@arg FORWARD_ADDR: -f --("forward-addr") +takes_value {validator::validate_address} required_if("PROTOCOL", "tunnel") "Forwarding data directly to this address (for tunnel)")
|
||||
|
||||
(@arg PROTOCOL: --protocol +takes_value default_value("socks5") possible_values(AVAILABLE_PROTOCOLS) +next_line_help "Protocol that for communicating with clients")
|
||||
|
||||
(@arg NO_DELAY: --("no-delay") !takes_value "Set TCP_NODELAY option for socket")
|
||||
@@ -101,6 +101,13 @@ fn main() {
|
||||
.help("Resolve hostname to IPv6 address first"),
|
||||
);
|
||||
|
||||
#[cfg(feature = "local-tunnel")]
|
||||
{
|
||||
app = clap_app!(@app (app)
|
||||
(@arg FORWARD_ADDR: -f --("forward-addr") +takes_value {validator::validate_address} required_if("PROTOCOL", "tunnel") "Forwarding data directly to this address (for tunnel)")
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
app = clap_app!(@app (app)
|
||||
@@ -135,16 +142,16 @@ fn main() {
|
||||
#[cfg(feature = "local-flow-stat")]
|
||||
{
|
||||
app = clap_app!(@app (app)
|
||||
(@arg STAT_PATH: --("stat-path") +takes_value "Specify stat_path for traffic stat (only for Android)")
|
||||
(@arg STAT_PATH: --("stat-path") +takes_value "Specify socket path (unix domain socket) for sending traffic statistic")
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
{
|
||||
app = clap_app!(@app (app)
|
||||
(@arg LOCAL_DNS_ADDR: --("local-dns") +takes_value {validator::validate_socket_addr} "Specify the address of local DNS server (only for Android)")
|
||||
(@arg REMOTE_DNS_ADDR: --("remote-dns") +takes_value {validator::validate_address} "Specify the address of remote DNS server (only for Android)")
|
||||
(@arg DNS_LOCAL_ADDR: --("dns-relay") +takes_value {validator::validate_server_addr} "Specify the address of DNS relay (only for Android)")
|
||||
(@arg LOCAL_DNS_ADDR: --("local-dns-addr") +takes_value {validator::validate_socket_addr} "Specify the address of local DNS server, send queries directly")
|
||||
(@arg REMOTE_DNS_ADDR: --("remote-dns-addr") +takes_value {validator::validate_address} "Specify the address of remote DNS server, send queries through shadowsocks' tunnel")
|
||||
(@arg DNS_LOCAL_ADDR: --("dns-addr") +takes_value required_if("PROTOCOL", "dns") {validator::validate_server_addr} "DNS address, listen to this address if specified")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -199,6 +206,8 @@ fn main() {
|
||||
Some("tunnel") => ConfigType::TunnelLocal,
|
||||
#[cfg(feature = "local-redir")]
|
||||
Some("redir") => ConfigType::RedirLocal,
|
||||
#[cfg(feature = "local-dns")]
|
||||
Some("dns") => ConfigType::DnsLocal,
|
||||
Some(p) => panic!("not supported `protocol` \"{}\"", p),
|
||||
None => ConfigType::Socks5Local,
|
||||
};
|
||||
@@ -247,15 +256,16 @@ fn main() {
|
||||
config.server.push(svr_addr);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
#[cfg(all(feature = "local-dns", target_os = "android"))]
|
||||
{
|
||||
config.local_dns_path = Some(From::from("local_dns_path"));
|
||||
}
|
||||
|
||||
if matches.is_present("VPN_MODE") {
|
||||
// A socket `protect_path` in CWD
|
||||
// Same as shadowsocks-libev's android.c
|
||||
config.protect_path = Some(From::from("protect_path"));
|
||||
}
|
||||
#[cfg(target_os = "android")]
|
||||
if matches.is_present("VPN_MODE") {
|
||||
// A socket `protect_path` in CWD
|
||||
// Same as shadowsocks-libev's android.c
|
||||
config.protect_path = Some(From::from("protect_path"));
|
||||
}
|
||||
|
||||
#[cfg(feature = "local-flow-stat")]
|
||||
@@ -265,7 +275,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
{
|
||||
use std::net::SocketAddr;
|
||||
|
||||
@@ -326,6 +336,7 @@ fn main() {
|
||||
config.ipv6_first = true;
|
||||
}
|
||||
|
||||
#[cfg(feature = "local-tunnel")]
|
||||
if let Some(faddr) = matches.value_of("FORWARD_ADDR") {
|
||||
let addr = faddr.parse::<Address>().expect("forward-addr");
|
||||
config.forward = Some(addr);
|
||||
|
||||
341
src/config.rs
341
src/config.rs
@@ -679,7 +679,7 @@ pub enum ConfigType {
|
||||
/// Config for dns relay local
|
||||
///
|
||||
/// Requires `local` configuration
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
DnsLocal,
|
||||
|
||||
/// Config for server
|
||||
@@ -696,7 +696,7 @@ impl ConfigType {
|
||||
ConfigType::Socks5Local => true,
|
||||
#[cfg(feature = "local-socks4")]
|
||||
ConfigType::Socks4Local => true,
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
ConfigType::DnsLocal => true,
|
||||
#[cfg(feature = "local-tunnel")]
|
||||
ConfigType::TunnelLocal => true,
|
||||
@@ -719,7 +719,7 @@ impl ConfigType {
|
||||
ConfigType::Socks5Local => false,
|
||||
#[cfg(feature = "local-socks4")]
|
||||
ConfigType::Socks4Local => false,
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
ConfigType::DnsLocal => false,
|
||||
#[cfg(feature = "local-tunnel")]
|
||||
ConfigType::TunnelLocal => false,
|
||||
@@ -784,112 +784,33 @@ impl FromStr for Mode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Transparent Proxy type
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, EnumIter)]
|
||||
pub enum RedirType {
|
||||
/// For not supported platforms
|
||||
NotSupported,
|
||||
|
||||
/// For Linux-like systems' Netfilter `REDIRECT`. Only for TCP connections.
|
||||
///
|
||||
/// This is supported from Linux 2.4 Kernel. Document: https://www.netfilter.org/documentation/index.html#documentation-howto
|
||||
///
|
||||
/// NOTE: Filter rule `REDIRECT` can only be applied to TCP connections.
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
Redirect,
|
||||
|
||||
/// For Linux-like systems' Netfilter TPROXY rule.
|
||||
///
|
||||
/// NOTE: Filter rule `TPROXY` can be applied to TCP and UDP connections.
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
TProxy,
|
||||
|
||||
/// Packet Filter (pf)
|
||||
///
|
||||
/// Supported by OpenBSD 3.0+, FreeBSD 5.3+, NetBSD 3.0+, Solaris 11.3+, macOS 10.7+, iOS, QNX
|
||||
///
|
||||
/// Document: https://www.freebsd.org/doc/handbook/firewalls-pf.html
|
||||
#[cfg(any(
|
||||
target_os = "openbsd",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "solaris",
|
||||
target_os = "macos",
|
||||
target_os = "ios"
|
||||
))]
|
||||
PacketFilter,
|
||||
|
||||
/// IPFW
|
||||
///
|
||||
/// Supported by FreeBSD, macOS 10.6- (Have been removed completely on macOS 10.10)
|
||||
///
|
||||
/// Document: https://www.freebsd.org/doc/handbook/firewalls-ipfw.html
|
||||
#[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "ios"))]
|
||||
IpFirewall,
|
||||
}
|
||||
|
||||
impl RedirType {
|
||||
cfg_if! {
|
||||
if #[cfg(any(target_os = "linux", target_os = "android"))] {
|
||||
/// Default TCP transparent proxy solution on this platform
|
||||
pub fn tcp_default() -> RedirType {
|
||||
RedirType::Redirect
|
||||
}
|
||||
|
||||
/// Default UDP transparent proxy solution on this platform
|
||||
pub fn udp_default() -> RedirType {
|
||||
RedirType::TProxy
|
||||
}
|
||||
} else if #[cfg(any(target_os = "openbsd", target_os = "freebsd"))] {
|
||||
/// Default TCP transparent proxy solution on this platform
|
||||
pub fn tcp_default() -> RedirType {
|
||||
RedirType::PacketFilter
|
||||
}
|
||||
|
||||
/// Default UDP transparent proxy solution on this platform
|
||||
pub fn udp_default() -> RedirType {
|
||||
RedirType::PacketFilter
|
||||
}
|
||||
} else if #[cfg(any(target_os = "netbsd", target_os = "solaris", target_os = "macos", target_os = "ios"))] {
|
||||
/// Default TCP transparent proxy solution on this platform
|
||||
pub fn tcp_default() -> RedirType {
|
||||
RedirType::PacketFilter
|
||||
}
|
||||
|
||||
/// Default UDP transparent proxy solution on this platform
|
||||
pub fn udp_default() -> RedirType {
|
||||
RedirType::NotSupported
|
||||
}
|
||||
} else {
|
||||
/// Default TCP transparent proxy solution on this platform
|
||||
pub fn tcp_default() -> RedirType {
|
||||
RedirType::NotSupported
|
||||
}
|
||||
|
||||
/// Default UDP transparent proxy solution on this platform
|
||||
pub fn udp_default() -> RedirType {
|
||||
RedirType::NotSupported
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if transparent proxy is supported on this platform
|
||||
pub fn is_supported(self) -> bool {
|
||||
self != RedirType::NotSupported
|
||||
}
|
||||
|
||||
/// Name of redirect type (transparent proxy type)
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
// Dummy, shouldn't be used in any useful situations
|
||||
RedirType::NotSupported => "not_supported",
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "local-redir")] {
|
||||
/// Transparent Proxy type
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, EnumIter)]
|
||||
pub enum RedirType {
|
||||
/// For not supported platforms
|
||||
NotSupported,
|
||||
|
||||
/// For Linux-like systems' Netfilter `REDIRECT`. Only for TCP connections.
|
||||
///
|
||||
/// This is supported from Linux 2.4 Kernel. Document: https://www.netfilter.org/documentation/index.html#documentation-howto
|
||||
///
|
||||
/// NOTE: Filter rule `REDIRECT` can only be applied to TCP connections.
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
RedirType::Redirect => "redirect",
|
||||
Redirect,
|
||||
|
||||
/// For Linux-like systems' Netfilter TPROXY rule.
|
||||
///
|
||||
/// NOTE: Filter rule `TPROXY` can be applied to TCP and UDP connections.
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
RedirType::TProxy => "tproxy",
|
||||
TProxy,
|
||||
|
||||
/// Packet Filter (pf)
|
||||
///
|
||||
/// Supported by OpenBSD 3.0+, FreeBSD 5.3+, NetBSD 3.0+, Solaris 11.3+, macOS 10.7+, iOS, QNX
|
||||
///
|
||||
/// Document: https://www.freebsd.org/doc/handbook/firewalls-pf.html
|
||||
#[cfg(any(
|
||||
target_os = "openbsd",
|
||||
target_os = "freebsd",
|
||||
@@ -898,67 +819,150 @@ impl RedirType {
|
||||
target_os = "macos",
|
||||
target_os = "ios"
|
||||
))]
|
||||
RedirType::PacketFilter => "pf",
|
||||
PacketFilter,
|
||||
|
||||
/// IPFW
|
||||
///
|
||||
/// Supported by FreeBSD, macOS 10.6- (Have been removed completely on macOS 10.10)
|
||||
///
|
||||
/// Document: https://www.freebsd.org/doc/handbook/firewalls-ipfw.html
|
||||
#[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "ios"))]
|
||||
RedirType::IpFirewall => "ipfw",
|
||||
IpFirewall,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all available types
|
||||
pub fn available_types() -> Vec<&'static str> {
|
||||
let mut v = Vec::new();
|
||||
for e in Self::iter() {
|
||||
match e {
|
||||
RedirType::NotSupported => continue,
|
||||
#[allow(unreachable_patterns)]
|
||||
_ => v.push(e.name()),
|
||||
impl RedirType {
|
||||
cfg_if! {
|
||||
if #[cfg(any(target_os = "linux", target_os = "android"))] {
|
||||
/// Default TCP transparent proxy solution on this platform
|
||||
pub fn tcp_default() -> RedirType {
|
||||
RedirType::Redirect
|
||||
}
|
||||
|
||||
/// Default UDP transparent proxy solution on this platform
|
||||
pub fn udp_default() -> RedirType {
|
||||
RedirType::TProxy
|
||||
}
|
||||
} else if #[cfg(any(target_os = "openbsd", target_os = "freebsd"))] {
|
||||
/// Default TCP transparent proxy solution on this platform
|
||||
pub fn tcp_default() -> RedirType {
|
||||
RedirType::PacketFilter
|
||||
}
|
||||
|
||||
/// Default UDP transparent proxy solution on this platform
|
||||
pub fn udp_default() -> RedirType {
|
||||
RedirType::PacketFilter
|
||||
}
|
||||
} else if #[cfg(any(target_os = "netbsd", target_os = "solaris", target_os = "macos", target_os = "ios"))] {
|
||||
/// Default TCP transparent proxy solution on this platform
|
||||
pub fn tcp_default() -> RedirType {
|
||||
RedirType::PacketFilter
|
||||
}
|
||||
|
||||
/// Default UDP transparent proxy solution on this platform
|
||||
pub fn udp_default() -> RedirType {
|
||||
RedirType::NotSupported
|
||||
}
|
||||
} else {
|
||||
/// Default TCP transparent proxy solution on this platform
|
||||
pub fn tcp_default() -> RedirType {
|
||||
RedirType::NotSupported
|
||||
}
|
||||
|
||||
/// Default UDP transparent proxy solution on this platform
|
||||
pub fn udp_default() -> RedirType {
|
||||
RedirType::NotSupported
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if transparent proxy is supported on this platform
|
||||
pub fn is_supported(self) -> bool {
|
||||
self != RedirType::NotSupported
|
||||
}
|
||||
|
||||
/// Name of redirect type (transparent proxy type)
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
// Dummy, shouldn't be used in any useful situations
|
||||
RedirType::NotSupported => "not_supported",
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
RedirType::Redirect => "redirect",
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
RedirType::TProxy => "tproxy",
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "openbsd",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "solaris",
|
||||
target_os = "macos",
|
||||
target_os = "ios"
|
||||
))]
|
||||
RedirType::PacketFilter => "pf",
|
||||
|
||||
#[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "ios"))]
|
||||
RedirType::IpFirewall => "ipfw",
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all available types
|
||||
pub fn available_types() -> Vec<&'static str> {
|
||||
let mut v = Vec::new();
|
||||
for e in Self::iter() {
|
||||
match e {
|
||||
RedirType::NotSupported => continue,
|
||||
#[allow(unreachable_patterns)]
|
||||
_ => v.push(e.name()),
|
||||
}
|
||||
}
|
||||
v
|
||||
}
|
||||
}
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for RedirType {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
f.write_str(self.name())
|
||||
}
|
||||
}
|
||||
impl Display for RedirType {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
f.write_str(self.name())
|
||||
}
|
||||
}
|
||||
|
||||
/// Error type for `RedirType`'s `FromStr::Err`
|
||||
#[derive(Debug)]
|
||||
pub struct InvalidRedirType;
|
||||
/// Error type for `RedirType`'s `FromStr::Err`
|
||||
#[derive(Debug)]
|
||||
pub struct InvalidRedirType;
|
||||
|
||||
impl FromStr for RedirType {
|
||||
type Err = InvalidRedirType;
|
||||
impl FromStr for RedirType {
|
||||
type Err = InvalidRedirType;
|
||||
|
||||
fn from_str(s: &str) -> Result<RedirType, InvalidRedirType> {
|
||||
match s {
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
"redirect" => Ok(RedirType::Redirect),
|
||||
fn from_str(s: &str) -> Result<RedirType, InvalidRedirType> {
|
||||
match s {
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
"redirect" => Ok(RedirType::Redirect),
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
"tproxy" => Ok(RedirType::TProxy),
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
"tproxy" => Ok(RedirType::TProxy),
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "openbsd",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "solaris",
|
||||
target_os = "macos",
|
||||
target_os = "ios",
|
||||
))]
|
||||
"pf" => Ok(RedirType::PacketFilter),
|
||||
#[cfg(any(
|
||||
target_os = "openbsd",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "solaris",
|
||||
target_os = "macos",
|
||||
target_os = "ios",
|
||||
))]
|
||||
"pf" => Ok(RedirType::PacketFilter),
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "freebsd",
|
||||
target_os = "macos",
|
||||
target_os = "ios",
|
||||
target_os = "dragonfly"
|
||||
))]
|
||||
"ipfw" => Ok(RedirType::IpFirewall),
|
||||
#[cfg(any(
|
||||
target_os = "freebsd",
|
||||
target_os = "macos",
|
||||
target_os = "ios",
|
||||
target_os = "dragonfly"
|
||||
))]
|
||||
"ipfw" => Ok(RedirType::IpFirewall),
|
||||
|
||||
_ => Err(InvalidRedirType),
|
||||
_ => Err(InvalidRedirType),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1044,6 +1048,7 @@ pub struct Config {
|
||||
/// Local server's bind address, or ShadowSocks server's outbound address
|
||||
pub local_addr: Option<ClientConfig>,
|
||||
/// Destination address for tunnel
|
||||
#[cfg(feature = "local-tunnel")]
|
||||
pub forward: Option<Address>,
|
||||
/// DNS configuration, uses system-wide DNS configuration by default
|
||||
///
|
||||
@@ -1079,28 +1084,32 @@ pub struct Config {
|
||||
pub nofile: Option<u64>,
|
||||
/// ACL configuration
|
||||
pub acl: Option<AccessControl>,
|
||||
/// Path to stat callback unix address, only for Android
|
||||
/// TCP Transparent Proxy type
|
||||
#[cfg(feature = "local-redir")]
|
||||
pub tcp_redir: RedirType,
|
||||
/// UDP Transparent Proxy type
|
||||
#[cfg(feature = "local-redir")]
|
||||
pub udp_redir: RedirType,
|
||||
/// Android flow statistic report Unix socket path
|
||||
/// Flow statistic report Unix socket path (only for Android)
|
||||
#[cfg(feature = "local-flow-stat")]
|
||||
pub stat_path: Option<PathBuf>,
|
||||
/// Path to protect callback unix address, only for Android
|
||||
pub protect_path: Option<PathBuf>,
|
||||
/// Path for local DNS resolver, only for Android
|
||||
/// Path for local DNS resolver
|
||||
#[cfg(all(feature = "local-dns", target_os = "android"))]
|
||||
pub local_dns_path: Option<PathBuf>,
|
||||
/// Internal DNS's bind address
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
pub dns_local_addr: Option<ClientConfig>,
|
||||
/// Local DNS's address
|
||||
///
|
||||
/// Sending DNS query directly to this address
|
||||
#[cfg(feature = "local-dns")]
|
||||
pub local_dns_addr: Option<SocketAddr>,
|
||||
/// Remote DNS's address
|
||||
///
|
||||
/// Sending DNS query through proxy to this address
|
||||
#[cfg(feature = "local-dns")]
|
||||
pub remote_dns_addr: Option<Address>,
|
||||
/// Uses IPv6 addresses first
|
||||
///
|
||||
@@ -1185,6 +1194,7 @@ impl Config {
|
||||
Config {
|
||||
server: Vec::new(),
|
||||
local_addr: None,
|
||||
#[cfg(feature = "local-tunnel")]
|
||||
forward: None,
|
||||
#[cfg(feature = "trust-dns")]
|
||||
dns: None,
|
||||
@@ -1199,15 +1209,20 @@ impl Config {
|
||||
udp_bind_addr: None,
|
||||
nofile: None,
|
||||
acl: None,
|
||||
#[cfg(feature = "local-redir")]
|
||||
tcp_redir: RedirType::tcp_default(),
|
||||
#[cfg(feature = "local-redir")]
|
||||
udp_redir: RedirType::udp_default(),
|
||||
#[cfg(feature = "local-flow-stat")]
|
||||
stat_path: None,
|
||||
protect_path: None,
|
||||
#[cfg(all(feature = "local-dns", target_os = "android"))]
|
||||
local_dns_path: None,
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
dns_local_addr: None,
|
||||
#[cfg(feature = "local-dns")]
|
||||
local_dns_addr: None,
|
||||
#[cfg(feature = "local-dns")]
|
||||
remote_dns_addr: None,
|
||||
ipv6_first: false,
|
||||
#[cfg(feature = "local-http-native-tls")]
|
||||
@@ -1568,9 +1583,19 @@ impl Config {
|
||||
}
|
||||
|
||||
/// Check if DNS Relay is enabled
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
pub(crate) fn is_local_dns_relay(&self) -> bool {
|
||||
self.config_type == ConfigType::DnsLocal || self.local_dns_addr.is_some() || self.local_dns_path.is_some()
|
||||
if self.config_type == ConfigType::DnsLocal || self.local_dns_addr.is_some() {
|
||||
return true;
|
||||
}
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(target_os = "android")] {
|
||||
self.local_dns_path.is_some()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! Shadowsocks Server Context
|
||||
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
use std::net::IpAddr;
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
use std::time::Duration;
|
||||
use std::{
|
||||
io,
|
||||
@@ -15,10 +15,10 @@ use std::{
|
||||
|
||||
use bloomfilter::Bloom;
|
||||
use log::{log_enabled, warn};
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
use lru_time_cache::LruCache;
|
||||
use spin::Mutex as SpinMutex;
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
use tokio::sync::Mutex as AsyncMutex;
|
||||
#[cfg(feature = "trust-dns")]
|
||||
use trust_dns_resolver::TokioAsyncResolver;
|
||||
@@ -27,7 +27,7 @@ use trust_dns_resolver::TokioAsyncResolver;
|
||||
use crate::crypto::CipherType;
|
||||
#[cfg(feature = "trust-dns")]
|
||||
use crate::relay::dns_resolver::create_resolver;
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
use crate::relay::dnsrelay::upstream::LocalUpstream;
|
||||
#[cfg(feature = "local-flow-stat")]
|
||||
use crate::relay::flow::ServerFlowStatistic;
|
||||
@@ -179,11 +179,11 @@ pub struct Context {
|
||||
local_flow_statistic: ServerFlowStatistic,
|
||||
|
||||
// For DNS relay's ACL domain name reverse lookup -- whether the IP shall be forwarded
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
reverse_lookup_cache: AsyncMutex<LruCache<IpAddr, bool>>,
|
||||
|
||||
// For local DNS upstream
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
local_dns: Option<LocalUpstream>,
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ impl Context {
|
||||
}
|
||||
|
||||
let nonce_ppbloom = SpinMutex::new(PingPongBloom::new(config.config_type));
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
let local_dns = if config.is_local_dns_relay() {
|
||||
Some(LocalUpstream::new(&config))
|
||||
} else {
|
||||
@@ -240,11 +240,11 @@ impl Context {
|
||||
nonce_ppbloom,
|
||||
#[cfg(feature = "local-flow-stat")]
|
||||
local_flow_statistic: ServerFlowStatistic::new(),
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
reverse_lookup_cache: AsyncMutex::new(LruCache::with_expiry_duration(Duration::from_secs(
|
||||
3 * 24 * 60 * 60,
|
||||
))),
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
local_dns,
|
||||
}
|
||||
}
|
||||
@@ -317,7 +317,7 @@ impl Context {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
#[inline(always)]
|
||||
async fn dns_resolve_impl(&self, host: &str, port: u16) -> io::Result<Vec<SocketAddr>> {
|
||||
match self.local_dns {
|
||||
@@ -326,7 +326,7 @@ impl Context {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "local-dns-relay"))]
|
||||
#[cfg(not(feature = "local-dns"))]
|
||||
#[inline(always)]
|
||||
async fn dns_resolve_impl(&self, host: &str, port: u16) -> io::Result<Vec<SocketAddr>> {
|
||||
resolve(self, host, port).await
|
||||
@@ -373,7 +373,7 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Add a record to the reverse lookup cache
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
pub async fn add_to_reverse_lookup_cache(&self, addr: &IpAddr, forward: bool) {
|
||||
let is_exception = forward
|
||||
!= match self.acl() {
|
||||
@@ -405,7 +405,7 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Get local DNS connector
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
pub fn local_dns(&self) -> &LocalUpstream {
|
||||
&self.local_dns.as_ref().expect("local DNS uninitialized")
|
||||
}
|
||||
@@ -416,7 +416,7 @@ impl Context {
|
||||
// Proxy everything by default
|
||||
None => false,
|
||||
Some(a) => {
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
{
|
||||
if let Address::SocketAddress(ref saddr) = target {
|
||||
// do the reverse lookup in our local cache
|
||||
|
||||
@@ -117,7 +117,7 @@ pub async fn run(mut config: Config) -> io::Result<()> {
|
||||
vf.push(udp_fut.boxed());
|
||||
}
|
||||
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
if context.config().is_local_dns_relay() {
|
||||
use crate::relay::dnsrelay::run as run_dns;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Relay server in local and server side implementations.
|
||||
|
||||
pub(crate) mod dns_resolver;
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
pub mod dnsrelay;
|
||||
pub(crate) mod flow;
|
||||
pub(crate) mod loadbalancing;
|
||||
|
||||
@@ -21,7 +21,7 @@ pub async fn run(context: SharedContext) -> io::Result<()> {
|
||||
ConfigType::HttpsLocal => super::http_local::run(context).await,
|
||||
#[cfg(feature = "local-redir")]
|
||||
ConfigType::RedirLocal => super::redir_local::run(context).await,
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
ConfigType::DnsLocal => unreachable!(),
|
||||
ConfigType::Server => unreachable!(),
|
||||
ConfigType::Manager => unreachable!(),
|
||||
|
||||
@@ -476,7 +476,7 @@ async fn connect_proxy_server(context: &Context, svr_cfg: &ServerConfig) -> io::
|
||||
ConfigType::Socks4Local => svr_cfg.external_addr(),
|
||||
#[cfg(feature = "local-tunnel")]
|
||||
ConfigType::TunnelLocal => svr_cfg.external_addr(),
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
ConfigType::DnsLocal => svr_cfg.external_addr(),
|
||||
#[cfg(feature = "local-http")]
|
||||
ConfigType::HttpLocal => svr_cfg.external_addr(),
|
||||
|
||||
@@ -34,7 +34,7 @@ pub async fn run(context: SharedContext) -> io::Result<()> {
|
||||
any(feature = "local-http-native-tls", feature = "local-http-rustls")
|
||||
))]
|
||||
ConfigType::HttpsLocal => unreachable!(),
|
||||
#[cfg(feature = "local-dns-relay")]
|
||||
#[cfg(feature = "local-dns")]
|
||||
ConfigType::DnsLocal => unreachable!(),
|
||||
ConfigType::Server => unreachable!(),
|
||||
ConfigType::Manager => unreachable!(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![cfg(feature = "local-dns-relay")]
|
||||
#![cfg(feature = "local-dns")]
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user