Skip to content

Commit

Permalink
Fix FreeBSD build
Browse files Browse the repository at this point in the history
  • Loading branch information
moubctez committed Jan 18, 2025
1 parent 74dafcb commit b14bdb8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
39 changes: 23 additions & 16 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions src/netlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ where
}

/// Create WireGuard interface.
/// Note: maximum 15 characters for `ifname`.
pub(crate) fn create_interface(ifname: &str) -> NetlinkResult<()> {
let mut message = LinkMessage::default();
message.header.flags = LinkFlags::Up;
Expand Down
26 changes: 11 additions & 15 deletions src/wgapi_freebsd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{net::IpAddr, str::FromStr};
use std::net::IpAddr;

use crate::{
bsd,
Expand All @@ -14,7 +14,7 @@ use crate::{
impl WireguardInterfaceApi for WGApi<Kernel> {
/// Creates a WireGuard network interface.
fn create_interface(&self) -> Result<(), WireguardInterfaceError> {
bsd::load_wireguard_kernel_module();
let _ = bsd::load_wireguard_kernel_module();
debug!("Creating interface {}", &self.ifname);
bsd::create_interface(&self.ifname)?;
debug!("Interface {} created successfully", &self.ifname);
Expand Down Expand Up @@ -64,17 +64,11 @@ impl WireguardInterfaceApi for WGApi<Kernel> {
self.ifname
);

// assign IP address to interface
debug!(
"Parsing address {} for interface {}",
config.address, self.ifname
);
let address = IpAddrMask::from_str(&config.address)?;
debug!(
"Address {} parsed successfully for interface {}",
config.address, self.ifname
);
self.assign_address(&address)?;
// Assign IP address to the interface.
for address in &config.addresses {
self.assign_address(address)?;
}

// configure interface
debug!(
"Applying the WireGuard host configuration for interface {}",
Expand All @@ -99,13 +93,15 @@ impl WireguardInterfaceApi for WGApi<Kernel> {
}

info!(
"Interface {} has been successfully configured. It has been assigned the following address: {}",
self.ifname, address
"Interface {} has been successfully configured. \
It has been assigned the following addresses: {:?}",
self.ifname, config.addresses
);
debug!(
"Interface {} configured with config: {config:?}",
self.ifname
);

Ok(())
}

Expand Down

0 comments on commit b14bdb8

Please sign in to comment.