]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
pause and resume sockets if we're not reading from them.
authorAlan T. DeKok <aland@freeradius.org>
Fri, 20 Aug 2021 12:51:56 +0000 (08:51 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 20 Aug 2021 12:51:56 +0000 (08:51 -0400)
src/include/listen.h
src/main/process.c
src/main/tls_listen.c

index f4578e8a47d34a35084e5fce828c3b1057282fbf..bf9824a5da1ea0368f4e223314e7284d4cc597e6 100644 (file)
@@ -45,6 +45,8 @@ typedef enum RAD_LISTEN_TYPE {
 typedef enum RAD_LISTEN_STATUS {
        RAD_LISTEN_STATUS_INIT = 0,
        RAD_LISTEN_STATUS_KNOWN,
+       RAD_LISTEN_STATUS_PAUSE,
+       RAD_LISTEN_STATUS_RESUME,
        RAD_LISTEN_STATUS_FROZEN,
        RAD_LISTEN_STATUS_EOL,
        RAD_LISTEN_STATUS_REMOVE_NOW
index 38b49360e4012c9d946afafcc46ef7421a164d47..55f5592dd0cef0571e02c8acebacebb78e32df22 100644 (file)
@@ -5428,6 +5428,7 @@ static void event_new_fd(rad_listen_t *this)
                /*
                 *      All sockets: add the FD to the event handler.
                 */
+       insert_fd:
                if (fr_event_fd_insert(el, 0, this->fd,
                                       event_socket_handler, this)) {
                        this->status = RAD_LISTEN_STATUS_KNOWN;
@@ -5438,6 +5439,13 @@ static void event_new_fd(rad_listen_t *this)
                this->status = RAD_LISTEN_STATUS_REMOVE_NOW;
        } /* end of INIT */
 
+       if (this->status == RAD_LISTEN_STATUS_PAUSE) {
+               fr_event_fd_delete(el, 0, this->fd);
+               return;
+       }
+
+       if (this->status == RAD_LISTEN_STATUS_RESUME) goto insert_fd;
+
 #ifdef WITH_TCP
        /*
         *      The socket has reached a timeout.  Try to close it.
index b2fc15da8c03bedb5706a47fb29cf26aa507ef0a..ee636d8b4b12c317b5b123cdcda14f7bb2c030fc 100644 (file)
@@ -530,6 +530,14 @@ check_for_setup:
                request->packet->data[3] = 20;
                sock->state = LISTEN_TLS_CHECKING;
                PTHREAD_MUTEX_UNLOCK(&sock->mutex);
+
+               /*
+                *      Don't read from the socket until the request
+                *      returns.
+                */
+               listener->status = RAD_LISTEN_STATUS_PAUSE;
+               radius_update_listener(listener);
+
                return 1;
        }
 
@@ -794,6 +802,12 @@ int dual_tls_send(rad_listen_t *listener, REQUEST *request)
                        return 0;
                }
 
+               /*
+                *      Resume reading from the listener.
+                */
+               listener->status = RAD_LISTEN_STATUS_RESUME;
+               radius_update_listener(listener);
+
                rad_assert(sock->request->packet != request->packet);
 
                sock->state = LISTEN_TLS_SETUP;