Skip to content

Commit d718da3

Browse files
committed
Fix the flags methods on RouterKey ans Aspa
1 parent 5db66b2 commit d718da3

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/rtr/pdu.rs

+37-2
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,11 @@ impl RouterKey {
545545
/// The only flag currently used is the least significant bit that is
546546
/// 1 for an announcement and 0 for a withdrawal.
547547
pub fn flags(&self) -> u8 {
548-
(self.fixed.header.session >> 8) as u8
548+
// The two-byte Session field is reused for the Flags byte and one
549+
// reserved byte (of zeroes). As the value of the Session field is in
550+
// network byte order, we are actually looking at (Reserved, Flags),
551+
// so we want the lower byte here.
552+
self.fixed.header.session as u8
549553
}
550554

551555
/// Returns the subject key identifier.
@@ -845,7 +849,11 @@ impl Aspa {
845849
/// The only flag currently used is the least significant bit that is
846850
/// 1 for an announcement and 0 for a withdrawal.
847851
pub fn flags(&self) -> u8 {
848-
(self.fixed.header.session >> 8) as u8
852+
// The two-byte Session field is reused for the Flags byte and one
853+
// reserved byte (of zeroes). As the value of the Session field is in
854+
// network byte order, we are actually looking at (Reserved, Flags),
855+
// so we want the lower byte here.
856+
self.fixed.header.session as u8
849857
}
850858

851859
/// Returns the customer ASN.
@@ -1818,6 +1826,19 @@ mod test {
18181826
);
18191827
}
18201828

1829+
#[test]
1830+
fn router_key_flags() {
1831+
for flags in [0, 1, 128, 255] {
1832+
let key = RouterKey::new(
1833+
1, flags,
1834+
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],
1835+
Asn::from_u32(0x1000f),
1836+
RouterKeyInfo::new(Bytes::from_static(&[21,22,23,24])).unwrap()
1837+
);
1838+
assert_eq!(key.flags(), flags);
1839+
}
1840+
}
1841+
18211842
#[tokio::test]
18221843
async fn read_write_aspa() {
18231844
read_write!(
@@ -1836,6 +1857,20 @@ mod test {
18361857
);
18371858
}
18381859

1860+
#[test]
1861+
fn aspa_flags() {
1862+
for flags in [0, 1, 128, 255] {
1863+
let aspa = Aspa::new(
1864+
2, flags,
1865+
Asn::from_u32(0x1000f),
1866+
ProviderAsns::try_from_iter([
1867+
Asn::from_u32(0x1000d), Asn::from_u32(0x1000e)
1868+
]).unwrap(),
1869+
);
1870+
assert_eq!(aspa.flags(), flags);
1871+
}
1872+
}
1873+
18391874
#[test]
18401875
fn provider_count() {
18411876
assert_eq!(

0 commit comments

Comments
 (0)