Skip to content

Commit b99d2b8

Browse files
authored
Fix version ASPA EndOfData PDUs (#328)
The ASPA PDUs are introduced in RTR version 2. The End-of-Data PDUs in RTR version 2 are the same as in RTR version 1, but the code did not recognize incoming PDUs with version set to 2. This PR fixes that.
1 parent 29779fa commit b99d2b8

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/rtr/client.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ use super::state::State;
2222
const IO_TIMEOUT: Duration = Duration::from_secs(10);
2323

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

3127

3228
//------------ PayloadTarget -------------------------------------------------

src/rtr/pdu.rs

+37-3
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ impl Payload {
12731273
///
12741274
/// This PDU differs between version 0 and 1 of RTR. Consequently, this
12751275
/// generic version is an enum that can be both, depending on the version
1276-
/// requested.
1276+
/// requested. For version 2, the PDU is the same as for version 1.
12771277
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
12781278
pub enum EndOfData {
12791279
V0(EndOfDataV0),
@@ -1317,7 +1317,7 @@ impl EndOfData {
13171317
EndOfDataV0::read_payload(header, sock)
13181318
.await.map(EndOfData::V0)
13191319
}
1320-
1 => {
1320+
1|2 => {
13211321
EndOfDataV1::read_payload(header, sock)
13221322
.await.map(EndOfData::V1)
13231323
}
@@ -1334,7 +1334,7 @@ impl EndOfData {
13341334
pub fn version(&self) -> u8 {
13351335
match *self {
13361336
EndOfData::V0(_) => 0,
1337-
EndOfData::V1(_) => 1,
1337+
EndOfData::V1(v1_or_v2) => v1_or_v2.header.version()
13381338
}
13391339
}
13401340

@@ -1914,6 +1914,40 @@ mod test {
19141914
);
19151915
}
19161916

1917+
macro_rules! test_eod_pdu_version {
1918+
($version:expr, $raw:expr) => {
1919+
if let Err(eod) = Payload::read(&mut $raw.as_slice()).await.unwrap() {
1920+
assert_eq!($version, eod.version());
1921+
} else {
1922+
panic!("expected End of Data PDU");
1923+
}
1924+
}
1925+
}
1926+
1927+
#[tokio::test]
1928+
async fn end_of_data_versions() {
1929+
test_eod_pdu_version!(
1930+
0,
1931+
vec![0, 7, 0x12, 0x34, 0, 0, 0, 12, 0xde, 0xad, 0xbe, 0xef]
1932+
);
1933+
test_eod_pdu_version!(
1934+
1,
1935+
vec![
1936+
0x01, 0x07, 0x8e, 0xef, 0x00, 0x00, 0x00, 0x18,
1937+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x8f,
1938+
0x00, 0x00, 0x02, 0x58, 0x00, 0x00, 0x1c, 0x20
1939+
]
1940+
);
1941+
test_eod_pdu_version!(
1942+
2,
1943+
vec![
1944+
0x02, 0x07, 0x8e, 0xef, 0x00, 0x00, 0x00, 0x18,
1945+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x8f,
1946+
0x00, 0x00, 0x02, 0x58, 0x00, 0x00, 0x1c, 0x20
1947+
]
1948+
);
1949+
}
1950+
19171951
#[tokio::test]
19181952
async fn read_write_cache_reset() {
19191953
read_write!(

0 commit comments

Comments
 (0)