Skip to content

Commit

Permalink
routing: add Adjacency type and Adjacency table
Browse files Browse the repository at this point in the history
Add minimal definitions for adjacency and adjacency table. We'll
use the adjacency table to map directly connected next-hops to
MAC addresses for the L2 dst MAC re-write. This table should play
the role of an ARP/neigh cache, and we may populate it from the
kernel neighbor system, or via netlink.

Signed-off-by: Fredi Raspall <[email protected]>
  • Loading branch information
Fredi-raspall committed Feb 6, 2025
1 parent 4a8e20f commit e17aa05
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions routing/src/adjacency.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::interface::IfIndex;
use net::eth::mac::Mac;
use std::collections::HashMap;
use std::net::IpAddr;

#[allow(dead_code)]
pub struct Adjacency {
pub address: IpAddr,
pub mac: Mac,
pub ifindex: IfIndex,
}
pub struct AdjacencyTable(HashMap<IpAddr, Adjacency>);

#[allow(dead_code)]
impl AdjacencyTable {
pub(crate) fn new() -> Self {
Self(HashMap::new())
// Todo: use a fast hasher
}
}

#[allow(dead_code)]
impl AdjacencyTable {
pub(crate) fn add_adjacency(&mut self, address: IpAddr, mac: Mac, ifindex: IfIndex) {
self.0.insert(
address,
Adjacency {
address,
mac,
ifindex,
},
);
}
pub(crate) fn del_adjacency(&mut self, address: &IpAddr) {
self.0.remove(address);
}
pub(crate) fn get_adjacency(&self, address: &IpAddr) -> Option<&Adjacency> {
self.0.get(address)
}
}
1 change: 1 addition & 0 deletions routing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod adjacency;
mod encapsulation;
mod errors;
mod interface;
Expand Down

0 comments on commit e17aa05

Please sign in to comment.