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

net: Fix for dhcp=off #135

Merged
merged 1 commit into from
Dec 18, 2021
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
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