Skip to content

Commit

Permalink
Merge pull request #150 from amosproj/features_refactor
Browse files Browse the repository at this point in the history
Features refactor
  • Loading branch information
ffranzgitHub authored Dec 10, 2024
2 parents 027d6eb + f3fa860 commit 4f1ac53
Show file tree
Hide file tree
Showing 10 changed files with 599 additions and 468 deletions.
18 changes: 15 additions & 3 deletions rust/backend/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ pub struct VfsWriteCall {

impl VfsWriteCall {
pub fn new(pid: u32, tid: u32, begin_time_stamp: u64, fp: u64, bytes_written: usize) -> Self {
Self { pid, tid, begin_time_stamp, fp, bytes_written}
Self {
pid,
tid,
begin_time_stamp,
fp,
bytes_written,
}
}
}

Expand All @@ -35,7 +41,13 @@ pub struct SysSendmsgCall {

impl SysSendmsgCall {
pub fn new(pid: u32, tid: u32, begin_time_stamp: u64, fd: u64, duration_nano_sec: u64) -> Self {
Self { pid, tid, begin_time_stamp, fd, duration_nano_sec }
Self {
pid,
tid,
begin_time_stamp,
fd,
duration_nano_sec,
}
}
}

Expand All @@ -58,7 +70,7 @@ pub struct JNICall {
}

#[inline(always)]
pub fn generate_id(pid: u32, tgid: u32) -> u64{
pub fn generate_id(pid: u32, tgid: u32) -> u64 {
let pid_u64 = pid as u64;
let tgid_u64 = tgid as u64;

Expand Down
42 changes: 1 addition & 41 deletions rust/backend/daemon/src/ebpf_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
//
// SPDX-License-Identifier: MIT

use aya::{Ebpf, EbpfError};
use shared::config::Configuration;
use aya::EbpfError;
use thiserror::Error;

use crate::features::{SysSendmsgFeature, VfsFeature, JNIReferencesFeature};

#[derive(Debug, Error)]
pub enum EbpfErrorWrapper {
#[error(transparent)]
Expand All @@ -23,40 +20,3 @@ impl From<EbpfErrorWrapper> for tonic::Status {
}
}

pub struct State {
vfs_write_feature: VfsFeature,
sys_sendmsg_feature: SysSendmsgFeature,
jni_references_feature: JNIReferencesFeature,
}

impl State {
pub fn new() -> State {
State {
vfs_write_feature: VfsFeature::new(),
sys_sendmsg_feature: SysSendmsgFeature::new(),
jni_references_feature: JNIReferencesFeature::new()
}
}

pub fn init(&mut self, ebpf: &mut Ebpf) -> Result<(), EbpfError> {
self.vfs_write_feature.create(ebpf)?;
self.sys_sendmsg_feature.create(ebpf)?;
self.jni_references_feature.create(ebpf)?;


Ok(())
}

pub fn update_from_config(
&mut self,
ebpf: &mut Ebpf,
config: &Configuration,
) -> Result<(), EbpfError> {
self.vfs_write_feature.apply(ebpf, config.vfs_write.as_ref())?;
self.sys_sendmsg_feature.apply(ebpf, config.sys_sendmsg.as_ref())?;
self.jni_references_feature.apply(ebpf, config.jni_references.as_ref())?;


Ok(())
}
}
Loading

0 comments on commit 4f1ac53

Please sign in to comment.