route: add /scheme/netcfg/route/gateway read-only node

Reads the default gateway from the route table:
  cat /scheme/netcfg/route/gateway
  →  'default via 192.168.1.1\n'
or 'no default route\n' if no default gateway configured.

Looks up the route for 0.0.0.0 (the default route CIDR) and
returns its 'via' address. Mirrors Linux 'ip route show default'.
This commit is contained in:
Red Bear OS
2026-07-08 18:44:55 +03:00
parent 649ba27669
commit 1fad3ab869
+11
View File
@@ -266,6 +266,17 @@ fn mk_root_node(
format!("routes: {}\n", count)
}
},
"gateway" => {
ro [route_table] || {
let table = route_table.borrow();
let zero: IpAddress = IpAddress::v4(0, 0, 0, 0);
let gw = table.lookup_gateway(&zero);
match gw {
Some(addr) => format!("default via {}\n", addr),
None => "no default route\n".to_string(),
}
}
},
"add" => {
wo [iface, notifier, route_table] (Option<Rule>, None)
|cur_value, line| {