From: Alberto Leiva Popper Date: Mon, 23 Mar 2026 22:26:49 +0000 (-0600) Subject: Reimplement RTR version validation X-Git-Tag: 1.7.0.experimental~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0f8dfb55e7bfa1bca610fb6d7c7457715f6cfda1;p=thirdparty%2FFORT-validator.git Reimplement RTR version validation Fixes #171. --- diff --git a/src/rtr/pdu_stream.c b/src/rtr/pdu_stream.c index 4c64dce8..498eec4c 100644 --- a/src/rtr/pdu_stream.c +++ b/src/rtr/pdu_stream.c @@ -238,70 +238,27 @@ read_hdr(struct pdu_stream *stream, struct pdu_header *header) } static int -validate_rtr_version(struct pdu_stream *stream, struct pdu_header *header, +validate_rtr_version(struct pdu_stream *stream, struct pdu_header *hdr, struct rtr_buffer *request) { - switch (stream->rtr_version) { - case RTR_V2: - switch (header->version) { - case RTR_V2: + if (stream->rtr_version == -1) { + if (RTR_V0 <= hdr->version && hdr->version <= RTR_V2) { + stream->rtr_version = hdr->version; return 0; - case RTR_V1: - case RTR_V0: - goto unexpected; - default: - goto unsupported; - } - - case RTR_V1: - switch (header->version) { - case RTR_V1: - return 0; - case RTR_V0: - case RTR_V2: - goto unexpected; - default: - goto unsupported; - } - - case RTR_V0: - switch (header->version) { - case RTR_V0: - return 0; - case RTR_V1: - case RTR_V2: - goto unexpected; - default: - goto unsupported; - } - - case -1: - switch (header->version) { - case RTR_V0: - case RTR_V1: - case RTR_V2: - stream->rtr_version = header->version; - return 0; - default: - goto unsupported; } + return err_pdu_send_unsupported_proto_version( + stream->fd, RTR_V2, request, + "The maximum supported RTR version is 2." + ); } - pr_crit("Unknown RTR version %u", stream->rtr_version); - -unsupported: - return err_pdu_send_unsupported_proto_version( - stream->fd, - (stream->rtr_version != -1) ? stream->rtr_version : RTR_V0, - request, - "The maximum supported RTR version is 2." - ); - -unexpected: - return err_pdu_send_unexpected_proto_version( - stream->fd, stream->rtr_version, request, - "The RTR version does not match the one we negotiated during the handshake." - ); + if (stream->rtr_version != hdr->version) + return err_pdu_send_unexpected_proto_version( + stream->fd, stream->rtr_version, request, + "The RTR version does not match the one we negotiated during the handshake." + ); + + return 0; } static int