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
19 changes: 9 additions & 10 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "defguard_wireguard_rs"
version = "0.11.2"
version = "0.12.0"
edition = "2024"
rust-version = "1.91"
description = "A unified multi-platform high-level API for managing WireGuard interfaces"
Expand Down Expand Up @@ -36,7 +36,10 @@ windows = { version = "0.62", features = [
"Win32_NetworkManagement_IpHelper",
"Win32_NetworkManagement_Ndis",
"Win32_Networking_WinSock",
"Win32_Security",
"Win32_System_Com",
"Win32_System_LibraryLoader",
"Win32_System_Registry",
] }
wireguard-nt = "0.5"

Expand All @@ -48,9 +51,6 @@ netlink-packet-utils = "0.6"
netlink-packet-wireguard = "0.5"
netlink-sys = "0.9"

[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))'.dependencies]
regex = "1.12"

[features]
default = ["serde"]
check_dependencies = []
Expand Down
6 changes: 6 additions & 0 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use defguard_wireguard_rs::{
};
use x25519_dalek::{EphemeralSecret, PublicKey};

#[cfg(not(target_os = "netbsd"))]
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create new API object for interface
let ifname: String = if cfg!(target_os = "linux") || cfg!(target_os = "freebsd") {
Expand Down Expand Up @@ -57,3 +58,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

#[cfg(target_os = "netbsd")]
fn main() {
println!("This example is not for NetBSD");
}
6 changes: 6 additions & 0 deletions examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use defguard_wireguard_rs::{
};
use x25519_dalek::{EphemeralSecret, PublicKey};

#[cfg(not(target_os = "netbsd"))]
fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

Expand Down Expand Up @@ -91,3 +92,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

#[cfg(target_os = "netbsd")]
fn main() {
println!("This example is not for NetBSD");
}
3 changes: 3 additions & 0 deletions src/bsd/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ fn test_assign_address() {
fn test_get_mtu() {
let ifname = "lo0";
let mtu = get_mtu(ifname).unwrap();
#[cfg(not(target_os = "netbsd"))]
assert_eq!(mtu, 16384);
#[cfg(target_os = "netbsd")]
assert_eq!(mtu, 33624);
}
30 changes: 18 additions & 12 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use std::env;

#[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "netbsd"))]
use crate::dns::detect_dns_backend;
use crate::{error::WireguardInterfaceError, utils::get_command_path};

#[cfg(target_os = "linux")]
const COMMANDS: [&str; 2] = ["resolvconf", "ip"];

#[cfg(target_os = "windows")]
const COMMANDS: [&str; 0] = [];
const COMMANDS: [&str; 1] = ["ip"];

#[cfg(target_os = "macos")]
const COMMANDS: [&str; 1] = ["networksetup"];

#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
const COMMANDS: [&str; 1] = ["resolvconf"];
#[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "windows"))]
const COMMANDS: [&str; 0] = [];

pub(crate) fn check_external_dependencies() -> Result<(), WireguardInterfaceError> {
debug!("Checking if all commands required by wireguard-rs are available");
Expand All @@ -25,10 +24,17 @@ pub(crate) fn check_external_dependencies() -> Result<(), WireguardInterfaceErro
.iter()
.find(|cmd| get_command_path(cmd).map_or(true, |path_opt| path_opt.is_none()));

missing_command.map_or_else(|| {
debug!("All commands required by wireguard-rs are available");
Ok(())
}, |cmd| Err(WireguardInterfaceError::MissingDependency(format!(
"Command `{cmd}` required by wireguard-rs couldn't be found. The following directories were checked: {paths:?}"
))))
if let Some(cmd) = missing_command {
return Err(WireguardInterfaceError::MissingDependency(format!(
"Command `{cmd}` required by wireguard-rs couldn't be found. The following directories were checked: {paths:?}"
)));
}

// DNS can be configured through more than one backend, so check that at least one of them
// is available instead of requiring a specific command.
#[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "netbsd"))]
detect_dns_backend()?;

debug!("All commands required by wireguard-rs are available");
Ok(())
}
Loading
Loading