Skip to content

Commit c01a995

Browse files
committed
mullvad: fix musl and edit service
1 parent 6def676 commit c01a995

File tree

4 files changed

+144
-25
lines changed

4 files changed

+144
-25
lines changed

srcpkgs/mullvadvpn/files/mullvad/run

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@ export MULLVAD_RPC_SOCKET_PATH=/run/mullvad-vpn/mullvad
88
export TALPID_NET_CLS_MOUNT_DIR=/run/mullvad-vpn/cgroup
99
export MULLVAD_MANAGEMENT_SOCKET_GROUP=_mullvad
1010

11-
# it needs write to /etc/resolv.conf{,.mullvadbackup}
12-
# as well as cap_net_raw for sockets
11+
# needs cap_dac_override to write /etc/resolv.conf{,.mullvadbackup}
12+
# and cap_net_raw for sockets
1313

1414
_user=_mullvad
15-
# _caps=-all,+net_admin,+net_bind_service
15+
_caps=-all,+net_admin,+net_bind_service,+net_raw,+dac_override
1616

1717
! [ -d /run/mullvad-vpn ] && install -m 750 -g $_user -o $_user -d /run/mullvad-vpn
1818

1919
exec 2>&1
20-
#exec setpriv --reuid $_user --regid $_user --clear-groups \
21-
# --ambient-caps $_caps \
22-
# --inh-caps $_caps \
23-
# --bounding-set $_caps \
24-
# --no-new-privs -- /usr/bin/mullvad-daemon -v --disable-stdout-timestamps
25-
26-
exec /usr/bin/mullvad-daemon -v --disable-stdout-timestamps
20+
exec setpriv --reuid $_user --regid $_user --clear-groups \
21+
--ambient-caps $_caps \
22+
--inh-caps $_caps \
23+
--bounding-set $_caps \
24+
--no-new-privs -- /usr/bin/mullvad-daemon -v --disable-stdout-timestamps
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
From ecd6066dabb3ff321bedc2b025ad76bb99622836 Mon Sep 17 00:00:00 2001
2+
From: Markus Pettersson <markus.pettersson@mullvad.net>
3+
Date: Fri, 4 Jul 2025 21:12:51 +0200
4+
Subject: [PATCH] Add musl as a target ABI for wireguard-go-rs
5+
6+
Do not assume target ABI to be glibc. The current solution is not
7+
directly extensible by the user, but it easily could be if we really
8+
wanted to. At least we don't break cross-compilation to musl targets
9+
though.
10+
---
11+
wireguard-go-rs/build.rs | 25 ++++++++++++++++++++++---
12+
1 file changed, 22 insertions(+), 3 deletions(-)
13+
14+
diff --git a/wireguard-go-rs/build.rs b/wireguard-go-rs/build.rs
15+
index a544e4e161e1..8978bef7b5b3 100644
16+
--- a/wireguard-go-rs/build.rs
17+
+++ b/wireguard-go-rs/build.rs
18+
@@ -53,6 +53,14 @@ enum AndroidTarget {
19+
I686, // "i686"
20+
}
21+
22+
+#[derive(PartialEq, Eq, Clone, Copy)]
23+
+enum Libc {
24+
+ /// glibc
25+
+ Gnu,
26+
+ /// musl libc
27+
+ Musl,
28+
+}
29+
+
30+
impl AndroidTarget {
31+
fn from_str(input: &str) -> anyhow::Result<Self> {
32+
use AndroidTarget::*;
33+
@@ -113,6 +121,16 @@ fn target_arch() -> anyhow::Result<Arch> {
34+
}
35+
}
36+
37+
+// https://doc.rust-lang.org/reference/conditional-compilation.html#target_env
38+
+fn target_libc() -> anyhow::Result<Libc> {
39+
+ let target_arch = env::var("CARGO_CFG_TARGET_ENV").context("Missing 'CARGO_CFG_TARGET_ENV")?;
40+
+ match target_arch.as_str() {
41+
+ "gnu" => Ok(Libc::Gnu),
42+
+ "musl" => Ok(Libc::Musl),
43+
+ _ => bail!("Unsupported target ABI/libc: {target_arch}"),
44+
+ }
45+
+}
46+
+
47+
/// Compile libwg and maybenot and place them in the target dir relative to `OUT_DIR`.
48+
fn build_windows_dynamic_lib(out_dir: &str) -> anyhow::Result<()> {
49+
let target_dir = Path::new(out_dir)
50+
@@ -179,9 +197,10 @@ fn build_linux_static_lib(out_dir: &str) -> anyhow::Result<()> {
51+
};
52+
53+
if is_cross_compiling()? {
54+
- match target_arch {
55+
- Arch::Arm64 => go_build.env("CC", "aarch64-linux-gnu-gcc"),
56+
- Arch::Amd64 => bail!("cross-compiling to linux x86_64 is not implemented"),
57+
+ match (target_arch, target_libc()?) {
58+
+ (Arch::Arm64, Libc::Gnu) => go_build.env("CC", "aarch64-linux-gnu-gcc"),
59+
+ (Arch::Arm64, Libc::Musl) => go_build.env("CC", "aarch64-linux-musl-gcc"),
60+
+ (Arch::Amd64, _) => bail!("cross-compiling to linux x86_64 is not implemented"),
61+
};
62+
}
63+

srcpkgs/mullvadvpn/template

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,17 @@ short_desc="Mullvad VPN client app (cli only)"
2222
maintainer="dkwo <npiazza@disroot.org>"
2323
license="GPL-3.0-or-later"
2424
homepage="https://mullvad.net/"
25+
changelog="https://raw.githubusercontent.com/mullvad/mullvadvpn-app/refs/heads/main/CHANGELOG.md"
2526
distfiles="https://github.com/mullvad/mullvadvpn-app/archive/refs/tags/${version}.tar.gz
2627
https://github.com/mullvad/wireguard-go/archive/refs/tags/${_wggover}.tar.gz"
2728
checksum="0231665feed54636fe088c18fdff08d2381cbbcb8f6c0ea97990b3b9d9438500
2829
fd9fa45155098223a17ea934eaa6eb44ee990cd2a7ab638bce482f62fd8502e8"
2930
skip_extraction="${_wggover}.tar.gz"
3031
system_accounts="_mullvad"
31-
# make_dirs="
32-
# /var/cache/mullvad-vpn 0750 _mullvad _mullvad
33-
# /var/log/mullvad-vpn 0750 _mullvad _mullvad
34-
# /etc/mullvad-vpn 0750 _mullvad _mullvad"
35-
36-
case "${XBPS_TARGET_MACHINE}" in
37-
*musl)
38-
broken="https://github.com/mullvad/mullvadvpn-app/issues/8390"
39-
;;
40-
esac
41-
# cross to musl fails since wireguard-go-rs exports CC="aarch64-linux-gnu-gcc"
32+
make_dirs="
33+
/var/cache/mullvad-vpn 0750 _mullvad _mullvad
34+
/var/log/mullvad-vpn 0750 _mullvad _mullvad
35+
/etc/mullvad-vpn 0750 _mullvad _mullvad"
4236

4337
post_extract() {
4438
vsrcextract -C wireguard-go-rs/libwg/wireguard-go "${_wggover}.tar.gz"
@@ -55,13 +49,12 @@ do_install() {
5549

5650
vinstall target/${RUST_TARGET}/release/libtalpid_openvpn_plugin.so 644 usr/lib
5751
vinstall dist-assets/relays.json 644 usr/share/mullvad
58-
}
5952

60-
post_install() {
6153
compdir=$(mktemp -d)
62-
for shell in bash zsh fish; do
63-
vtargetrun ${DESTDIR}/usr/bin/mullvad shell-completions ${shell} ${compdir}
54+
for _shell in bash zsh fish; do
55+
vtargetrun ${DESTDIR}/usr/bin/mullvad shell-completions ${_shell} ${compdir}
6456
done
57+
6558
vcompletion ${compdir}/mullvad.bash bash mullvad
6659
vcompletion ${compdir}/_mullvad zsh mullvad
6760
vcompletion ${compdir}/mullvad.fish fish mullvad

0 commit comments

Comments
 (0)