Skip to content

Commit

Permalink
Shut down VPN connection when connection is lost.
Browse files Browse the repository at this point in the history
Simplified VPN polling code.
  • Loading branch information
zlogic committed Dec 2, 2024
1 parent d09aa16 commit 612b737
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/ikev2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,28 +269,27 @@ impl Server {
);
}
}
if let Some(vpn_status) = poll_result.vpn_status {
let can_recv = match vpn_status {
Ok(ready) => ready,
Err(err) => {
warn!("VPN reported an error status: {}", err);
false
let vpn_can_recv = match poll_result.vpn_status {
Some(Ok(ready)) => ready,
Some(Err(err)) => {
warn!("VPN reported an error status: {}", err);
if let Err(err) = vpn_service.start_disconnection(&rt) {
warn!("Failed to start VPN disconnection: {}", err);
}
};

let read_bytes = if can_recv {
match vpn_service.read_vpn_packet(&mut vpn_buffer).await {
Ok(bytes) => bytes,
Err(err) => {
warn!("Failed to receive packet from VPN: {}", err);
if let Err(err) = vpn_service.start_disconnection(&rt) {
warn!("Failed to start VPN disconnection: {}", err);
}
0
false
}
None => false,
};
if vpn_can_recv {
let read_bytes = match vpn_service.read_vpn_packet(&mut vpn_buffer).await {
Ok(bytes) => bytes,
Err(err) => {
warn!("Failed to receive packet from VPN: {}", err);
if let Err(err) = vpn_service.start_disconnection(&rt) {
warn!("Failed to start VPN disconnection: {}", err);
}
0
}
} else {
0
};
if let Err(err) = sessions
.process_vpn_packet(&mut vpn_buffer, read_bytes)
Expand Down

0 comments on commit 612b737

Please sign in to comment.