diff --git a/Cargo.toml b/Cargo.toml index da739ee6..6f775e70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,8 +79,9 @@ rust_2018_idioms = "warn" unsafe_code = "forbid" [workspace.lints.clippy] -too_many_arguments = "allow" +borrowed_box = "allow" manual_range_contains = "allow" +too_many_arguments = "allow" [profile.release] lto = true # Enable link-time optimization for improved runtime performance diff --git a/holo-bgp/src/events.rs b/holo-bgp/src/events.rs index 863d5546..06a502e4 100644 --- a/holo-bgp/src/events.rs +++ b/holo-bgp/src/events.rs @@ -488,11 +488,11 @@ where ); // Update nexthop tracking. - if let Some(old_route) = adj_rib.in_post.take() { + if let Some(old_route) = adj_rib.in_post() { rib::nexthop_untrack( &mut table.nht, &prefix, - &old_route, + old_route, &instance.tx.ibus, ); } @@ -506,7 +506,8 @@ where adj_rib.update_in_post(Box::new(route), &mut rib.attr_sets); } PolicyResult::Reject => { - if let Some(route) = adj_rib.in_post.take() { + if let Some(route) = adj_rib.remove_in_post(&mut rib.attr_sets) + { rib::nexthop_untrack( &mut table.nht, &prefix, @@ -563,21 +564,17 @@ where rpinfo.route_type, ); - let mut update = false; - if let Some(adj_rib_route) = &mut adj_rib.out_post { - if adj_rib_route.attrs != route.attrs { - *adj_rib_route = Box::new(route); - update = true; - } + // Check if the Adj-RIB-Out was updated. + let update = if let Some(adj_rib_route) = adj_rib.out_post() { + adj_rib_route.attrs != route.attrs } else { + true + }; + + if update { adj_rib .update_out_post(Box::new(route), &mut rib.attr_sets); - update = true; - } - // If the Adj-RIB-Out was updated, enqueue the route for - // transmission. - if update { // Update route's attributes before transmission. let mut attrs = rpinfo.attrs; attrs_tx_update::( @@ -593,7 +590,7 @@ where } } PolicyResult::Reject => { - if adj_rib.out_post.take().is_some() { + if adj_rib.remove_out_post(&mut rib.attr_sets).is_some() { // Update neighbor's Tx queue. let update_queue = A::update_queue(&mut nbr.update_queues); update_queue.unreach.insert(prefix); @@ -802,10 +799,10 @@ where let dest = entry.get(); if dest.local.is_none() && dest.adj_rib.values().all(|adj_rib| { - adj_rib.in_pre.is_none() - && adj_rib.in_post.is_none() - && adj_rib.out_pre.is_none() - && adj_rib.out_post.is_none() + adj_rib.in_pre().is_none() + && adj_rib.in_post().is_none() + && adj_rib.out_pre().is_none() + && adj_rib.out_post().is_none() }) { entry.remove(); diff --git a/holo-bgp/src/neighbor.rs b/holo-bgp/src/neighbor.rs index 879dc293..99df858b 100644 --- a/holo-bgp/src/neighbor.rs +++ b/holo-bgp/src/neighbor.rs @@ -929,10 +929,9 @@ impl Neighbor { let table = A::table(&mut rib.tables); for (prefix, dest) in table.prefixes.iter_mut() { // Clear the Adj-RIB-In and Adj-RIB-Out. - if let Some(adj_rib) = dest.adj_rib.remove(&self.remote_addr).take() - { + if let Some(mut adj_rib) = dest.adj_rib.remove(&self.remote_addr) { // Update nexthop tracking. - if let Some(adj_in_route) = &adj_rib.in_post { + if let Some(adj_in_route) = adj_rib.in_post() { rib::nexthop_untrack( &mut table.nht, prefix, @@ -940,6 +939,11 @@ impl Neighbor { ibus_tx, ); } + + adj_rib.remove_in_pre(&mut rib.attr_sets); + adj_rib.remove_in_post(&mut rib.attr_sets); + adj_rib.remove_out_pre(&mut rib.attr_sets); + adj_rib.remove_out_post(&mut rib.attr_sets); } // Enqueue prefix for the BGP Decision Process. diff --git a/holo-bgp/src/northbound/state.rs b/holo-bgp/src/northbound/state.rs index 82494128..4c2d8c0b 100644 --- a/holo-bgp/src/northbound/state.rs +++ b/holo-bgp/src/northbound/state.rs @@ -940,7 +940,7 @@ fn load_callbacks() -> Callbacks { |(prefix, dest)| { dest.adj_rib .get(&nbr.remote_addr) - .and_then(|adj_rib| adj_rib.in_pre.as_ref()) + .and_then(|adj_rib| adj_rib.in_pre()) .map(|route| { ListEntry::RibV4AdjInPreRoute(prefix, route) }) @@ -1041,7 +1041,7 @@ fn load_callbacks() -> Callbacks { |(prefix, dest)| { dest.adj_rib .get(&nbr.remote_addr) - .and_then(|adj_rib| adj_rib.in_post.as_ref()) + .and_then(|adj_rib| adj_rib.in_post()) .map(|route| { ListEntry::RibV4AdjInPostRoute(prefix, route) }) @@ -1147,7 +1147,7 @@ fn load_callbacks() -> Callbacks { |(prefix, dest)| { dest.adj_rib .get(&nbr.remote_addr) - .and_then(|adj_rib| adj_rib.out_pre.as_ref()) + .and_then(|adj_rib| adj_rib.out_pre()) .map(|route| { ListEntry::RibV4AdjOutPreRoute(prefix, route) }) @@ -1248,7 +1248,7 @@ fn load_callbacks() -> Callbacks { |(prefix, dest)| { dest.adj_rib .get(&nbr.remote_addr) - .and_then(|adj_rib| adj_rib.out_post.as_ref()) + .and_then(|adj_rib| adj_rib.out_post()) .map(|route| { ListEntry::RibV4AdjOutPostRoute(prefix, route) }) @@ -1458,7 +1458,7 @@ fn load_callbacks() -> Callbacks { |(prefix, dest)| { dest.adj_rib .get(&nbr.remote_addr) - .and_then(|adj_rib| adj_rib.in_pre.as_ref()) + .and_then(|adj_rib| adj_rib.in_pre()) .map(|route| { ListEntry::RibV6AdjInPreRoute(prefix, route) }) @@ -1559,7 +1559,7 @@ fn load_callbacks() -> Callbacks { |(prefix, dest)| { dest.adj_rib .get(&nbr.remote_addr) - .and_then(|adj_rib| adj_rib.in_post.as_ref()) + .and_then(|adj_rib| adj_rib.in_post()) .map(|route| { ListEntry::RibV6AdjInPostRoute(prefix, route) }) @@ -1665,7 +1665,7 @@ fn load_callbacks() -> Callbacks { |(prefix, dest)| { dest.adj_rib .get(&nbr.remote_addr) - .and_then(|adj_rib| adj_rib.out_pre.as_ref()) + .and_then(|adj_rib| adj_rib.out_pre()) .map(|route| { ListEntry::RibV6AdjOutPreRoute(prefix, route) }) @@ -1766,7 +1766,7 @@ fn load_callbacks() -> Callbacks { |(prefix, dest)| { dest.adj_rib .get(&nbr.remote_addr) - .and_then(|adj_rib| adj_rib.out_post.as_ref()) + .and_then(|adj_rib| adj_rib.out_post()) .map(|route| { ListEntry::RibV6AdjOutPostRoute(prefix, route) }) diff --git a/holo-bgp/src/rib.rs b/holo-bgp/src/rib.rs index 769fac41..d082d791 100644 --- a/holo-bgp/src/rib.rs +++ b/holo-bgp/src/rib.rs @@ -61,10 +61,10 @@ pub struct Destination { #[derive(Debug, Default)] pub struct AdjRib { - pub in_pre: Option>, - pub in_post: Option>, - pub out_pre: Option>, - pub out_post: Option>, + in_pre: Option>, + in_post: Option>, + out_pre: Option>, + out_post: Option>, } #[derive(Clone, Debug, Eq, PartialEq)] @@ -214,6 +214,22 @@ impl AdjRib { *table = Some(route) } + pub(crate) fn in_pre(&self) -> Option<&Box> { + self.in_pre.as_ref() + } + + pub(crate) fn in_post(&self) -> Option<&Box> { + self.in_post.as_ref() + } + + pub(crate) fn out_pre(&self) -> Option<&Box> { + self.out_pre.as_ref() + } + + pub(crate) fn out_post(&self) -> Option<&Box> { + self.out_post.as_ref() + } + pub(crate) fn remove_in_pre( &mut self, attr_sets: &mut AttrSetsCxt, @@ -791,14 +807,14 @@ pub(crate) fn loc_rib_update( Debug::BestPathNotFound(prefix.into()).log(); // Remove route from the Loc-RIB. - if let Some(local_route) = dest.local.take() - && !local_route.origin.is_local() - { + if let Some(local_route) = dest.local.take() { // Check attribute sets that might need to be removed. attr_sets.remove_route_attr_sets(&local_route.attrs); // Uninstall route from the global RIB. - southbound::tx::route_uninstall(ibus_tx, prefix); + if !local_route.origin.is_local() { + southbound::tx::route_uninstall(ibus_tx, prefix); + } } } }