Skip to content

Commit

Permalink
Merge pull request #20 from matissecallewaert/enhancement/change-to-t…
Browse files Browse the repository at this point in the history
…wo-ebpf-programs

🏗️ Update so only two ebpf programs are needed
  • Loading branch information
matissecallewaert authored Mar 19, 2024
2 parents d491482 + bed7b6a commit c8358cf
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 458 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ jobs:
- name: Install bpf-linker
run: cargo install bpf-linker

- name: Build ingress eBPF program ipv4
run: cargo xtask ingress-ebpf-ipv4
- name: Build eBPF program ipv4
run: cargo xtask ebpf-ipv4

- name: Build egress eBPF program ipv4
run: cargo xtask egress-ebpf-ipv4

- name: Build ingress eBPF program ipv6
run: cargo xtask ingress-ebpf-ipv6

- name: Build egress eBPF program ipv6
run: cargo xtask egress-ebpf-ipv6
- name: Build eBPF program ipv6
run: cargo xtask ebpf-ipv6

- name: Build userspace program
run: cargo build --verbose
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions egress-ebpf-ipv4/Cargo.toml → ebpf-ipv4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "egress-ebpf-ipv4"
name = "ebpf-ipv4"
version = "0.1.0"
edition = "2021"

Expand All @@ -10,7 +10,7 @@ common = { path = "../common" }
network-types = "0.0.5"

[[bin]]
name = "feature-extraction-tool-egress-ipv4"
name = "feature-extraction-tool-ipv4"
path = "src/main.rs"

[profile.dev]
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions egress-ebpf-ipv4/src/main.rs → ebpf-ipv4/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
}

#[map]
static EVENTS_EGRESS_IPV4: PerfEventArray<BasicFeaturesIpv4> = PerfEventArray::with_max_entries(1024, 0);
static EVENTS_IPV4: PerfEventArray<BasicFeaturesIpv4> = PerfEventArray::with_max_entries(1024, 0);

#[classifier]
pub fn tc_flow_track(ctx: TcContext) -> i32 {
Expand Down Expand Up @@ -148,7 +148,7 @@ fn try_tc_flow_track(ctx: TcContext) -> Result<i32, ()> {
};

// the zero value is a flag
EVENTS_EGRESS_IPV4.output(&ctx, &flow, 0);
EVENTS_IPV4.output(&ctx, &flow, 0);

Ok(TC_ACT_PIPE)
}
File renamed without changes.
4 changes: 2 additions & 2 deletions egress-ebpf-ipv6/Cargo.toml → ebpf-ipv6/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "egress-ebpf-ipv6"
name = "ebpf-ipv6"
version = "0.1.0"
edition = "2021"

Expand All @@ -10,7 +10,7 @@ common = { path = "../common" }
network-types = "0.0.5"

[[bin]]
name = "feature-extraction-tool-egress-ipv6"
name = "feature-extraction-tool-ipv6"
path = "src/main.rs"

[profile.dev]
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions egress-ebpf-ipv6/src/main.rs → ebpf-ipv6/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
}

#[map]
static EVENTS_EGRESS_IPV6: PerfEventArray<BasicFeaturesIpv6> = PerfEventArray::with_max_entries(1024, 0);
static EVENTS_IPV6: PerfEventArray<BasicFeaturesIpv6> = PerfEventArray::with_max_entries(1024, 0);

#[classifier]
pub fn tc_flow_track(ctx: TcContext) -> i32 {
Expand Down Expand Up @@ -148,7 +148,7 @@ fn try_tc_flow_track(ctx: TcContext) -> Result<i32, ()> {
};

// the zero value is a flag
EVENTS_EGRESS_IPV6.output(&ctx, &flow, 0);
EVENTS_IPV6.output(&ctx, &flow, 0);

Ok(TC_ACT_PIPE)
}
24 changes: 12 additions & 12 deletions feature-extraction-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,39 +101,39 @@ where
// Loading the eBPF program for egress, the macros make sure the correct file is loaded
#[cfg(debug_assertions)]
let mut bpf_egress_ipv4 = Bpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/debug/feature-extraction-tool-egress-ipv4"
"../../target/bpfel-unknown-none/debug/feature-extraction-tool-ipv4"
))?;
#[cfg(not(debug_assertions))]
let mut bpf_egress_ipv4 = Bpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/feature-extraction-tool-egress-ipv4"
"../../target/bpfel-unknown-none/release/feature-extraction-tool-ipv4"
))?;

#[cfg(debug_assertions)]
let mut bpf_egress_ipv6 = Bpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/debug/feature-extraction-tool-egress-ipv6"
"../../target/bpfel-unknown-none/debug/feature-extraction-tool-ipv6"
))?;
#[cfg(not(debug_assertions))]
let mut bpf_egress_ipv6 = Bpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/feature-extraction-tool-egress-ipv6"
"../../target/bpfel-unknown-none/release/feature-extraction-tool-ipv6"
))?;

// Loading the eBPF program for ingress, the macros make sure the correct file is loaded
#[cfg(debug_assertions)]
let mut bpf_ingress_ipv4 = Bpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/debug/feature-extraction-tool-ingress-ipv4"
"../../target/bpfel-unknown-none/debug/feature-extraction-tool-ipv4"
))?;
#[cfg(not(debug_assertions))]
let mut bpf_ingress_ipv4 = Bpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/feature-extraction-tool-ingress-ipv4"
"../../target/bpfel-unknown-none/release/feature-extraction-tool-ipv4"
))?;

#[cfg(debug_assertions)]
let mut bpf_ingress_ipv6 = Bpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/debug/feature-extraction-tool-ingress-ipv6"
"../../target/bpfel-unknown-none/debug/feature-extraction-tool-ipv6"
))?;
#[cfg(not(debug_assertions))]
let mut bpf_ingress_ipv6 = Bpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/feature-extraction-tool-ingress-ipv6"
"../../target/bpfel-unknown-none/release/feature-extraction-tool-ipv6"
))?;

// Loading and attaching the eBPF program function for egress
Expand Down Expand Up @@ -172,16 +172,16 @@ where

// Attach to the event arrays
let mut flows_egress_ipv4 =
AsyncPerfEventArray::try_from(bpf_egress_ipv4.take_map("EVENTS_EGRESS_IPV4").unwrap())?;
AsyncPerfEventArray::try_from(bpf_egress_ipv4.take_map("EVENTS_IPV4").unwrap())?;

let mut flows_egress_ipv6 =
AsyncPerfEventArray::try_from(bpf_egress_ipv6.take_map("EVENTS_EGRESS_IPV6").unwrap())?;
AsyncPerfEventArray::try_from(bpf_egress_ipv6.take_map("EVENTS_IPV6").unwrap())?;

let mut flows_ingress_ipv4 =
AsyncPerfEventArray::try_from(bpf_ingress_ipv4.take_map("EVENTS_INGRESS_IPV4").unwrap())?;
AsyncPerfEventArray::try_from(bpf_ingress_ipv4.take_map("EVENTS_IPV4").unwrap())?;

let mut flows_ingress_ipv6 =
AsyncPerfEventArray::try_from(bpf_ingress_ipv6.take_map("EVENTS_INGRESS_IPV6").unwrap())?;
AsyncPerfEventArray::try_from(bpf_ingress_ipv6.take_map("EVENTS_IPV6").unwrap())?;

let flow_map_ipv4: Arc<DashMap<String, T>> = Arc::new(DashMap::new());

Expand Down
6 changes: 0 additions & 6 deletions ingress-ebpf-ipv4/.cargo/config.toml

This file was deleted.

33 changes: 0 additions & 33 deletions ingress-ebpf-ipv4/Cargo.toml

This file was deleted.

2 changes: 0 additions & 2 deletions ingress-ebpf-ipv4/rust-toolchain.toml

This file was deleted.

1 change: 0 additions & 1 deletion ingress-ebpf-ipv4/rustfmt.toml

This file was deleted.

154 changes: 0 additions & 154 deletions ingress-ebpf-ipv4/src/main.rs

This file was deleted.

6 changes: 0 additions & 6 deletions ingress-ebpf-ipv6/.cargo/config.toml

This file was deleted.

Loading

0 comments on commit c8358cf

Please sign in to comment.