Skip to content

Commit e3bec10

Browse files
committed
fix win7 build and bump version
1 parent 6079445 commit e3bec10

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tun-easytier"
3-
version = "1.0.0"
3+
version = "1.1.1"
44
edition = "2021"
55
authors = ["meh. <meh@schizofreni.co>", "@ssrlive", "sijie.sun <sunsijie@buaa.edu.cn>"]
66
license = "WTFPL"

src/platform/windows/device.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,22 @@ impl Device {
5656
Err(_) => wintun::Adapter::create(&wintun, tun_name, tun_name, guid)?,
5757
};
5858

59-
let address = config
60-
.address
61-
.unwrap_or(IpAddr::V4(Ipv4Addr::new(10, 1, 0, 2)));
62-
let mask = config
63-
.netmask
64-
.unwrap_or(IpAddr::V4(Ipv4Addr::new(255, 255, 255, 0)));
65-
let gateway = config.destination.map(IpAddr::from);
66-
adapter.set_network_addresses_tuple(address, mask, gateway)?;
67-
#[cfg(feature = "wintun-dns")]
68-
if let Some(dns_servers) = &config.platform_config.dns_servers {
69-
adapter.set_dns_servers(dns_servers)?;
59+
// on win7 guid will not be correctly assigned, user should skip the config step.
60+
if !config.platform_config.skip_config && adapter.get_name().is_ok() {
61+
let address = config
62+
.address
63+
.unwrap_or(IpAddr::V4(Ipv4Addr::new(10, 1, 0, 2)));
64+
let mask = config
65+
.netmask
66+
.unwrap_or(IpAddr::V4(Ipv4Addr::new(255, 255, 255, 0)));
67+
let gateway = config.destination.map(IpAddr::from);
68+
adapter.set_network_addresses_tuple(address, mask, gateway)?;
69+
#[cfg(feature = "wintun-dns")]
70+
if let Some(dns_servers) = &config.platform_config.dns_servers {
71+
adapter.set_dns_servers(dns_servers)?;
72+
}
7073
}
74+
7175
let mtu = config.mtu.unwrap_or(crate::DEFAULT_MTU);
7276

7377
let session = adapter.start_session(
@@ -85,8 +89,10 @@ impl Device {
8589
name: tun_name.to_string(),
8690
};
8791

88-
// This is not needed since we use netsh to set the address.
89-
device.configure(config)?;
92+
if !config.platform_config.skip_config && adapter.get_name().is_ok() {
93+
// This is not needed since we use netsh to set the address.
94+
device.configure(config)?;
95+
}
9096

9197
Ok(device)
9298
}

src/platform/windows/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct PlatformConfig {
3333
#[cfg(feature = "wintun-dns")]
3434
pub(crate) dns_servers: Option<Vec<IpAddr>>,
3535
pub(crate) ring_cap: Option<u32>,
36+
pub(crate) skip_config: bool,
3637
}
3738

3839
impl Default for PlatformConfig {
@@ -43,6 +44,7 @@ impl Default for PlatformConfig {
4344
#[cfg(feature = "wintun-dns")]
4445
dns_servers: None,
4546
ring_cap: None,
47+
skip_config: false,
4648
}
4749
}
4850
}
@@ -78,6 +80,10 @@ impl PlatformConfig {
7880
pub fn ring_cap(&mut self, ring_cap: Option<u32>) {
7981
self.ring_cap = ring_cap;
8082
}
83+
84+
pub fn skip_config(&mut self, skip_config: bool) {
85+
self.skip_config = skip_config;
86+
}
8187
}
8288

8389
/// Create a TUN device with the given name.

0 commit comments

Comments
 (0)