@@ -574,13 +574,9 @@ impl<'a> Socket<'a> {
574574 // 0x0f * 4 = 60 bytes.
575575 const MAX_IPV4_HEADER_LEN : usize = 60 ;
576576
577- // We don't directly modify self.transaction_id because sending the packet
578- // may fail. We only want to update state after successfully sending.
579- let next_transaction_id = Self :: random_transaction_id ( cx) ;
580-
581577 let mut dhcp_repr = DhcpRepr {
582578 message_type : DhcpMessageType :: Discover ,
583- transaction_id : next_transaction_id ,
579+ transaction_id : self . transaction_id ,
584580 secs : 0 ,
585581 client_hardware_address : ethernet_addr,
586582 client_ip : Ipv4Address :: UNSPECIFIED ,
@@ -624,6 +620,9 @@ impl<'a> Socket<'a> {
624620 return Ok ( ( ) ) ;
625621 }
626622
623+ let next_transaction_id = Self :: random_transaction_id ( cx) ;
624+ dhcp_repr. transaction_id = next_transaction_id;
625+
627626 // send packet
628627 net_debug ! (
629628 "DHCP send DISCOVER to {}: {:?}" ,
@@ -666,7 +665,6 @@ impl<'a> Socket<'a> {
666665 + ( self . retry_config . initial_request_timeout << ( state. retry as u32 / 2 ) ) ;
667666 state. retry += 1 ;
668667
669- self . transaction_id = next_transaction_id;
670668 Ok ( ( ) )
671669 }
672670 ClientState :: Renewing ( state) => {
@@ -692,6 +690,9 @@ impl<'a> Socket<'a> {
692690 dhcp_repr. message_type = DhcpMessageType :: Request ;
693691 dhcp_repr. client_ip = state. config . address . address ( ) ;
694692
693+ let next_transaction_id = Self :: random_transaction_id ( cx) ;
694+ dhcp_repr. transaction_id = next_transaction_id;
695+
695696 net_debug ! ( "DHCP send renew to {}: {:?}" , ipv4_repr. dst_addr, dhcp_repr) ;
696697 ipv4_repr. payload_len = udp_repr. header_len ( ) + dhcp_repr. buffer_len ( ) ;
697698 emit ( cx, ( ipv4_repr, udp_repr, dhcp_repr) ) ?;
0 commit comments