Skip to content
Merged
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
13 changes: 7 additions & 6 deletions src/socket/dhcpv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,9 @@ impl<'a> Socket<'a> {
// 0x0f * 4 = 60 bytes.
const MAX_IPV4_HEADER_LEN: usize = 60;

// We don't directly modify self.transaction_id because sending the packet
// may fail. We only want to update state after successfully sending.
let next_transaction_id = Self::random_transaction_id(cx);

let mut dhcp_repr = DhcpRepr {
message_type: DhcpMessageType::Discover,
transaction_id: next_transaction_id,
transaction_id: self.transaction_id,
secs: 0,
client_hardware_address: ethernet_addr,
client_ip: Ipv4Address::UNSPECIFIED,
Expand Down Expand Up @@ -624,6 +620,9 @@ impl<'a> Socket<'a> {
return Ok(());
}

let next_transaction_id = Self::random_transaction_id(cx);
dhcp_repr.transaction_id = next_transaction_id;

// send packet
net_debug!(
"DHCP send DISCOVER to {}: {:?}",
Expand Down Expand Up @@ -666,7 +665,6 @@ impl<'a> Socket<'a> {
+ (self.retry_config.initial_request_timeout << (state.retry as u32 / 2));
state.retry += 1;

self.transaction_id = next_transaction_id;
Ok(())
}
ClientState::Renewing(state) => {
Expand All @@ -692,6 +690,9 @@ impl<'a> Socket<'a> {
dhcp_repr.message_type = DhcpMessageType::Request;
dhcp_repr.client_ip = state.config.address.address();

let next_transaction_id = Self::random_transaction_id(cx);
dhcp_repr.transaction_id = next_transaction_id;

net_debug!("DHCP send renew to {}: {:?}", ipv4_repr.dst_addr, dhcp_repr);
ipv4_repr.payload_len = udp_repr.header_len() + dhcp_repr.buffer_len();
emit(cx, (ipv4_repr, udp_repr, dhcp_repr))?;
Expand Down