diff --git a/Cargo.toml b/Cargo.toml index db5f3b2..c1ab1b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ bitflags = {version="2.3.3", features = ["serde"], optional = true} bytes = {version = "1.4.0", optional = true} hex= {version = "0.4.3", optional = true} # bmp/openbmp parsing log= {version = "0.4", optional = true } -oneio = {version= "0.13.1", default-features = false, optional = true } +oneio = {version= "0.13.2", default-features = false, optional = true } regex = {version = "1", optional = true} # used in parser filter chrono = {version="0.4.24", optional = true} # parser filter serde_json = {version = "1.0", optional = true } # RIS Live parsing diff --git a/README.md b/README.md index 1cddf34..259788f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # BGPKIT Parser -*This readme is generated from the library's doc comments using [cargo-readme](https://github.com/livioribeiro/cargo-readme). Please refer to the Rust docs website for the full documentation: [latest stable](https://docs.rs/bgpkit-parser/latest/bgpkit_parser/); [bleeding-edge](https://docs.rs/bgpkit-parser/0.10.0-alpha.1/bgpkit_parser/).* +*This readme is generated from the library's doc comments using [cargo-readme](https://github.com/livioribeiro/cargo-readme). Please refer to the Rust docs website for the full documentation: [latest stable](https://docs.rs/bgpkit-parser/latest/bgpkit_parser/); [bleeding-edge](https://docs.rs/bgpkit-parser/0.10.0-alpha.2/bgpkit_parser/).* [![Rust](https://github.com/bgpkit/bgpkit-parser/actions/workflows/rust.yml/badge.svg)](https://github.com/bgpkit/bgpkit-parser/actions/workflows/rust.yml) [![Crates.io](https://img.shields.io/crates/v/bgpkit-parser)](https://crates.io/crates/bgpkit-parser) @@ -343,7 +343,7 @@ If you would like to see any specific RFC's support, please submit an issue on G ### BMP - [X] [RFC 7854](https://datatracker.ietf.org/doc/html/rfc7854): BGP Monitoring Protocol (BMP) -- [ ] [RFC 8671](https://datatracker.ietf.org/doc/html/rfc8671): Support for Adj-RIB-Out in the BGP Monitoring Protocol (BMP) +- [X] [RFC 8671](https://datatracker.ietf.org/doc/html/rfc8671): Support for Adj-RIB-Out in the BGP Monitoring Protocol (BMP) ### Communities diff --git a/src/lib.rs b/src/lib.rs index 6d10ee6..057c775 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -336,7 +336,7 @@ If you would like to see any specific RFC's support, please submit an issue on G ## BMP - [X] [RFC 7854](https://datatracker.ietf.org/doc/html/rfc7854): BGP Monitoring Protocol (BMP) -- [ ] [RFC 8671](https://datatracker.ietf.org/doc/html/rfc8671): Support for Adj-RIB-Out in the BGP Monitoring Protocol (BMP) +- [X] [RFC 8671](https://datatracker.ietf.org/doc/html/rfc8671): Support for Adj-RIB-Out in the BGP Monitoring Protocol (BMP) ## Communities diff --git a/src/models/bgp/mod.rs b/src/models/bgp/mod.rs index 8c8484d..07cf9b5 100644 --- a/src/models/bgp/mod.rs +++ b/src/models/bgp/mod.rs @@ -16,7 +16,6 @@ pub use role::*; use crate::models::network::*; use capabilities::BgpCapabilityType; -use error::BgpError; use num_enum::{IntoPrimitive, TryFromPrimitive}; use std::net::Ipv4Addr; diff --git a/src/parser/bmp/messages/headers.rs b/src/parser/bmp/messages/headers.rs index 327d83e..4993ddd 100644 --- a/src/parser/bmp/messages/headers.rs +++ b/src/parser/bmp/messages/headers.rs @@ -121,12 +121,36 @@ pub enum PeerType { } bitflags! { + /// BMP per-peer header flags + /// + /// RFC section at + /// - RFC 7854: https://www.rfc-editor.org/rfc/rfc7854#section-4.2. + /// - RFC 8671: https://www.rfc-editor.org/rfc/rfc8671#section-4 + /// + /// RFC 8671 extended the flags definition by adding one additional flag to indicate whenther + /// the messages are Adj-RIB-in or Adj-RIB-out. + /// + /// ```text + /// 0 1 2 3 4 5 6 7 + /// +-+-+-+-+-+-+-+-+ + /// |V|L|A|O| Resv | + /// +-+-+-+-+-+-+-+-+ + /// ``` + /// When the O flag is set to 1, the following fields in the per-peer header are redefined: + /// - Peer Address: The remote IP address associated with the TCP session over which the encapsulated Protocol Data Unit (PDU) is sent. + /// - Peer AS: The Autonomous System number of the peer to which the encapsulated PDU is sent. + /// - Peer BGP ID: The BGP Identifier of the peer to which the encapsulated PDU is sent. + /// - Timestamp: The time when the encapsulated routes were advertised (one may also think of + /// this as the time when they were installed in the Adj-RIB-Out), expressed in seconds and + /// microseconds since midnight (zero hour), January 1, 1970 (UTC). If zero, the time is + /// unavailable. Precision of the timestamp is implementation-dependent. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct PeerFlags: u8 { - const ADDRESS_FAMILY_IPV6 = 0x80; - const IS_POST_POLICY = 0x40; - const AS_SIZE_16BIT = 0x20; + const ADDRESS_FAMILY_IPV6 = 0b1000_0000; + const IS_POST_POLICY = 0b0100_0000; + const AS_SIZE_16BIT = 0b0010_0000; + const IS_ADJ_RIB_OUT = 0b0001_0000; } } @@ -146,6 +170,16 @@ impl PeerFlags { AsnLength::Bits32 } + + /// Returns true if the peer streams Adj-RIB-out BMP messages + pub fn is_adj_rib_out(&self) -> bool { + self.contains(PeerFlags::IS_ADJ_RIB_OUT) + } + + /// Returns true if the peer streams post-policy BMP messages + pub fn is_post_policy(&self) -> bool { + self.contains(PeerFlags::IS_POST_POLICY) + } } pub fn parse_per_peer_header(data: &mut Bytes) -> Result { diff --git a/src/parser/bmp/messages/stats_report.rs b/src/parser/bmp/messages/stats_report.rs index 914ae28..3c5f894 100644 --- a/src/parser/bmp/messages/stats_report.rs +++ b/src/parser/bmp/messages/stats_report.rs @@ -8,6 +8,9 @@ pub struct StatsReport { pub counters: Vec, } +/// Statistics count values +/// +/// Types of BMP statistics are listed here: #[derive(Debug)] pub struct StatCounter { pub stat_type: u16, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index f2f700f..d5373d6 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -16,10 +16,8 @@ pub mod rislive; pub(crate) use self::utils::*; pub(crate) use bgp::attributes::AttributeParser; -pub(crate) use mrt::{parse_bgp4mp, parse_table_dump_message, parse_table_dump_v2_message}; use crate::models::MrtRecord; -use filter::Filter; pub use mrt::mrt_elem::Elementor; use oneio::{get_cache_reader, get_reader};