diff options
-rw-r--r-- | Cargo.lock | 6 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/main.rs | 31 |
3 files changed, 34 insertions, 5 deletions
@@ -365,8 +365,8 @@ dependencies = [ [[package]] name = "rsdsl_ip_config" -version = "0.2.2" -source = "git+https://github.com/rsdsl/ip_config.git#3239a5eeef22de4c50d4d00a9f51bebb5207633c" +version = "0.2.3" +source = "git+https://github.com/rsdsl/ip_config.git#785ed5e7455297cf89a31387b396e4e8b1b3dc28" dependencies = [ "serde", ] @@ -393,7 +393,7 @@ dependencies = [ [[package]] name = "rsdsl_pd_config" version = "0.1.0" -source = "git+https://github.com/rsdsl/pd_config.git#98ee1876a08a1c3844d0b439a8ba52e5b3423810" +source = "git+https://github.com/rsdsl/pd_config.git#6cf4dbd588730396d5d03f5d01ad88ff37bf79b0" dependencies = [ "serde", ] @@ -12,7 +12,7 @@ futures-util = "0.3.27" ipnet = "2.8.0" libc = "0.2.149" netlink-packet-route = "0.17.0" -rsdsl_ip_config = { git = "https://github.com/rsdsl/ip_config.git", version = "0.2.2" } +rsdsl_ip_config = { git = "https://github.com/rsdsl/ip_config.git", version = "0.2.3" } rsdsl_pd_config = { git = "https://github.com/rsdsl/pd_config.git", version = "0.1.0" } rtnetlink = "0.13.1" serde_json = "1.0" diff --git a/src/main.rs b/src/main.rs index 4e681de..e659d9d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -105,7 +105,36 @@ fn configure_wan_logged() { } fn configure_wan() -> Result<()> { - todo!() + 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())?; + + if let Some(v4) = ds_config.v4 { + addr::add("ppp0".to_string(), v4.addr.into(), 32)?; + route::add4(Ipv4Addr::UNSPECIFIED, 0, None, "ppp0".to_string())?; + } + + if let Some(v6) = ds_config.v6 { + addr::add("ppp0".to_string(), v6.laddr.into(), 64)?; + route::add6(Ipv6Addr::UNSPECIFIED, 0, None, "ppp0".to_string())?; + } + } + + Ok(()) +} + +fn read_ds_config_optional() -> Option<DsConfig> { + let mut file = File::open(rsdsl_ip_config::LOCATION).ok()?; + serde_json::from_reader(&mut file).ok() +} + +fn read_pd_config_optional() -> Option<PdConfig> { + let mut file = File::open(rsdsl_pd_config::LOCATION).ok()?; + serde_json::from_reader(&mut file).ok() } fn next_ifid1<T: Iterator<Item = Ipv6Net>>(subnets: &mut T) -> Result<Ipv6Addr> { |