aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/error.rs2
-rw-r--r--src/main.rs29
2 files changed, 31 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index 5999027..6ade514 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -32,6 +32,8 @@ pub enum Error {
DhcprotoDecode(#[from] dhcproto::error::DecodeError),
#[error("dhcproto encode: {0}")]
DhcprotoEncode(#[from] dhcproto::error::EncodeError),
+ #[error("notify: {0}")]
+ Notify(#[from] notify::Error),
#[error("rsdsl_netlinkd: {0}")]
RsdslNetlinkd(#[from] rsdsl_netlinkd::error::Error),
#[error("serde_json: {0}")]
diff --git a/src/main.rs b/src/main.rs
index 4054785..6b50a0d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,6 +3,7 @@ use std::fs::File;
use std::mem::MaybeUninit;
use std::net::{Ipv6Addr, SocketAddr, SocketAddrV6};
use std::os::fd::AsRawFd;
+use std::path::Path;
use std::process;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
@@ -11,6 +12,8 @@ use std::time::{Duration, Instant};
use dhcproto::v6::{duid::Duid, DhcpOption, IAPrefix, Message, MessageType, OptionCode, IAPD, ORO};
use dhcproto::{Decodable, Decoder, Encodable, Encoder, Name};
+use notify::event::{CreateKind, ModifyKind};
+use notify::{Event, EventKind, RecursiveMode, Watcher};
use rsdsl_dhcp6::util::setsockopt;
use rsdsl_dhcp6::{Error, Result};
use rsdsl_ip_config::DsConfig;
@@ -44,6 +47,13 @@ fn main() -> Result<()> {
println!("wait for up ppp0");
link::wait_up("ppp0".into())?;
+ let ds_config = Path::new(rsdsl_ip_config::LOCATION);
+
+ println!("wait for pppoe");
+ while !ds_config.exists() {
+ thread::sleep(Duration::from_secs(8));
+ }
+
let mut file = File::open(rsdsl_ip_config::LOCATION)?;
let dsconfig: DsConfig = serde_json::from_reader(&mut file)?;
@@ -98,6 +108,20 @@ fn main() -> Result<()> {
thread::sleep(Duration::from_secs(3));
});
+ let state2 = state.clone();
+ let mut watcher = notify::recommended_watcher(move |res: notify::Result<Event>| match res {
+ Ok(event) => match event.kind {
+ EventKind::Create(kind) if kind == CreateKind::File => restart(state2.clone()),
+ EventKind::Modify(kind) if matches!(kind, ModifyKind::Data(_)) => {
+ restart(state2.clone())
+ }
+ _ => {}
+ },
+ Err(e) => println!("watch error: {:?}", e),
+ })?;
+
+ watcher.watch(ds_config, RecursiveMode::NonRecursive)?;
+
loop {
let mut buf = [MaybeUninit::new(0); BUFSIZE];
let (n, remote) = sock.recv_from(&mut buf)?;
@@ -550,3 +574,8 @@ fn write_pdconfig(ia_prefix: &IAPrefix, dnss: &[Ipv6Addr], aftr: &Option<String>
Ok(())
}
+
+fn restart(state: Arc<Mutex<State>>) {
+ *state.lock().expect("state mutex is poisoned") = State::default();
+ println!("reinitialize reconnected pppoe");
+}