diff --git a/.chrony.metadata b/.chrony.metadata index e898eed..5d00761 100644 --- a/.chrony.metadata +++ b/.chrony.metadata @@ -1,2 +1,2 @@ -564dd010a10fbdcc7c177337115ccffa43fe0f95 SOURCES/chrony-3.1.tar.gz -922f475728383b56b03eeadaf990c9231a51a9e3 SOURCES/clknetsim-ce89a1.tar.gz +64db6c31e013222cc0a2b66322192b4cedf6e048 SOURCES/chrony-3.2.tar.gz +a56b3edc67f6af8c42775c2004fa8e5c09cc9be8 SOURCES/clknetsim-71dbbc.tar.gz diff --git a/.gitignore b/.gitignore index 6c4aebf..967e3c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -SOURCES/chrony-3.1.tar.gz -SOURCES/clknetsim-ce89a1.tar.gz +SOURCES/chrony-3.2.tar.gz +SOURCES/clknetsim-71dbbc.tar.gz diff --git a/SOURCES/chrony-defconfig.patch b/SOURCES/chrony-defconfig.patch new file mode 100644 index 0000000..c5bbfcc --- /dev/null +++ b/SOURCES/chrony-defconfig.patch @@ -0,0 +1,13 @@ +diff -up chrony-3.2/examples/chrony.conf.example2.defconfig chrony-3.2/examples/chrony.conf.example2 +--- chrony-3.2/examples/chrony.conf.example2.defconfig 2017-09-15 08:32:09.000000000 +0200 ++++ chrony-3.2/examples/chrony.conf.example2 2017-09-18 12:48:08.688020942 +0200 +@@ -28,9 +28,6 @@ rtcsync + # Specify file containing keys for NTP authentication. + #keyfile /etc/chrony.keys + +-# Get TAI-UTC offset and leap seconds from the system tz database. +-#leapsectz right/UTC +- + # Specify directory for log files. + logdir /var/log/chrony + diff --git a/SOURCES/chrony-phcdelay.patch b/SOURCES/chrony-phcdelay.patch deleted file mode 100644 index d1d510e..0000000 --- a/SOURCES/chrony-phcdelay.patch +++ /dev/null @@ -1,33 +0,0 @@ -commit abb09418b16993ecd8289dd459dff91701f4f971 -Author: Miroslav Lichvar -Date: Wed Apr 19 12:20:14 2017 +0200 - - sys_linux: don't drop PHC samples with zero delay - - When processing data from the PTP_SYS_OFFSET ioctl, the sample is - dropped when an interval between two consecutive readings of the system - clock is negative or zero, assuming the clock has been stepped between - the two readings. - - With a real PHC the interval is normally expected to be at least a - microsecond, but with a virtual PHC and a low-resolution system clock - it's possible to get two readings with the same system time. Modify the - check to drop only samples with a negative delay. - -diff --git a/sys_linux.c b/sys_linux.c -index c06112a..649afb0 100644 ---- a/sys_linux.c -+++ b/sys_linux.c -@@ -705,9 +705,11 @@ get_phc_sample(int phc_fd, double precision, struct timespec *phc_ts, - phc_tss[i] = ts2; - delays[i] = UTI_DiffTimespecsToDouble(&ts3, &ts1); - -- if (delays[i] <= 0.0) -+ if (delays[i] < 0.0) { - /* Step in the middle of a PHC reading? */ -+ DEBUG_LOG(LOGF_SysLinux, "Bad PTP_SYS_OFFSET sample delay=%e", delays[i]); - return 0; -+ } - - if (!i || delays[i] < min_delay) - min_delay = delays[i]; diff --git a/SOURCES/chrony-select-timeout.patch b/SOURCES/chrony-select-timeout.patch new file mode 100644 index 0000000..6f585a4 --- /dev/null +++ b/SOURCES/chrony-select-timeout.patch @@ -0,0 +1,44 @@ +commit d0b24860363a3704e28569ce9a6987717834edea +Author: Miroslav Lichvar +Date: Tue Dec 5 11:08:24 2017 +0100 + + client: don't call select() with invalid timeout + + If the system clock was stepped forward after chronyc sent a request and + before it read the clock in order to calculate the receive timeout, + select() could be called with a negative timeout, which resulted in an + infinite loop waiting for select() to succeed. + + Fix the submit_request() function to not call select() with a negative + timeout. Also, return immediately on any error of select(). + +diff --git a/client.c b/client.c +index 5c3a99e..4e23158 100644 +--- a/client.c ++++ b/client.c +@@ -1394,9 +1394,16 @@ submit_request(CMD_Request *request, CMD_Reply *reply) + + timeout = initial_timeout / 1000.0 * (1U << (n_attempts - 1)) - + UTI_DiffTimespecsToDouble(&ts_now, &ts_start); +- UTI_DoubleToTimeval(timeout, &tv); + DEBUG_LOG("Timeout %f seconds", timeout); + ++ /* Avoid calling select() with an invalid timeout */ ++ if (timeout <= 0.0) { ++ new_attempt = 1; ++ continue; ++ } ++ ++ UTI_DoubleToTimeval(timeout, &tv); ++ + FD_ZERO(&rdfd); + FD_ZERO(&wrfd); + FD_ZERO(&exfd); +@@ -1410,6 +1417,7 @@ submit_request(CMD_Request *request, CMD_Reply *reply) + + if (select_status < 0) { + DEBUG_LOG("select failed : %s", strerror(errno)); ++ return 0; + } else if (select_status == 0) { + /* Timeout must have elapsed, try a resend? */ + new_attempt = 1; diff --git a/SOURCES/chrony-timestamping.patch b/SOURCES/chrony-timestamping.patch index ce719a3..6b60ef9 100644 --- a/SOURCES/chrony-timestamping.patch +++ b/SOURCES/chrony-timestamping.patch @@ -1,7 +1,7 @@ -diff -up chrony-3.1/configure.timestamping chrony-3.1/configure ---- chrony-3.1/configure.timestamping 2017-01-31 11:22:11.000000000 +0100 -+++ chrony-3.1/configure 2017-02-03 12:09:22.911633573 +0100 -@@ -651,8 +651,8 @@ if [ $feat_timestamping = "1" ] && [ $tr +diff -up chrony-3.2/configure.timestamping chrony-3.2/configure +--- chrony-3.2/configure.timestamping 2017-09-19 13:58:21.093194558 +0200 ++++ chrony-3.2/configure 2017-09-19 13:57:56.109116276 +0200 +@@ -683,15 +683,15 @@ if [ $feat_timestamping = "1" ] && [ $tr test_code 'SW/HW timestamping' 'sys/types.h sys/socket.h linux/net_tstamp.h linux/errqueue.h linux/ptp_clock.h' '' '' ' int val = SOF_TIMESTAMPING_SOFTWARE | SOF_TIMESTAMPING_RX_SOFTWARE | @@ -12,10 +12,18 @@ diff -up chrony-3.1/configure.timestamping chrony-3.1/configure setsockopt(0, SOL_SOCKET, SO_SELECT_ERR_QUEUE + SO_TIMESTAMPING, &val, sizeof (val));' then -diff -up chrony-3.1/doc/chrony.conf.man.in.timestamping chrony-3.1/doc/chrony.conf.man.in ---- chrony-3.1/doc/chrony.conf.man.in.timestamping 2017-01-31 11:34:16.000000000 +0100 -+++ chrony-3.1/doc/chrony.conf.man.in 2017-02-03 12:09:22.911633573 +0100 -@@ -3065,7 +3065,7 @@ timestamping. If the server or peer supp + add_def HAVE_LINUX_TIMESTAMPING + EXTRA_OBJECTS="$EXTRA_OBJECTS hwclock.o ntp_io_linux.o" + +- if test_code 'other timestamping options' \ ++ if true || test_code 'other timestamping options' \ + 'sys/types.h sys/socket.h linux/net_tstamp.h' '' '' ' + struct scm_ts_pktinfo pktinfo; + pktinfo.if_index = pktinfo.pkt_length = 0; +diff -up chrony-3.2/doc/chrony.conf.man.in.timestamping chrony-3.2/doc/chrony.conf.man.in +--- chrony-3.2/doc/chrony.conf.man.in.timestamping 2017-09-15 10:17:41.000000000 +0200 ++++ chrony-3.2/doc/chrony.conf.man.in 2017-09-19 13:52:59.544187046 +0200 +@@ -3201,13 +3201,12 @@ timestamping. If the server or peer supp be enabled by the \fBxleave\fP option in the \fBserver\fP or the \fBpeer\fP directive. .sp @@ -23,22 +31,35 @@ diff -up chrony-3.1/doc/chrony.conf.man.in.timestamping chrony-3.1/doc/chrony.co +This directive is supported on Linux. The NIC must support HW timestamping, which can be verified with the \fBethtool \-T\fP command. The list of capabilities should include \fISOF_TIMESTAMPING_RAW_HARDWARE\fP, - \fISOF_TIMESTAMPING_TX_HARDWARE\fP, \fISOF_TIMESTAMPING_RX_HARDWARE\fP, and the filter -diff -up chrony-3.1/ntp_io_linux.c.timestamping chrony-3.1/ntp_io_linux.c ---- chrony-3.1/ntp_io_linux.c.timestamping 2017-01-31 11:22:11.000000000 +0100 -+++ chrony-3.1/ntp_io_linux.c 2017-02-03 12:10:10.720767667 +0100 -@@ -36,6 +36,10 @@ + \fISOF_TIMESTAMPING_TX_HARDWARE\fP, and \fISOF_TIMESTAMPING_RX_HARDWARE\fP. Receive + filter \fIHWTSTAMP_FILTER_ALL\fP, or \fIHWTSTAMP_FILTER_NTP_ALL\fP, is necessary for +-timestamping of received packets. Timestamping of packets received from bridged +-and bonded interfaces is supported on Linux 4.13 and newer. When \fBchronyd\fP is ++timestamping of received packets. When \fBchronyd\fP is + running, no other process (e.g. a PTP daemon) should be working with the NIC + clock. + .sp +diff -up chrony-3.2/ntp_io_linux.c.timestamping chrony-3.2/ntp_io_linux.c +--- chrony-3.2/ntp_io_linux.c.timestamping 2017-09-15 08:32:09.000000000 +0200 ++++ chrony-3.2/ntp_io_linux.c 2017-09-19 13:52:59.544187046 +0200 +@@ -35,6 +35,16 @@ #include #include +/* Missing in older kernel headers */ +#define SOF_TIMESTAMPING_OPT_CMSG (1<<10) ++#define SOF_TIMESTAMPING_OPT_PKTINFO (1<<13) ++#define SOF_TIMESTAMPING_OPT_TX_SWHW (1<<14) +#define SCM_TSTAMP_SND 0 ++#define HWTSTAMP_FILTER_NTP_ALL 15 ++#ifndef SCM_TIMESTAMPING_PKTINFO ++#define SCM_TIMESTAMPING_PKTINFO 58 ++#endif + #include "array.h" #include "conf.h" #include "hwclock.h" -@@ -95,6 +99,10 @@ static int ts_tx_flags; +@@ -94,6 +104,10 @@ static int ts_tx_flags; /* Flag indicating the socket options can't be changed in control messages */ static int permanent_ts_options; @@ -49,33 +70,19 @@ diff -up chrony-3.1/ntp_io_linux.c.timestamping chrony-3.1/ntp_io_linux.c /* ================================================== */ static int -@@ -253,6 +261,84 @@ update_interface_speed(struct Interface +@@ -278,7 +292,7 @@ update_interface_speed(struct Interface + + /* ================================================== */ + +-#if defined(HAVE_LINUX_TIMESTAMPING_OPT_PKTINFO) || defined(HAVE_LINUX_TIMESTAMPING_OPT_TX_SWHW) ++#if 1 + static int + check_timestamping_option(int option) + { +@@ -301,6 +315,61 @@ check_timestamping_option(int option) /* ================================================== */ -+static int -+check_sof_opt_cmsg() -+{ -+ int sock_fd, flags; -+ -+ sock_fd = socket(AF_INET, SOCK_DGRAM, 0); -+ if (sock_fd < 0) -+ return 0; -+ -+ flags = SOF_TIMESTAMPING_OPT_CMSG; -+ -+ if (setsockopt(sock_fd, SOL_SOCKET, SO_TIMESTAMPING, &flags, sizeof (flags)) < 0) { -+ DEBUG_LOG(LOGF_NtpIOLinux, "SOF_TIMESTAMPING_OPT_CMSG not supported"); -+ close(sock_fd); -+ return 0; -+ } -+ -+ close(sock_fd); -+ return 1; -+} -+ -+/* ================================================== */ -+ +static int +get_single_hwts_index() +{ @@ -89,7 +96,7 @@ diff -up chrony-3.1/ntp_io_linux.c.timestamping chrony-3.1/ntp_io_linux.c + return INVALID_IF_INDEX; + + if (getifaddrs(&ifaddr)) { -+ DEBUG_LOG(LOGF_NtpIOLinux, "getifaddrs() failed : %s", strerror(errno)); ++ DEBUG_LOG("getifaddrs() failed : %s", strerror(errno)); + close(sock_fd); + return INVALID_IF_INDEX; + } @@ -134,8 +141,8 @@ diff -up chrony-3.1/ntp_io_linux.c.timestamping chrony-3.1/ntp_io_linux.c void NIO_Linux_Initialise(void) { -@@ -289,8 +375,20 @@ NIO_Linux_Initialise(void) - ts_tx_flags = SOF_TIMESTAMPING_TX_SOFTWARE; +@@ -345,8 +414,20 @@ NIO_Linux_Initialise(void) + #endif } - /* Enable IP_PKTINFO in messages looped back to the error queue */ @@ -145,21 +152,34 @@ diff -up chrony-3.1/ntp_io_linux.c.timestamping chrony-3.1/ntp_io_linux.c + /* Enable IP_PKTINFO in messages looped back to the error queue if possible. + If not, HW timestamping of IPv4 packets can be supported only with one + interface capable of HW timestamping. */ -+ if (check_sof_opt_cmsg()) { ++ if (check_timestamping_option(SOF_TIMESTAMPING_OPT_CMSG)) { + ts_flags |= SOF_TIMESTAMPING_OPT_CMSG; + } else if (ARR_GetSize(interfaces) > 0) { + single_hwts_if_index = get_single_hwts_index(); + if (single_hwts_if_index == INVALID_IF_INDEX) -+ LOG(LOGS_WARN, LOGF_NtpIOLinux, "Missing SOF_TIMESTAMPING_OPT_CMSG option for HW timestamping with multiple HW-timestamping interfaces"); ++ LOG(LOGS_WARN, "Missing SOF_TIMESTAMPING_OPT_CMSG option for HW timestamping with multiple HW-timestamping interfaces"); + else -+ LOG(LOGS_INFO, LOGF_NtpIOLinux, "Enabled single-interface HW-timestamping mode"); ++ LOG(LOGS_INFO, "Enabled single-interface HW-timestamping mode"); + } /* Kernels before 4.7 ignore timestamping flags set in control messages */ permanent_ts_options = !SYS_Linux_CheckKernelVersion(4, 7); -@@ -499,7 +597,9 @@ NIO_Linux_ProcessMessage(NTP_Remote_Addr - +@@ -590,7 +671,11 @@ NIO_Linux_ProcessMessage(NTP_Remote_Addr for (cmsg = CMSG_FIRSTHDR(hdr); cmsg; cmsg = CMSG_NXTHDR(hdr, cmsg)) { + #ifdef HAVE_LINUX_TIMESTAMPING_OPT_PKTINFO + if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_TIMESTAMPING_PKTINFO) { +- struct scm_ts_pktinfo ts_pktinfo; ++ struct { ++ __u32 if_index; ++ __u32 pkt_length; ++ __u32 reserved[2]; ++ } ts_pktinfo; + + memcpy(&ts_pktinfo, CMSG_DATA(cmsg), sizeof (ts_pktinfo)); + +@@ -602,11 +687,16 @@ NIO_Linux_ProcessMessage(NTP_Remote_Addr + #endif + if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_TIMESTAMPING) { - struct scm_timestamping ts3; + struct { @@ -168,14 +188,10 @@ diff -up chrony-3.1/ntp_io_linux.c.timestamping chrony-3.1/ntp_io_linux.c memcpy(&ts3, CMSG_DATA(cmsg), sizeof (ts3)); -@@ -507,6 +607,10 @@ NIO_Linux_ProcessMessage(NTP_Remote_Addr - LCL_CookTime(&ts3.ts[0], &local_ts->ts, &local_ts->err); - local_ts->source = NTP_TS_KERNEL; - } else if (!UTI_IsZeroTimespec(&ts3.ts[2])) { -+ if (local_addr->if_index == INVALID_IF_INDEX && -+ single_hwts_if_index != INVALID_IF_INDEX) -+ local_addr->if_index = single_hwts_if_index; -+ - iface = get_interface(local_addr->if_index); + if (!UTI_IsZeroTimespec(&ts3.ts[2])) { ++ if (ts_if_index == INVALID_IF_INDEX) ++ ts_if_index = single_hwts_if_index; ++ + iface = get_interface(ts_if_index); if (iface) { process_hw_timestamp(iface, &ts3.ts[2], local_ts, !is_tx ? length : 0, diff --git a/SPECS/chrony.spec b/SPECS/chrony.spec index 068e58f..e2fb655 100644 --- a/SPECS/chrony.spec +++ b/SPECS/chrony.spec @@ -1,9 +1,9 @@ %global _hardened_build 1 -%global clknetsim_ver ce89a1 +%global clknetsim_ver 71dbbc %bcond_without debug Name: chrony -Version: 3.1 +Version: 3.2 Release: 2%{?dist} Summary: An NTP client/server @@ -20,10 +20,12 @@ Source10: https://github.com/mlichvar/clknetsim/archive/%{clknetsim_ver}/c # add NTP servers from DHCP when starting service Patch1: chrony-service-helper.patch -# add limited support for SW/HW timestamping on older kernels +# enable support for SW/HW timestamping on older kernels Patch2: chrony-timestamping.patch -# don't drop PHC samples with zero delay -Patch3: chrony-phcdelay.patch +# revert upstream changes in packaged chrony.conf example +Patch3: chrony-defconfig.patch +# fix chronyc getting stuck in infinite loop after clock step +Patch4: chrony-select-timeout.patch BuildRequires: libcap-devel libedit-devel nss-devel pps-tools-devel %ifarch %{ix86} x86_64 %{arm} aarch64 ppc64 ppc64le s390 s390x @@ -44,15 +46,15 @@ in permanently connected environments. It can use also hardware reference clocks, system real-time clock or manual input as time references. %if 0%{!?vendorzone:1} -%{?fedora: %global vendorzone fedora.} -%{?rhel: %global vendorzone centos.} +%global vendorzone %(source /etc/os-release && echo ${ID}.) %endif %prep %setup -q -n %{name}-%{version}%{?prerelease} -a 10 %patch1 -p1 -b .service-helper %patch2 -p1 -b .timestamping -%patch3 -p1 -b .phcdelay +%patch3 -p1 -b .defconfig +%patch4 -p1 -b .select-timeout # review changes in packaged configuration files and scripts md5sum -c <<-EOF | (! grep -v 'OK$') @@ -60,10 +62,13 @@ md5sum -c <<-EOF | (! grep -v 'OK$') 58978d335ec3752ac2c38fa82b48f0a5 examples/chrony.conf.example2 ba6bb05c50e03f6b5ab54a2b7914800d examples/chrony.keys.example 6a3178c4670de7de393d9365e2793740 examples/chrony.logrotate - 298b7f611078aa0176aad58e936c7b0d examples/chrony.nm-dispatcher + 27cbc940c94575de320dbd251cbb4514 examples/chrony.nm-dispatcher a85246982a89910b1e2d3356b7d131d7 examples/chronyd.service EOF +# don't allow empty vendor zone +test -n "%{vendorzone}" + # use our vendor zone and replace the pool directive with server # directives as some configuration tools don't support it yet sed -e 's|^\(pool \)\(pool.ntp.org.*\)|'\ @@ -136,7 +141,7 @@ echo 'chronyd.service' > \ # set random seed to get deterministic results export CLKNETSIM_RANDOM_SEED=24502 make %{?_smp_mflags} -C test/simulation/clknetsim -make check +make quickcheck %pre getent group chrony > /dev/null || /usr/sbin/groupadd -r chrony @@ -174,8 +179,12 @@ getent passwd chrony > /dev/null || /usr/sbin/useradd -r -g chrony \ %dir %attr(-,chrony,chrony) %{_localstatedir}/log/chrony %changelog -* Mon Jul 31 2017 CentOS Sources - 3.1-2.el7.centos -- rebrand vendorzone +* Tue Dec 05 2017 Miroslav Lichvar 3.2-2 +- fix chronyc getting stuck in infinite loop after clock step (#1520884) + +* Tue Sep 19 2017 Miroslav Lichvar 3.2-1 +- update to 3.2 (#1482565 #1462081 #1454765) +- use ID from /etc/os-release to set pool.ntp.org vendor zone * Mon Apr 24 2017 Miroslav Lichvar 3.1-2 - don't drop PHC samples with zero delay (#1443342)