]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Clear RTR client request queue on error
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 7 Jul 2026 23:15:45 +0000 (17:15 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 7 Jul 2026 23:15:45 +0000 (17:15 -0600)
If Fort decides to abandon a client because of misbehavior, it will
finish handling the current request (if there is one), cancel all
subsequent queued requests, and terminate the connection.

src/rtr/pdu_stream.c
src/rtr/pdu_stream.h
src/rtr/rtr.c

index 71c46fd31481ad87ef3a4f0f5269bd7b109e5c53..d2b791149e34b9b0586373cc84207240c48fca45 100644 (file)
@@ -55,10 +55,24 @@ struct pdu_stream *pdustream_create(int fd, char const *addr)
        return result;
 }
 
+void
+pdustream_clear_requests(struct pdu_stream *stream)
+{
+       struct rtr_request *req;
+
+       while ((req = TAILQ_FIRST(&stream->requests)) != NULL) {
+               TAILQ_REMOVE(&stream->requests, req, lh);
+               rtreq_destroy(req);
+       }
+
+       stream->reqcount = 0;
+}
+
 void
 pdustream_destroy(struct pdu_stream *stream)
 {
        close(stream->fd);
+       pdustream_clear_requests(stream);
        free(stream);
 }
 
index 7bbdf13f1bc4bc2250f679952f8caaca24ea9279..7e917ff17e47a2f2c03758a8ecb3fdeada3fee4c 100644 (file)
@@ -54,6 +54,7 @@ struct rtr_request {
 };
 
 struct pdu_stream *pdustream_create(int, char const *);
+void pdustream_clear_requests(struct pdu_stream *);
 void pdustream_destroy(struct pdu_stream *);
 
 bool pdustream_parse(struct pdu_stream *, bool *);
index 0d28744915f6e5a844fa6985def2a43c51acbe37..68bee7b9abd1258e00bc1375cee1304a73773556 100644 (file)
@@ -590,7 +590,7 @@ apply_pollfds(struct pollfd *pollfds, size_t nclients)
 
                /* PR_DEBUG_MSG("pfd:%d client:%d", pfd->fd, client->fd); */
 
-               if (client->eos && TAILQ_EMPTY(&client->requests)) {
+               if (!client->claimed && client->eos) {
                        pdustream_destroy(client);
                        clients.array[i] = NULL;
                }
@@ -606,6 +606,7 @@ disable_read(struct pdu_stream *stream)
        if (shutdown(stream->fd, SHUT_RD) < 0)
                pr_op_warn("Can't shut down read end of client socket: %s",
                    strerror(errno));
+       pdustream_clear_requests(stream);
        stream->eos = true;
 }