Skip to content

Commit 01c63c4

Browse files
[#158]: added control to skip load of blocklist if the addresses vector is empty. Added comments and annotations
1 parent 398bff0 commit 01c63c4

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

core/common/src/map_handlers.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ pub async fn populate_blocklist() -> Result<(), Error> {
121121
.filter(|s| !s.is_empty())
122122
.collect();
123123
//String parsing from "x y" to ["x","y"]
124-
info!("Inserting addresses: {:?}", addresses);
125-
for item in addresses {
124+
if addresses.is_empty() {
125+
warn!("No addresses found in the blocklist. Skipping load");
126+
}
127+
for item in &addresses {
128+
info!("Inserting addresses: {:?}", &item);
126129
let addr = Ipv4Addr::from_str(&item)?.octets();
127130
let _ = blocklist_map.insert(addr, addr, 0);
128131
}
@@ -138,6 +141,7 @@ pub async fn populate_blocklist() -> Result<(), Error> {
138141
}
139142

140143
#[cfg(feature = "map-handlers")]
144+
// TODO: modify this to accept also HashMap types
141145
pub fn load_perf_event_array_from_mapdata(
142146
path: &'static str,
143147
) -> Result<aya::maps::PerfEventArray<aya::maps::MapData>, Error> {

core/common/src/program_handlers.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,38 @@ pub fn load_program(
1313
.lock()
1414
.map_err(|e| anyhow::anyhow!("Cannot get value from lock. Reason: {}", e))?;
1515

16-
// Load and attach the eBPF programs
16+
// Load and attach the eBPF program
1717
let program: &mut KProbe = bpf_new
1818
.program_mut(program_name)
1919
.ok_or_else(|| anyhow::anyhow!("Program {} not found", program_name))?
2020
.try_into()
2121
.map_err(|e| anyhow::anyhow!("Failed to convert program: {:?}", e))?;
2222

23+
// STEP 1: load program
24+
2325
program
2426
.load()
2527
.map_err(|e| anyhow::anyhow!("Cannot load program: {}. Error: {}", &program_name, e))?;
2628

29+
// STEP 2: Attach the loaded program to kernel symbol
2730
match program.attach(kernel_symbol, 0) {
28-
Ok(_) => info!("{} program attached successfully", kernel_symbol),
31+
Ok(_) => info!(
32+
"{} program attached successfully to kernel symbol {}",
33+
&program_name, &kernel_symbol
34+
),
2935
Err(e) => {
30-
error!("Error attaching {} program {:?}", kernel_symbol, e);
36+
error!(
37+
"Error attaching {} program to kernel symbol {}. Reason: {:?}",
38+
&program_name, &kernel_symbol, e
39+
);
3140
return Err(anyhow::anyhow!(
32-
"Failed to attach {}: {:?}",
33-
kernel_symbol,
41+
"Failed to attach program {} to kernel symbol {}. Reason {:?}",
42+
&program_name,
43+
&kernel_symbol,
3444
e
3545
));
3646
}
3747
};
3848

39-
info!(
40-
"eBPF program {} loaded and attached successfully",
41-
program_name
42-
);
4349
Ok(())
4450
}

0 commit comments

Comments
 (0)