netstack: centralize 'eth0' in DEFAULT_IFACE constant (21 sites)
The netcfg scheme's 'ifaces' subtree had 21 hardcoded 'eth0' literals — one in the routing tree path and 20 in device lookups. This made any non-eth0 interface (wlan0, enp3s0, etc.) invisible to netcfg's ifaces config path. The 'ifaces' routing tree is statically routed (compile-time key in the dispatch! macro), so a full schema refactor to runtime-keyed map is out of scope for this minimal change. Instead, this commit: 1. Introduces DEFAULT_IFACE: &str = 'eth0' const at the top of src/scheme/netcfg/mod.rs (with a docstring explaining the architectural choice and the follow-up path). 2. Replaces all 21 hardcoded 'eth0' literals with the DEFAULT_IFACE constant. The routing tree path uses DEFAULT_IFACE in the dispatch! macro expansion; the device lookups use DEFAULT_IFACE in devices.borrow().get(DEFAULT_IFACE). This is a pure refactor — no behavior change for the default 'eth0' case. Future work: convert the routing tree to runtime-keyed so a system with wlan0 as primary can serve the ifaces subtree at /ifaces/wlan0/... Found by the Round 12 audit (local/docs/3D-DESKTOP-COMPREHENSIVE-PLAN.md §10).
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
mod nodes;
|
||||
mod notifier;
|
||||
|
||||
/// Default interface name served at the `/ifaces/<name>` scheme path.
|
||||
/// Centralizes the historical `eth0` choice so future schema refactors
|
||||
/// can change it in one place. Follow-up work: runtime-keyed routing map.
|
||||
const DEFAULT_IFACE: &str = "eth0";
|
||||
|
||||
use redox_scheme::{
|
||||
scheme::{register_scheme_inner, SchemeState, SchemeSync},
|
||||
CallerCtx, OpenResult, RequestKind, SignalBehavior, Socket,
|
||||
@@ -513,11 +518,11 @@ fn mk_root_node(
|
||||
}
|
||||
},
|
||||
"ifaces" => {
|
||||
"eth0" => {
|
||||
DEFAULT_IFACE => {
|
||||
"mac" => {
|
||||
rw [iface, notifier, devices] (Option<EthernetAddress>, None)
|
||||
|| {
|
||||
match devices.borrow().get("eth0") {
|
||||
match devices.borrow().get(DEFAULT_IFACE) {
|
||||
Some(dev) => {
|
||||
match dev.mac_address() {
|
||||
Some(addr) => format!("{addr}\n"),
|
||||
@@ -542,7 +547,7 @@ fn mk_root_node(
|
||||
}
|
||||
|cur_value| {
|
||||
if let Some(mac) = *cur_value {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut("eth0") {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut(DEFAULT_IFACE) {
|
||||
dev.set_mac_address(mac);
|
||||
notifier.borrow_mut().schedule_notify("ifaces/eth0/mac");
|
||||
}
|
||||
@@ -554,7 +559,7 @@ fn mk_root_node(
|
||||
"list" => {
|
||||
ro [devices]
|
||||
|| {
|
||||
let res = match devices.borrow().get("eth0") {
|
||||
let res = match devices.borrow().get(DEFAULT_IFACE) {
|
||||
Some(dev) => {
|
||||
match dev.ip_address() {
|
||||
Some(addr) => format!("{addr}\n"),
|
||||
@@ -584,7 +589,7 @@ fn mk_root_node(
|
||||
|cur_value| {
|
||||
// TODO: Multiple IPs
|
||||
if let Some(cidr) = cur_value.take() {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut("eth0") {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut(DEFAULT_IFACE) {
|
||||
|
||||
let mut route_table = route_table.borrow_mut();
|
||||
if let Some(old_addr) = dev.ip_address() {
|
||||
@@ -628,7 +633,7 @@ fn mk_root_node(
|
||||
"arp" => {
|
||||
"list" => {
|
||||
ro [devices] || {
|
||||
match devices.borrow().get("eth0") {
|
||||
match devices.borrow().get(DEFAULT_IFACE) {
|
||||
Some(dev) => dev.arp_table(),
|
||||
None => "Device not found\n".into(),
|
||||
}
|
||||
@@ -636,7 +641,7 @@ fn mk_root_node(
|
||||
},
|
||||
"stats" => {
|
||||
ro [devices] || {
|
||||
match devices.borrow().get("eth0") {
|
||||
match devices.borrow().get(DEFAULT_IFACE) {
|
||||
Some(dev) => dev.arp_stats(),
|
||||
None => "Device not found\n".into(),
|
||||
}
|
||||
@@ -654,7 +659,7 @@ fn mk_root_node(
|
||||
}
|
||||
|cur_value| {
|
||||
*cur_value = None;
|
||||
if let Some(dev) = devices.borrow_mut().get_mut("eth0") {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut(DEFAULT_IFACE) {
|
||||
dev.flush_arp();
|
||||
}
|
||||
Ok(())
|
||||
@@ -683,7 +688,7 @@ fn mk_root_node(
|
||||
if idx != 6 {
|
||||
return Err(SyscallError::new(syscall::EINVAL));
|
||||
}
|
||||
if let Some(dev) = devices.borrow_mut().get_mut("eth0") {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut(DEFAULT_IFACE) {
|
||||
dev.add_static_neighbor(ip, mac).map_err(|_| {
|
||||
SyscallError::new(syscall::EINVAL)
|
||||
})?;
|
||||
@@ -699,7 +704,7 @@ fn mk_root_node(
|
||||
|_cur_value, line| {
|
||||
let ip: IpAddress = line.trim().parse()
|
||||
.map_err(|_| SyscallError::new(syscall::EINVAL))?;
|
||||
if let Some(dev) = devices.borrow_mut().get_mut("eth0") {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut(DEFAULT_IFACE) {
|
||||
if !dev.remove_neighbor(ip) {
|
||||
return Err(SyscallError::new(syscall::ENOENT));
|
||||
}
|
||||
@@ -713,7 +718,7 @@ fn mk_root_node(
|
||||
},
|
||||
"stats" => {
|
||||
ro [devices] || {
|
||||
match devices.borrow().get("eth0") {
|
||||
match devices.borrow().get(DEFAULT_IFACE) {
|
||||
Some(dev) => {
|
||||
let s = dev.statistics();
|
||||
format!("rx_bytes={} rx_packets={} tx_bytes={} tx_packets={} rx_errors={} tx_errors={} rx_dropped={} tx_dropped={} mtu={} link={}\n",
|
||||
@@ -727,7 +732,7 @@ fn mk_root_node(
|
||||
},
|
||||
"link" => {
|
||||
ro [devices] || {
|
||||
match devices.borrow().get("eth0") {
|
||||
match devices.borrow().get(DEFAULT_IFACE) {
|
||||
Some(dev) => format!("{}\n", dev.link_state()),
|
||||
None => "Device not found\n".into(),
|
||||
}
|
||||
@@ -736,7 +741,7 @@ fn mk_root_node(
|
||||
"mtu" => {
|
||||
rw [devices] (Option<usize>, None)
|
||||
|| {
|
||||
match devices.borrow().get("eth0") {
|
||||
match devices.borrow().get(DEFAULT_IFACE) {
|
||||
Some(dev) => format!("{}\n", dev.mtu()),
|
||||
None => "Device not found\n".into(),
|
||||
}
|
||||
@@ -744,7 +749,7 @@ fn mk_root_node(
|
||||
|cur_value, line| {
|
||||
let mtu = line.trim().parse::<usize>()
|
||||
.map_err(|_| SyscallError::new(syscall::EINVAL))?;
|
||||
if let Some(dev) = devices.borrow_mut().get_mut("eth0") {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut(DEFAULT_IFACE) {
|
||||
dev.set_mtu(mtu);
|
||||
*cur_value = Some(mtu);
|
||||
Ok(())
|
||||
@@ -757,14 +762,14 @@ fn mk_root_node(
|
||||
"qdisc" => {
|
||||
rw [devices] (Option<String>, None)
|
||||
|| {
|
||||
match devices.borrow().get("eth0") {
|
||||
match devices.borrow().get(DEFAULT_IFACE) {
|
||||
Some(dev) => dev.qdisc_info(),
|
||||
None => "Device not found\n".into(),
|
||||
}
|
||||
}
|
||||
|cur_value, line| {
|
||||
let kind = line.trim().to_string();
|
||||
if let Some(dev) = devices.borrow_mut().get_mut("eth0") {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut(DEFAULT_IFACE) {
|
||||
dev.set_qdisc(&kind).map_err(|e| {
|
||||
SyscallError::new(syscall::EINVAL)
|
||||
})?;
|
||||
@@ -779,7 +784,7 @@ fn mk_root_node(
|
||||
"enabled" => {
|
||||
rw [devices] (Option<bool>, None)
|
||||
|| {
|
||||
match devices.borrow().get("eth0") {
|
||||
match devices.borrow().get(DEFAULT_IFACE) {
|
||||
Some(dev) => if dev.is_enabled() { "up\n".to_string() } else { "down\n".to_string() },
|
||||
None => "Device not found\n".into(),
|
||||
}
|
||||
@@ -788,7 +793,7 @@ fn mk_root_node(
|
||||
let s = line.trim();
|
||||
match s {
|
||||
"up" | "1" | "true" | "yes" | "on" => {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut("eth0") {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut(DEFAULT_IFACE) {
|
||||
dev.set_enabled(true);
|
||||
*cur_value = Some(true);
|
||||
Ok(())
|
||||
@@ -797,7 +802,7 @@ fn mk_root_node(
|
||||
}
|
||||
}
|
||||
"down" | "0" | "false" | "no" | "off" => {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut("eth0") {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut(DEFAULT_IFACE) {
|
||||
dev.set_enabled(false);
|
||||
*cur_value = Some(false);
|
||||
Ok(())
|
||||
@@ -813,7 +818,7 @@ fn mk_root_node(
|
||||
"promiscuous" => {
|
||||
rw [devices] (Option<bool>, None)
|
||||
|| {
|
||||
match devices.borrow().get("eth0") {
|
||||
match devices.borrow().get(DEFAULT_IFACE) {
|
||||
Some(dev) => if dev.is_promiscuous() { "on\n".to_string() } else { "off\n".to_string() },
|
||||
None => "Device not found\n".into(),
|
||||
}
|
||||
@@ -825,7 +830,7 @@ fn mk_root_node(
|
||||
"off" | "0" | "false" | "no" => false,
|
||||
_ => return Err(SyscallError::new(syscall::EINVAL)),
|
||||
};
|
||||
if let Some(dev) = devices.borrow_mut().get_mut("eth0") {
|
||||
if let Some(dev) = devices.borrow_mut().get_mut(DEFAULT_IFACE) {
|
||||
dev.set_promiscuous(enabled);
|
||||
*cur_value = Some(enabled);
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user