From fbb88ee2296121459ab17985857915b680ade8a4 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:58:28 +0200 Subject: [PATCH] change some logs under linux (#79) * change some logs under linux * fmt --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/utils.rs | 2 +- src/wgapi_freebsd.rs | 12 +++++++++--- src/wgapi_linux.rs | 31 +++++++++++++++++++++++-------- src/wgapi_userspace.rs | 9 ++++++--- 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73f351c..3d8502f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -151,7 +151,7 @@ dependencies = [ [[package]] name = "defguard_wireguard_rs" -version = "0.5.4" +version = "0.5.5" dependencies = [ "base64", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index f4de18e..77866dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "defguard_wireguard_rs" -version = "0.5.4" +version = "0.5.5" edition = "2021" description = "A unified multi-platform high-level API for managing WireGuard interfaces" license = "Apache-2.0" diff --git a/src/utils.rs b/src/utils.rs index 1ce8833..f588c42 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -156,7 +156,7 @@ pub(crate) fn clear_dns(ifname: &str) -> Result<(), WireguardInterfaceError> { let mut cmd = Command::new("resolvconf"); let output = cmd.args(args).output()?; check_command_output_status(output)?; - info!("DNS configuration removed successfully for interface {ifname}"); + debug!("DNS configuration removed successfully for interface {ifname}"); Ok(()) } diff --git a/src/wgapi_freebsd.rs b/src/wgapi_freebsd.rs index 12fd364..c5aeb70 100644 --- a/src/wgapi_freebsd.rs +++ b/src/wgapi_freebsd.rs @@ -75,11 +75,17 @@ impl WireguardInterfaceApi for WGApi { ); self.assign_address(&address)?; // configure interface - debug!("Setting host configuration for interface {}", self.ifname); + debug!( + "Applying the WireGuard host configuration for interface {}", + self.ifname + ); let host = config.try_into()?; bsd::set_host(&self.ifname, &host)?; - debug!("Host configuration set for interface {}.", self.ifname); - trace!("Host configuration: {host:?}"); + debug!( + "WireGuard host configuration set for interface {}.", + self.ifname + ); + trace!("WireGuard host configuration: {host:?}"); // Set maximum transfer unit (MTU). if let Some(mtu) = config.mtu { diff --git a/src/wgapi_linux.rs b/src/wgapi_linux.rs index 3cb5a32..2d4b8f6 100644 --- a/src/wgapi_linux.rs +++ b/src/wgapi_linux.rs @@ -40,9 +40,15 @@ impl WireguardInterfaceApi for WGApi { ); // flush all IP addresses - debug!("Flushing all IP addresses from interface {}", self.ifname); + debug!( + "Flushing all existing IP addresses from interface {} before assigning a new one", + self.ifname + ); netlink::flush_interface(&self.ifname)?; - debug!("All IP addresses flushed from interface {}", self.ifname); + debug!( + "All existing IP addresses flushed from interface {}", + self.ifname + ); // assign IP address to interface debug!( @@ -57,11 +63,17 @@ impl WireguardInterfaceApi for WGApi { ); // configure interface - debug!("Setting host configuration for interface {}", self.ifname); + debug!( + "Applying the WireGuard host configuration for interface {}", + self.ifname + ); let host = config.try_into()?; netlink::set_host(&self.ifname, &host)?; - debug!("Host configuration set for interface {}.", self.ifname); - trace!("Host configuration: {host:?}"); + debug!( + "WireGuard host configuration set for interface {}.", + self.ifname + ); + trace!("WireGuard host configuration: {host:?}"); // set maximum transfer unit if let Some(mtu) = config.mtu { @@ -102,12 +114,15 @@ impl WireguardInterfaceApi for WGApi { fn remove_interface(&self) -> Result<(), WireguardInterfaceError> { debug!( - "Removing interface {}. Getting its host configuration first...", + "Removing interface {}. Getting its WireGuard host configuration first...", self.ifname ); let host = netlink::get_host(&self.ifname)?; - debug!("Host configuration read for interface {}", self.ifname); - trace!("Host configuration: {host:?}"); + debug!( + "WireGuard host configuration read for interface {}", + self.ifname + ); + trace!("WireGuard host configuration: {host:?}"); if let Some(fwmark) = host.fwmark { if fwmark != 0 { debug!("Cleaning fwmark rules for interface {}", self.ifname); diff --git a/src/wgapi_userspace.rs b/src/wgapi_userspace.rs index 78cff22..37b13fd 100644 --- a/src/wgapi_userspace.rs +++ b/src/wgapi_userspace.rs @@ -184,13 +184,16 @@ impl WireguardInterfaceApi for WGApi { // configure interface debug!( - "Applying the interface configuration to interface {}", + "Applying the WireGuard host configuration for interface {}", self.ifname ); let host = config.try_into()?; self.write_host(&host)?; - debug!("Interface configuration set for interface {}.", self.ifname); - trace!("Interface configuration: {host:?}"); + debug!( + "WireGuard host configuration set for interface {}.", + self.ifname + ); + trace!("WireGuard host configuration: {host:?}"); // Set maximum transfer unit (MTU). if let Some(mtu) = config.mtu {