Skip to content

Commit

Permalink
bgp: handle well-known communities during the route dissemination phase
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rwestphal committed Feb 22, 2024
1 parent 35574bc commit 5561840
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 23 additions & 1 deletion holo-bgp/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -728,6 +728,28 @@ pub(crate) fn advertise_routes<A>(
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
});

Expand Down
4 changes: 4 additions & 0 deletions holo-bgp/src/packet/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,10 @@ impl<T: CommType> CommList<T> {
fn length(&self) -> u16 {
ATTR_MIN_LEN_EXT + (self.0.len() * T::LENGTH) as u16
}

pub(crate) fn iter(&self) -> impl Iterator<Item = &T> {
self.0.iter()
}
}

// ===== helper functions =====
Expand Down

0 comments on commit 5561840

Please sign in to comment.