Skip to content

Commit

Permalink
dhcpv4: Replace the DiscoveryTimeout timer when discovery done
Browse files Browse the repository at this point in the history
We should replace `DiscoveryTimeout` timer with `RequestTimeout` when
the discovery is done and entering request phase.

Manually tested by checking debug logs of
`cargo run --example mozim_dhcpv4_async`.

DHCPv6 part does not have this problem as it only single retry timer
`DhcpV6Event::TransmitWait`.

Signed-off-by: Gris Ge <[email protected]>
  • Loading branch information
cathay4t committed Jan 6, 2025
1 parent 8f97403 commit e574d5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/dhcpv4/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,14 @@ impl DhcpV4Client {
return Ok(None);
}
};
self.phase = DhcpV4Phase::Request;
socket.send(&self.gen_request_pkg(&lease).to_eth_pkg_broadcast()?)?;
self.event_pool.add_timer(
Duration::from_secs(gen_dhcp_request_delay(0).into()),
DhcpV4Event::RequestTimeout,
)?;
self.retry_count = 0;
self.event_pool.del_timer(DhcpV4Event::DiscoveryTimeout)?;
self.phase = DhcpV4Phase::Request;
Ok(None)
}

Expand Down Expand Up @@ -221,6 +227,7 @@ impl DhcpV4Client {
};
self.clean_up();
self.lease = Some(lease.clone());
self.event_pool.del_timer(DhcpV4Event::RequestTimeout)?;
self.set_renew_rebind_timer(&lease)?;
Ok(Some(lease))
}
Expand Down
1 change: 1 addition & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ impl<T: DhcpEvent> DhcpEventPool<T> {
if let Some(timer_fd) = self.timer_fds.remove(&event) {
self.epoll.del_fd(timer_fd.as_raw_fd())?;
}
log::debug!("Deleted timer {event} from event pool");
Ok(())
}

Expand Down

0 comments on commit e574d5f

Please sign in to comment.