From c872714d1ad63062473b95e7e0c8ad7fffa37dd3 Mon Sep 17 00:00:00 2001 From: spyophobia <76800505+spyophobia@users.noreply.github.com> Date: Thu, 31 Aug 2023 22:40:57 +0800 Subject: [PATCH] [Regression fix] local DNS uses mode `tcp_and_udp` by default (#1285) Co-authored-by: zonyitoo --- README.md | 8 +++++--- crates/shadowsocks-service/src/config.rs | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 30564dc3..0c99ad70 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Related Projects: - `local-http` - Allow using HTTP protocol for `sslocal` - `local-http-native-tls` - Support HTTPS with [`native-tls`](https://crates.io/crates/native-tls) - + - `local-http-rustls` - Support HTTPS with [`rustls`](https://crates.io/crates/rustls) - `local-tunnel` - Allow using tunnel protocol for `sslocal` @@ -209,7 +209,7 @@ servers: # Whether to download v2ray and xray plugin. downloadPlugins: false -# Name of the ConfigMap with config.json configuration for shadowsocks-rust. +# Name of the ConfigMap with config.json configuration for shadowsocks-rust. configMapName: "" service: @@ -563,6 +563,8 @@ Example configuration: // Listen address "local_address": "127.0.0.1", "local_port": 53, + // OPTIONAL. DNS local server uses `tcp_and_udp` mode by default + "mode": "udp_only", // Local DNS address, DNS queries will be sent directly to this address "local_dns_address": "114.114.114.114", // OPTIONAL. Local DNS's port, 53 by default @@ -622,7 +624,7 @@ Example configuration: "servers": [ { // Fields are the same as the single server's configuration - + // Individual servers can be disabled // "disabled": true, "address": "0.0.0.0", diff --git a/crates/shadowsocks-service/src/config.rs b/crates/shadowsocks-service/src/config.rs index 4112a8d1..ccb3a8b2 100644 --- a/crates/shadowsocks-service/src/config.rs +++ b/crates/shadowsocks-service/src/config.rs @@ -891,12 +891,20 @@ pub struct LocalConfig { impl LocalConfig { /// Create a new `LocalConfig` pub fn new(protocol: ProtocolType) -> LocalConfig { + // DNS server runs in `TcpAndUdp` mode by default to maintain backwards compatibility + // see https://github.com/shadowsocks/shadowsocks-rust/issues/1281 + let mode = match protocol { + #[cfg(feature = "local-dns")] + ProtocolType::Dns => Mode::TcpAndUdp, + _ => Mode::TcpOnly, + }; + LocalConfig { addr: None, protocol, - mode: Mode::TcpOnly, + mode, udp_addr: None, #[cfg(feature = "local-tunnel")] @@ -1456,7 +1464,15 @@ impl Config { } }, None => { - local_config.mode = global_mode; + // DNS server runs in `TcpAndUdp` mode by default to maintain backwards compatibility + // see https://github.com/shadowsocks/shadowsocks-rust/issues/1281 + let mode = match protocol { + #[cfg(feature = "local-dns")] + ProtocolType::Dns => Mode::TcpAndUdp, + _ => global_mode, + }; + + local_config.mode = mode; } }