From: Alberto Leiva Popper Date: Tue, 7 Jul 2026 23:15:45 +0000 (-0600) Subject: Clear RTR client request queue on error X-Git-Tag: 1.7.0.experimental~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=92982af9ea42110f67ed796b2654c25643cf1e9f;p=thirdparty%2FFORT-validator.git Clear RTR client request queue on error 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. --- diff --git a/src/rtr/pdu_stream.c b/src/rtr/pdu_stream.c index 71c46fd3..d2b79114 100644 --- a/src/rtr/pdu_stream.c +++ b/src/rtr/pdu_stream.c @@ -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); } diff --git a/src/rtr/pdu_stream.h b/src/rtr/pdu_stream.h index 7bbdf13f..7e917ff1 100644 --- a/src/rtr/pdu_stream.h +++ b/src/rtr/pdu_stream.h @@ -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 *); diff --git a/src/rtr/rtr.c b/src/rtr/rtr.c index 0d287449..68bee7b9 100644 --- a/src/rtr/rtr.c +++ b/src/rtr/rtr.c @@ -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; }