From 55618406752e0e62c098ade7aee7947b2c8553b9 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 22 Feb 2024 14:54:07 -0300 Subject: [PATCH] bgp: handle well-known communities during the route dissemination phase For now, NO_EXPORT and NO_EXPORT_SUBCONFED are treated the same since RFC 3065 isn't supported yet ("Autonomous System Confederations for BGP"). Signed-off-by: Renato Westphal --- holo-bgp/src/events.rs | 24 +++++++++++++++++++++++- holo-bgp/src/packet/attribute.rs | 4 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/holo-bgp/src/events.rs b/holo-bgp/src/events.rs index 176f8cd0..ab8d1bb8 100644 --- a/holo-bgp/src/events.rs +++ b/holo-bgp/src/events.rs @@ -9,7 +9,7 @@ use std::net::IpAddr; use chrono::Utc; use holo_protocol::InstanceShared; -use holo_utils::bgp::RouteType; +use holo_utils::bgp::{RouteType, WellKnownCommunities}; use holo_utils::ip::{IpAddrKind, IpNetworkKind}; use holo_utils::policy::{PolicyResult, PolicyType}; use holo_utils::socket::{TcpConnInfo, TcpStream}; @@ -728,6 +728,28 @@ pub(crate) fn advertise_routes( return false; } + // Handle well-known communities. + if let Some(comm) = &route.attrs.comm { + for comm in comm + .value + .iter() + .filter_map(|comm| WellKnownCommunities::from_u32(comm.0)) + { + // Do not advertise to any other peer. + if comm == WellKnownCommunities::NoAdvertise { + return false; + } + + // Do not advertise to external peers. + if nbr.peer_type == PeerType::External + && (comm == WellKnownCommunities::NoExport + || comm == WellKnownCommunities::NoExportSubconfed) + { + return false; + } + } + } + true }); diff --git a/holo-bgp/src/packet/attribute.rs b/holo-bgp/src/packet/attribute.rs index aa9c99bd..e901a758 100644 --- a/holo-bgp/src/packet/attribute.rs +++ b/holo-bgp/src/packet/attribute.rs @@ -1400,6 +1400,10 @@ impl CommList { fn length(&self) -> u16 { ATTR_MIN_LEN_EXT + (self.0.len() * T::LENGTH) as u16 } + + pub(crate) fn iter(&self) -> impl Iterator { + self.0.iter() + } } // ===== helper functions =====