aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-11-18 18:30:18 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-11-18 18:30:18 +0100
commit9a00d1ba2c2c821b397a29fabd9ebec38a968e23 (patch)
tree1028f819c8e7d04d13b7cf07583d2d5bd730ce1b
parent697e7f4de49aa92d14b5070f82dffc1471b5b197 (diff)
update lease acquiration timestamp on sigusr2
-rw-r--r--src/client.rs6
-rw-r--r--src/main.rs15
2 files changed, 20 insertions, 1 deletions
diff --git a/src/client.rs b/src/client.rs
index fa90fba..5d2fcdb 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -221,6 +221,12 @@ impl Dhcp6c {
self.upper_status_rx.clone()
}
+ /// Returns a reference to the current internal lease if there is one,
+ /// or `None` otherwise.
+ pub fn lease(&self) -> Option<&Lease> {
+ self.lease.as_ref()
+ }
+
fn timeout_positive(&mut self) -> Option<Packet> {
match self.state {
Dhcp6cState::Starting | Dhcp6cState::Opened => None, // illegal
diff --git a/src/main.rs b/src/main.rs
index 4aa0b9a..2b761b9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,7 +9,7 @@ use std::time::SystemTime;
use tokio::net::UdpSocket;
use tokio::signal::unix::{signal, SignalKind};
-use tokio::time::{sleep, Duration};
+use tokio::time::{sleep, Duration, Instant};
use dhcproto::v6::{duid::Duid, DhcpOption, IAPrefix, Message, MessageType, OptionCode, IAPD, ORO};
use dhcproto::{Decodable, Decoder, Encodable, Encoder, Name};
@@ -113,6 +113,7 @@ async fn main() -> Result<()> {
let mut dhcp6c_rx = dhcp6c.opened();
let mut sigusr1 = signal(SignalKind::user_defined1())?;
+ let mut sigusr2 = signal(SignalKind::user_defined2())?;
let sock = Socket::new(Domain::IPV6, Type::DGRAM, None)?;
@@ -167,6 +168,18 @@ async fn main() -> Result<()> {
}
}
},
+ _ = sigusr2.recv() => {
+ if let Some(lease) = dhcp6c.lease() {
+ if let Some(pd_config) = dhcp6.lease.as_mut() {
+ pd_config.timestamp = SystemTime::now() - Instant::now().duration_since(lease.timestamp);
+
+ let mut file = File::create(rsdsl_pd_config::LOCATION)?;
+ serde_json::to_writer_pretty(&mut file, &pd_config)?;
+
+ println!("[info] <> update acquiration timestamp (ntp)");
+ }
+ }
+ },
packet = dhcp6c.to_send() => send_dhcp6(&mut dhcp6, &sock, packet).await,