Skip to content

Commit

Permalink
routing: change visibility of some objects
Browse files Browse the repository at this point in the history
Signed-off-by: Fredi Raspall <[email protected]>
  • Loading branch information
Fredi-raspall committed Feb 13, 2025
1 parent 165e44e commit 8c0d1a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions routing/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fn fmt_nhop_rec(f: &mut std::fmt::Formatter<'_>, rc: &Arc<Nhop>, depth: u8) -> s
}
impl Display for NhopStore {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Heading(format!("Next-hop Store ({})", self.0.len())).fmt(f)?;
for nhop in self.0.iter() {
Heading(format!("Next-hop Store ({})", self.len())).fmt(f)?;
for nhop in self.iter() {
fmt_nhop_rec(f, nhop, 0)?;
}
line(f)
Expand Down
22 changes: 15 additions & 7 deletions routing/src/nexthop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use crate::encapsulation::Encapsulation;
use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
use std::collections::btree_set;
pub use std::collections::BTreeSet;
use std::fmt::Debug;
use std::hash::Hash;
Expand All @@ -18,12 +19,12 @@ use std::sync::{Arc, RwLock};
#[derive(Debug)]
/// A collection of unique next-hops. Next-hops are identified by a next-hop key
/// that can contain an address, ifindex and encapsulation.
pub(crate) struct NhopStore(pub(crate) BTreeSet<Arc<Nhop>>);
pub(crate) struct NhopStore(BTreeSet<Arc<Nhop>>);

#[derive(Debug)]
/// A next-hop object that can be shared by multiple routes and that can have
/// references to other next-hops in this (or other?) table.
pub(crate) struct Nhop {
pub struct Nhop {
pub(crate) key: NhopKey,
pub(crate) resolvers: RwLock<Vec<Arc<Nhop>>>,
}
Expand All @@ -39,11 +40,11 @@ pub enum FwAction {
/// make a shared next-hop unique and distinguishable from the rest. This type is also used
/// as return value in next-hop resolution routines.
#[derive(Debug, Default, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub(crate) struct NhopKey {
pub(crate) address: Option<IpAddr>,
pub(crate) ifindex: Option<u32>,
pub(crate) encap: Option<Encapsulation>,
pub(crate) fwaction: FwAction,
pub struct NhopKey {
pub address: Option<IpAddr>,
pub ifindex: Option<u32>,
pub encap: Option<Encapsulation>,
pub fwaction: FwAction,
}

#[allow(dead_code)]
Expand Down Expand Up @@ -320,6 +321,13 @@ impl NhopStore {
self.get_nhop(&key).map(|nh| nh.quick_resolve())
}

//////////////////////////////////////////////////////////////////
/// Iterate over all next-hops in the next-hop store
//////////////////////////////////////////////////////////////////
pub(crate) fn iter(&self) -> btree_set::Iter<'_, Arc<Nhop>> {
self.0.iter()
}

/// Dump the contents of the next-hop map
#[cfg(test)]
pub(crate) fn dump(&self) {
Expand Down

0 comments on commit 8c0d1a4

Please sign in to comment.