Skip to content

Commit

Permalink
implement JniReferencesFeature in daemon
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Weisshuhn <[email protected]>
  • Loading branch information
der-whity committed Dec 5, 2024
1 parent 586b496 commit 34291d1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion rust/backend/daemon/src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async fn test_get_configuration(client: &mut ZiofaClient<Channel>, verbose: bool
uprobes: vec![],
vfs_write: Some(VfsWriteConfig { entries: std::collections::HashMap::new() }),
sys_sendmsg: Some(SysSendmsgConfig { entries: std::collections::HashMap::new() }),
jni_references: Some(JniReferencesConfig { entries: std::collections::HashMap::new() }),
jni_references: Some(JniReferencesConfig { pids: vec![] }),
}
}
};
Expand Down
8 changes: 7 additions & 1 deletion rust/backend/daemon/src/ebpf_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use aya::{Ebpf, EbpfError};
use shared::config::Configuration;
use thiserror::Error;

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

#[derive(Debug, Error)]
pub enum EbpfErrorWrapper {
Expand All @@ -26,19 +26,23 @@ 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(())
}
Expand All @@ -50,6 +54,8 @@ impl State {
) -> 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.sys_sendmsg.as_ref())?;


Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions rust/backend/daemon/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ use aya::{
use shared::config::{SysSendmsgConfig, VfsWriteConfig, JniReferencesConfig};


pub struct JNIReferences {
pub struct JNIReferencesFeature {
trace_add_local_link: Option<UProbeLink>,
trace_del_local_link: Option<UProbeLink>,
trace_add_global_link: Option<UProbeLink>,
trace_del_global_link: Option<UProbeLink>,
}

impl JNIReferences {
pub fn new() -> JNIReferences {
JNIReferences {
impl JNIReferencesFeature {
pub fn new() -> JNIReferencesFeature {
JNIReferencesFeature {
trace_add_local_link: None,
trace_del_local_link: None,
trace_add_global_link: None,
Expand Down Expand Up @@ -148,7 +148,7 @@ impl JNIReferences {
match config {
Some(config) => {
self.attach(ebpf)?;
self.update_pids(ebpf, &config.entries)?;
self.update_pids(ebpf, &config.pids)?;
}
None => {
self.detach(ebpf)?;
Expand Down
3 changes: 2 additions & 1 deletion rust/backend/daemon/tests/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// SPDX-License-Identifier: MIT

use shared::config::{Configuration, SysSendmsgConfig, VfsWriteConfig};
use shared::config::{Configuration, SysSendmsgConfig, VfsWriteConfig, JniReferencesConfig};
use shared::ziofa::{process::Cmd, ziofa_client::ZiofaClient};
use tonic::transport::Channel;

Expand Down Expand Up @@ -65,6 +65,7 @@ async fn set_get_configuration() {
uprobes: vec![],
vfs_write: Some(VfsWriteConfig { entries: std::collections::HashMap::new() }),
sys_sendmsg: Some(SysSendmsgConfig { entries: std::collections::HashMap::new() }),
jni_references: Some(JniReferencesConfig { pids: vec![] }),
};
assert_eq!(
client
Expand Down
2 changes: 1 addition & 1 deletion rust/shared/proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ message SysSendmsgConfig {
}

message JniReferencesConfig {
repeated uint32 entries = 1;
repeated uint32 pids = 1;
}

0 comments on commit 34291d1

Please sign in to comment.