mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-17 00:17:34 +00:00
@@ -144,6 +144,11 @@ fn main() {
|
||||
.long("acl")
|
||||
.takes_value(true)
|
||||
.help("Path to ACL (Access Control List)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("IPV6_FIRST")
|
||||
.short("6")
|
||||
.help("Resovle hostname to IPv6 address first"),
|
||||
);
|
||||
|
||||
if cfg!(target_os = "android") {
|
||||
@@ -319,6 +324,12 @@ fn main() {
|
||||
config.acl = Some(acl);
|
||||
}
|
||||
|
||||
if matches.is_present("IPV6_FIRST") {
|
||||
config.ipv6_first = true;
|
||||
}
|
||||
|
||||
// DONE READING options
|
||||
|
||||
if config.local.is_none() {
|
||||
eprintln!(
|
||||
"missing `local_address`, consider specifying it by --local-addr command line option, \
|
||||
|
||||
@@ -103,6 +103,11 @@ fn main() {
|
||||
.takes_value(true)
|
||||
.help("Path to ACL (Access Control List)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("IPV6_FIRST")
|
||||
.short("6")
|
||||
.help("Resovle hostname to IPv6 address first"),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let debug_level = matches.occurrences_of("VERBOSE");
|
||||
@@ -169,6 +174,12 @@ fn main() {
|
||||
config.acl = Some(acl);
|
||||
}
|
||||
|
||||
if matches.is_present("IPV6_FIRST") {
|
||||
config.ipv6_first = true;
|
||||
}
|
||||
|
||||
// DONE reading options
|
||||
|
||||
if config.manager_address.is_none() {
|
||||
eprintln!(
|
||||
"missing `manager_address`, consider specifying it by --manager-address command line option, \
|
||||
|
||||
@@ -138,6 +138,11 @@ fn main() {
|
||||
.long("acl")
|
||||
.takes_value(true)
|
||||
.help("Path to ACL (Access Control List)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("IPV6_FIRST")
|
||||
.short("6")
|
||||
.help("Resovle hostname to IPv6 address first"),
|
||||
);
|
||||
|
||||
let available_types = RedirType::available_types();
|
||||
@@ -270,6 +275,12 @@ fn main() {
|
||||
config.udp_redir = udp_redir.parse::<RedirType>().expect("UDP redir type");
|
||||
}
|
||||
|
||||
if matches.is_present("IPV6_FIRST") {
|
||||
config.ipv6_first = true;
|
||||
}
|
||||
|
||||
// DONE READING options
|
||||
|
||||
if config.local.is_none() {
|
||||
eprintln!(
|
||||
"missing `local_address`, consider specifying it by --local-addr command line option, \
|
||||
|
||||
@@ -137,6 +137,11 @@ fn main() {
|
||||
.takes_value(true)
|
||||
.help("Path to ACL (Access Control List)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("IPV6_FIRST")
|
||||
.short("6")
|
||||
.help("Resovle hostname to IPv6 address first"),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
drop(available_ciphers);
|
||||
@@ -232,6 +237,12 @@ fn main() {
|
||||
config.acl = Some(acl);
|
||||
}
|
||||
|
||||
if matches.is_present("IPV6_FIRST") {
|
||||
config.ipv6_first = true;
|
||||
}
|
||||
|
||||
// DONE READING options
|
||||
|
||||
if config.server.is_empty() {
|
||||
eprintln!(
|
||||
"missing proxy servers, consider specifying it by \
|
||||
|
||||
@@ -139,6 +139,11 @@ fn main() {
|
||||
.takes_value(true)
|
||||
.help("Set RLIMIT_NOFILE with both soft and hard limit (only for *nix systems)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("IPV6_FIRST")
|
||||
.short("6")
|
||||
.help("Resovle hostname to IPv6 address first"),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
drop(available_ciphers);
|
||||
@@ -232,6 +237,12 @@ fn main() {
|
||||
config.nofile = Some(nofile.parse::<u64>().expect("an unsigned integer for `nofile`"));
|
||||
}
|
||||
|
||||
if matches.is_present("IPV6_FIRST") {
|
||||
config.ipv6_first = true;
|
||||
}
|
||||
|
||||
// DONE READING options
|
||||
|
||||
if config.local.is_none() {
|
||||
eprintln!(
|
||||
"missing `local_address`, consider specifying it by --local-addr command line option, \
|
||||
|
||||
@@ -114,6 +114,8 @@ struct SSConfig {
|
||||
no_delay: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
nofile: Option<u64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
ipv6_first: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@@ -912,6 +914,9 @@ pub struct Config {
|
||||
/// Remote DNS's address
|
||||
#[cfg(target_os = "android")]
|
||||
pub remote_dns_addr: Option<Address>,
|
||||
/// Uses IPv6 addresses first
|
||||
/// This would affect DNS resolution logic
|
||||
pub ipv6_first: bool,
|
||||
}
|
||||
|
||||
/// Configuration parsing error kind
|
||||
@@ -1001,6 +1006,7 @@ impl Config {
|
||||
local_dns_addr: None,
|
||||
#[cfg(target_os = "android")]
|
||||
remote_dns_addr: None,
|
||||
ipv6_first: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1180,6 +1186,11 @@ impl Config {
|
||||
// This is mostly used for manager for creating new servers
|
||||
nconfig.timeout = config.timeout.map(Duration::from_secs);
|
||||
|
||||
// Uses IPv6 first
|
||||
if let Some(f) = config.ipv6_first {
|
||||
nconfig.ipv6_first = f;
|
||||
}
|
||||
|
||||
Ok(nconfig)
|
||||
}
|
||||
|
||||
@@ -1384,6 +1395,10 @@ impl fmt::Display for Config {
|
||||
|
||||
jconf.nofile = self.nofile;
|
||||
|
||||
if self.ipv6_first {
|
||||
jconf.ipv6_first = Some(self.ipv6_first);
|
||||
}
|
||||
|
||||
write!(f, "{}", json5::to_string(&jconf).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ impl ServerState {
|
||||
#[cfg(feature = "trust-dns")]
|
||||
pub async fn new_shared(config: &Config, rt: Handle) -> SharedServerState {
|
||||
let state = ServerState {
|
||||
dns_resolver: match create_resolver(config.get_dns_config(), config.timeout, rt).await {
|
||||
dns_resolver: match create_resolver(config.get_dns_config(), config.timeout, config.ipv6_first, rt).await {
|
||||
Ok(resolver) => Some(resolver),
|
||||
Err(..) => None,
|
||||
},
|
||||
|
||||
@@ -9,7 +9,7 @@ use std::{
|
||||
use log::{error, trace};
|
||||
use tokio::{self, runtime::Handle};
|
||||
use trust_dns_resolver::{
|
||||
config::{ResolverConfig, ResolverOpts},
|
||||
config::{LookupIpStrategy, ResolverConfig, ResolverOpts},
|
||||
TokioAsyncResolver,
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ use crate::context::Context;
|
||||
pub async fn create_resolver(
|
||||
dns: Option<ResolverConfig>,
|
||||
timeout: Option<Duration>,
|
||||
ipv6_first: bool,
|
||||
rt: Handle,
|
||||
) -> io::Result<TokioAsyncResolver> {
|
||||
let mut resolver_opts = ResolverOpts::default();
|
||||
@@ -27,6 +28,10 @@ pub async fn create_resolver(
|
||||
resolver_opts.timeout = d;
|
||||
}
|
||||
|
||||
if ipv6_first {
|
||||
resolver_opts.ip_strategy = LookupIpStrategy::Ipv6thenIpv4;
|
||||
}
|
||||
|
||||
{
|
||||
// To make this independent, if targeting macOS, BSD, Linux, or Windows, we can use the system's configuration:
|
||||
#[cfg(any(unix, windows))]
|
||||
|
||||
Reference in New Issue
Block a user