From e3bec10b73a7632851f824bf21cf2f4d7f20be0a Mon Sep 17 00:00:00 2001 From: "sijie.sun" Date: Wed, 7 Aug 2024 22:46:46 +0800 Subject: [PATCH] fix win7 build and bump version --- Cargo.toml | 2 +- src/platform/windows/device.rs | 32 +++++++++++++++++++------------- src/platform/windows/mod.rs | 6 ++++++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2fb12e59..3237c593 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tun-easytier" -version = "1.0.0" +version = "1.1.1" edition = "2021" authors = ["meh. ", "@ssrlive", "sijie.sun "] license = "WTFPL" diff --git a/src/platform/windows/device.rs b/src/platform/windows/device.rs index 33dd4823..e2dd36d2 100644 --- a/src/platform/windows/device.rs +++ b/src/platform/windows/device.rs @@ -56,18 +56,22 @@ impl Device { Err(_) => wintun::Adapter::create(&wintun, tun_name, tun_name, guid)?, }; - let address = config - .address - .unwrap_or(IpAddr::V4(Ipv4Addr::new(10, 1, 0, 2))); - let mask = config - .netmask - .unwrap_or(IpAddr::V4(Ipv4Addr::new(255, 255, 255, 0))); - let gateway = config.destination.map(IpAddr::from); - adapter.set_network_addresses_tuple(address, mask, gateway)?; - #[cfg(feature = "wintun-dns")] - if let Some(dns_servers) = &config.platform_config.dns_servers { - adapter.set_dns_servers(dns_servers)?; + // on win7 guid will not be correctly assigned, user should skip the config step. + if !config.platform_config.skip_config && adapter.get_name().is_ok() { + let address = config + .address + .unwrap_or(IpAddr::V4(Ipv4Addr::new(10, 1, 0, 2))); + let mask = config + .netmask + .unwrap_or(IpAddr::V4(Ipv4Addr::new(255, 255, 255, 0))); + let gateway = config.destination.map(IpAddr::from); + adapter.set_network_addresses_tuple(address, mask, gateway)?; + #[cfg(feature = "wintun-dns")] + if let Some(dns_servers) = &config.platform_config.dns_servers { + adapter.set_dns_servers(dns_servers)?; + } } + let mtu = config.mtu.unwrap_or(crate::DEFAULT_MTU); let session = adapter.start_session( @@ -85,8 +89,10 @@ impl Device { name: tun_name.to_string(), }; - // This is not needed since we use netsh to set the address. - device.configure(config)?; + if !config.platform_config.skip_config && adapter.get_name().is_ok() { + // This is not needed since we use netsh to set the address. + device.configure(config)?; + } Ok(device) } diff --git a/src/platform/windows/mod.rs b/src/platform/windows/mod.rs index 0c3261ba..7732b246 100644 --- a/src/platform/windows/mod.rs +++ b/src/platform/windows/mod.rs @@ -33,6 +33,7 @@ pub struct PlatformConfig { #[cfg(feature = "wintun-dns")] pub(crate) dns_servers: Option>, pub(crate) ring_cap: Option, + pub(crate) skip_config: bool, } impl Default for PlatformConfig { @@ -43,6 +44,7 @@ impl Default for PlatformConfig { #[cfg(feature = "wintun-dns")] dns_servers: None, ring_cap: None, + skip_config: false, } } } @@ -78,6 +80,10 @@ impl PlatformConfig { pub fn ring_cap(&mut self, ring_cap: Option) { self.ring_cap = ring_cap; } + + pub fn skip_config(&mut self, skip_config: bool) { + self.skip_config = skip_config; + } } /// Create a TUN device with the given name.