Skip to content

Commit 192ed54

Browse files
committed
trust-dns setsockopt with outbound socket configs
Outbound configurations, like outbound-fwmark, outbound-bind-interface, outbound-bind-addr, ... will also applies to the TCP/UDP sockets created by trust-dns DNS resolver. NOTE: On Android platform, DNS sockets will also be protected.
1 parent 7d7fb19 commit 192ed54

File tree

17 files changed

+253
-124
lines changed

17 files changed

+253
-124
lines changed

Cargo.lock

Lines changed: 14 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "shadowsocks-rust"
3-
version = "1.15.3"
3+
version = "1.16.0"
44
authors = ["Shadowsocks Contributors"]
55
description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls."
66
repository = "https://github.com/shadowsocks/shadowsocks-rust"
@@ -167,7 +167,7 @@ jemallocator = { version = "0.5", optional = true }
167167
snmalloc-rs = { version = "0.3", optional = true }
168168
rpmalloc = { version = "0.2", optional = true }
169169

170-
shadowsocks-service = { version = "1.15.0", path = "./crates/shadowsocks-service" }
170+
shadowsocks-service = { version = "1.16.0", path = "./crates/shadowsocks-service" }
171171

172172
[target.'cfg(unix)'.dependencies]
173173
daemonize = "0.5"

crates/shadowsocks-service/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "shadowsocks-service"
3-
version = "1.15.3"
3+
version = "1.16.0"
44
authors = ["Shadowsocks Contributors"]
55
description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls."
66
repository = "https://github.com/shadowsocks/shadowsocks-rust"
@@ -107,7 +107,8 @@ libc = "0.2.141"
107107
hyper = { version = "0.14.25", optional = true, features = ["full"] }
108108
tower = { version = "0.4", optional = true }
109109

110-
trust-dns-resolver = { version = "0.22", optional = true, features = ["serde-config"] }
110+
# trust-dns-resolver = { version = "0.22", optional = true, features = ["serde-config"] }
111+
trust-dns-resolver = { git = "https://github.com/bluejekyll/trust-dns.git", optional = true, features = ["serde-config"] }
111112

112113
idna = "0.3"
113114
ipnet = "2.7"
@@ -121,7 +122,7 @@ smoltcp = { version = "0.9", optional = true, default-features = false, features
121122
serde = { version = "1.0", features = ["derive"] }
122123
json5 = "0.4"
123124

124-
shadowsocks = { version = "1.15.3", path = "../shadowsocks", default-features = false }
125+
shadowsocks = { version = "1.16.0", path = "../shadowsocks", default-features = false }
125126

126127
# Just for the ioctl call macro
127128
[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies]

crates/shadowsocks-service/src/config.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,26 +2112,12 @@ impl Config {
21122112
};
21132113

21142114
if protocol.enable_udp() {
2115-
c.add_name_server(NameServerConfig {
2116-
socket_addr,
2117-
protocol: Protocol::Udp,
2118-
tls_dns_name: None,
2119-
trust_nx_responses: false,
2120-
#[cfg(any(feature = "dns-over-tls", feature = "dns-over-https"))]
2121-
tls_config: None,
2122-
bind_addr: None,
2123-
});
2115+
let ns_config = NameServerConfig::new(socket_addr, Protocol::Udp);
2116+
c.add_name_server(ns_config);
21242117
}
21252118
if protocol.enable_tcp() {
2126-
c.add_name_server(NameServerConfig {
2127-
socket_addr,
2128-
protocol: Protocol::Tcp,
2129-
tls_dns_name: None,
2130-
trust_nx_responses: false,
2131-
#[cfg(any(feature = "dns-over-tls", feature = "dns-over-https"))]
2132-
tls_config: None,
2133-
bind_addr: None,
2134-
});
2119+
let ns_config = NameServerConfig::new(socket_addr, Protocol::Tcp);
2120+
c.add_name_server(ns_config);
21352121
}
21362122
}
21372123

crates/shadowsocks-service/src/dns/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub async fn build_dns_resolver(dns: DnsConfig, ipv6_first: bool, connect_opts:
2323
};
2424

2525
if !force_system_builtin {
26-
return match DnsResolver::trust_dns_system_resolver(ipv6_first).await {
26+
return match DnsResolver::trust_dns_system_resolver(connect_opts.clone()).await {
2727
Ok(r) => Some(r),
2828
Err(err) => {
2929
warn!(
@@ -41,7 +41,7 @@ pub async fn build_dns_resolver(dns: DnsConfig, ipv6_first: bool, connect_opts:
4141
None
4242
}
4343
#[cfg(feature = "trust-dns")]
44-
DnsConfig::TrustDns(dns) => match DnsResolver::trust_dns_resolver(dns, ipv6_first).await {
44+
DnsConfig::TrustDns(dns) => match DnsResolver::trust_dns_resolver(dns, connect_opts.clone()).await {
4545
Ok(r) => Some(r),
4646
Err(err) => {
4747
use log::warn;

crates/shadowsocks-service/src/local/dns/dns_resolver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::{
44
io::{self, ErrorKind},
5-
net::SocketAddr,
5+
net::{Ipv4Addr, Ipv6Addr, SocketAddr},
66
};
77

88
use async_trait::async_trait;
@@ -175,8 +175,8 @@ fn store_dns(res: Message, port: u16) -> Vec<SocketAddr> {
175175
let mut vaddr = Vec::new();
176176
for record in res.answers() {
177177
match record.data() {
178-
Some(RData::A(addr)) => vaddr.push(SocketAddr::new((*addr).into(), port)),
179-
Some(RData::AAAA(addr)) => vaddr.push(SocketAddr::new((*addr).into(), port)),
178+
Some(RData::A(addr)) => vaddr.push(SocketAddr::new(Ipv4Addr::from(*addr).into(), port)),
179+
Some(RData::AAAA(addr)) => vaddr.push(SocketAddr::new(Ipv6Addr::from(*addr).into(), port)),
180180
Some(rdata) => {
181181
trace!("skipped rdata {:?}", rdata);
182182
}

crates/shadowsocks-service/src/local/dns/server.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ fn should_forward_by_response(
413413
return true;
414414
}
415415
let forward = match $rec.data() {
416-
Some(RData::A(ip)) => acl.check_ip_in_proxy_list(&IpAddr::V4(*ip)),
417-
Some(RData::AAAA(ip)) => acl.check_ip_in_proxy_list(&IpAddr::V6(*ip)),
416+
Some(RData::A(ip)) => acl.check_ip_in_proxy_list(&IpAddr::V4((*ip).into())),
417+
Some(RData::AAAA(ip)) => acl.check_ip_in_proxy_list(&IpAddr::V6((*ip).into())),
418418
// MX records cause type A additional section processing for the host specified by EXCHANGE.
419419
Some(RData::MX(mx)) => examine_name!(mx.exchange(), $is_answer),
420420
// NS records cause both the usual additional section processing to locate a type A record...
@@ -498,8 +498,16 @@ impl DnsClient {
498498
for rec in result.answers() {
499499
trace!("dns answer: {:?}", rec);
500500
match rec.data() {
501-
Some(RData::A(ip)) => self.context.add_to_reverse_lookup_cache((*ip).into(), forward).await,
502-
Some(RData::AAAA(ip)) => self.context.add_to_reverse_lookup_cache((*ip).into(), forward).await,
501+
Some(RData::A(ip)) => {
502+
self.context
503+
.add_to_reverse_lookup_cache(Ipv4Addr::from(*ip).into(), forward)
504+
.await
505+
}
506+
Some(RData::AAAA(ip)) => {
507+
self.context
508+
.add_to_reverse_lookup_cache(Ipv6Addr::from(*ip).into(), forward)
509+
.await
510+
}
503511
_ => (),
504512
}
505513
}

crates/shadowsocks/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "shadowsocks"
3-
version = "1.15.3"
3+
version = "1.16.0"
44
authors = ["Shadowsocks Contributors"]
55
description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls."
66
repository = "https://github.com/shadowsocks/shadowsocks-rust"
@@ -68,7 +68,8 @@ socket2 = { version = "0.5", features = ["all"] }
6868
tokio = { version = "1.9.0", features = ["io-util", "macros", "net", "parking_lot", "process", "rt", "sync", "time"] }
6969
tokio-tfo = "0.2.0"
7070

71-
trust-dns-resolver = { version = "0.22", optional = true }
71+
# trust-dns-resolver = { version = "0.22", optional = true }
72+
trust-dns-resolver = { git = "https://github.com/bluejekyll/trust-dns.git", optional = true }
7273
arc-swap = { version = "1.6", optional = true }
7374
notify = { version = "5.1.0", optional = true }
7475

0 commit comments

Comments
 (0)