Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.

## Unreleased

### Breaking changes

* **`Afi` and `Safi` gain the EVPN family and `ExtendedCommunity` gains `MacMobility`**: `Afi::L2vpn` (25) and `Safi::Evpn` (70) now parse instead of failing, and the MAC Mobility extended community (type `0x06`, sub-type `0x00`) parses into `ExtendedCommunity::MacMobility { sticky, sequence }` instead of a raw 8-byte blob. `ExtendedCommunity::Raw` now reports the registered type of an undecoded community (`Evpn` for the other EVPN sub-types) rather than `Unknown`. Downstream exhaustive matches on these enums need a new arm.

### Added

* **EVPN NLRI support** ([RFC 7432](https://datatracker.ietf.org/doc/html/rfc7432), [RFC 9136](https://datatracker.ietf.org/doc/html/rfc9136)): `MP_REACH_NLRI` and `MP_UNREACH_NLRI` for AFI 25 / SAFI 70 decode into `Nlri::evpn_nlris`, one `EvpnNlri` per route with its route distinguisher and a route-type-specific body: type 2 (MAC/IP advertisement: ESI, Ethernet tag, MAC, optional IP, label), type 3 (inclusive multicast), and type 5 (IP prefix). Route types 1 and 4 keep their octets in `EvpnRoutePayload::Raw`, and an EVPN end-of-RIB marker decodes to an empty list. Until now an EVPN BMP feed produced only `AttributeValue::Raw` and no fields at all. The encoder writes the same routes back, so `MrtRecord::try_from(&BmpMessage)` keeps converting EVPN route monitoring messages, and text output renders an `ANNOUNCED (EVPN)` / `WITHDRAWN (EVPN)` section instead of dropping them.
* **MAC Mobility extended community encoder**: `ExtendedCommunity::MacMobility` re-encodes to the 8 wire octets, so a decoded EVPN route survives a decode/encode round trip of its communities.

## v0.23.0 - 2026-10-17

### Breaking changes
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,13 @@ Additional known attribute type codes are raw-retained (`AttributeValue::Raw`) a

## Advanced Features

**EVPN** (AFI 25 / SAFI 70):
- [RFC 7432](https://datatracker.ietf.org/doc/html/rfc7432): BGP MPLS-Based Ethernet VPN - route types 2
and 3, and the MAC Mobility extended community
- [RFC 9136](https://datatracker.ietf.org/doc/html/rfc9136): IP Prefix Advertisement in EVPN - route type 5

Route types 1 and 4 are accepted and preserved as raw octets; they are not decoded yet.

**FlowSpec**:
- [RFC 8955](https://datatracker.ietf.org/doc/html/rfc8955): Dissemination of Flow Specification Rules
- [RFC 8956](https://datatracker.ietf.org/doc/html/rfc8956): Dissemination of Flow Specification Rules for IPv6
Expand Down
58 changes: 58 additions & 0 deletions src/models/bgp/attributes/nlri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub struct Nlri {
/// Flow-Spec NLRI data - RFC 8955/8956
#[cfg_attr(feature = "ts-rs", ts(type = "Record<string, unknown>[] | null"))]
pub flowspec_nlris: Option<Vec<crate::models::bgp::flowspec::FlowSpecNlri>>,
/// EVPN NLRI data - RFC 7432 (AFI 25, SAFI 70)
#[cfg_attr(feature = "ts-rs", ts(type = "Record<string, unknown>[] | null"))]
pub evpn_nlris: Option<Vec<crate::models::bgp::evpn::EvpnNlri>>,
Comment thread
digizeph marked this conversation as resolved.
Resolved
Comment thread
digizeph marked this conversation as resolved.
Resolved
}

impl Nlri {
Expand All @@ -52,11 +55,26 @@ impl Nlri {
matches!(self.safi, Safi::FlowSpec | Safi::FlowSpecL3Vpn)
}

/// Returns true if this NLRI refers to EVPN (AFI 25, SAFI 70).
pub const fn is_evpn(&self) -> bool {
matches!(self.afi, Afi::L2vpn) && matches!(self.safi, Safi::Evpn)
}

/// Returns true if this NLRI refers to MPLS-labeled prefixes (SAFI 4).
pub const fn is_mpls_labeled(&self) -> bool {
matches!(self.safi, Safi::MplsLabel)
}

/// Returns true when this NLRI carries no reachability information in any
/// family, which is the shape of an MP_UNREACH end-of-RIB marker.
pub fn is_empty(&self) -> bool {
self.prefixes.is_empty()
&& self.labeled_prefixes.as_ref().is_none_or(|p| p.is_empty())
&& self.link_state_nlris.as_ref().is_none_or(|n| n.is_empty())
&& self.flowspec_nlris.as_ref().is_none_or(|n| n.is_empty())
&& self.evpn_nlris.as_ref().is_none_or(|n| n.is_empty())
}

/// Returns true if this NLRI refers to reachable prefixes
pub const fn is_reachable(&self) -> bool {
self.next_hop.is_some()
Expand Down Expand Up @@ -88,6 +106,7 @@ impl Nlri {
labeled_prefixes: None,
link_state_nlris: None,
flowspec_nlris: None,
evpn_nlris: None,
}
}

Expand All @@ -105,6 +124,7 @@ impl Nlri {
labeled_prefixes: None,
link_state_nlris: None,
flowspec_nlris: None,
evpn_nlris: None,
}
}

Expand All @@ -122,6 +142,7 @@ impl Nlri {
labeled_prefixes: None,
link_state_nlris: Some(nlri_list),
flowspec_nlris: None,
evpn_nlris: None,
}
}

Expand All @@ -137,6 +158,7 @@ impl Nlri {
labeled_prefixes: None,
link_state_nlris: Some(nlri_list),
flowspec_nlris: None,
evpn_nlris: None,
}
}

Expand All @@ -156,6 +178,7 @@ impl Nlri {
labeled_prefixes: None,
link_state_nlris: None,
flowspec_nlris: Some(flowspec_nlris),
evpn_nlris: None,
}
}

Expand All @@ -173,6 +196,7 @@ impl Nlri {
labeled_prefixes: None,
link_state_nlris: None,
flowspec_nlris: Some(flowspec_nlris),
evpn_nlris: None,
}
}

Expand All @@ -191,6 +215,39 @@ impl Nlri {
labeled_prefixes: Some(labeled_prefixes),
link_state_nlris: None,
flowspec_nlris: None,
evpn_nlris: None,
}
}

/// Create a new EVPN reachable NLRI (AFI 25 / SAFI 70) - RFC 7432
pub fn new_evpn_reachable(
next_hop: Option<IpAddr>,
nlri_list: Vec<crate::models::bgp::evpn::EvpnNlri>,
) -> Nlri {
let next_hop = next_hop.map(NextHopAddress::from);
Nlri {
afi: Afi::L2vpn,
safi: Safi::Evpn,
next_hop,
prefixes: Vec::new(),
labeled_prefixes: None,
link_state_nlris: None,
flowspec_nlris: None,
evpn_nlris: Some(nlri_list),
}
}

/// Create a new EVPN unreachable NLRI (AFI 25 / SAFI 70) - RFC 7432
pub fn new_evpn_unreachable(nlri_list: Vec<crate::models::bgp::evpn::EvpnNlri>) -> Nlri {
Nlri {
afi: Afi::L2vpn,
safi: Safi::Evpn,
next_hop: None,
prefixes: Vec::new(),
labeled_prefixes: None,
link_state_nlris: None,
flowspec_nlris: None,
evpn_nlris: Some(nlri_list),
}
}

Expand All @@ -205,6 +262,7 @@ impl Nlri {
labeled_prefixes: None,
link_state_nlris: None,
flowspec_nlris: None,
evpn_nlris: None,
}
}
}
Expand Down
67 changes: 66 additions & 1 deletion src/models/bgp/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub enum ExtendedCommunityType {
TransitiveIpv4Addr = 0x01,
TransitiveFourOctetAs = 0x02,
TransitiveOpaque = 0x03,
/// EVPN extended community - RFC 7432 §7
Evpn = 0x06,

// non-transitive types
NonTransitiveTwoOctetAs = 0x40,
Expand All @@ -67,6 +69,29 @@ pub enum ExtendedCommunityType {
Unknown(u8),
}

impl ExtendedCommunityType {
/// Map a wire type octet to a variant.
///
/// [`From<u8>`] cannot be used in a constant context, and
/// [`ExtendedCommunity::community_type`] is `const`, so the mapping is
/// spelled out here. Keep it in step with the enum.
pub const fn from_byte(byte: u8) -> Self {
use ExtendedCommunityType::*;
match byte {
0x00 => TransitiveTwoOctetAs,
0x01 => TransitiveIpv4Addr,
0x02 => TransitiveFourOctetAs,
0x03 => TransitiveOpaque,
0x06 => Evpn,
0x40 => NonTransitiveTwoOctetAs,
0x41 => NonTransitiveIpv4Addr,
0x42 => NonTransitiveFourOctetAs,
0x43 => NonTransitiveOpaque,
other => Unknown(other),
}
}
}

/// Extended Communities.
///
/// ## Overview
Expand Down Expand Up @@ -116,6 +141,8 @@ pub enum ExtendedCommunity {
FlowSpecTrafficMarking(FlowSpecTrafficMarking),
/// BGP Link Bandwidth - RFC 10005
LinkBandwidth(LinkBandwidth),
/// MAC Mobility - RFC 7432 §7.7
MacMobility(MacMobility),
Raw([u8; 8]),
}

Expand All @@ -142,7 +169,8 @@ impl ExtendedCommunity {
NonTransitiveTwoOctetAs
}
}
ExtendedCommunity::Raw(buffer) => Unknown(buffer[0]),
ExtendedCommunity::MacMobility(_) => Evpn,
ExtendedCommunity::Raw(buffer) => ExtendedCommunityType::from_byte(buffer[0]),
}
}
}
Expand All @@ -159,6 +187,33 @@ pub struct Ipv6AddrExtCommunity {
pub local_admin: [u8; 2],
}

/// MAC Mobility Extended Community - RFC 7432 §7.7
///
/// Carried with a MAC/IP Advertisement (route type 2). The sequence number is
/// how a fabric orders competing advertisements for the same MAC: the highest
/// value wins, and a PE that sees a locally learned MAC it previously knew as
/// remote re-advertises it with the sequence number incremented.
///
/// ```text
/// 0 1 2 3
/// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | Type = 0x06 | Sub-Type = 0x00| Flags | Reserved |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | Sequence Number |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// ```
#[derive(Debug, PartialEq, Clone, Copy, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS), ts(export))]
pub struct MacMobility {
/// Sticky/static flag (bit 0 of the flags octet): the MAC is considered
/// immobile and does not take part in sequence-number comparison.
pub sticky: bool,
/// Sequence number, 32 bits big-endian.
pub sequence: u32,
}

/// Two-Octet AS Specific Extended Community
///
/// <https://datatracker.ietf.org/doc/html/rfc4360#section-3.1>
Expand Down Expand Up @@ -439,6 +494,16 @@ impl Display for ExtendedCommunity {
ec_type, 0x04, link_bandwidth.global_admin, link_bandwidth.bandwidth
)
}
ExtendedCommunity::MacMobility(mobility) => {
write!(
f,
"{}:{}:{}:{}",
ec_type,
0x00,
u8::from(mobility.sticky),
mobility.sequence
)
}
ExtendedCommunity::Raw(ec) => {
write!(f, "{}", ToHexString(ec))
}
Expand Down
Loading
Loading