From: Martin Burnicki Date: Tue, 19 Jun 2018 10:30:58 +0000 (+0200) Subject: New macro REFID_IS_TEXT(). X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2421956b556b5b52ae55448739f6ad9d6076c5b;p=thirdparty%2Fntp.git New macro REFID_IS_TEXT(). bk: 5b28db62QmYo5BRwW7ggxo1-uj8j-A --- diff --git a/ChangeLog b/ChangeLog index dcfa59c07..61e886ebd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ + New macro REFID_ISTEXT() which is also used in ntpd/ntp_control.c. + --- (4.2.8p11) 2018/02/27 Released by Harlan Stenn @@ -12,7 +14,7 @@ * [Sec 3012] Sybil vulnerability: noepeer support. HStenn, JPerlinger. * [Bug 3457] OpenSSL FIPS mode regression * [Bug 3455] ntpd doesn't use scope id when binding multicast - - applied patch by Sean Haugh + - applied patch by Sean Haugh * [Bug 3452] PARSE driver prints uninitialized memory. * [Bug 3450] Dubious error messages from plausibility checks in get_systime() - removed error log caused by rounding/slew, ensured postcondition diff --git a/include/ntp.h b/include/ntp.h index fb739c756..cfbb7d2e7 100644 --- a/include/ntp.h +++ b/include/ntp.h @@ -610,6 +610,18 @@ struct pkt { #define STRATUM_TO_PKT(s) ((u_char)(((s) == (STRATUM_UNSPEC)) ?\ (STRATUM_PKT_UNSPEC) : (s))) + +/* + * A test to determine if the refid should be interpreted as text string. + * This is usually the case for a refclock, which has stratum 0 internally, + * which results in sys_stratum 1 if the refclock becomes system peer, or + * in case of a kiss-of-death (KoD) packet that has STRATUM_PKT_UNSPEC (==0) + * in the packet which is converted to STRATUM_UNSPEC when the packet + * is evaluated. + */ +#define REFID_ISTEXT(s) (((s) <= 1) || ((s) >= STRATUM_UNSPEC)) + + /* * Event codes. Used for reporting errors/events to the control module */ diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index f908d41fa..72cb8c43b 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -1951,10 +1951,10 @@ ctl_putsys( break; case CS_REFID: - if (sys_stratum > 1 && sys_stratum < STRATUM_UNSPEC) - ctl_putadr(sys_var[varid].text, sys_refid, NULL); - else + if (REFID_ISTEXT(sys_stratum)) ctl_putrefid(sys_var[varid].text, sys_refid); + else + ctl_putadr(sys_var[varid].text, sys_refid, NULL); break; case CS_REFTIME: @@ -2678,11 +2678,10 @@ ctl_putpeer( break; } #endif - if (p->stratum > 1 && p->stratum < STRATUM_UNSPEC) - ctl_putadr(peer_var[id].text, p->refid, - NULL); - else + if (REFID_ISTEXT(p->stratum)) ctl_putrefid(peer_var[id].text, p->refid); + else + ctl_putadr(peer_var[id].text, p->refid, NULL); break; case CP_REFTIME: