Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b485933
Add boringtun submodule
oskirby Apr 24, 2025
5e489f1
Enable ffi-bindings feature in boringtun
oskirby Apr 25, 2025
f8047f8
Re-implement WireguardUtilsMacos with boringtun
oskirby Apr 25, 2025
acc2a78
Rename WireguardPeerMacos to WgSessionMacos
oskirby Apr 25, 2025
9fae4b8
Initial attempt at multihop
oskirby Apr 25, 2025
f139c06
Rename WireguardUtilsMacos to WgUtilsMacos
oskirby Apr 25, 2025
700db85
Implement IPv4 defragmentation support
oskirby Apr 25, 2025
9611a4d
Fix panic in boringtun if MTU exceeded
oskirby Apr 25, 2025
7b0b12a
Fix padding bug leading to packet drops
oskirby Apr 26, 2025
2cf3a2d
Set MTU dynamically from the routing table
oskirby Apr 28, 2025
fa73dca
Remove the wireguard-go tunnel binary
oskirby Apr 28, 2025
a3bad39
Remove wireguard-go submodule
oskirby Apr 28, 2025
3543268
Set boringtun module to shallow checkout
oskirby Apr 28, 2025
71ea3ae
Fix some lint
oskirby Apr 28, 2025
5c0b137
Tidy up timeout and rengotiate handling
oskirby Apr 28, 2025
5bf8378
Fix some rebase breakage
oskirby Jul 18, 2025
4e2e8ba
Move socket data handling into WgSessionMacos
oskirby Jul 18, 2025
31cb53b
Oops - multihop was turned off at the controller
oskirby Jul 19, 2025
238e340
A bunch of hacking to get mutlihop working again
oskirby Jul 19, 2025
749afb0
Lets go mutlithreaded and use a QThreadPool for the encryption
oskirby Jul 19, 2025
8217427
Move the tunnel receive loop into its own thread
oskirby Jul 19, 2025
84e3071
Move decryption workers into their own thread
oskirby Jul 19, 2025
a65333c
Fix worker shutdown bugs
oskirby Jul 21, 2025
5d16026
Tweak handshake time calculation
oskirby Jul 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
path = 3rdparty/wireguard-apple
url = https://github.com/mozilla/wireguard-apple.git
shallow = true
[submodule "3rdparty/wireguard-go"]
path = 3rdparty/wireguard-go
url = https://github.com/WireGuard/wireguard-go
shallow = true
[submodule "3rdparty/adjust-ios-sdk"]
path = 3rdparty/adjust-ios-sdk
url = https://github.com/adjust/ios_sdk.git
Expand All @@ -35,3 +31,7 @@
[submodule "3rdparty/c-ares"]
path = 3rdparty/c-ares
url = https://github.com/c-ares/c-ares
[submodule "3rdparty/boringtun"]
path = 3rdparty/boringtun
url = https://github.com/cloudflare/boringtun
shallow = true
1 change: 1 addition & 0 deletions 3rdparty/boringtun
Submodule boringtun added at 18eaf5
1 change: 0 additions & 1 deletion 3rdparty/wireguard-go
Submodule wireguard-go deleted from ee1c8e
21 changes: 15 additions & 6 deletions scripts/cmake/rustlang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ endfunction()
# LIBRARY_FILE: Filename of the expected library to be built.
# CARGO_ENV: Environment variables to pass to cargo
# SHARED: Whether or not we are building a shared library. Defaults to "false".
# EXTRA_ARGS: Additional arguments to pass when building the crate.
#
# This function generates commands necessary to build static archives
# in ${BINARY_DIR}/${ARCH}/debug/ and ${BINARY_DIR}/${ARCH}/release/
Expand All @@ -173,7 +174,7 @@ function(build_rust_archives)
cmake_parse_arguments(RUST_BUILD
""
"ARCH;BINARY_DIR;PACKAGE_DIR;CRATE_NAME"
"CARGO_ENV;SHARED"
"CARGO_ENV;SHARED;EXTRA_ARGS"
${ARGN})

list(APPEND RUST_BUILD_CARGO_ENV CARGO_HOME=${CMAKE_BINARY_DIR}/cargo_home)
Expand Down Expand Up @@ -233,7 +234,7 @@ function(build_rust_archives)
JOB_POOL cargo
WORKING_DIRECTORY ${RUST_BUILD_PACKAGE_DIR}
COMMAND ${CMAKE_COMMAND} -E env ${RUST_BUILD_CARGO_ENV}
${CARGO_BUILD_TOOL} build --lib --release --target ${ARCH} --target-dir ${RUST_BUILD_BINARY_DIR}
${CARGO_BUILD_TOOL} build --lib --release --target ${ARCH} --target-dir ${RUST_BUILD_BINARY_DIR} ${RUST_BUILD_EXTRA_ARGS}
)

## Outputs for the debug build
Expand All @@ -243,7 +244,7 @@ function(build_rust_archives)
JOB_POOL cargo
WORKING_DIRECTORY ${RUST_BUILD_PACKAGE_DIR}
COMMAND ${CMAKE_COMMAND} -E env ${RUST_BUILD_CARGO_ENV}
${CARGO_BUILD_TOOL} build --lib --target ${ARCH} --target-dir ${RUST_BUILD_BINARY_DIR}
${CARGO_BUILD_TOOL} build --lib --target ${ARCH} --target-dir ${RUST_BUILD_BINARY_DIR} ${RUST_BUILD_EXTRA_ARGS}
)

## Reset our policy changes
Expand All @@ -261,7 +262,7 @@ function(build_rust_archives)
${RUST_BUILD_BINARY_DIR}/${ARCH}/release/.noexist
WORKING_DIRECTORY ${RUST_BUILD_PACKAGE_DIR}
COMMAND ${CMAKE_COMMAND} -E env ${RUST_BUILD_CARGO_ENV}
${CARGO_BUILD_TOOL} build --lib --release --target ${ARCH} --target-dir ${RUST_BUILD_BINARY_DIR}
${CARGO_BUILD_TOOL} build --lib --release --target ${ARCH} --target-dir ${RUST_BUILD_BINARY_DIR} ${RUST_BUILD_EXTRA_ARGS}
)

## Outputs for the debug build
Expand All @@ -271,7 +272,7 @@ function(build_rust_archives)
${RUST_BUILD_BINARY_DIR}/${ARCH}/debug/.noexist
WORKING_DIRECTORY ${RUST_BUILD_PACKAGE_DIR}
COMMAND ${CMAKE_COMMAND} -E env ${RUST_BUILD_CARGO_ENV}
${CARGO_BUILD_TOOL} build --lib --target ${ARCH} --target-dir ${RUST_BUILD_BINARY_DIR}
${CARGO_BUILD_TOOL} build --lib --target ${ARCH} --target-dir ${RUST_BUILD_BINARY_DIR} ${RUST_BUILD_EXTRA_ARGS}
)
endif()
endfunction()
Expand All @@ -290,12 +291,13 @@ endfunction()
# DEPENDS: Additional files on which the target depends.
# SHARED: Whether or not we are building a shared library. Defaults to "false".
# FW_NAME: Standalone dylibs need to be wrapped in a framework for distribtuion. Required when building shared lib for iOS.
# FEATURES: Additional features to enable when building the crate.
#
function(add_rust_library TARGET_NAME)
cmake_parse_arguments(RUST_TARGET
""
"BINARY_DIR;PACKAGE_DIR;CRATE_NAME"
"ARCH;CARGO_ENV;DEPENDS;SHARED;FW_NAME"
"ARCH;CARGO_ENV;DEPENDS;SHARED;FW_NAME;FEATURES"
${ARGN})

if(NOT RUST_TARGET_SHARED)
Expand Down Expand Up @@ -347,6 +349,12 @@ function(add_rust_library TARGET_NAME)
endif()
endif()

set(RUST_TARGET_EXTRA_ARGS)
if(RUST_TARGET_FEATURES)
list(JOIN RUST_TARGET_FEATURES "," RUST_TARGET_FEATURES_JOINED)
list(APPEND RUST_TARGET_EXTRA_ARGS --features ${RUST_TARGET_FEATURES_JOINED})
endif()

get_rust_library_filename(${RUST_TARGET_SHARED} ${RUST_TARGET_CRATE_NAME})

## Build the rust library file(s)
Expand All @@ -358,6 +366,7 @@ function(add_rust_library TARGET_NAME)
CRATE_NAME ${RUST_TARGET_CRATE_NAME}
CARGO_ENV ${RUST_TARGET_CARGO_ENV}
SHARED ${RUST_TARGET_SHARED}
EXTRA_ARGS ${RUST_TARGET_EXTRA_ARGS}
)

if(RUST_TARGET_DEPENDS)
Expand Down
18 changes: 16 additions & 2 deletions src/cmake/macos-daemon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,27 @@ target_sources(daemon PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/macosdnsmanager.h
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/macosroutemonitor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/macosroutemonitor.h
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/wireguardutilsmacos.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/wireguardutilsmacos.h
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/wgsessionmacos.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/wgsessionmacos.h
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/wgsessionworker.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/wgsessionworker.h
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/wgutilsmacos.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/wgutilsmacos.h
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/xpcdaemonserver.h
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/daemon/xpcdaemonserver.mm
${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/xpcdaemonprotocol.h
)

# Build and link boringtun
add_rust_library(boringtun
PACKAGE_DIR ${CMAKE_SOURCE_DIR}/3rdparty/boringtun/boringtun
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
FEATURES ffi-bindings
CRATE_NAME boringtun
)
target_include_directories(daemon PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty/boringtun/boringtun/src)
target_link_libraries(daemon PRIVATE boringtun)

# Embed the daemon property list.
configure_file(${CMAKE_SOURCE_DIR}/macos/app/daemon.plist.in daemon.plist)
if(XCODE)
Expand Down
64 changes: 0 additions & 64 deletions src/cmake/macos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,70 +83,6 @@ target_sources(mozillavpn PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/update/balrog.h
)

# Build the Wireguard Go tunnel
file(GLOB_RECURSE WIREGUARD_GO_DEPS ${CMAKE_SOURCE_DIR}/3rdparty/wireguard-go/*.go)
set(WIREGUARD_GO_ENV
GOCACHE=${CMAKE_BINARY_DIR}/go-cache
CC=${CMAKE_C_COMPILER}
CXX=${CMAKE_CXX_COMPILER}
GOROOT=${GOLANG_GOROOT}
SDKROOT=${OSX_SDK_PATH}
MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
GOOS=darwin
CGO_ENABLED=1
GO111MODULE=on
)
if (CMAKE_CROSSCOMPILING)
list(APPEND WIREGUARD_GO_ENV
CGO_CFLAGS='-target ${CMAKE_SYSTEM_PROCESSOR}-apple-darwin${CMAKE_SYSTEM_VERSION}'
CGO_LDFLAGS='-target ${CMAKE_SYSTEM_PROCESSOR}-apple-darwin${CMAKE_SYSTEM_VERSION}'
)
endif()

if(CMAKE_OSX_ARCHITECTURES)
foreach(OSXARCH ${CMAKE_OSX_ARCHITECTURES})
string(REPLACE "x86_64" "amd64" GOARCH ${OSXARCH})
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/wireguard-go-${OSXARCH}
COMMENT "Building wireguard-go for ${OSXARCH}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/wireguard-go
DEPENDS
${WIREGUARD_GO_DEPS}
${CMAKE_SOURCE_DIR}/3rdparty/wireguard-go/go.mod
${CMAKE_SOURCE_DIR}/3rdparty/wireguard-go/go.sum
COMMAND ${CMAKE_COMMAND} -E env ${WIREGUARD_GO_ENV} GOARCH=${GOARCH}
${GOLANG_BUILD_TOOL} build -buildmode exe -buildvcs=false -trimpath -v -ldflags='-s -w'
-o ${CMAKE_CURRENT_BINARY_DIR}/wireguard-go-${OSXARCH}
)
list(APPEND WG_GO_ARCH_BUILDS ${CMAKE_CURRENT_BINARY_DIR}/wireguard-go-${OSXARCH})
endforeach()

add_custom_target(build_wireguard_go
COMMENT "Building wireguard-go"
DEPENDS ${WG_GO_ARCH_BUILDS}
COMMAND ${LIPO_BUILD_TOOL} -create -output ${CMAKE_CURRENT_BINARY_DIR}/wireguard-go ${WG_GO_ARCH_BUILDS}
)
else()
# This only builds for the host architecture.
add_custom_target(build_wireguard_go
COMMENT "Building wireguard-go"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/wireguard-go
DEPENDS
${WIREGUARD_GO_DEPS}
${CMAKE_SOURCE_DIR}/3rdparty/wireguard-go/go.mod
${CMAKE_SOURCE_DIR}/3rdparty/wireguard-go/go.sum
COMMAND ${CMAKE_COMMAND} -E env ${WIREGUARD_GO_ENV}
${GOLANG_BUILD_TOOL} build -buildmode exe -buildvcs=false -trimpath -v -ldflags='-s -w'
-o ${CMAKE_CURRENT_BINARY_DIR}/wireguard-go
)
endif()
add_dependencies(mozillavpn build_wireguard_go)
osx_codesign_target(build_wireguard_go FILES ${CMAKE_CURRENT_BINARY_DIR}/wireguard-go)
osx_bundle_files(mozillavpn
FILES ${CMAKE_CURRENT_BINARY_DIR}/wireguard-go
DESTINATION Resources/utils
)

# Install the daemon into the bundle.
add_dependencies(mozillavpn daemon)
osx_bundle_files(mozillavpn
Expand Down
40 changes: 1 addition & 39 deletions src/platforms/macos/daemon/iputilsmacos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#include "logger.h"
#include "macosdaemon.h"

constexpr uint32_t ETH_MTU = 1500;
constexpr uint32_t WG_MTU_OVERHEAD = 80;

namespace {
Logger logger("IPUtilsMacos");
}
Expand All @@ -42,43 +39,8 @@ bool IPUtilsMacos::addInterfaceIPs(const InterfaceConfig& config) {
}

bool IPUtilsMacos::setMTUAndUp(const InterfaceConfig& config) {
// Not implemented - this is handled by WgUtilsMacos
Q_UNUSED(config);
QString ifname = MacOSDaemon::instance()->m_wgutils->interfaceName();
struct ifreq ifr;

// Create socket file descriptor to perform the ioctl operations on
int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sockfd < 0) {
logger.error() << "Failed to create ioctl socket.";
return false;
}
auto guard = qScopeGuard([&] { close(sockfd); });

// MTU
strncpy(ifr.ifr_name, qPrintable(ifname), IFNAMSIZ);
ifr.ifr_mtu = ETH_MTU - WG_MTU_OVERHEAD;
int ret = ioctl(sockfd, SIOCSIFMTU, &ifr);
if (ret) {
logger.error() << "Failed to set MTU:" << strerror(errno);
return false;
}

// Get the interface flags
strncpy(ifr.ifr_name, qPrintable(ifname), IFNAMSIZ);
ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr);
if (ret) {
logger.error() << "Failed to get interface flags:" << strerror(errno);
return false;
}

// Up
ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
ret = ioctl(sockfd, SIOCSIFFLAGS, &ifr);
if (ret) {
logger.error() << "Failed to set device up:" << strerror(errno);
return false;
}

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/macos/daemon/macosdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ MacOSDaemon::MacOSDaemon(QObject* parent) : Daemon(parent) {

logger.debug() << "Daemon created";

m_wgutils = new WireguardUtilsMacos(this);
m_wgutils = new WgUtilsMacos(this);
m_dnsutils = new DnsUtilsMacos(this);
m_iputils = new IPUtilsMacos(this);

Expand Down
4 changes: 2 additions & 2 deletions src/platforms/macos/daemon/macosdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "daemon/daemon.h"
#include "dnsutilsmacos.h"
#include "iputilsmacos.h"
#include "wireguardutilsmacos.h"
#include "wgutilsmacos.h"

class MacOSDaemon final : public Daemon {
friend class IPUtilsMacos;
Expand All @@ -26,7 +26,7 @@ class MacOSDaemon final : public Daemon {
IPUtils* iputils() override { return m_iputils; }

private:
WireguardUtilsMacos* m_wgutils = nullptr;
WgUtilsMacos* m_wgutils = nullptr;
DnsUtilsMacos* m_dnsutils = nullptr;
IPUtilsMacos* m_iputils = nullptr;
};
Expand Down
5 changes: 5 additions & 0 deletions src/platforms/macos/daemon/macosroutemonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ void MacosRouteMonitor::handleRtmUpdate(const struct rt_msghdr* rtm,
return;
}

// Emit a signal that the default route has changed.
QHostAddress gateway(
reinterpret_cast<const struct sockaddr*>(addrlist[1].constData()));
emit defaultRouteUpdated(protocol, gateway, ifindex, rtm->rtm_rmx.rmx_mtu);

// Update the exclusion routes with the new default route.
logger.debug() << "Updating default route via" << ifname
<< addrToString(addrlist[1]);
Expand Down
4 changes: 4 additions & 0 deletions src/platforms/macos/daemon/macosroutemonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class MacosRouteMonitor final : public QObject {
const void* sa);
static QList<QByteArray> parseAddrList(const QByteArray& data);

signals:
void defaultRouteUpdated(int proto, QHostAddress& gateway, int ifindex,
int mtu);

private slots:
void rtsockReady();

Expand Down
Loading
Loading