From ea535b9647f2f32f9316886d3b07c86c7ae31674 Mon Sep 17 00:00:00 2001 From: Martin Hoffmann Date: Fri, 12 Jan 2024 11:53:09 +0100 Subject: [PATCH] Return expected version in the RTR server error PDU on mismatch. --- src/rtr/server.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/rtr/server.rs b/src/rtr/server.rs index 40b65d5..d63f0aa 100644 --- a/src/rtr/server.rs +++ b/src/rtr/server.rs @@ -20,6 +20,13 @@ use super::payload::{Action, PayloadRef, Timing}; use super::state::State; +//============ Constants ===================================================== + +/// The maximum protocol version we support. +/// +/// We support all protcol versions from 0 up to and including this value. +const MAX_VERSION: u8 = 2; + //============ Traits ======================================================== //------------ PayloadSource et al. ------------------------------------------ @@ -323,7 +330,7 @@ where Sock: AsyncRead + Unpin { if current != header.version() { Err(Query::Error( pdu::Error::new( - header.version(), + current, // respond with the version expected 8, header, "version switched during connection" @@ -334,10 +341,10 @@ where Sock: AsyncRead + Unpin { Ok(()) } } - else if header.version() > 2 { + else if header.version() > MAX_VERSION { Err(Query::Error( pdu::Error::new( - header.version(), + MAX_VERSION, // respond with what they should try 4, header, "only versions 0 to 2 supported"