Skip to content

Commit

Permalink
fix win7 build and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
KKRainbow committed Aug 7, 2024
1 parent 6079445 commit e3bec10
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tun-easytier"
version = "1.0.0"
version = "1.1.1"
edition = "2021"
authors = ["meh. <[email protected]>", "@ssrlive", "sijie.sun <[email protected]>"]
license = "WTFPL"
Expand Down
32 changes: 19 additions & 13 deletions src/platform/windows/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions src/platform/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct PlatformConfig {
#[cfg(feature = "wintun-dns")]
pub(crate) dns_servers: Option<Vec<IpAddr>>,
pub(crate) ring_cap: Option<u32>,
pub(crate) skip_config: bool,
}

impl Default for PlatformConfig {
Expand All @@ -43,6 +44,7 @@ impl Default for PlatformConfig {
#[cfg(feature = "wintun-dns")]
dns_servers: None,
ring_cap: None,
skip_config: false,
}
}
}
Expand Down Expand Up @@ -78,6 +80,10 @@ impl PlatformConfig {
pub fn ring_cap(&mut self, ring_cap: Option<u32>) {
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.
Expand Down

0 comments on commit e3bec10

Please sign in to comment.