util: rename functions dealing with integers in NTP format

This should prevent confusion with int32_t, int64_t and other types.
This commit is contained in:
Miroslav Lichvar 2016-08-18 11:48:17 +02:00
parent d0dfa1de9e
commit 99cc94529d
3 changed files with 33 additions and 33 deletions

View file

@ -295,10 +295,10 @@ do_time_checks(void)
NTP_int64 nts1, nts2;
int r;
UTI_TimespecToInt64(&ts1, &nts1, NULL);
UTI_TimespecToInt64(&ts2, &nts2, NULL);
UTI_Int64ToTimespec(&nts1, &ts1);
UTI_Int64ToTimespec(&nts2, &ts2);
UTI_TimespecToNtp64(&ts1, &nts1, NULL);
UTI_TimespecToNtp64(&ts2, &nts2, NULL);
UTI_Ntp64ToTimespec(&nts1, &ts1);
UTI_Ntp64ToTimespec(&nts2, &ts2);
r = ts1.tv_sec == NTP_ERA_SPLIT &&
ts1.tv_sec + (1ULL << 32) - 1 == ts2.tv_sec;
@ -881,29 +881,29 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
/* If we're sending a client mode packet and we aren't synchronized yet,
we might have to set up artificial values for some of these parameters */
message.root_delay = UTI_DoubleToInt32(our_root_delay);
message.root_dispersion = UTI_DoubleToInt32(our_root_dispersion);
message.root_delay = UTI_DoubleToNtp32(our_root_delay);
message.root_dispersion = UTI_DoubleToNtp32(our_root_dispersion);
message.reference_id = htonl(our_ref_id);
/* Now fill in timestamps */
UTI_TimespecToInt64(&our_ref_time, &message.reference_ts, NULL);
UTI_TimespecToNtp64(&our_ref_time, &message.reference_ts, NULL);
/* Originate - this comes from the last packet the source sent us */
message.originate_ts = *orig_ts;
/* Prepare random bits which will be added to the receive timestamp */
UTI_GetInt64Fuzz(&ts_fuzz, precision);
UTI_GetNtp64Fuzz(&ts_fuzz, precision);
/* Receive - this is when we received the last packet from the source.
This timestamp will have been adjusted so that it will now look to
the source like we have been running on our latest estimate of
frequency all along */
UTI_TimespecToInt64(&local_receive, &message.receive_ts, &ts_fuzz);
UTI_TimespecToNtp64(&local_receive, &message.receive_ts, &ts_fuzz);
/* Prepare random bits which will be added to the transmit timestamp. */
UTI_GetInt64Fuzz(&ts_fuzz, precision);
UTI_GetNtp64Fuzz(&ts_fuzz, precision);
/* Transmit - this our local time right now! Also, we might need to
store this for our own use later, next time we receive a message
@ -923,7 +923,7 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
local_transmit.tv_nsec += auth_mode == AUTH_SYMMETRIC ?
KEY_GetAuthDelay(key_id) : NSD_GetAuthDelay(key_id);
UTI_NormaliseTimespec(&local_transmit);
UTI_TimespecToInt64(&local_transmit, &message.transmit_ts, &ts_fuzz);
UTI_TimespecToNtp64(&local_transmit, &message.transmit_ts, &ts_fuzz);
if (auth_mode == AUTH_SYMMETRIC) {
auth_len = KEY_GenerateAuth(key_id, (unsigned char *) &message,
@ -941,7 +941,7 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
return NSD_SignAndSendPacket(key_id, &message, where_to, from, length);
}
} else {
UTI_TimespecToInt64(&local_transmit, &message.transmit_ts, &ts_fuzz);
UTI_TimespecToNtp64(&local_transmit, &message.transmit_ts, &ts_fuzz);
}
ret = NIO_SendPacket(&message, where_to, from, length);
@ -1252,11 +1252,11 @@ receive_packet(NTP_Packet *message, struct timespec *now, double now_err, NCR_In
pkt_leap = NTP_LVM_TO_LEAP(message->lvm);
pkt_refid = ntohl(message->reference_id);
pkt_root_delay = UTI_Int32ToDouble(message->root_delay);
pkt_root_dispersion = UTI_Int32ToDouble(message->root_dispersion);
pkt_root_delay = UTI_Ntp32ToDouble(message->root_delay);
pkt_root_dispersion = UTI_Ntp32ToDouble(message->root_dispersion);
UTI_Int64ToTimespec(&message->receive_ts, &remote_receive);
UTI_Int64ToTimespec(&message->transmit_ts, &remote_transmit);
UTI_Ntp64ToTimespec(&message->receive_ts, &remote_receive);
UTI_Ntp64ToTimespec(&message->transmit_ts, &remote_transmit);
/* Check if the packet is valid per RFC 5905, section 8.
The test values are 1 when passed and 0 when failed. */
@ -1409,10 +1409,10 @@ receive_packet(NTP_Packet *message, struct timespec *now, double now_err, NCR_In
pkt_root_delay, pkt_root_dispersion, pkt_refid,
message->stratum == NTP_INVALID_STRATUM ? UTI_RefidToString(pkt_refid) : "");
DEBUG_LOG(LOGF_NtpCore, "reference=%s origin=%s receive=%s transmit=%s",
UTI_TimestampToString(&message->reference_ts),
UTI_TimestampToString(&message->originate_ts),
UTI_TimestampToString(&message->receive_ts),
UTI_TimestampToString(&message->transmit_ts));
UTI_Ntp64ToString(&message->reference_ts),
UTI_Ntp64ToString(&message->originate_ts),
UTI_Ntp64ToString(&message->receive_ts),
UTI_Ntp64ToString(&message->transmit_ts));
DEBUG_LOG(LOGF_NtpCore, "offset=%f delay=%f dispersion=%f root_delay=%f root_dispersion=%f",
offset, delay, dispersion, root_delay, root_dispersion);
DEBUG_LOG(LOGF_NtpCore, "test123=%d%d%d test567=%d%d%d testABCD=%d%d%d%d kod_rate=%d valid=%d good=%d",

14
util.c
View file

@ -245,10 +245,10 @@ UTI_TimespecToString(struct timespec *ts)
for diagnostic display */
char *
UTI_TimestampToString(NTP_int64 *ntp_ts)
UTI_Ntp64ToString(NTP_int64 *ntp_ts)
{
struct timespec ts;
UTI_Int64ToTimespec(ntp_ts, &ts);
UTI_Ntp64ToTimespec(ntp_ts, &ts);
return UTI_TimespecToString(&ts);
}
@ -617,7 +617,7 @@ UTI_AdjustTimespec(struct timespec *old_ts, struct timespec *when, struct timesp
/* ================================================== */
void
UTI_GetInt64Fuzz(NTP_int64 *ts, int precision)
UTI_GetNtp64Fuzz(NTP_int64 *ts, int precision)
{
int start, bits;
@ -636,7 +636,7 @@ UTI_GetInt64Fuzz(NTP_int64 *ts, int precision)
/* ================================================== */
double
UTI_Int32ToDouble(NTP_int32 x)
UTI_Ntp32ToDouble(NTP_int32 x)
{
return (double) ntohl(x) / 65536.0;
}
@ -646,7 +646,7 @@ UTI_Int32ToDouble(NTP_int32 x)
#define MAX_NTP_INT32 (4294967295.0 / 65536.0)
NTP_int32
UTI_DoubleToInt32(double x)
UTI_DoubleToNtp32(double x)
{
NTP_int32 r;
@ -674,7 +674,7 @@ UTI_DoubleToInt32(double x)
#define NSEC_PER_NTP64 4.294967296
void
UTI_TimespecToInt64(struct timespec *src, NTP_int64 *dest, NTP_int64 *fuzz)
UTI_TimespecToNtp64(struct timespec *src, NTP_int64 *dest, NTP_int64 *fuzz)
{
uint32_t hi, lo, sec, nsec;
@ -703,7 +703,7 @@ UTI_TimespecToInt64(struct timespec *src, NTP_int64 *dest, NTP_int64 *fuzz)
/* ================================================== */
void
UTI_Int64ToTimespec(NTP_int64 *src, struct timespec *dest)
UTI_Ntp64ToTimespec(NTP_int64 *src, struct timespec *dest)
{
uint32_t ntp_sec, ntp_frac;

12
util.h
View file

@ -92,7 +92,7 @@ extern char *UTI_TimespecToString(struct timespec *ts);
/* Convert an NTP timestamp into a temporary string, largely for
diagnostic display */
extern char *UTI_TimestampToString(NTP_int64 *ts);
extern char *UTI_Ntp64ToString(NTP_int64 *ts);
/* Convert ref_id into a temporary string, for diagnostics */
extern char *UTI_RefidToString(uint32_t ref_id);
@ -118,14 +118,14 @@ extern char *UTI_TimeToLogForm(time_t t);
extern void UTI_AdjustTimespec(struct timespec *old_ts, struct timespec *when, struct timespec *new_ts, double *delta_time, double dfreq, double doffset);
/* Get zero NTP timestamp with random bits below precision */
extern void UTI_GetInt64Fuzz(NTP_int64 *ts, int precision);
extern void UTI_GetNtp64Fuzz(NTP_int64 *ts, int precision);
extern double UTI_Int32ToDouble(NTP_int32 x);
extern NTP_int32 UTI_DoubleToInt32(double x);
extern double UTI_Ntp32ToDouble(NTP_int32 x);
extern NTP_int32 UTI_DoubleToNtp32(double x);
extern void UTI_TimespecToInt64(struct timespec *src, NTP_int64 *dest, NTP_int64 *fuzz);
extern void UTI_TimespecToNtp64(struct timespec *src, NTP_int64 *dest, NTP_int64 *fuzz);
extern void UTI_Int64ToTimespec(NTP_int64 *src, struct timespec *dest);
extern void UTI_Ntp64ToTimespec(NTP_int64 *src, struct timespec *dest);
/* Check if time + offset is sane */
extern int UTI_IsTimeOffsetSane(struct timespec *ts, double offset);