Skip to content

Commit

Permalink
feat(rust): update ebpf
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjoDeundiak committed Nov 21, 2024
1 parent 0483daf commit 0fcfdec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_transport_tcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cfg-if = "1.0.0"
log = "0.4.21"
minicbor = { version = "0.25.1", default-features = false, features = ["derive"] }
ockam_core = { path = "../ockam_core", version = "^0.120.0" }
ockam_ebpf = { git = "https://github.com/build-trust/ockam-ebpf.git", version = "0.2.0", optional = true }
ockam_ebpf = { git = "https://github.com/build-trust/ockam-ebpf.git", version = "0.4.0", optional = true }
ockam_macros = { path = "../ockam_macros", version = "^0.35.0" }
ockam_node = { path = "../ockam_node", version = "^0.132.0" }
ockam_transport_core = { path = "../ockam_transport_core", version = "^0.97.0" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ struct IfaceLink {
struct OckamBpf {
ebpf: Ebpf,

inlet_port_map: aya::maps::HashMap<MapData, Port, Proto>,
outlet_port_map: aya::maps::HashMap<MapData, Port, Proto>,
port_map: aya::maps::HashMap<MapData, Port, Proto>,
}

impl Default for TcpTransportEbpfSupport {
Expand Down Expand Up @@ -219,21 +218,14 @@ impl TcpTransportEbpfSupport {
warn!("failed to initialize eBPF logger: {}", e);
}

let inlet_port_map = aya::maps::HashMap::<_, Port, Proto>::try_from(
ebpf.take_map("INLET_PORT_MAP").unwrap(),
)
.map_err(map_map_error)?;
let outlet_port_map = aya::maps::HashMap::<_, Port, Proto>::try_from(
ebpf.take_map("OUTLET_PORT_MAP").unwrap(),
)
.map_err(map_map_error)?;

let bpf = OckamBpf {
ebpf,
inlet_port_map,
outlet_port_map,
let port_map = if let Some(map) = ebpf.take_map("PORT_MAP") {
aya::maps::HashMap::<_, Port, Proto>::try_from(map).map_err(map_map_error)?
} else {
return Err(Error::new(Origin::Core, Kind::Io, "PORT_MAP doesn't exist"));
};

let bpf = OckamBpf { ebpf, port_map };

*bpf_lock = Some(bpf);

info!("Initialized eBPF");
Expand Down Expand Up @@ -343,7 +335,7 @@ impl TcpTransportEbpfSupport {

bpf.as_mut()
.unwrap()
.inlet_port_map
.port_map
.insert(port, self.ip_proto, 0)
.map_err(|e| TransportError::AddingInletPort(e.to_string()))?;

Expand All @@ -356,7 +348,7 @@ impl TcpTransportEbpfSupport {

bpf.as_mut()
.unwrap()
.inlet_port_map
.port_map
.remove(&port)
.map_err(|e| TransportError::RemovingInletPort(e.to_string()))?;

Expand All @@ -369,7 +361,7 @@ impl TcpTransportEbpfSupport {

bpf.as_mut()
.unwrap()
.outlet_port_map
.port_map
.insert(port, self.ip_proto, 0)
.map_err(|e| TransportError::AddingOutletPort(e.to_string()))?;

Expand All @@ -382,7 +374,7 @@ impl TcpTransportEbpfSupport {

bpf.as_mut()
.unwrap()
.outlet_port_map
.port_map
.remove(&port)
.map_err(|e| TransportError::RemovingOutletPort(e.to_string()))?;

Expand Down

0 comments on commit 0fcfdec

Please sign in to comment.