Skip to content

Commit e17aa05

Browse files
committed
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]>
1 parent 4a8e20f commit e17aa05

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

routing/src/adjacency.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use crate::interface::IfIndex;
2+
use net::eth::mac::Mac;
3+
use std::collections::HashMap;
4+
use std::net::IpAddr;
5+
6+
#[allow(dead_code)]
7+
pub struct Adjacency {
8+
pub address: IpAddr,
9+
pub mac: Mac,
10+
pub ifindex: IfIndex,
11+
}
12+
pub struct AdjacencyTable(HashMap<IpAddr, Adjacency>);
13+
14+
#[allow(dead_code)]
15+
impl AdjacencyTable {
16+
pub(crate) fn new() -> Self {
17+
Self(HashMap::new())
18+
// Todo: use a fast hasher
19+
}
20+
}
21+
22+
#[allow(dead_code)]
23+
impl AdjacencyTable {
24+
pub(crate) fn add_adjacency(&mut self, address: IpAddr, mac: Mac, ifindex: IfIndex) {
25+
self.0.insert(
26+
address,
27+
Adjacency {
28+
address,
29+
mac,
30+
ifindex,
31+
},
32+
);
33+
}
34+
pub(crate) fn del_adjacency(&mut self, address: &IpAddr) {
35+
self.0.remove(address);
36+
}
37+
pub(crate) fn get_adjacency(&self, address: &IpAddr) -> Option<&Adjacency> {
38+
self.0.get(address)
39+
}
40+
}

routing/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod adjacency;
12
mod encapsulation;
23
mod errors;
34
mod interface;

0 commit comments

Comments
 (0)