diff options
author | Himbeer <himbeer@disroot.org> | 2025-03-18 15:46:57 +0100 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2025-03-18 15:47:50 +0100 |
commit | 23c170d7ee9a485f9136dfbf1da02e9a72df1cd0 (patch) | |
tree | 3f88117af0a33c7dca53be3319f185d746595df2 | |
parent | f023bacabe03d7b522823283f2fb207ee56689bd (diff) |
This includes assigning metrics to default routes in such a way that
native connectivity is always preferred over DS-Lite.
-rw-r--r-- | Cargo.lock | 4 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/main.rs | 36 |
3 files changed, 31 insertions, 11 deletions
@@ -434,8 +434,8 @@ dependencies = [ [[package]] name = "rsdsl_netlinklib" -version = "0.5.0" -source = "git+https://github.com/rsdsl/netlinklib.git#7fae1fc884ecfe234e96b96f0a60d469905272ba" +version = "0.6.0" +source = "git+https://github.com/rsdsl/netlinklib.git#2567498ff9646c4ad6a11d4f2e0380b100cb9f1f" dependencies = [ "futures", "libc", @@ -12,7 +12,7 @@ netlink-packet-netfilter = "0.2.0" netlink-packet-utils = "0.5.2" netlink-sys = { version = "0.8.5", features = ["tokio", "tokio_socket"] } rsdsl_ip_config = { git = "https://github.com/rsdsl/ip_config.git", version = "0.3.0" } -rsdsl_netlinklib = { git = "https://github.com/rsdsl/netlinklib.git", version = "0.5.0", features = ["blocking"] } +rsdsl_netlinklib = { git = "https://github.com/rsdsl/netlinklib.git", features = ["blocking"] } rsdsl_pd_config = { git = "https://github.com/rsdsl/pd_config.git", version = "0.1.0" } serde_json = "1.0" signal-hook = "0.3.17" diff --git a/src/main.rs b/src/main.rs index 457930f..b6f44ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use rsdsl_netlinklib::blocking::Connection; +use rsdsl_netlinklib::route::{Route4, Route6}; use std::fs::{self, File}; use std::io; @@ -196,14 +197,30 @@ fn configure_wan(conn: &Connection) -> Result<()> { if let Some(v4) = ds_config.v4 { conn.address_add("ppp0".to_string(), v4.addr.into(), 32)?; - conn.route_add4(Ipv4Addr::UNSPECIFIED, 0, None, "ppp0".to_string())?; + conn.route_add4(Route4 { + dst: Ipv4Addr::UNSPECIFIED, + prefix_len: 0, + rtr: None, + on_link: false, + table: None, + metric: Some(100), + link: String::from("ppp0"), + })?; println!("[info] config ppp0 {}/32", v4.addr); } if let Some(v6) = ds_config.v6 { conn.address_add_link_local("ppp0".to_string(), v6.laddr.into(), 64)?; - conn.route_add6(Ipv6Addr::UNSPECIFIED, 0, None, "ppp0".to_string())?; + conn.route_add6(Route6 { + dst: Ipv6Addr::UNSPECIFIED, + prefix_len: 0, + rtr: None, + on_link: false, + table: None, + metric: Some(100), + link: String::from("ppp0"), + })?; println!("[info] config ppp0 ll {}/64", v6.laddr); @@ -255,12 +272,15 @@ fn configure_wan(conn: &Connection) -> Result<()> { conn.address_add("dslite0".to_string(), ADDR_B4.into(), 29)?; if ds_config.v4.is_none() { - conn.route_add4( - Ipv4Addr::UNSPECIFIED, - 0, - Some(ADDR_AFTR), - "dslite0".to_string(), - )?; + conn.route_add4(Route4 { + dst: Ipv4Addr::UNSPECIFIED, + prefix_len: 0, + rtr: Some(ADDR_AFTR), + on_link: false, + table: None, + metric: Some(50), + link: String::from("dslite0"), + })?; } println!("[info] config dslite0 {}/29", ADDR_B4); |