Skip to content

Commit

Permalink
Work around bad SNTP servers that return VN=4 responses (Azure#1063)
Browse files Browse the repository at this point in the history
We had a CI failure in the mini-sntp test that indicated that
one of the pool.ntp.org servers returns VN=4 even though the client request
has VN=3. This change works around such servers.

Also fixes a couple of typos in the file.
  • Loading branch information
arsing authored Apr 9, 2019
1 parent 1576565 commit 857c7d4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions edgelet/mini-sntp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where
.context(ErrorKind::SetWriteTimeoutOnSocket)?;

let mut num_retries_remaining = 3;
while num_retries_remaining > 0 {
loop {
match query_inner(&socket, addr) {
Ok(result) => return Ok(result),
Err(err) => {
Expand All @@ -65,8 +65,6 @@ where
}
}
}

unreachable!();
}

fn query_inner(socket: &UdpSocket, addr: SocketAddr) -> Result<SntpTimeQueryResult, Error> {
Expand Down Expand Up @@ -180,7 +178,17 @@ fn parse_server_response(
}
};

if packet.version_number != 3 {
// RFC 2030 says:
//
// >Version 4 servers are required to
// >reply in the same version as the request, so the VN field of the
// >request also specifies the version of the reply.
//
// But at least one pool.ntp.org server does not respect this and responds with VN=4
// even though our client requests have VN=3.
//
// So allow both VN=3 and VN=4 in the server response. The response body format is identical for both anyway.
if packet.version_number != 3 && packet.version_number != 4 {
return Err(
ErrorKind::BadServerResponse(BadServerResponseReason::VersionNumber(
packet.version_number,
Expand All @@ -193,10 +201,6 @@ fn parse_server_response(
return Err(ErrorKind::BadServerResponse(BadServerResponseReason::Mode(packet.mode)).into());
}

if packet.mode != 4 {
return Err(ErrorKind::BadServerResponse(BadServerResponseReason::Mode(packet.mode)).into());
}

if packet.originate_timestamp != request_transmit_timestamp {
return Err(
ErrorKind::BadServerResponse(BadServerResponseReason::OriginateTimestamp {
Expand Down

0 comments on commit 857c7d4

Please sign in to comment.