Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve network logs #628

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading