From 7cae63cb17aae6572b7fd108afde6d7cc8add86c Mon Sep 17 00:00:00 2001 From: WillisXue Date: Thu, 8 Aug 2024 23:03:41 +0800 Subject: [PATCH] fix win tun name, clean up custom tun name (#234) --- easytier/src/instance/virtual_nic.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/easytier/src/instance/virtual_nic.rs b/easytier/src/instance/virtual_nic.rs index c1fab26d..7515aa9b 100644 --- a/easytier/src/instance/virtual_nic.rs +++ b/easytier/src/instance/virtual_nic.rs @@ -243,7 +243,7 @@ pub struct VirtualNic { ifcfg: Box, } #[cfg(target_os = "windows")] -pub fn checkreg() -> io::Result<()> { +pub fn checkreg(dev_name:&str) -> io::Result<()> { use winreg::{enums::HKEY_LOCAL_MACHINE, enums::KEY_ALL_ACCESS, RegKey}; let hklm = RegKey::predef(HKEY_LOCAL_MACHINE); let profiles_key = hklm.open_subkey_with_flags( @@ -262,7 +262,7 @@ pub fn checkreg() -> io::Result<()> { // check if ProfileName contains "et" match subkey.get_value::("ProfileName") { Ok(profile_name) => { - if profile_name.contains("et_") { + if profile_name.contains("et_") || (!dev_name.is_empty() && dev_name == profile_name) { keys_to_delete.push(subkey_name); } } @@ -280,7 +280,7 @@ pub fn checkreg() -> io::Result<()> { // check if ProfileName contains "et" match subkey.get_value::("Description") { Ok(profile_name) => { - if profile_name.contains("et_") { + if profile_name.contains("et_") || (!dev_name.is_empty() && dev_name == profile_name) { keys_to_delete_unmanaged.push(subkey_name); } } @@ -342,7 +342,9 @@ impl VirtualNic { #[cfg(target_os = "windows")] { - match checkreg() { + let dev_name = self.global_ctx.get_flags().dev_name; + + match checkreg(&dev_name) { Ok(_) => tracing::trace!("delete successful!"), Err(e) => tracing::error!("An error occurred: {}", e), } @@ -355,12 +357,11 @@ impl VirtualNic { .map(char::from) .collect::() .to_lowercase(); - - let dev_name = self.global_ctx.get_flags().dev_name; + if !dev_name.is_empty() { config.tun_name(format!("{}", dev_name)); } else { - config.tun_name(format!("et{}_{}", c, s)); + config.tun_name(format!("et_{}_{}", c, s)); } config.platform_config(|config| {