summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarkus Pettersson <markus.pettersson@mullvad.net>2025-07-04 11:09:28 +0200
committerMarkus Pettersson <markus.pettersson@mullvad.net>2025-07-04 11:09:28 +0200
commit4fb0191a259a62efc1264ae71135a9114ce99fd7 (patch)
tree43fbef461828e09f9a093eb72197c8610db5dc35
parent3b1c4cce2f6f2810db2f5efcae99d4da1ca81ffd (diff)
parent5b62921a73d54fbc43908bce220601a6438993d7 (diff)
downloadmullvadvpn-4fb0191a259a62efc1264ae71135a9114ce99fd7.tar.xz
mullvadvpn-4fb0191a259a62efc1264ae71135a9114ce99fd7.zip
Merge branch 'fix-type-checking-for-linux-musl-targets-des-2294'
-rw-r--r--talpid-net/src/unix.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/talpid-net/src/unix.rs b/talpid-net/src/unix.rs
index 48d65c45f0..a6e11b1968 100644
--- a/talpid-net/src/unix.rs
+++ b/talpid-net/src/unix.rs
@@ -1,5 +1,7 @@
#![cfg(any(target_os = "linux", target_os = "macos"))]
+#[cfg(target_os = "linux")]
+use std::ffi::c_ulong;
use std::{ffi::c_uint, io, os::fd::AsRawFd};
use nix::{errno::Errno, net::if_::if_nametoindex};
@@ -26,9 +28,9 @@ const SIOCSIFMTU: u64 = 0x80206934;
#[cfg(target_os = "macos")]
const SIOCGIFMTU: u64 = 0xc0206933;
#[cfg(target_os = "linux")]
-const SIOCSIFMTU: u64 = libc::SIOCSIFMTU;
+const SIOCSIFMTU: c_ulong = libc::SIOCSIFMTU;
#[cfg(target_os = "linux")]
-const SIOCGIFMTU: u64 = libc::SIOCSIFMTU;
+const SIOCGIFMTU: c_ulong = libc::SIOCSIFMTU;
pub fn set_mtu(interface_name: &str, mtu: u16) -> Result<(), io::Error> {
let sock = socket2::Socket::new(
@@ -56,8 +58,14 @@ pub fn set_mtu(interface_name: &str, mtu: u16) -> Result<(), io::Error> {
};
ifr.ifr_ifru.ifru_mtu = mtu as i32;
+ // 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:
+ // https://docs.rs/libc/latest/x86_64-unknown-linux-musl/libc/fn.ioctl.html
+ // https://docs.rs/libc/latest/x86_64-unknown-linux-musl/libc/type.c_ulong.html
+ // https://docs.rs/libc/latest/x86_64-unknown-linux-musl/libc/constant.SIOCSIFMTU.html
+ #[allow(clippy::useless_conversion)]
+ let request = SIOCSIFMTU.try_into().unwrap();
// SAFETY: SIOCSIFMTU expects an ifreq with an MTU and interface set
- if unsafe { libc::ioctl(sock.as_raw_fd(), SIOCSIFMTU, &ifr) } < 0 {
+ if unsafe { libc::ioctl(sock.as_raw_fd(), request, &ifr) } < 0 {
let e = std::io::Error::last_os_error();
log::error!("{}", e.display_chain_with_msg("SIOCSIFMTU failed"));
return Err(e);
@@ -90,8 +98,14 @@ pub fn get_mtu(interface_name: &str) -> Result<u16, io::Error> {
)
};
+ // 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:
+ // https://docs.rs/libc/latest/x86_64-unknown-linux-musl/libc/fn.ioctl.html
+ // https://docs.rs/libc/latest/x86_64-unknown-linux-musl/libc/type.c_ulong.html
+ // https://docs.rs/libc/latest/x86_64-unknown-linux-musl/libc/constant.SIOCGIFMTU.html
+ #[allow(clippy::useless_conversion)]
+ let request = SIOCGIFMTU.try_into().unwrap();
// SAFETY: SIOCGIFMTU expects an ifreq with an interface set
- if unsafe { libc::ioctl(sock.as_raw_fd(), SIOCGIFMTU, &ifr) } < 0 {
+ if unsafe { libc::ioctl(sock.as_raw_fd(), request, &ifr) } < 0 {
let e = std::io::Error::last_os_error();
log::error!("{}", e.display_chain_with_msg("SIOCGIFMTU failed"));
return Err(e);