-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
routing: add Adjacency type and Adjacency table
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
1 parent
4a8e20f
commit e17aa05
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod adjacency; | ||
mod encapsulation; | ||
mod errors; | ||
mod interface; | ||
|