Skip to content

Commit 4cb4918

Browse files
author
Maciej Wójcik
committed
handle interface removal errors
1 parent 0d70f97 commit 4cb4918

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ pub enum WireguardInterfaceError {
3333
KernelNotSupported,
3434
#[error("DNS error: {0}")]
3535
DnsError(String),
36+
#[cfg(target_os = "windows")]
3637
#[error("Service installation failed: `{message}`")]
3738
ServiceInstallationFailed {
3839
err: std::io::Error,
3940
message: String,
4041
},
42+
#[cfg(target_os = "windows")]
43+
#[error("Tunnel service removal failed: `{0}`")]
44+
ServiceRemovalFailed(String),
4145
#[error("Socket is closed: {0}")]
4246
SocketClosed(String),
4347
}

src/wgapi_windows.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl WireguardInterfaceApi for WGApi<Kernel> {
251251
fn remove_interface(&self) -> Result<(), WireguardInterfaceError> {
252252
debug!("Removing interface {}", self.ifname);
253253

254-
Command::new("wireguard")
254+
let command_output = Command::new("wireguard")
255255
.arg("/uninstalltunnelservice")
256256
.arg(&self.ifname)
257257
.output()
@@ -260,6 +260,14 @@ impl WireguardInterfaceApi for WGApi<Kernel> {
260260
WireguardInterfaceError::CommandExecutionFailed(err)
261261
})?;
262262

263+
if !command_output.status.success() {
264+
let message = format!(
265+
"Failed to remove WireGuard tunnel service: {:?}",
266+
command_output.stdout
267+
);
268+
return Err(WireguardInterfaceError::ServiceRemovalError { message });
269+
}
270+
263271
info!("Interface {} removed successfully", self.ifname);
264272
Ok(())
265273
}

0 commit comments

Comments
 (0)