Skip to content

Commit

Permalink
bgp: implement the "replace-peer-as" configuration option
Browse files Browse the repository at this point in the history
Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed Feb 22, 2024
1 parent 0998877 commit 35574bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion holo-bgp/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ fn process_nbr_update(
rib,
reach.prefixes.clone(),
attrs,
instance.config.asn,
instance.shared,
&instance.state.policy_apply_tasks,
);
Expand All @@ -192,6 +193,7 @@ fn process_nbr_update(
rib,
prefixes,
attrs,
instance.config.asn,
instance.shared,
&instance.state.policy_apply_tasks,
);
Expand All @@ -208,6 +210,7 @@ fn process_nbr_update(
rib,
prefixes,
attrs,
instance.config.asn,
instance.shared,
&instance.state.policy_apply_tasks,
);
Expand Down Expand Up @@ -257,7 +260,8 @@ fn process_nbr_reach_prefixes<A>(
nbr: &Neighbor,
rib: &mut Rib,
nlri_prefixes: Vec<A::IpNetwork>,
attrs: Attrs,
mut attrs: Attrs,
local_asn: u32,
shared: &InstanceShared,
policy_apply_tasks: &PolicyApplyTasks,
) where
Expand All @@ -278,6 +282,12 @@ fn process_nbr_reach_prefixes<A>(
PeerType::External => RouteType::External,
};

if nbr.config.as_path_options.replace_peer_as {
// Replace occurrences of the peer's AS in the AS_PATH with the local
// autonomous system number.
attrs.base.as_path.replace(nbr.config.peer_as, local_asn);
}

// Update pre-policy Adj-RIB-In routes.
let table = A::table(&mut rib.tables);
let route_attrs = rib.attr_sets.get_route_attr_sets(attrs.clone());
Expand Down
10 changes: 10 additions & 0 deletions holo-bgp/src/packet/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,16 @@ impl AsPath {
}
}

pub(crate) fn replace(&mut self, from: u32, to: u32) {
for segment in self.segments.iter_mut() {
for member in segment.members.iter_mut() {
if *member == from {
*member = to;
}
}
}
}

pub(crate) fn contains(&self, asn: u32) -> bool {
self.segments.iter().any(|segment| segment.contains(asn))
}
Expand Down

0 comments on commit 35574bc

Please sign in to comment.