Skip to content

Commit

Permalink
net: Fix for dhcp=off (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuta authored Dec 18, 2021
1 parent 3ad3260 commit 76d7565
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
55 changes: 30 additions & 25 deletions kernel/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,31 @@ pub(self) static SOCKET_WAIT_QUEUE: Once<WaitQueue> = 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) {
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion libs/virtio/transports/virtio_pci_legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ impl VirtioTransport for VirtioLegacyPci {
}

fn read_device_status(&self) -> u8 {
info!("read dev");
self.port_base.read8(REG_DEVICE_STATUS)
}

Expand Down

0 comments on commit 76d7565

Please sign in to comment.