]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
nts: load cookies early
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 10 Feb 2021 11:23:13 +0000 (12:23 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 11 Feb 2021 08:52:57 +0000 (09:52 +0100)
Instead of waiting for the first request, try to load the cookies as
soon as the instance is created, or the NTS address is changed.

This enables loading of dump files for servers that are negotiated in
NTS-KE.

nts_ntp_client.c

index ed89edd9f764677f3da16899666c808f6bec0498..7e8e3fcd1e08c5930996ab06d71b420bf865e70c 100644 (file)
@@ -60,7 +60,6 @@ struct NNC_Instance_Record {
   NKC_Instance nke;
   SIV_Instance siv;
 
-  int load_attempt;
   int nke_attempts;
   double next_nke_attempt;
   double last_nke_success;
@@ -94,7 +93,6 @@ reset_instance(NNC_Instance inst)
     SIV_DestroyInstance(inst->siv);
   inst->siv = NULL;
 
-  inst->load_attempt = 0;
   inst->nke_attempts = 0;
   inst->next_nke_attempt = 0.0;
   inst->last_nke_success = 0.0;
@@ -129,6 +127,9 @@ NNC_CreateInstance(IPSockAddr *nts_address, const char *name, uint16_t ntp_port)
 
   reset_instance(inst);
 
+  /* Try to reload saved keys and cookies */
+  load_cookies(inst);
+
   return inst;
 }
 
@@ -288,12 +289,6 @@ NNC_PrepareForAuth(NNC_Instance inst)
   UTI_GetRandomBytes(inst->uniq_id, sizeof (inst->uniq_id));
   UTI_GetRandomBytes(inst->nonce, sizeof (inst->nonce));
 
-  /* Try to reload saved keys and cookies (once for the NTS-KE address) */
-  if (!inst->load_attempt) {
-    load_cookies(inst);
-    inst->load_attempt = 1;
-  }
-
   /* Get new cookies if there are not any, or they are no longer usable */
   if (!check_cookies(inst)) {
     if (!get_cookies(inst))
@@ -529,6 +524,8 @@ NNC_ChangeAddress(NNC_Instance inst, IPAddr *address)
   reset_instance(inst);
 
   DEBUG_LOG("NTS reset");
+
+  load_cookies(inst);
 }
 
 /* ================================================== */