X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fchrony.c;h=6fb369a2f167b043618318b98c88764902fd5540;hb=0d9f395599348e735e6f461e1c328293bef0d060;hp=bad9cb78891c46073aaf5a400b25f95bb4bd958b;hpb=8cec7f0908f222f5ae811712924bf7e67d6a38a4;p=collectd.git diff --git a/src/chrony.c b/src/chrony.c index bad9cb78..6fb369a2 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; @@ -185,13 +186,11 @@ typedef struct ATTRIB_PACKED { uint8_t ip6[16]; } addr; uint16_t f_family; + uint16_t padding; } tChrony_IPAddr; typedef struct ATTRIB_PACKED { tChrony_IPAddr addr; - uint16_t - dummy; /* FIXME: Strange dummy space. Needed on gcc 4.8.3/clang 3.4.1 on - x86_64 */ int16_t f_poll; /* 2^f_poll = Time between polls (s) */ uint16_t f_stratum; /* Remote clock stratum */ uint16_t f_state; /* 0 = RPY_SD_ST_SYNC, 1 = RPY_SD_ST_UNREACH, 2 = @@ -212,9 +211,6 @@ typedef struct ATTRIB_PACKED { typedef struct ATTRIB_PACKED { uint32_t f_ref_id; tChrony_IPAddr addr; - uint16_t - dummy; /* FIXME: Strange dummy space. Needed on gcc 4.8.3/clang 3.4.1 on - x86_64 */ uint32_t f_n_samples; /* Number of measurements done */ uint32_t f_n_runs; /* How many measurements to come */ uint32_t f_span_seconds; /* For how long we're measuring */ @@ -229,9 +225,6 @@ typedef struct ATTRIB_PACKED { typedef struct ATTRIB_PACKED { uint32_t f_ref_id; tChrony_IPAddr addr; - uint16_t - dummy; /* FIXME: Strange dummy space. Needed on gcc 4.8.3/clang 3.4.1 on - x86_64 */ uint16_t f_stratum; uint16_t f_leap_status; tTimeval f_ref_time; @@ -354,6 +347,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) { + size_t j = 0; + + for (int i = 0; i < 4; i++) { + int 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 +857,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, " @@ -882,6 +892,9 @@ static int chrony_request_source_data(int p_src_idx, char *src_addr, ntohs(chrony_resp.body.source_data.f_reachability)); chrony_push_data_valid("clock_last_meas", src_addr, is_reachable, ntohl(chrony_resp.body.source_data.f_since_sample)); + chrony_push_data_valid( + "time_offset", src_addr, is_reachable, + ntohf(chrony_resp.body.source_data.f_origin_latest_meas)); return CHRONY_RC_OK; } @@ -893,12 +906,11 @@ static int chrony_request_source_stats(int p_src_idx, const char *src_addr, size_t chrony_resp_size; tChrony_Request chrony_req; tChrony_Response chrony_resp; - double skew_ppm, frequency_error, time_offset; + double skew_ppm, frequency_error; if (*p_is_reachable == 0) { skew_ppm = 0; frequency_error = 0; - time_offset = 0; } else { chrony_init_req(&chrony_req); chrony_req.body.source_stats.f_index = htonl(p_src_idx); @@ -913,7 +925,6 @@ static int chrony_request_source_stats(int p_src_idx, const char *src_addr, skew_ppm = ntohf(chrony_resp.body.source_stats.f_skew_ppm); frequency_error = ntohf(chrony_resp.body.source_stats.f_rtc_gain_rate_ppm); - time_offset = ntohf(chrony_resp.body.source_stats.f_est_offset); DEBUG(PLUGIN_NAME ": Source[%d] stat: .addr = %s, .ref_id= %u, .n_samples = %u, " @@ -925,7 +936,8 @@ static int chrony_request_source_stats(int p_src_idx, const char *src_addr, ntohl(chrony_resp.body.source_stats.f_n_runs), ntohl(chrony_resp.body.source_stats.f_span_seconds), ntohf(chrony_resp.body.source_stats.f_rtc_seconds_fast), - frequency_error, skew_ppm, time_offset, + frequency_error, skew_ppm, + ntohf(chrony_resp.body.source_stats.f_est_offset), ntohf(chrony_resp.body.source_stats.f_est_offset_err)); } /* if (*is_reachable) */ @@ -934,8 +946,6 @@ static int chrony_request_source_stats(int p_src_idx, const char *src_addr, chrony_push_data_valid("clock_skew_ppm", src_addr, *p_is_reachable, skew_ppm); chrony_push_data_valid("frequency_error", src_addr, *p_is_reachable, frequency_error); /* unit: ppm */ - chrony_push_data_valid("time_offset", src_addr, *p_is_reachable, - time_offset); /* unit: s */ return CHRONY_RC_OK; }