reconnect client sockets (#1124059)
This commit is contained in:
parent
d14cc6f388
commit
2e02b570e3
85
chrony-reconnect.patch
Normal file
85
chrony-reconnect.patch
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
diff --git a/ntp_core.c b/ntp_core.c
|
||||||
|
--- a/ntp_core.c
|
||||||
|
+++ b/ntp_core.c
|
||||||
|
@@ -279,12 +332,17 @@ start_initial_timeout(NCR_Instance inst)
|
||||||
|
|
||||||
|
/* Mark source active */
|
||||||
|
SRC_SetActive(inst->source);
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
|
||||||
|
- /* Open client socket */
|
||||||
|
- if (inst->mode == MODE_CLIENT) {
|
||||||
|
- assert(inst->local_addr.sock_fd == INVALID_SOCK_FD);
|
||||||
|
- inst->local_addr.sock_fd = NIO_GetClientSocket(&inst->remote_addr);
|
||||||
|
- }
|
||||||
|
+/* ================================================== */
|
||||||
|
+
|
||||||
|
+static void
|
||||||
|
+close_client_socket(NCR_Instance inst)
|
||||||
|
+{
|
||||||
|
+ if (inst->mode == MODE_CLIENT && inst->local_addr.sock_fd != INVALID_SOCK_FD) {
|
||||||
|
+ NIO_CloseClientSocket(inst->local_addr.sock_fd);
|
||||||
|
+ inst->local_addr.sock_fd = INVALID_SOCK_FD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -305,11 +363,7 @@ take_offline(NCR_Instance inst)
|
||||||
|
/* And inactive */
|
||||||
|
SRC_UnsetActive(inst->source);
|
||||||
|
|
||||||
|
- /* Close client socket */
|
||||||
|
- if (inst->mode == MODE_CLIENT && inst->local_addr.sock_fd != INVALID_SOCK_FD) {
|
||||||
|
- NIO_CloseClientSocket(inst->local_addr.sock_fd);
|
||||||
|
- inst->local_addr.sock_fd = INVALID_SOCK_FD;
|
||||||
|
- }
|
||||||
|
+ close_client_socket(inst);
|
||||||
|
|
||||||
|
NCR_ResetInstance(inst);
|
||||||
|
}
|
||||||
|
@@ -328,7 +382,7 @@ NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourcePar
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case NTP_SERVER:
|
||||||
|
- /* Client socket will be obtained when timer is started */
|
||||||
|
+ /* Client socket will be obtained when sending request */
|
||||||
|
result->local_addr.sock_fd = INVALID_SOCK_FD;
|
||||||
|
result->mode = MODE_CLIENT;
|
||||||
|
break;
|
||||||
|
@@ -758,6 +812,13 @@ transmit_timeout(void *arg)
|
||||||
|
DEBUG_LOG(LOGF_NtpCore, "Transmit timeout for [%s:%d]",
|
||||||
|
UTI_IPToString(&inst->remote_addr.ip_addr), inst->remote_addr.port);
|
||||||
|
|
||||||
|
+ /* Open new client socket */
|
||||||
|
+ if (inst->mode == MODE_CLIENT) {
|
||||||
|
+ close_client_socket(inst);
|
||||||
|
+ assert(inst->local_addr.sock_fd == INVALID_SOCK_FD);
|
||||||
|
+ inst->local_addr.sock_fd = NIO_GetClientSocket(&inst->remote_addr);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
/* Check whether we need to 'warm up' the link to the other end by
|
||||||
|
sending an echo exchange to ensure both ends' ARP caches are
|
||||||
|
primed. On loaded systems this might also help ensure that bits
|
||||||
|
@@ -1257,6 +1318,10 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
|
||||||
|
adjust_poll(inst, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ /* If in client mode, no more packets are expected to be coming from the
|
||||||
|
+ server and the socket can be closed */
|
||||||
|
+ close_client_socket(inst);
|
||||||
|
+
|
||||||
|
requeue_transmit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
diff --git a/ntp_io.c b/ntp_io.c
|
||||||
|
--- a/ntp_io.c
|
||||||
|
+++ b/ntp_io.c
|
||||||
|
@@ -273,7 +266,7 @@ connect_socket(int sock_fd, NTP_Remote_Address *remote_addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connect(sock_fd, &addr.u, addr_len) < 0) {
|
||||||
|
- LOG(LOGS_ERR, LOGF_NtpIO, "Could not connect NTP socket to %s:%d : %s",
|
||||||
|
+ DEBUG_LOG(LOGF_NtpIO, "Could not connect NTP socket to %s:%d : %s",
|
||||||
|
UTI_IPToString(&remote_addr->ip_addr), remote_addr->port,
|
||||||
|
strerror(errno));
|
||||||
|
return 0;
|
@ -22,6 +22,7 @@ Source9: chrony-wait.service
|
|||||||
# simulator for test suite from https://github.com/mlichvar/clknetsim.git
|
# simulator for test suite from https://github.com/mlichvar/clknetsim.git
|
||||||
Source10: clknetsim-%{clknetsim_ver}.tar.gz
|
Source10: clknetsim-%{clknetsim_ver}.tar.gz
|
||||||
%{?gitpatch:Patch0: chrony-%{version}%{?prerelease}-%{gitpatch}.patch.gz}
|
%{?gitpatch:Patch0: chrony-%{version}%{?prerelease}-%{gitpatch}.patch.gz}
|
||||||
|
Patch1: chrony-reconnect.patch
|
||||||
|
|
||||||
BuildRequires: libcap-devel libedit-devel nss-devel pps-tools-devel
|
BuildRequires: libcap-devel libedit-devel nss-devel pps-tools-devel
|
||||||
BuildRequires: bison texinfo systemd-units
|
BuildRequires: bison texinfo systemd-units
|
||||||
@ -46,6 +47,7 @@ clocks, system real-time clock or manual input as time references.
|
|||||||
%prep
|
%prep
|
||||||
%setup -q -n %{name}-%{version}%{?prerelease} -a 10
|
%setup -q -n %{name}-%{version}%{?prerelease} -a 10
|
||||||
%{?gitpatch:%patch0 -p1}
|
%{?gitpatch:%patch0 -p1}
|
||||||
|
%patch1 -p1 -b .reconnect
|
||||||
|
|
||||||
%{?gitpatch: echo %{version}-%{gitpatch} > version.txt}
|
%{?gitpatch: echo %{version}-%{gitpatch} > version.txt}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user