From d039af7234b4e884e9d9fe3561d879610e0c82cf Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 19 Apr 2026 22:17:51 +0200 Subject: [PATCH] Fix #1458: 'show ntp tracking' does not show reference id properly admin@gateway:~$ chronyc tracking Reference ID : C23ACD14 (svl1.ntp.netnod.se) Stratum : 2 Ref time (UTC) : Sun Apr 19 20:28:40 2026 System time : 0.000000000 seconds fast of NTP time Last offset : -17.822519302 seconds RMS offset : 17.822519302 seconds Frequency : 1064.750 ppm slow Residual freq : +0.581 ppm Skew : 0.794 ppm Root delay : 0.018065268 seconds Root dispersion : 0.000200240 seconds Update interval : 0.0 seconds Leap status : Normal vs admin@gateway:/> show ntp tracking Reference ID : 194.58.205.20 Stratum : 2 Ref time (UTC) : Sun Apr 19 20:28:40 2026 System time : 0.000000 seconds slow of NTP time Last offset : -17.822519302 seconds RMS offset : 17.822519302 seconds Frequency : 1064.750 ppm slow Residual freq : +0.581 ppm Skew : 0.794 ppm Root delay : 0.018065 seconds Root dispersion : 0.000188 seconds Update interval : 0.0 seconds Leap status : Normal Signed-off-by: Joachim Wiberg --- src/statd/python/yanger/ietf_ntp.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/statd/python/yanger/ietf_ntp.py b/src/statd/python/yanger/ietf_ntp.py index 80c80e2e..58022c8c 100644 --- a/src/statd/python/yanger/ietf_ntp.py +++ b/src/statd/python/yanger/ietf_ntp.py @@ -191,9 +191,20 @@ def add_ntp_clock_state(out): refid_ip = parts[0] refid_name = parts[1] - if refid_name: - # NTP refids are always 4 bytes; chronyc strips trailing padding. - # YANG typedef 'refid' requires exactly length 4 for strings. + def _is_ipv4(s): + p = s.split('.') + if len(p) != 4: + return False + try: + return all(0 <= int(x) <= 255 for x in p) + except ValueError: + return False + + if refid_name and _is_ipv4(refid_name): + # chronyc reports the IPv4 server address as the name field; use it directly + system_status["clock-refid"] = refid_name + elif refid_name and ':' not in refid_name: + # Short NTP code (GPS, NIST, INIT, …); YANG refid requires length 4 system_status["clock-refid"] = refid_name.ljust(4)[:4] elif refid_ip and len(refid_ip) == 8: try: