diff --git a/kernel/net/mod.rs b/kernel/net/mod.rs index 143dbc46..230971e8 100644 --- a/kernel/net/mod.rs +++ b/kernel/net/mod.rs @@ -67,29 +67,31 @@ pub(self) static SOCKET_WAIT_QUEUE: Once = Once::new(); pub fn process_packets() { let mut sockets = SOCKETS.lock(); let mut iface = INTERFACE.lock(); - let mut dhcp = DHCP_CLIENT.lock(); let timestamp = read_monotonic_clock().into(); loop { - if let Some(config) = dhcp - .poll(&mut iface, &mut sockets, timestamp) - .unwrap_or_else(|e| { - trace!("DHCP: {:?}", e); - None - }) - { - if let Some(cidr) = config.address { - iface.update_ip_addrs(|addrs| { - if let Some(addr) = addrs.iter_mut().next() { - *addr = IpCidr::Ipv4(cidr); - } - }); - info!("DHCP: got a IPv4 address: {}", cidr); + if *DHCP_ENABLED { + let mut dhcp = DHCP_CLIENT.lock(); + if let Some(config) = dhcp + .poll(&mut iface, &mut sockets, timestamp) + .unwrap_or_else(|e| { + trace!("DHCP: {:?}", e); + None + }) + { + if let Some(cidr) = config.address { + iface.update_ip_addrs(|addrs| { + if let Some(addr) = addrs.iter_mut().next() { + *addr = IpCidr::Ipv4(cidr); + } + }); + info!("DHCP: got a IPv4 address: {}", cidr); + } + + config + .router + .map(|router| iface.routes_mut().add_default_ipv4_route(router).unwrap()); } - - config - .router - .map(|router| iface.routes_mut().add_default_ipv4_route(router).unwrap()); } match iface.poll(&mut sockets, timestamp) { @@ -103,14 +105,17 @@ pub fn process_packets() { } } - SOCKET_WAIT_QUEUE.wake_all(); - POLL_WAIT_QUEUE.wake_all(); + if *DHCP_ENABLED { + let dhcp = DHCP_CLIENT.lock(); + dhcp.next_poll(timestamp); + } - // TODO: timeout - let mut _timeout = dhcp.next_poll(timestamp); - if let Some(sockets_timeout) = iface.poll_delay(&sockets, timestamp) { - _timeout = sockets_timeout; + if let Some(_timeout) = iface.poll_delay(&sockets, timestamp) { + // TODO: Use timeout } + + SOCKET_WAIT_QUEUE.wake_all(); + POLL_WAIT_QUEUE.wake_all(); } struct OurRxToken { diff --git a/libs/virtio/transports/virtio_pci_legacy.rs b/libs/virtio/transports/virtio_pci_legacy.rs index 77581dfd..e49eb635 100644 --- a/libs/virtio/transports/virtio_pci_legacy.rs +++ b/libs/virtio/transports/virtio_pci_legacy.rs @@ -62,7 +62,6 @@ impl VirtioTransport for VirtioLegacyPci { } fn read_device_status(&self) -> u8 { - info!("read dev"); self.port_base.read8(REG_DEVICE_STATUS) }