Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return expected version in the RTR server error PDU on mismatch. #280

Merged
merged 6 commits into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
partim marked this conversation as resolved.
Show resolved Hide resolved
4,
header,
"only versions 0 to 2 supported"
concat!(
"only versions 0 up to and including ",
stringify!(MAX_VERSION),
" supported"
)
)
))
}
Expand Down
Loading