From: Miroslav Lichvar Date: Thu, 21 Sep 2023 09:02:24 +0000 (+0200) Subject: ntp: add function for detection of experimental fields X-Git-Tag: 4.5-pre1~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07134f262518de5e4d7dcd99300ed503e8fa3b8f;p=thirdparty%2Fchrony.git ntp: add function for detection of experimental fields --- diff --git a/ntp_core.c b/ntp_core.c index d67c1522..0e415731 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -1492,6 +1492,14 @@ is_zero_data(unsigned char *data, int length) /* ================================================== */ +static int +is_exp_ef(void *body, int body_length, int expected_body_length, uint32_t magic) +{ + return body_length == expected_body_length && *(uint32_t *)body == htonl(magic); +} + +/* ================================================== */ + static int parse_packet(NTP_Packet *packet, int length, NTP_PacketInfo *info) { @@ -1579,8 +1587,8 @@ parse_packet(NTP_Packet *packet, int length, NTP_PacketInfo *info) info->auth.mode = NTP_AUTH_NTS; break; case NTP_EF_EXP_MONO_ROOT: - if (ef_body_length == sizeof (NTP_EFExpMonoRoot) && - ntohl(((NTP_EFExpMonoRoot *)ef_body)->magic) == NTP_EF_EXP_MONO_ROOT_MAGIC) + if (is_exp_ef(ef_body, ef_body_length, sizeof (NTP_EFExpMonoRoot), + NTP_EF_EXP_MONO_ROOT_MAGIC)) info->ext_field_flags |= NTP_EF_FLAG_EXP_MONO_ROOT; break; default: @@ -1893,8 +1901,8 @@ process_response(NCR_Instance inst, int saved, NTP_Local_Address *local_addr, switch (ef_type) { case NTP_EF_EXP_MONO_ROOT: if (inst->ext_field_flags & NTP_EF_FLAG_EXP_MONO_ROOT && - ef_body_length == sizeof (*ef_mono_root) && - ntohl(((NTP_EFExpMonoRoot *)ef_body)->magic) == NTP_EF_EXP_MONO_ROOT_MAGIC) + is_exp_ef(ef_body, ef_body_length, sizeof (*ef_mono_root), + NTP_EF_EXP_MONO_ROOT_MAGIC)) ef_mono_root = ef_body; break; }