diff --git a/netstack/src/scheme/netcfg/mod.rs b/netstack/src/scheme/netcfg/mod.rs index a29721b3fc..08235b81e2 100644 --- a/netstack/src/scheme/netcfg/mod.rs +++ b/netstack/src/scheme/netcfg/mod.rs @@ -2,6 +2,11 @@ mod nodes; mod notifier; +/// Default interface name served at the `/ifaces/` 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, 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, 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::() .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, 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, 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, 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(())