From fedba5c8e2b3115ba9db852e4c9592e5fadc18bb Mon Sep 17 00:00:00 2001 From: lbl <1791778603@qq.com> Date: Sun, 23 Aug 2026 14:17:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=85=E5=BD=93=20no=5Ftun=20=3D=20true=20?= =?UTF-8?q?=E6=97=B6=E6=8F=90=E7=A4=BA=E8=BF=81=E7=A7=BB=EF=BC=8Cno=5Ftun?= =?UTF-8?q?=20=3D=20false=20=E9=9D=99=E9=BB=98=E5=BF=BD=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/args_config.rs | 13 ++++++++++--- vnt-web/src/service_http.rs | 6 +++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/args_config.rs b/src/args_config.rs index e914571..c70aca6 100644 --- a/src/args_config.rs +++ b/src/args_config.rs @@ -181,7 +181,7 @@ pub fn build_config_from_args_and_file( ) -> anyhow::Result<(Config, CtrlConfig)> { if file .as_ref() - .is_some_and(|config| config.legacy_no_tun.is_some()) + .is_some_and(|config| config.legacy_no_tun == Some(true)) { return Err(anyhow!( "configuration key 'no_tun' was removed; use device_mode = \"no|tun|tap\"" @@ -323,7 +323,7 @@ fn build_from_args_only(args: Args) -> anyhow::Result<(Config, CtrlConfig)> { } fn build_from_file_only(file: FileConfig) -> anyhow::Result<(Config, CtrlConfig)> { - if file.legacy_no_tun.is_some() { + if file.legacy_no_tun == Some(true) { return Err(anyhow!( "configuration key 'no_tun' was removed; use device_mode = \"no|tun|tap\"" )); @@ -546,9 +546,16 @@ mod tests { let legacy: FileConfig = toml::from_str("no_tun = true").unwrap(); let error = match build_config_from_args_and_file(None, Some(legacy)) { Err(error) => error, - Ok(_) => panic!("legacy no_tun must be rejected"), + Ok(_) => panic!("legacy no_tun = true must be rejected"), }; assert!(error.to_string().contains("device_mode")); + + let legacy_false: FileConfig = toml::from_str( + "no_tun = false\nserver = [\"quic://127.0.0.1:29872\"]\nnetwork_code = \"test\"", + ) + .unwrap(); + build_config_from_args_and_file(None, Some(legacy_false)) + .expect("legacy no_tun = false should be ignored"); } #[test] diff --git a/vnt-web/src/service_http.rs b/vnt-web/src/service_http.rs index eca6deb..c9481e4 100644 --- a/vnt-web/src/service_http.rs +++ b/vnt-web/src/service_http.rs @@ -288,7 +288,7 @@ pub struct StartConfig { impl StartConfig { fn reject_legacy_no_tun(&self) -> anyhow::Result<()> { - if self.legacy_no_tun.is_some() { + if self.legacy_no_tun == Some(true) { bail!("configuration key 'no_tun' was removed; use device_mode = \"no|tun|tap\"") } Ok(()) @@ -1800,6 +1800,10 @@ network_code = "test" let legacy: StartConfig = toml::from_str(&format!("{base}no_tun = true\n")).unwrap(); assert!(legacy.reject_legacy_no_tun().is_err()); + + let legacy_false: StartConfig = + toml::from_str(&format!("{base}no_tun = false\n")).unwrap(); + assert!(legacy_false.reject_legacy_no_tun().is_ok()); } /// 两个实例同时处于 Starting 互不影响