Set MTU on IPv6 interface for wireguard-nt only if IPv6 is enabled

This commit is contained in:
David Lönnhager 2025-03-17 17:15:47 +01:00
parent 22fc75dc52
commit b0ba6488ea
4 changed files with 19 additions and 7 deletions

View File

@ -98,7 +98,7 @@ impl WintunAdapter {
pub fn prepare_interface(&self) { pub fn prepare_interface(&self) {
if let Err(error) = if let Err(error) =
talpid_tunnel::network_interface::initialize_interfaces(self.luid(), None) talpid_tunnel::network_interface::initialize_interfaces(self.luid(), None, None)
{ {
log::error!( log::error!(
"{}", "{}",

View File

@ -7,8 +7,15 @@ use windows_sys::Win32::{
/// Sets MTU, metric, and disables unnecessary features for the IP interfaces /// Sets MTU, metric, and disables unnecessary features for the IP interfaces
/// on the specified network interface (identified by `luid`). /// on the specified network interface (identified by `luid`).
pub fn initialize_interfaces(luid: NET_LUID_LH, mtu: Option<u32>) -> io::Result<()> { pub fn initialize_interfaces(
for family in &[AddressFamily::Ipv4, AddressFamily::Ipv6] { luid: NET_LUID_LH,
ipv4_mtu: Option<u32>,
ipv6_mtu: Option<u32>,
) -> io::Result<()> {
for (family, mtu) in &[
(AddressFamily::Ipv4, ipv4_mtu),
(AddressFamily::Ipv6, ipv6_mtu),
] {
let mut row = match get_ip_interface_entry(*family, &luid) { let mut row = match get_ip_interface_entry(*family, &luid) {
Ok(row) => row, Ok(row) => row,
Err(error) if error.raw_os_error() == Some(ERROR_NOT_FOUND as i32) => continue, Err(error) if error.raw_os_error() == Some(ERROR_NOT_FOUND as i32) => continue,
@ -16,7 +23,7 @@ pub fn initialize_interfaces(luid: NET_LUID_LH, mtu: Option<u32>) -> io::Result<
}; };
if let Some(mtu) = mtu { if let Some(mtu) = mtu {
row.NlMtu = mtu; row.NlMtu = *mtu;
} }
// Disable DAD, DHCP, and router discovery // Disable DAD, DHCP, and router discovery

View File

@ -311,7 +311,8 @@ impl WgGoTunnel {
.map_err(|e| BoxedError::new(TunnelError::SetupIpInterfaces(e)))?; .map_err(|e| BoxedError::new(TunnelError::SetupIpInterfaces(e)))?;
log::debug!("Waiting for tunnel IP interfaces: Done"); log::debug!("Waiting for tunnel IP interfaces: Done");
if let Err(error) = talpid_tunnel::network_interface::initialize_interfaces(luid, None) if let Err(error) =
talpid_tunnel::network_interface::initialize_interfaces(luid, None, None)
{ {
log::error!( log::error!(
"{}", "{}",

View File

@ -543,8 +543,12 @@ async fn setup_ip_listener(device: Arc<WgNtAdapter>, mtu: u32, has_ipv6: bool) -
.map_err(Error::IpInterfaces)?; .map_err(Error::IpInterfaces)?;
log::debug!("Waiting for tunnel IP interfaces: Done"); log::debug!("Waiting for tunnel IP interfaces: Done");
talpid_tunnel::network_interface::initialize_interfaces(luid, Some(mtu)) talpid_tunnel::network_interface::initialize_interfaces(
.map_err(Error::SetTunnelMtu)?; luid,
Some(mtu),
has_ipv6.then_some(mtu),
)
.map_err(Error::SetTunnelMtu)?;
device device
.set_state(WgAdapterState::Up) .set_state(WgAdapterState::Up)