Skip to content

Commit f38ff15

Browse files
[#92]: added lib.rs file in identity component to use the identity functions in the agent api. added better error handling for attach_detach_veth function
1 parent c99351f commit f38ff15

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

core/src/components/identity/src/helpers.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,24 @@ use aya::{
55
Bpf,
66
maps::{
77
MapData,
8-
perf::{PerfEventArray, PerfEventArrayBuffer},
8+
perf::{PerfEventArrayBuffer},
99
},
1010
programs::{SchedClassifier, TcAttachType},
11-
util::online_cpus,
1211
};
1312
use bytes::BytesMut;
1413
use nix::net::if_::if_nameindex;
1514
use std::collections::HashMap;
1615
use std::sync::Mutex;
1716
use std::{
18-
ascii,
1917
borrow::BorrowMut,
2018
net::Ipv4Addr,
21-
string,
2219
sync::{
2320
Arc,
2421
atomic::{AtomicBool, Ordering},
2522
},
2623
};
27-
use tracing::{error, event, info, warn};
24+
use tracing::{error, info, warn};
2825

29-
use anyhow::Context;
30-
use std::path::Path;
31-
use tokio::{fs, signal};
3226
/*
3327
* decleare bpf path env variable
3428
*/
@@ -142,13 +136,22 @@ pub async fn display_veth_events<T: BorrowMut<MapData>>(
142136
state,
143137
dev_addr
144138
);
145-
attach_detach_veth(
139+
match attach_detach_veth(
146140
bpf.clone(),
147141
vethlog.event_type,
148142
veth_name,
149143
link_ids.clone(),
150144
)
151-
.await;
145+
.await
146+
{
147+
std::result::Result::Ok(_) => {
148+
info!("Attach/Detach veth function attached correctly")
149+
}
150+
Err(e) => error!(
151+
"Error attaching Attach/Detach function. Error : {}",
152+
e
153+
),
154+
}
152155
}
153156
Err(_) => info!("Unknown name or corrupted field"),
154157
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub mod helpers;
2+
pub mod structs;
3+
pub mod enums;
4+
pub mod map_handlers;

core/src/components/identity/src/map_handlers.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::path::PathBuf;
2-
use std::sync::Mutex;
3-
use std::sync::Arc;
41
use anyhow::Error;
5-
use aya::maps::Map;
2+
use anyhow::Ok;
63
use aya::Bpf;
7-
use tracing::{error};
4+
use aya::maps::Map;
5+
use std::path::PathBuf;
6+
use std::sync::Arc;
7+
use std::sync::Mutex;
88
use tokio::fs;
9-
9+
use tracing::error;
1010

1111
pub fn init_bpf_maps(bpf: Arc<Mutex<Bpf>>) -> Result<(Map, Map), anyhow::Error> {
1212
// this function init the bpfs maps used in the main program
@@ -45,8 +45,7 @@ pub fn init_bpf_maps(bpf: Arc<Mutex<Bpf>>) -> Result<(Map, Map), anyhow::Error>
4545
//TODO: chmod 700 <path> to setup the permissions to pin maps TODO:add this permission in the CLI
4646
//TODO: add bpf mounts during cli installation
4747
pub async fn map_pinner(maps: &(Map, Map), path: &PathBuf) -> Result<(), Error> {
48-
49-
//FIXME: add exception for already pinned maps
48+
//FIXME: add exception for already pinned maps
5049
if !path.exists() {
5150
error!("Pin path {:?} does not exist. Creating it...", path);
5251
let _ = fs::create_dir_all(path)

0 commit comments

Comments
 (0)