Skip to content

Commit cffbc84

Browse files
authored
Merge pull request #245 from bgpkit/bugfix/open-capacities
Fix BGP Open Messages Capacities parsing
2 parents 12b82a9 + a41821b commit cffbc84

File tree

11 files changed

+753
-109
lines changed

11 files changed

+753
-109
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ examples/debug-file.rs
1313

1414
.env
1515
.claude
16+
*.pcap
17+
*.bin

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ We now set a minimum supported Rust version (MSRV) of 1.87.0.
132132
* previously path_id was read but discarded, now properly stored in `RibEntry`
133133
* clarified in-bounds indexing for BGP attribute types when tracking seen attributes (PR #239)
134134
* index attribute type as `u8` when indexing the seen-attributes array to ensure bounds correctness
135+
* fixed BGP OPEN message optional parameter parsing to support multiple capabilities per parameter
136+
* changed `ParamValue::Capability` to `ParamValue::Capacities(Vec<Capability>)` to properly handle RFC 5492 format
137+
* previously parser only read the first capability in each optional parameter, ignoring subsequent capabilities
138+
* now correctly parses all capabilities within each optional parameter
139+
* updated encoding logic to write all capabilities in the vector
135140

136141
## v0.11.1 - 2025-06-06
137142

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ If you would like to see any specific RFC's support, please submit an issue on G
371371
- [X] [RFC 4724](https://datatracker.ietf.org/doc/html/rfc4724): Graceful Restart Mechanism for BGP
372372
- [X] [RFC 4456](https://datatracker.ietf.org/doc/html/rfc4456): BGP Route Reflection: An Alternative to Full Mesh Internal BGP (IBGP)
373373
- [X] [RFC 5065](https://datatracker.ietf.org/doc/html/rfc5065): Autonomous System Confederations for BGP
374+
- [X] [RFC 5492](https://datatracker.ietf.org/doc/html/rfc5492): Capabilities Advertisement with BGP-4
374375
- [X] [RFC 6793](https://datatracker.ietf.org/doc/html/rfc6793): BGP Support for Four-Octet Autonomous System (AS) Number Space
375376
- [X] [RFC 7606](https://datatracker.ietf.org/doc/html/rfc7606): Revised Error Handling for BGP UPDATE Messages
376377
- [X] [RFC 7911](https://datatracker.ietf.org/doc/html/rfc7911): Advertisement of Multiple Paths in BGP (ADD-PATH)

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ If you would like to see any specific RFC's support, please submit an issue on G
363363
- [X] [RFC 4724](https://datatracker.ietf.org/doc/html/rfc4724): Graceful Restart Mechanism for BGP
364364
- [X] [RFC 4456](https://datatracker.ietf.org/doc/html/rfc4456): BGP Route Reflection: An Alternative to Full Mesh Internal BGP (IBGP)
365365
- [X] [RFC 5065](https://datatracker.ietf.org/doc/html/rfc5065): Autonomous System Confederations for BGP
366+
- [X] [RFC 5492](https://datatracker.ietf.org/doc/html/rfc5492): Capabilities Advertisement with BGP-4
366367
- [X] [RFC 6793](https://datatracker.ietf.org/doc/html/rfc6793): BGP Support for Four-Octet Autonomous System (AS) Number Space
367368
- [X] [RFC 7606](https://datatracker.ietf.org/doc/html/rfc7606): Revised Error Handling for BGP UPDATE Messages
368369
- [X] [RFC 7911](https://datatracker.ietf.org/doc/html/rfc7911): Advertisement of Multiple Paths in BGP (ADD-PATH)

src/models/bgp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub struct OptParam {
105105
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
106106
pub enum ParamValue {
107107
Raw(Vec<u8>),
108-
Capability(Capability),
108+
Capacities(Vec<Capability>),
109109
}
110110

111111
/// BGP Capability.

src/parser/bgp/messages.rs

Lines changed: 286 additions & 88 deletions
Large diffs are not rendered by default.

src/parser/bmp/error.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ use num_enum::TryFromPrimitiveError;
1010
use std::error::Error;
1111
use std::fmt::{Display, Formatter};
1212

13-
#[derive(Debug, PartialEq, Clone, Copy, Eq)]
13+
#[derive(Debug, PartialEq, Clone, Eq)]
1414
pub enum ParserBmpError {
1515
InvalidOpenBmpHeader,
1616
UnsupportedOpenBmpMessage,
1717
UnknownTlvType,
1818
UnknownTlvValue,
1919
CorruptedBmpMessage,
20+
CorruptedBgpMessage(String),
2021
TruncatedBmpMessage,
2122
}
2223

@@ -41,6 +42,9 @@ impl Display for ParserBmpError {
4142
ParserBmpError::UnknownTlvValue => {
4243
write!(f, "Unknown TLV value")
4344
}
45+
ParserBmpError::CorruptedBgpMessage(s) => {
46+
write!(f, "Corrupted BGP message: {}", s)
47+
}
4448
}
4549
}
4650
}
@@ -55,8 +59,8 @@ impl From<std::io::Error> for ParserBmpError {
5559
}
5660

5761
impl From<ParserError> for ParserBmpError {
58-
fn from(_: ParserError) -> Self {
59-
ParserBmpError::CorruptedBmpMessage
62+
fn from(e: ParserError) -> Self {
63+
ParserBmpError::CorruptedBgpMessage(e.to_string())
6064
}
6165
}
6266

@@ -126,6 +130,10 @@ mod tests {
126130
ParserBmpError::CorruptedBmpMessage.to_string(),
127131
"Corrupted BMP message"
128132
);
133+
assert_eq!(
134+
ParserBmpError::CorruptedBgpMessage("test".to_string()).to_string(),
135+
"Corrupted BGP message: test"
136+
);
129137
assert_eq!(
130138
ParserBmpError::TruncatedBmpMessage.to_string(),
131139
"Truncated BMP message"
@@ -148,7 +156,7 @@ mod tests {
148156
);
149157
assert_eq!(
150158
ParserBmpError::from(ParserError::ParseError("test".to_string())),
151-
ParserBmpError::CorruptedBmpMessage
159+
ParserBmpError::CorruptedBgpMessage("Error: test".to_string())
152160
);
153161
assert_eq!(
154162
ParserBmpError::from(TryFromPrimitiveError::<BmpMsgType>::new(0)),

0 commit comments

Comments
 (0)