Skip to content

Commit

Permalink
feat(rust): disable ebpf logs
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjoDeundiak committed Nov 8, 2024
1 parent 693a64f commit 6b7be5c
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 8 deletions.
6 changes: 5 additions & 1 deletion implementations/rust/ockam/ockam_ebpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ description = """
eBPF program used by Ockam TCP Portals
"""

[features]
default = []
logging = ["aya-log-ebpf"]

[dependencies]
aya-ebpf = "0.1.1"
aya-log-ebpf = "0.1.1"
aya-log-ebpf = { version = "0.1.1", optional = true }
network-types = "0.0.7"

[[bin]]
Expand Down
Binary file modified implementations/rust/ockam/ockam_ebpf/ockam_ebpf
Binary file not shown.
14 changes: 7 additions & 7 deletions implementations/rust/ockam/ockam_ebpf/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use aya_ebpf::bindings::TC_ACT_PIPE;
use aya_ebpf::macros::map;
use aya_ebpf::maps::HashMap;
use aya_ebpf::programs::TcContext;
use aya_log_ebpf::{error, trace, warn};

use crate::conversion::{convert_ockam_to_tcp, convert_tcp_to_ockam};
use crate::{error, trace, warn};

pub type Proto = u8;

Expand Down Expand Up @@ -140,7 +140,7 @@ fn handle_ingress_tcp_protocol(ctx: &TcContext, ipv4hdr: *mut Ipv4Hdr) -> Result
syn,
ack,
fin,
rst,
rst
);

convert_tcp_to_ockam(ctx, ipv4hdr, proto);
Expand Down Expand Up @@ -169,7 +169,7 @@ fn handle_ingress_tcp_protocol(ctx: &TcContext, ipv4hdr: *mut Ipv4Hdr) -> Result
syn,
ack,
fin,
rst,
rst
);

convert_tcp_to_ockam(ctx, ipv4hdr, proto);
Expand All @@ -193,7 +193,7 @@ fn handle_ingress_tcp_protocol(ctx: &TcContext, ipv4hdr: *mut Ipv4Hdr) -> Result
syn,
ack,
fin,
rst,
rst
);

Ok(TC_ACT_PIPE)
Expand Down Expand Up @@ -271,7 +271,7 @@ fn handle_egress_ockam_protocol(ctx: &TcContext, ipv4hdr: *mut Ipv4Hdr) -> Resul
syn,
ack,
fin,
rst,
rst
);

convert_ockam_to_tcp(ctx, ipv4hdr, tcphdr);
Expand Down Expand Up @@ -300,7 +300,7 @@ fn handle_egress_ockam_protocol(ctx: &TcContext, ipv4hdr: *mut Ipv4Hdr) -> Resul
syn,
ack,
fin,
rst,
rst
);

convert_ockam_to_tcp(ctx, ipv4hdr, tcphdr);
Expand All @@ -326,7 +326,7 @@ fn handle_egress_ockam_protocol(ctx: &TcContext, ipv4hdr: *mut Ipv4Hdr) -> Resul
syn,
ack,
fin,
rst,
rst
);

Ok(TC_ACT_PIPE)
Expand Down
6 changes: 6 additions & 0 deletions implementations/rust/ockam/ockam_ebpf/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ mod checksum_helpers;
mod common;
mod conversion;

#[cfg(feature = "logging")]
mod logger_aya;

#[cfg(not(feature = "logging"))]
mod logger_noop;

use crate::common::Direction;

#[classifier]
Expand Down
36 changes: 36 additions & 0 deletions implementations/rust/ockam/ockam_ebpf/src/logger_aya.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// TODO: Doesn't work yet

#[macro_export]
macro_rules! error {
($($x:expr),*) => {
aya_log_ebpf::error!{ $($x,)+ }
};
}

#[macro_export]
macro_rules! warn {
($($x:expr),*) => {
aya_log_ebpf::warn!{ $($x,)+ }
}
}

#[macro_export]
macro_rules! debug {
($($x:expr),*) => {
aya_log_ebpf::debug!{ $($x,)+ }
}
}

#[macro_export]
macro_rules! info {
($($x:expr),*) => {
aya_log_ebpf::info!{ $($x,)+ }
}
}

#[macro_export]
macro_rules! trace {
($($x:expr),*) => {
aya_log_ebpf::trace!{ $($x,)+ }
}
}
44 changes: 44 additions & 0 deletions implementations/rust/ockam/ockam_ebpf/src/logger_noop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#[macro_export]
macro_rules! error {
($($x:expr),*) => {{
$(
_ = $x;
)*
}};
}

#[macro_export]
macro_rules! warn {
($($x:expr),*) => {{
$(
_ = $x;
)*
}};
}

#[macro_export]
macro_rules! debug {
($($x:expr),*) => {{
$(
_ = $x;
)*
}};
}

#[macro_export]
macro_rules! info {
($($x:expr),*) => {{
$(
_ = $x;
)*
}};
}

#[macro_export]
macro_rules! trace {
($($x:expr),*) => {{
$(
_ = $x;
)*
}};
}

0 comments on commit 6b7be5c

Please sign in to comment.