Skip to content

Commit

Permalink
dhcpv4: Remove todo!()
Browse files Browse the repository at this point in the history
Instead of panic on unknown phase, we generate a error message and move
on.

Signed-off-by: Gris Ge <[email protected]>
  • Loading branch information
cathay4t committed Dec 15, 2024
1 parent 7f1dd30 commit f0d93aa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
34 changes: 32 additions & 2 deletions src/dhcpv4/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ impl Default for DhcpV4Phase {
}
}

impl std::fmt::Display for DhcpV4Phase {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Self::Done => "done",
Self::Discovery => "discovery",
Self::Request => "request",
Self::Renew => "renew",
Self::Rebind => "rebind",
}
)
}
}

#[derive(Debug)]
pub struct DhcpV4Client {
config: DhcpV4Config,
Expand Down Expand Up @@ -494,11 +510,25 @@ impl DhcpV4Client {
DhcpV4Phase::Discovery => self.process_discovery(),
DhcpV4Phase::Request => self.process_request(),
DhcpV4Phase::Rebind => self.process_rebind_recv(),
_ => todo!(),
_ => {
log::error!(
"BUG: Got in-coming packet on raw socket \
with unexpected phase {}",
self.phase
);
Ok(None)
}
},
DhcpV4Event::UdpPackageIn => match self.phase {
DhcpV4Phase::Renew => self.process_renew_recv(),
_ => todo!(),
_ => {
log::error!(
"BUG: Got in-coming packet on UDP socket \
with unexpected phase {}",
self.phase
);
Ok(None)
}
},
DhcpV4Event::RequestTimeout => self.process_request_timeout(),
DhcpV4Event::DiscoveryTimeout => self.process_discovery_timeout(),
Expand Down
2 changes: 0 additions & 2 deletions src/integ_tests/dhcpv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ fn test_dhcpv4_manual_client_id() {

let lease = get_lease(&mut cli);

println!("HAHA {:?}", lease);

assert!(lease.is_some());
if let Some(lease) = lease {
// Even though we didn't send it in the DHCP request, dnsmasq should
Expand Down

0 comments on commit f0d93aa

Please sign in to comment.