[chrony-dev] [PATCH 3/4] Support previous protocol version in chronyc |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
This adds compatibility with chronyd using the previous protocol version
(chrony versions 1.27, 1.28, 1.29).
---
client.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/client.c b/client.c
index c7bc74d..1aaf714 100644
--- a/client.c
+++ b/client.c
@@ -1239,6 +1239,7 @@ static unsigned long token = 0;
static int max_retries = 2;
static int initial_timeout = 1000;
+static int proto_version = PROTO_VERSION_NUMBER;
/* This is the core protocol module. Complete particular fields in
the outgoing packet, send it, wait for a response, handle retries,
@@ -1264,7 +1265,6 @@ submit_request(CMD_Request *request, CMD_Reply *reply, int *reply_auth_ok)
int n_attempts;
fd_set rdfd, wrfd, exfd;
- request->version = PROTO_VERSION_NUMBER;
request->pkt_type = PKT_TYPE_CMD_REQUEST;
request->res1 = 0;
request->res2 = 0;
@@ -1279,6 +1279,7 @@ submit_request(CMD_Request *request, CMD_Reply *reply, int *reply_auth_ok)
n_attempts = 0;
do {
+ request->version = proto_version;
command_length = PKL_CommandLength(request);
padding_length = PKL_CommandPaddingLength(request);
assert(command_length > 0 && command_length > padding_length);
@@ -1405,7 +1406,7 @@ submit_request(CMD_Request *request, CMD_Reply *reply, int *reply_auth_ok)
continue;
}
- bad_header = ((reply->version != PROTO_VERSION_NUMBER &&
+ bad_header = ((reply->version != proto_version &&
!(reply->version >= PROTO_VERSION_MISMATCH_COMPAT_CLIENT &&
ntohs(reply->status) == STT_BADPKTVERSION)) ||
(reply->pkt_type != PKT_TYPE_CMD_REPLY) ||
@@ -1421,6 +1422,19 @@ submit_request(CMD_Request *request, CMD_Reply *reply, int *reply_auth_ok)
continue;
}
+#if PROTO_VERSION_NUMBER == 6
+ /* Protocol version 5 is similar to 6 except there is no padding.
+ If a version 5 reply with STT_BADPKTVERSION is received,
+ switch our version and try again. */
+ if (proto_version == PROTO_VERSION_NUMBER &&
+ reply->version == PROTO_VERSION_NUMBER - 1) {
+ proto_version = PROTO_VERSION_NUMBER - 1;
+ continue;
+ }
+#else
+#error unknown compatibility with PROTO_VERSION - 1
+#endif
+
/* Good packet received, print out results */
#if 0
printf("Reply cmd=%d reply=%d stat=%d seq=%d utok=%08lx tok=%d\n",
--
1.8.4.2
--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble? Email listmaster@xxxxxxxxxxxxxxxxxxxx.