Skip to content

Commit

Permalink
Merge pull request #475 from sawolf/ntp-stratum-issue
Browse files Browse the repository at this point in the history
check_ntp: add --allow-zero-stratum flag to resolve several commenters' issues on #329
  • Loading branch information
sawolf committed Sep 19, 2019
2 parents 76be8ec + 4e939ed commit 3240fff
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion plugins/check_ntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ typedef struct {
uint16_t status;
} ntp_assoc_status_pair;

static int allow_zero_stratum = 0;

/* bits 1,2 are the leap indicator */
#define LI_MASK 0xc0
#define LI(x) ((x&LI_MASK)>>6)
Expand Down Expand Up @@ -305,7 +307,7 @@ int best_offset_server(const ntp_server_results *slist, int nservers){
/* Sort out servers that didn't respond or responede with a 0 stratum;
* stratum 0 is for reference clocks so no NTP server should ever report
* a stratum 0 */
if ( slist[cserver].stratum == 0){
if ( slist[cserver].stratum == 0 && !allow_zero_stratum){
if (verbose) printf("discarding peer %d: stratum=%d\n", cserver, slist[cserver].stratum);
continue;
}
Expand Down Expand Up @@ -674,6 +676,7 @@ int process_arguments(int argc, char **argv){
{"jcrit", required_argument, 0, 'k'},
{"timeout", required_argument, 0, 't'},
{"hostname", required_argument, 0, 'H'},
{"allow-zero-stratum", no_argument, 0, 'z'},
{0, 0, 0, 0}
};

Expand Down Expand Up @@ -722,6 +725,9 @@ int process_arguments(int argc, char **argv){
case 't':
timeout_interval = parse_timeout_string(optarg);
break;
case 'z':
allow_zero_stratum = 1;
break;
case '4':
address_family = AF_INET;
break;
Expand Down Expand Up @@ -868,6 +874,8 @@ void print_help(void){
printf (" %s\n", _("Warning threshold for jitter"));
printf (" %s\n", "-k, --jcrit=THRESHOLD");
printf (" %s\n", _("Critical threshold for jitter"));
printf (" %s\n", "-z, --allow-zero-stratum");
printf (" %s\n", _("Do not discard DNS servers which report a stratum of zero (0)"));
printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
printf (UT_VERBOSE);

Expand Down

0 comments on commit 3240fff

Please sign in to comment.