Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
102 changes: 54 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "defguard_wireguard_rs"
version = "0.9.5"
version = "0.9.6"
edition = "2024"
rust-version = "1.87"
description = "A unified multi-platform high-level API for managing WireGuard interfaces"
Expand Down Expand Up @@ -44,7 +44,7 @@ wireguard-nt = "0.5"
[target.'cfg(target_os = "linux")'.dependencies]
netlink-packet-core = "0.8"
netlink-packet-generic = "0.4"
netlink-packet-route = "0.29"
netlink-packet-route = "0.30"
netlink-packet-utils = "0.6"
netlink-packet-wireguard = "0.3"
netlink-sys = "0.8"
Expand Down
23 changes: 17 additions & 6 deletions src/bsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,26 @@ pub fn delete_peer(if_name: &str, public_key: &Key) -> Result<(), IoError> {
wg_data.write_data()
}

#[cfg(target_os = "freebsd")]
#[link(name = "c")]
unsafe extern "C" {
// Note: libc crate doesn't export kldload.
fn kldload(file: *const libc::c_char) -> libc::c_int;
}

#[cfg(target_os = "freebsd")]
pub fn load_wireguard_kernel_module() -> Result<(), IoError> {
// Ignore the return value for the time being.
let retval = unsafe { libc::kld_load(c"if_wg".as_ptr()) };
if retval == 0 {
Ok(())
} else {
Err(IoError::KernelModule)
// Prefer kldload(2) to kld_load(3).
// The latter needs libutil, which differs between FreeBSD 14 and 15.
let retval = unsafe { kldload(c"if_wg".as_ptr()) };
// Based on https://github.com/freebsd/freebsd-src/blob/main/lib/libutil/kld.c#L70
if retval == -1 {
let err = std::io::Error::last_os_error();
if err.raw_os_error() != Some(libc::EEXIST) {
return Err(IoError::KernelModule);
}
}
Ok(())
}

pub fn create_interface(if_name: &str) -> Result<(), IoError> {
Expand Down