Skip to content

Commit

Permalink
Return expected version in the RTR server error PDU on mismatch. (#280)
Browse files Browse the repository at this point in the history
This PR changes the version reported by the RTR server in the header of the
RTR error PDU when a request has an invalid version. It returns the maximum
supported version if a version hasn’t been negotiated yet. It returns the
negotiated version if the client uses a different version after negotiation.

---------

Co-authored-by: Luuk Hendriks <github@luukhendriks.eu>
  • Loading branch information
partim and DRiKE authored Jan 16, 2024
1 parent 89b700b commit 90801f6
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/rtr/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ use super::payload::{Action, PayloadRef, Timing};
use super::state::State;


//============ Constants =====================================================

/// The maximum protocol version we support.
///
/// We support all protocol versions from 0 up to and including this value.
const MAX_VERSION: u8 = 2;

//============ Traits ========================================================

//------------ PayloadSource et al. ------------------------------------------
Expand Down Expand Up @@ -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"
Expand All @@ -334,13 +341,17 @@ 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"
concat!(
"only versions 0 up to and including ",
stringify!(MAX_VERSION),
" supported"
)
)
))
}
Expand Down

0 comments on commit 90801f6

Please sign in to comment.