From 720a50bafae00ef767d0629720e7e871fa7a7fbd Mon Sep 17 00:00:00 2001 From: Reactor Scram Date: Thu, 4 Jan 2024 18:31:17 -0600 Subject: [PATCH] fix(windows): set MTU for IPv6 too (#3121) This can be seen in `Get-NetIPInterface` even if #3120 isn't merged --- .../tunnel/src/device_channel/tun_windows.rs | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/rust/connlib/tunnel/src/device_channel/tun_windows.rs b/rust/connlib/tunnel/src/device_channel/tun_windows.rs index 5628f3872..6f3b2d9ee 100644 --- a/rust/connlib/tunnel/src/device_channel/tun_windows.rs +++ b/rust/connlib/tunnel/src/device_channel/tun_windows.rs @@ -15,7 +15,7 @@ use windows::Win32::{ IpHelper::{GetIpInterfaceEntry, SetIpInterfaceEntry, MIB_IPINTERFACE_ROW}, Ndis::NET_LUID_LH, }, - Networking::WinSock::AF_INET, + Networking::WinSock::{AF_INET, AF_INET6}, }; // TODO: Double-check that all these get dropped gracefully on disconnect @@ -221,19 +221,40 @@ fn set_iface_config(luid: wintun::NET_LUID_LH, mtu: u32) -> Result<()> { Value: unsafe { luid.Value }, }; - let mut row = MIB_IPINTERFACE_ROW { - Family: AF_INET, - InterfaceLuid: luid, - ..Default::default() - }; + // Set MTU for IPv4 + { + let mut row = MIB_IPINTERFACE_ROW { + Family: AF_INET, + InterfaceLuid: luid, + ..Default::default() + }; - unsafe { GetIpInterfaceEntry(&mut row) }?; + unsafe { GetIpInterfaceEntry(&mut row) }?; - row.NlMtu = mtu; - // https://stackoverflow.com/questions/54857292/setipinterfaceentry-returns-error-invalid-parameter - row.SitePrefixLength = 0; + // https://stackoverflow.com/questions/54857292/setipinterfaceentry-returns-error-invalid-parameter + row.SitePrefixLength = 0; - // Ignore error if we can't set everything - unsafe { SetIpInterfaceEntry(&mut row) }?; + // Set MTU for IPv4 + row.NlMtu = mtu; + unsafe { SetIpInterfaceEntry(&mut row) }?; + } + + // Set MTU for IPv6 + { + let mut row = MIB_IPINTERFACE_ROW { + Family: AF_INET6, + InterfaceLuid: luid, + ..Default::default() + }; + + unsafe { GetIpInterfaceEntry(&mut row) }?; + + // https://stackoverflow.com/questions/54857292/setipinterfaceentry-returns-error-invalid-parameter + row.SitePrefixLength = 0; + + // Set MTU for IPv4 + row.NlMtu = mtu; + unsafe { SetIpInterfaceEntry(&mut row) }?; + } Ok(()) }