mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-04 01:45:07 -05:00
ntp: move authentication calls in transmit_packet()
Move the calls resetting and generating authentication data out of the loop checking for unique TX timestamp. This allows the timestamps to be manipulated after the check.
This commit is contained in:
24
ntp_core.c
24
ntp_core.c
@@ -1054,10 +1054,10 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
|
|||||||
UTI_ZeroNtp64(&message.receive_ts);
|
UTI_ZeroNtp64(&message.receive_ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
|
||||||
if (!parse_packet(&message, NTP_HEADER_LENGTH, &info))
|
if (!parse_packet(&message, NTP_HEADER_LENGTH, &info))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
do {
|
||||||
/* Prepare random bits which will be added to the transmit timestamp */
|
/* Prepare random bits which will be added to the transmit timestamp */
|
||||||
UTI_GetNtp64Fuzz(&ts_fuzz, precision);
|
UTI_GetNtp64Fuzz(&ts_fuzz, precision);
|
||||||
|
|
||||||
@@ -1072,6 +1072,17 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
|
|||||||
UTI_TimespecToNtp64(interleaved ? &local_tx->ts : &local_transmit,
|
UTI_TimespecToNtp64(interleaved ? &local_tx->ts : &local_transmit,
|
||||||
&message.transmit_ts, &ts_fuzz);
|
&message.transmit_ts, &ts_fuzz);
|
||||||
|
|
||||||
|
/* Do not send a packet with a non-zero transmit timestamp which is
|
||||||
|
equal to any of the following timestamps:
|
||||||
|
- receive (to allow reliable detection of the interleaved mode)
|
||||||
|
- originate (to prevent the packet from being its own valid response
|
||||||
|
in the symmetric mode)
|
||||||
|
- previous transmit (to invalidate responses to the previous packet)
|
||||||
|
(the precision must be at least -30 to prevent an infinite loop!) */
|
||||||
|
} while (!UTI_IsZeroNtp64(&message.transmit_ts) &&
|
||||||
|
UTI_IsEqualAnyNtp64(&message.transmit_ts, &message.receive_ts,
|
||||||
|
&message.originate_ts, local_ntp_tx));
|
||||||
|
|
||||||
/* Generate the authentication data */
|
/* Generate the authentication data */
|
||||||
if (auth) {
|
if (auth) {
|
||||||
if (!NAU_GenerateRequestAuth(auth, &message, &info)) {
|
if (!NAU_GenerateRequestAuth(auth, &message, &info)) {
|
||||||
@@ -1086,17 +1097,6 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do not send a packet with a non-zero transmit timestamp which is
|
|
||||||
equal to any of the following timestamps:
|
|
||||||
- receive (to allow reliable detection of the interleaved mode)
|
|
||||||
- originate (to prevent the packet from being its own valid response
|
|
||||||
in the symmetric mode)
|
|
||||||
- previous transmit (to invalidate responses to the previous packet)
|
|
||||||
(the precision must be at least -30 to prevent an infinite loop!) */
|
|
||||||
} while (!UTI_IsZeroNtp64(&message.transmit_ts) &&
|
|
||||||
UTI_IsEqualAnyNtp64(&message.transmit_ts, &message.receive_ts,
|
|
||||||
&message.originate_ts, local_ntp_tx));
|
|
||||||
|
|
||||||
if (request_info && request_info->length < info.length) {
|
if (request_info && request_info->length < info.length) {
|
||||||
DEBUG_LOG("Response longer than request req_len=%d res_len=%d",
|
DEBUG_LOG("Response longer than request req_len=%d res_len=%d",
|
||||||
request_info->length, info.length);
|
request_info->length, info.length);
|
||||||
|
|||||||
Reference in New Issue
Block a user