Skip to content

Commit

Permalink
Improve rtr client version negotiation. (#282)
Browse files Browse the repository at this point in the history
This PR improves (well, fixes) the protocol version negotiation of the RTR
client.

Previously it just accepted whatever version the server proposed. Now it
requests a pre-defined maximum version and rejects any response with a
version greater than it.
  • Loading branch information
partim authored Jan 17, 2024
1 parent 3814337 commit e00b657
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/rtr/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ use super::state::State;

const IO_TIMEOUT: Duration = Duration::from_secs(10);

/// The protocol version we initially propose.
///
/// While the client technically supports version 2 as well, the format of the
/// ASPA PDU has not yet been agreed upon. Rather than possibly deploying
/// broken servers, we only start with version 1 for now.
const INITIAL_VERSION: u8 = 1;


//------------ PayloadTarget -------------------------------------------------

Expand Down Expand Up @@ -191,7 +198,7 @@ impl<Sock, Target> Client<Sock, Target> {

/// Returns the protocol version to use.
fn version(&self) -> u8 {
self.version.unwrap_or(1)
self.version.unwrap_or(INITIAL_VERSION)
}
}

Expand Down Expand Up @@ -426,6 +433,15 @@ where
Ok(())
}
}
else if version > INITIAL_VERSION {
Err(io::Error::new(
io::ErrorKind::InvalidData,
format!(
"server requested unsupported protocol version {}",
version
)
))
}
else {
self.version = Some(version);
Ok(())
Expand Down

0 comments on commit e00b657

Please sign in to comment.