]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
nts: disable input when sending data in NTS-KE session
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 13 Jul 2020 10:21:39 +0000 (12:21 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 16 Jul 2020 10:03:43 +0000 (12:03 +0200)
Ignore read events when sending data to avoid spinning with blocked
output.

nts_ke_session.c

index a686db25e99537390aafff8d217332ed0ad44dad..a0ef424d82786792f512e4147c7052aab7ac14c3 100644 (file)
@@ -317,6 +317,15 @@ check_alpn(NKSN_Instance inst)
 
 /* ================================================== */
 
+static void
+set_input_output(NKSN_Instance inst, int output)
+{
+  SCH_SetFileHandlerEvent(inst->sock_fd, SCH_FILE_INPUT, !output);
+  SCH_SetFileHandlerEvent(inst->sock_fd, SCH_FILE_OUTPUT, output);
+}
+
+/* ================================================== */
+
 static void
 change_state(NKSN_Instance inst, KeState state)
 {
@@ -338,7 +347,7 @@ change_state(NKSN_Instance inst, KeState state)
       assert(0);
   }
 
-  SCH_SetFileHandlerEvent(inst->sock_fd, SCH_FILE_OUTPUT, output);
+  set_input_output(inst, output);
 
   inst->state = state;
 }
@@ -406,8 +415,7 @@ handle_event(NKSN_Instance inst, int event)
         }
 
         /* Disable output when the handshake is trying to receive data */
-        SCH_SetFileHandlerEvent(inst->sock_fd, SCH_FILE_OUTPUT,
-                                gnutls_record_get_direction(inst->tls_session));
+        set_input_output(inst, gnutls_record_get_direction(inst->tls_session));
         return 0;
       }
 
@@ -515,8 +523,7 @@ handle_event(NKSN_Instance inst, int event)
         }
 
         /* Disable output when the TLS shutdown is trying to receive data */
-        SCH_SetFileHandlerEvent(inst->sock_fd, SCH_FILE_OUTPUT,
-                                gnutls_record_get_direction(inst->tls_session));
+        set_input_output(inst, gnutls_record_get_direction(inst->tls_session));
         return 0;
       }