Skip to content

Commit

Permalink
Add nts_cookie_not_server
Browse files Browse the repository at this point in the history
See #794, but that bug was accidentally fixed
by bd596fa
when I updated the cookie_decode counters.
  • Loading branch information
Hal-Murray committed Jul 24, 2023
1 parent 418c338 commit d9a786f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion include/nts.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ extern uint64_t nts_server_send;
extern uint64_t nts_server_recv_good;
extern uint64_t nts_server_recv_bad;
extern uint64_t nts_cookie_make;
extern uint64_t nts_cookie_decode_total; /* total attempts, includes too old */
extern uint64_t nts_cookie_not_server; /* we are not a NTS server */
extern uint64_t nts_cookie_decode_total; /* total attempts, includes too old */
extern uint64_t nts_cookie_decode_current;
extern uint64_t nts_cookie_decode_old;
extern uint64_t nts_cookie_decode_old2;
Expand Down
1 change: 1 addition & 0 deletions ntpclients/ntpq.py
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,7 @@ def do_ntsinfo(self, _line):
("nts_server_recv_bad", "NTS server recvs w error: ", NTP_UINT),
("nts_server_send", "NTS server sends: ", NTP_UINT),
("nts_cookie_make", "NTS make cookies: ", NTP_UINT),
("nts_cookie_not_server", "NTS cookies not server: ", NTP_UINT),
("nts_cookie_decode_total", "NTS decode cookies total: ", NTP_UINT),
("nts_cookie_decode_current", " NTS decode cookies current:", NTP_UINT),
("nts_cookie_decode_old", " NTS decode cookies old: ", NTP_UINT),
Expand Down
1 change: 1 addition & 0 deletions ntpd/ntp_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ static const struct var sys_var[] = {
Var_u64("nts_server_recv_good", RO, nts_server_recv_good),
Var_u64("nts_server_recv_bad", RO, nts_server_recv_bad),
Var_u64("nts_cookie_make", RO, nts_cookie_make),
Var_u64("nts_cookie_not_server", RO, nts_cookie_not_server),
Var_u64("nts_cookie_decode_total", RO, nts_cookie_decode_total),
Var_u64("nts_cookie_decode_current", RO, nts_cookie_decode_current),
/* Following line is a hack for old versions of ntpq
Expand Down
12 changes: 9 additions & 3 deletions ntpd/nts_cookie.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ AES_SIV_CTX* cookie_ctx;

/* Statistics for ntpq */
uint64_t nts_cookie_make = 0;
uint64_t nts_cookie_not_server = 0;
uint64_t nts_cookie_decode_total = 0;
uint64_t nts_cookie_decode_current = 0;
uint64_t nts_cookie_decode_old = 0; /* one day old */
uint64_t nts_cookie_decode_old2 = 0; /* two days old */
uint64_t nts_cookie_decode_current = 0; /* less than one day old, current key*/
uint64_t nts_cookie_decode_old = 0; /* zero to one day old */
uint64_t nts_cookie_decode_old2 = 0; /* one to two days old */
uint64_t nts_cookie_decode_older = 0; /* more than 2 days old */
uint64_t nts_cookie_decode_too_old = 0;
uint64_t nts_cookie_decode_error = 0;
Expand Down Expand Up @@ -383,6 +384,11 @@ bool nts_unpack_cookie(uint8_t *cookie, int cookielen,
if (NULL == cookie_ctx)
return false; /* We aren't initialized yet. */

if (0 == nts_nKeys) {
nts_cookie_not_server++;
return false; /* We are not a NTS enabled server. */
}

/* We may get garbage from the net */
if (cookielen > NTS_MAX_COOKIELEN)
return false;
Expand Down

0 comments on commit d9a786f

Please sign in to comment.