aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2025-04-05 16:01:12 +0200
committerHimbeer <himbeer@disroot.org>2025-04-05 16:01:12 +0200
commit2788c6fe38dc5b1e49f40058d026427a43c24fc8 (patch)
treeeeac3f90025f66d64a2246a8027a3ca119cd08e5
parent541c0603d38f1340d033878658fc55073b022c77 (diff)
Fix overflow in DHCPv6 client remaining seconds calculation
This fixes an issue where overflows (e.g. due to time mismatches between router and manager) cause the DHCPv6 client display logic to crash. Now, 0 is displayed instead.
-rw-r--r--src-tauri/src/main.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index da58602..5bb2103 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -151,13 +151,11 @@ impl Dhcpv6Status {
impl From<Dhcpv6Lease> for Dhcpv6Status {
fn from(lease: Dhcpv6Lease) -> Self {
let validity = if lease.is_valid() { "✅" } else { "❌" };
+ let localnow = Local::now();
+ let ts = DateTime::<Local>::from(lease.timestamp);
Self {
- timestamp: format!(
- "{} {}",
- validity,
- DateTime::<Local>::from(lease.timestamp).format("%d.%m.%Y %H:%M:%S UTC%Z")
- ),
+ timestamp: format!("{} {}", validity, ts.format("%d.%m.%Y %H:%M:%S UTC%Z")),
srvaddr: if lease.server
== SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, 0, 0, 0))
{
@@ -173,7 +171,7 @@ impl From<Dhcpv6Lease> for Dhcpv6Status {
} else {
let remaining_secs = std::cmp::max(
(Duration::from_secs(lease.t1.into())
- - lease.timestamp.elapsed().unwrap_or(Duration::ZERO))
+ .saturating_sub(lease.timestamp.elapsed().unwrap_or(Duration::ZERO)))
.as_secs(),
0,
);
@@ -189,7 +187,7 @@ impl From<Dhcpv6Lease> for Dhcpv6Status {
} else {
let remaining_secs = std::cmp::max(
(Duration::from_secs(lease.t2.into())
- - lease.timestamp.elapsed().unwrap_or(Duration::ZERO))
+ .saturating_sub(lease.timestamp.elapsed().unwrap_or(Duration::ZERO)))
.as_secs(),
0,
);
@@ -207,7 +205,7 @@ impl From<Dhcpv6Lease> for Dhcpv6Status {
} else {
let remaining_secs = std::cmp::max(
(Duration::from_secs(lease.preflft.into())
- - lease.timestamp.elapsed().unwrap_or(Duration::ZERO))
+ .saturating_sub(lease.timestamp.elapsed().unwrap_or(Duration::ZERO)))
.as_secs(),
0,
);
@@ -223,7 +221,7 @@ impl From<Dhcpv6Lease> for Dhcpv6Status {
} else {
let remaining_secs = std::cmp::max(
(Duration::from_secs(lease.validlft.into())
- - lease.timestamp.elapsed().unwrap_or(Duration::ZERO))
+ .saturating_sub(lease.timestamp.elapsed().unwrap_or(Duration::ZERO)))
.as_secs(),
0,
);