Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Support set wintun dns servers #74

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/platform/windows/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ impl Device {
.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)?;
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(wintun::MAX_RING_CAPACITY)?;
Expand Down
8 changes: 8 additions & 0 deletions src/platform/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

mod device;

use std::net::IpAddr;

pub use device::{Device, Tun};

use crate::configuration::Configuration;
Expand All @@ -26,13 +28,15 @@ use crate::error::Result;
pub struct PlatformConfig {
pub(crate) device_guid: Option<u128>,
pub(crate) wintun_path: String,
pub(crate) dns_servers: Option<Vec<IpAddr>>,
}

impl Default for PlatformConfig {
fn default() -> Self {
Self {
device_guid: None,
wintun_path: "wintun".to_string(),
dns_servers: None,
}
}
}
Expand All @@ -49,6 +53,10 @@ impl PlatformConfig {
pub fn custom_wintun_path(&mut self, wintun_path: &str) {
self.wintun_path = wintun_path.to_string();
}

pub fn dns_servers(&mut self, dns_servers: Option<Vec<IpAddr>>) {
self.dns_servers = dns_servers;
}
}

/// Create a TUN device with the given name.
Expand Down