mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-05 02:55:06 -05:00
Add new cmdmon status codes for packet version and length mismatch
With next procotol version this will allow chronyc to report that chronyd is using a different protocol version.
This commit is contained in:
38
cmdmon.c
38
cmdmon.c
@@ -1822,19 +1822,10 @@ read_from_cmd_socket(void *anything)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (read_length != expected_length) {
|
||||
LOG(LOGS_WARN, LOGF_CmdMon, "Read incorrectly sized packet from %s:%hu", UTI_IPToString(&remote_ip), remote_port);
|
||||
CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
|
||||
/* For now, just ignore the packet. We may want to send a reply
|
||||
back eventually */
|
||||
return;
|
||||
}
|
||||
|
||||
if ((rx_message.version != PROTO_VERSION_NUMBER) ||
|
||||
(rx_message.pkt_type != PKT_TYPE_CMD_REQUEST) ||
|
||||
(rx_message.res1 != 0) ||
|
||||
(rx_message.res2 != 0)) {
|
||||
if (read_length < offsetof(CMD_Request, data) ||
|
||||
rx_message.pkt_type != PKT_TYPE_CMD_REQUEST ||
|
||||
rx_message.res1 != 0 ||
|
||||
rx_message.res2 != 0) {
|
||||
|
||||
/* We don't know how to process anything like this */
|
||||
CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
|
||||
@@ -1842,6 +1833,27 @@ read_from_cmd_socket(void *anything)
|
||||
return;
|
||||
}
|
||||
|
||||
if (rx_message.version != PROTO_VERSION_NUMBER) {
|
||||
tx_message.status = htons(STT_NOHOSTACCESS);
|
||||
LOG(LOGS_WARN, LOGF_CmdMon, "Read packet with protocol version %d (expected %d) from %s:%hu", rx_message.version, PROTO_VERSION_NUMBER, UTI_IPToString(&remote_ip), remote_port);
|
||||
CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
|
||||
|
||||
if (rx_message.version >= PROTO_VERSION_MISMATCH_COMPAT) {
|
||||
tx_message.status = htons(STT_BADPKTVERSION);
|
||||
transmit_reply(&tx_message, &where_from);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (read_length != expected_length) {
|
||||
LOG(LOGS_WARN, LOGF_CmdMon, "Read incorrectly sized packet from %s:%hu", UTI_IPToString(&remote_ip), remote_port);
|
||||
CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
|
||||
|
||||
tx_message.status = htons(STT_BADPKTLENGTH);
|
||||
transmit_reply(&tx_message, &where_from);
|
||||
return;
|
||||
}
|
||||
|
||||
rx_command = ntohs(rx_message.command);
|
||||
|
||||
/* OK, we have a valid message. Now dispatch on message type and process it. */
|
||||
|
||||
Reference in New Issue
Block a user