From: Miroslav Lichvar Date: Thu, 23 Feb 2017 14:28:19 +0000 (+0100) Subject: chrony: fix type instances for reference clocks X-Git-Tag: collectd-5.8.0~172^2~3 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3dc5837eeb4f16aaa608914e46ef925d6c5124a2;p=collectd.git chrony: fix type instances for reference clocks When chronyd is using a reference clock, the reference ID of the source is provided as an IPv4 address in the source report. Format it as an ASCII string instead of an IPv4 address. --- diff --git a/src/chrony.c b/src/chrony.c index bad9cb78..835c4253 100644 --- a/src/chrony.c +++ b/src/chrony.c @@ -77,6 +77,7 @@ static uint32_t g_chrony_seq_is_initialized; #define IPADDR_INET4 1 #define IPADDR_INET6 2 #define IPV6_STR_MAX_SIZE (8 * 4 + 7 + 1) +#define MODE_REFCLOCK 2 typedef enum { PKT_TYPE_CMD_REQUEST = 1, PKT_TYPE_CMD_REPLY = 2 } ePacketType; @@ -354,6 +355,19 @@ static char *niptoha(const tChrony_IPAddr *addr, char *p_buf, return p_buf; } +static void nreftostr(uint32_t nrefid, char *p_buf, size_t p_buf_size) { + int i, j, c; + + for (i = j = 0; i < 4; i++) { + c = ntohl(nrefid) << i * 8 >> 24; + if (!isalnum(c) || j + 1 >= p_buf_size) + continue; + p_buf[j++] = c; + } + if (j < p_buf_size) + p_buf[j] = '\0'; +} + static int chrony_set_timeout(void) { /* Set the socket's timeout to g_chrony_timeout; a value of 0 signals * infinite timeout */ @@ -851,7 +865,11 @@ static int chrony_request_source_data(int p_src_idx, char *src_addr, return rc; } - niptoha(&chrony_resp.body.source_data.addr, src_addr, addr_size); + if (ntohs(chrony_resp.body.source_data.f_mode) == MODE_REFCLOCK) + nreftostr(chrony_resp.body.source_data.addr.addr.ip4, src_addr, addr_size); + else + niptoha(&chrony_resp.body.source_data.addr, src_addr, addr_size); + DEBUG(PLUGIN_NAME ": Source[%d] data: .addr = %s, .poll = %u, .stratum = %u, " ".state = %u, .mode = %u, .flags = %u, .reach = %u, " ".latest_meas_ago = %u, .orig_latest_meas = %f, "