|
| 1 | +From 5b62921a73d54fbc43908bce220601a6438993d7 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Markus Pettersson <markus.pettersson@mullvad.net> |
| 3 | +Date: Mon, 30 Jun 2025 22:23:26 +0200 |
| 4 | +Subject: [PATCH] Fix type error for musl targets |
| 5 | + |
| 6 | +--- |
| 7 | + talpid-net/src/unix.rs | 22 ++++++++++++++++++---- |
| 8 | + 1 file changed, 18 insertions(+), 4 deletions(-) |
| 9 | + |
| 10 | +diff --git a/talpid-net/src/unix.rs b/talpid-net/src/unix.rs |
| 11 | +index 48d65c45f076..a6e11b196825 100644 |
| 12 | +--- a/talpid-net/src/unix.rs |
| 13 | ++++ b/talpid-net/src/unix.rs |
| 14 | +@@ -1,5 +1,7 @@ |
| 15 | + #![cfg(any(target_os = "linux", target_os = "macos"))] |
| 16 | + |
| 17 | ++#[cfg(target_os = "linux")] |
| 18 | ++use std::ffi::c_ulong; |
| 19 | + use std::{ffi::c_uint, io, os::fd::AsRawFd}; |
| 20 | + |
| 21 | + use nix::{errno::Errno, net::if_::if_nametoindex}; |
| 22 | +@@ -26,9 +28,9 @@ const SIOCSIFMTU: u64 = 0x80206934; |
| 23 | + #[cfg(target_os = "macos")] |
| 24 | + const SIOCGIFMTU: u64 = 0xc0206933; |
| 25 | + #[cfg(target_os = "linux")] |
| 26 | +-const SIOCSIFMTU: u64 = libc::SIOCSIFMTU; |
| 27 | ++const SIOCSIFMTU: c_ulong = libc::SIOCSIFMTU; |
| 28 | + #[cfg(target_os = "linux")] |
| 29 | +-const SIOCGIFMTU: u64 = libc::SIOCSIFMTU; |
| 30 | ++const SIOCGIFMTU: c_ulong = libc::SIOCSIFMTU; |
| 31 | + |
| 32 | + pub fn set_mtu(interface_name: &str, mtu: u16) -> Result<(), io::Error> { |
| 33 | + let sock = socket2::Socket::new( |
| 34 | +@@ -56,8 +58,14 @@ pub fn set_mtu(interface_name: &str, mtu: u16) -> Result<(), io::Error> { |
| 35 | + }; |
| 36 | + ifr.ifr_ifru.ifru_mtu = mtu as i32; |
| 37 | + |
| 38 | ++ // For some reason, libc crate defines ioctl to take a c_int (which is defined as i32), but the c_ulong type is defined as u64: |
| 39 | ++ // https://docs.rs/libc/latest/x86_64-unknown-linux-musl/libc/fn.ioctl.html |
| 40 | ++ // https://docs.rs/libc/latest/x86_64-unknown-linux-musl/libc/type.c_ulong.html |
| 41 | ++ // https://docs.rs/libc/latest/x86_64-unknown-linux-musl/libc/constant.SIOCSIFMTU.html |
| 42 | ++ #[allow(clippy::useless_conversion)] |
| 43 | ++ let request = SIOCSIFMTU.try_into().unwrap(); |
| 44 | + // SAFETY: SIOCSIFMTU expects an ifreq with an MTU and interface set |
| 45 | +- if unsafe { libc::ioctl(sock.as_raw_fd(), SIOCSIFMTU, &ifr) } < 0 { |
| 46 | ++ if unsafe { libc::ioctl(sock.as_raw_fd(), request, &ifr) } < 0 { |
| 47 | + let e = std::io::Error::last_os_error(); |
| 48 | + log::error!("{}", e.display_chain_with_msg("SIOCSIFMTU failed")); |
| 49 | + return Err(e); |
| 50 | +@@ -90,8 +98,14 @@ pub fn get_mtu(interface_name: &str) -> Result<u16, io::Error> { |
| 51 | + ) |
| 52 | + }; |
| 53 | + |
| 54 | ++ // For some reason, libc crate defines ioctl to take a c_int (which is defined as i32), but the c_ulong type is defined as u64: |
| 55 | ++ // https://docs.rs/libc/latest/x86_64-unknown-linux-musl/libc/fn.ioctl.html |
| 56 | ++ // https://docs.rs/libc/latest/x86_64-unknown-linux-musl/libc/type.c_ulong.html |
| 57 | ++ // https://docs.rs/libc/latest/x86_64-unknown-linux-musl/libc/constant.SIOCGIFMTU.html |
| 58 | ++ #[allow(clippy::useless_conversion)] |
| 59 | ++ let request = SIOCGIFMTU.try_into().unwrap(); |
| 60 | + // SAFETY: SIOCGIFMTU expects an ifreq with an interface set |
| 61 | +- if unsafe { libc::ioctl(sock.as_raw_fd(), SIOCGIFMTU, &ifr) } < 0 { |
| 62 | ++ if unsafe { libc::ioctl(sock.as_raw_fd(), request, &ifr) } < 0 { |
| 63 | + let e = std::io::Error::last_os_error(); |
| 64 | + log::error!("{}", e.display_chain_with_msg("SIOCGIFMTU failed")); |
| 65 | + return Err(e); |
0 commit comments