Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Examples/run-with-docker/config/blocklist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# One IPv4 address per line. Empty lines and lines starting with '#' are ignored.
# Example:
# 192.0.2.10
# 198.51.100.25
48 changes: 28 additions & 20 deletions Examples/run-with-docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,34 @@ services:
networks:
- cortexflow

#cortexflow-identity:
# image: lorenzotettamanti/cortexflow-identity:0.1.2
# container_name: cortexflow-identity
# stop_signal: SIGINT
# restart: unless-stopped
# privileged: true
# pid: host
# init: true
# command: ["/usr/local/bin/cortexflow-identity-service"]
# volumes:
# - type: bind
# source: /sys/fs/bpf
# target: /sys/fs/bpf
# bind:
# propagation: shared
# - /lib/modules:/lib/modules:ro
# - /sys/kernel/debug:/sys/kernel/debug
# - /proc:/host/proc:ro
# networks:
# - cortexflow
cortexflow-identity:
image: lorenzotettamanti/cortexflow-identity:0.1.2
container_name: cortexflow-identity
stop_signal: SIGINT
restart: unless-stopped
privileged: true
pid: host
init: true
command: ["/usr/local/bin/cortexflow-identity-service"]
environment:
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
- OTEL_EXPORTER_OTLP_PROTOCOL=grpc
- OTEL_SERVICE_NAME=cortexflow-identity
- OTEL_RESOURCE_ATTRIBUTES=service.namespace=cortexflow,service.version=0.1.5
- DEFAULT_MAP_READING_TIME=100
- BLOCKLIST_FILE=/etc/cortexbrain/blocklist
volumes:
- type: bind
source: /sys/fs/bpf
target: /sys/fs/bpf
bind:
propagation: shared
- /lib/modules:/lib/modules:ro
- /sys/kernel/debug:/sys/kernel/debug
- /proc:/host/proc:ro
- ./config:/etc/cortexbrain:ro
networks:
- cortexflow

otel-collector:
image: otel/opentelemetry-collector-contrib:0.162.0
Expand Down
35 changes: 29 additions & 6 deletions cli/Cargo.lock

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

47 changes: 16 additions & 31 deletions core/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 core/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tonic = "0.14.0"
tonic-prost = "0.14.0"
tracing = "0.1.41"
aya = "0.13.1"
cortexbrain-common = { version="0.1.4", features = [
cortexbrain-common = { path="../common", features = [
"map-handlers",
"network-structs",
"buffer-reader",
Expand Down
3 changes: 1 addition & 2 deletions core/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ COPY --from=ebpf-builder /usr/src/app/target/bpfel-unknown-none/release/conntrac

# Set env vars for your app
ENV BPF_PATH="/usr/src/cortexbrain-agent/conntracker"
ENV PIN_MAP_PATH="/sys/fs/bpf/cortexbrain-identity-service/"
ENV PIN_BLOCKLIST_MAP_PATH="/sys/fs/bpf/cortexbrain-agent/"
ENV PIN_MAP_PATH="/sys/fs/bpf/maps"

# Default command
CMD ["agent-api"]
21 changes: 7 additions & 14 deletions core/api/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anyhow::Context;
use anyhow::anyhow;
use aya::maps::perf::PerfEventArrayBuffer;
use chrono::Local;
Expand All @@ -7,7 +6,7 @@ use cortexbrain_common::buffer_type::PacketLog;
use cortexbrain_common::buffer_type::PacketLossMetrics;
use cortexbrain_common::buffer_type::TimeStampMetrics;
use cortexbrain_common::formatters::{format_ipv4, format_ipv6};
use cortexbrain_common::map_handlers::load_perf_event_array_from_mapdata;
use cortexbrain_common::map_handlers::{blocklist_map_path, load_perf_event_array_from_mapdata};
use std::str::FromStr;
use std::sync::Mutex;
use tonic::{Request, Response, Status};
Expand Down Expand Up @@ -35,8 +34,6 @@ use crate::agent::{
RmIpFromBlocklistRequest, RmIpFromBlocklistResponse, VethHashMapResponse, VethResponse,
agent_server::Agent,
};
use crate::constants::PIN_BLOCKLIST_MAP_PATH;

use crate::helpers::comm_to_string;
use aya::maps::Map;
use std::net::Ipv4Addr;
Expand Down Expand Up @@ -445,8 +442,8 @@ impl Agent for AgentApi {
let req = request.into_inner();

//open blocklist map
let mapdata = MapData::from_pin("/sys/fs/bpf/maps/blocklist_map")
.expect("cannot open blocklist_map Mapdata");
let mapdata =
MapData::from_pin(blocklist_map_path()).expect("cannot open Blocklist Mapdata");
let blocklist_mapdata = Map::HashMap(mapdata); //load mapdata
let mut blocklist_map: ayaHashMap<MapData, [u8; 4], [u8; 4]> =
ayaHashMap::try_from(blocklist_mapdata).unwrap();
Expand All @@ -469,10 +466,6 @@ impl Agent for AgentApi {
.unwrap();
info!("CURRENT BLOCKLIST: {:?}", blocklist_map);
}
let _path = std::env::var(PIN_BLOCKLIST_MAP_PATH)
.context("Blocklist map path not found!")
.unwrap();

//convert the maps with a buffer to match the protobuffer types
let mut converted_blocklist_map: HashMap<String, String> = HashMap::new();
for item in blocklist_map.iter() {
Expand All @@ -496,8 +489,8 @@ impl Agent for AgentApi {
) -> Result<Response<BlocklistResponse>, Status> {
info!("Returning blocklist hashmap");
//open blocklist map
let mapdata = MapData::from_pin("/sys/fs/bpf/maps/blocklist_map")
.expect("cannot open blocklist_map Mapdata");
let mapdata =
MapData::from_pin(blocklist_map_path()).expect("cannot open Blocklist Mapdata");
let blocklist_mapdata = Map::HashMap(mapdata); //load mapdata

let blocklist_map: ayaHashMap<MapData, [u8; 4], [u8; 4]> =
Expand Down Expand Up @@ -526,8 +519,8 @@ impl Agent for AgentApi {
let req = request.into_inner();
info!("Removing ip from blocklist map");
//open blocklist map
let mapdata = MapData::from_pin("/sys/fs/bpf/maps/blocklist_map")
.expect("cannot open blocklist_map Mapdata");
let mapdata =
MapData::from_pin(blocklist_map_path()).expect("cannot open Blocklist Mapdata");
let blocklist_mapdata = Map::HashMap(mapdata); //load mapdata
let mut blocklist_map: ayaHashMap<MapData, [u8; 4], [u8; 4]> =
ayaHashMap::try_from(blocklist_mapdata).unwrap();
Expand Down
1 change: 0 additions & 1 deletion core/api/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub const PIN_BLOCKLIST_MAP_PATH: &str = "PIN_BLOCKLIST_MAP_PATH";
pub const TASK_COMM_LEN: usize = 16;
5 changes: 3 additions & 2 deletions core/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@ opentelemetry = "0.32.0"
opentelemetry_sdk = { version = "0.32.0", features = ["logs", "rt-tokio"] }
opentelemetry-stdout = { version = "0.32.0", features = ["logs"] }
opentelemetry-appender-tracing = "0.32.0"
opentelemetry-otlp = { version = "0.32.0", features = ["logs", "grpc-tonic"] }
opentelemetry-otlp = { version = "0.32.0", features = ["logs", "metrics", "grpc-tonic"] }
bytemuck = "1.25.0"
bytes = "1.12.1"
bytemuck_derive = "1.10.2"
tokio = {version="1.49.0",features=["sync"]}
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
lru = { version = "0.19.2", optional = true }

[dev-dependencies]
opentelemetry_sdk = { version = "0.32.0", features = ["testing"] }

[features]
map-handlers = []
program-handlers = []
network-structs = []
network-structs = ["dep:lru"]
monitoring-structs = []
buffer-reader = []
experimental = []
Loading
Loading