@@ -76,6 +76,7 @@ typedef struct {
76
76
uint32_t msg_tr_id ;
77
77
uint32_t message_tr_id ;
78
78
uint32_t first_transmit_time ;
79
+ uint16_t delayed_tx ;
79
80
uint16_t timeout ;
80
81
uint16_t timeout_init ;
81
82
uint16_t timeout_max ;
@@ -768,7 +769,7 @@ int dhcp_service_send_resp(uint32_t msg_tr_id, uint8_t options, uint8_t *msg_ptr
768
769
dhcp_tr_delete (msg_tr_ptr );
769
770
return 0 ;
770
771
}
771
- uint32_t dhcp_service_send_req (uint16_t instance_id , uint8_t options , void * ptr , const uint8_t addr [static 16 ], uint8_t * msg_ptr , uint16_t msg_len , dhcp_service_receive_resp_cb * receive_resp_cb )
772
+ uint32_t dhcp_service_send_req (uint16_t instance_id , uint8_t options , void * ptr , const uint8_t addr [static 16 ], uint8_t * msg_ptr , uint16_t msg_len , dhcp_service_receive_resp_cb * receive_resp_cb , uint16_t delay_tx )
772
773
{
773
774
tr_debug ("Send DHCPv6 request" );
774
775
msg_tr_t * msg_tr_ptr ;
@@ -792,7 +793,8 @@ uint32_t dhcp_service_send_req(uint16_t instance_id, uint8_t options, void *ptr,
792
793
msg_tr_ptr -> instance_id = instance_id ;
793
794
msg_tr_ptr -> socket = dhcp_service -> dhcp_client_socket ;
794
795
msg_tr_ptr -> recv_resp_cb = receive_resp_cb ;
795
- msg_tr_ptr -> first_transmit_time = protocol_core_monotonic_time ;
796
+ msg_tr_ptr -> delayed_tx = delay_tx ;
797
+ msg_tr_ptr -> first_transmit_time = protocol_core_monotonic_time + delay_tx ;
796
798
dhcp_tr_set_retry_timers (msg_tr_ptr , msg_tr_ptr -> msg_ptr [0 ]);
797
799
common_write_24_bit (msg_tr_ptr -> msg_tr_id , & msg_tr_ptr -> msg_ptr [1 ]);
798
800
@@ -911,12 +913,20 @@ void dhcp_service_send_message(msg_tr_t *msg_tr_ptr)
911
913
912
914
uint8_t * ptr = msg_tr_ptr -> relay_start ;
913
915
* ptr = DHCPV6_RELAY_REPLY ;
914
- retval = socket_sendmsg (msg_tr_ptr -> socket , & msghdr , NS_MSG_LEGACY0 );
916
+ if (msg_tr_ptr -> delayed_tx ) {
917
+ retval = 0 ;
918
+ } else {
919
+ retval = socket_sendmsg (msg_tr_ptr -> socket , & msghdr , NS_MSG_LEGACY0 );
920
+ }
915
921
916
922
} else {
917
- int16_t tc = 0 ;
918
- socket_setsockopt (msg_tr_ptr -> socket , SOCKET_IPPROTO_IPV6 , SOCKET_IPV6_TCLASS , & tc , sizeof (tc ));
919
- retval = socket_sendto (msg_tr_ptr -> socket , & msg_tr_ptr -> addr , msg_tr_ptr -> msg_ptr , msg_tr_ptr -> msg_len );
923
+ if (msg_tr_ptr -> delayed_tx ) {
924
+ retval = 0 ;
925
+ } else {
926
+ int16_t tc = 0 ;
927
+ socket_setsockopt (msg_tr_ptr -> socket , SOCKET_IPPROTO_IPV6 , SOCKET_IPV6_TCLASS , & tc , sizeof (tc ));
928
+ retval = socket_sendto (msg_tr_ptr -> socket , & msg_tr_ptr -> addr , msg_tr_ptr -> msg_ptr , msg_tr_ptr -> msg_len );
929
+ }
920
930
}
921
931
if (retval != 0 ) {
922
932
tr_warn ("dhcp service socket_sendto fails: %i" , retval );
@@ -928,6 +938,18 @@ bool dhcp_service_timer_tick(uint16_t ticks)
928
938
{
929
939
bool activeTimerNeed = false;
930
940
ns_list_foreach_safe (msg_tr_t , cur_ptr , & dhcp_service -> tr_list ) {
941
+
942
+ if (cur_ptr -> delayed_tx ) {
943
+ activeTimerNeed = true;
944
+ if (cur_ptr -> delayed_tx <= ticks ) {
945
+ cur_ptr -> delayed_tx = 0 ;
946
+ dhcp_service_send_message (cur_ptr );
947
+ } else {
948
+ cur_ptr -> delayed_tx -= ticks ;
949
+ }
950
+ continue ;
951
+ }
952
+
931
953
if (cur_ptr -> timeout == 0 ) {
932
954
continue ;
933
955
}
@@ -1023,7 +1045,7 @@ int dhcp_service_send_resp(uint32_t msg_tr_id, uint8_t options, uint8_t *msg_ptr
1023
1045
return -1 ;
1024
1046
}
1025
1047
1026
- uint32_t dhcp_service_send_req (uint16_t instance_id , uint8_t options , void * ptr , const uint8_t addr [static 16 ], uint8_t * msg_ptr , uint16_t msg_len , dhcp_service_receive_resp_cb * receive_resp_cb )
1048
+ uint32_t dhcp_service_send_req (uint16_t instance_id , uint8_t options , void * ptr , const uint8_t addr [static 16 ], uint8_t * msg_ptr , uint16_t msg_len , dhcp_service_receive_resp_cb * receive_resp_cb , uint16_t delay_tx )
1027
1049
{
1028
1050
(void )instance_id ;
1029
1051
(void )options ;
@@ -1032,6 +1054,7 @@ uint32_t dhcp_service_send_req(uint16_t instance_id, uint8_t options, void *ptr,
1032
1054
(void )msg_ptr ;
1033
1055
(void )msg_len ;
1034
1056
(void )receive_resp_cb ;
1057
+ (void )delay_tx ;
1035
1058
return 0 ;
1036
1059
}
1037
1060
0 commit comments