From 00db1e3bbcb563cd58012f9cbc501e77007edc0f Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Mon, 13 Nov 2023 14:22:03 +0100 Subject: fix informing of netlinkd when the ppp link goes down --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 23 ++++++++++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f673a13..558e035 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -462,7 +462,7 @@ dependencies = [ [[package]] name = "rsdsl_netlinkd" -version = "0.7.2" +version = "0.7.3" dependencies = [ "bitfield", "futures", diff --git a/Cargo.toml b/Cargo.toml index 2a98fd4..0b47ac4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rsdsl_netlinkd" -version = "0.7.2" +version = "0.7.3" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index f09685f..70d491d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -107,12 +107,17 @@ fn configure_wan_logged() { fn configure_wan() -> Result<()> { if let Some(ds_config) = read_ds_config_optional() { - link::set_mtu("ppp0".to_string(), 1492)?; - link::up("ppp0".to_string())?; - - // Deconfigure everything, just to be safe. - addr::flush("ppp0".to_string())?; - route::flush("ppp0".to_string())?; + // Only initialize the interface if an NCP is opened. + // This not being the case is a good indicator + // of the interface not being present due to not having a PPP session. + if ds_config.v4.is_some() || ds_config.v6.is_some() { + link::set_mtu("ppp0".to_string(), 1492)?; + link::up("ppp0".to_string())?; + + // Deconfigure everything, just to be safe. + addr::flush("ppp0".to_string())?; + route::flush("ppp0".to_string())?; + } if let Some(v4) = ds_config.v4 { addr::add("ppp0".to_string(), v4.addr.into(), 32)?; @@ -183,10 +188,10 @@ fn configure_wan() -> Result<()> { println!("[info] config dslite0 {}/29", ADDR_B4); } - } else { - // Deconfiguration is critical too, forward event to dhcp6. - inform_dhcp6(); } + } else { + // Deconfiguration is critical too, forward event to dhcp6. + inform_dhcp6(); } } -- cgit v1.2.3