Skip to content

Commit

Permalink
Improve network logs (#628)
Browse files Browse the repository at this point in the history
* Split kernel net log

* Log net config changes
  • Loading branch information
vinc authored May 29, 2024
1 parent 7ee3003 commit 420579b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/sys/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,10 @@ const E1000_DEVICES: [u16; 9] = [

pub fn init() {
let add = |mut device: EthernetDevice, name| {
log!("NET DRV {}", name);
if let Some(mac) = device.config().mac() {
let addr = format!("{}", mac).to_uppercase();
log!("NET {} MAC {}", name, addr);
log!("NET MAC {}", addr);

let config = smoltcp::iface::Config::new(mac.into());
let iface = Interface::new(config, &mut device, time());
Expand Down
3 changes: 0 additions & 3 deletions src/usr/dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,17 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> {

if let Some((address, router, dns_servers)) = dhcp_config {
shell::exec(&format!("net config ip {}", address)).ok();
shell::exec("net config ip").ok();

if let Some(router) = router {
shell::exec(&format!("net config gw {}", router)).ok();
} else {
shell::exec("net config gw 0.0.0.0").ok();
}
shell::exec("net config gw").ok();

let dns: Vec<_> = dns_servers.iter().map(|s| s.to_string()).collect();
if !dns.is_empty() {
shell::exec(&format!("net config dns {}", dns.join(","))).ok();
}
shell::exec("net config dns").ok();

return Ok(());
}
Expand Down
6 changes: 5 additions & 1 deletion src/usr/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub fn set_config(attribute: &str, value: &str) {
iface.update_ip_addrs(|addrs| {
addrs.clear();
addrs.push(addr).unwrap();
log!("NET IP {}", value);
});
} else {
error!("Network error");
Expand All @@ -205,6 +206,7 @@ pub fn set_config(attribute: &str, value: &str) {
iface.routes_mut().remove_default_ipv4_route();
} else if let Ok(ip) = Ipv4Address::from_str(value) {
iface.routes_mut().add_default_ipv4_route(ip).unwrap();
log!("NET GW {}", value);
} else {
error!("Could not parse address");
}
Expand All @@ -216,7 +218,9 @@ pub fn set_config(attribute: &str, value: &str) {
let servers = value.trim();
if servers.split(',').all(|s| Ipv4Address::from_str(s).is_ok()) {
let s = format!("{}\n", servers);
if fs::write(DNS_FILE, s.as_bytes()).is_err() {
if fs::write(DNS_FILE, s.as_bytes()).is_ok() {
log!("NET DNS {}", servers);
} else {
error!("Could not write to '{}'", DNS_FILE);
}
} else {
Expand Down

0 comments on commit 420579b

Please sign in to comment.