generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mr-Kanister <[email protected]>
- Loading branch information
1 parent
bb00a1e
commit 12b0f29
Showing
4 changed files
with
149 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
use aya::{ | ||
programs::{kprobe::KProbeLinkId, KProbe}, | ||
Ebpf, EbpfError, | ||
}; | ||
|
||
pub struct VfsFeature { | ||
vfs_write_id: Option<KProbeLinkId>, | ||
vfs_write_ret_id: Option<KProbeLinkId>, | ||
} | ||
|
||
impl VfsFeature { | ||
pub fn new() -> VfsFeature { | ||
VfsFeature { | ||
vfs_write_id: None, | ||
vfs_write_ret_id: None, | ||
} | ||
} | ||
|
||
pub fn create(&mut self, ebpf: &mut Ebpf) -> Result<(), EbpfError> { | ||
let vfs_write: &mut KProbe = ebpf | ||
.program_mut("vfs_write") | ||
.ok_or(EbpfError::ProgramError( | ||
aya::programs::ProgramError::InvalidName { | ||
name: "vfs_write".to_string(), | ||
}, | ||
))? | ||
.try_into()?; | ||
vfs_write.load()?; | ||
|
||
let vfs_write_ret: &mut KProbe = ebpf | ||
.program_mut("vfs_write_ret") | ||
.ok_or(EbpfError::ProgramError( | ||
aya::programs::ProgramError::InvalidName { | ||
name: "vfs_write_ret".to_string(), | ||
}, | ||
))? | ||
.try_into()?; | ||
vfs_write_ret.load()?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn attach(&mut self, ebpf: &mut Ebpf) -> Result<(), EbpfError> { | ||
let vfs_write: &mut KProbe = ebpf | ||
.program_mut("vfs_write") | ||
.ok_or(EbpfError::ProgramError( | ||
aya::programs::ProgramError::InvalidName { | ||
name: "vfs_write".to_string(), | ||
}, | ||
))? | ||
.try_into()?; | ||
self.vfs_write_id = Some(vfs_write.attach("vfs_write", 0)?); | ||
|
||
let vfs_write_ret: &mut KProbe = ebpf | ||
.program_mut("vfs_write_ret") | ||
.ok_or(EbpfError::ProgramError( | ||
aya::programs::ProgramError::InvalidName { | ||
name: "vfs_write_ret".to_string(), | ||
}, | ||
))? | ||
.try_into()?; | ||
self.vfs_write_ret_id = Some(vfs_write_ret.attach("vfs_write", 0)?); | ||
Ok(()) | ||
} | ||
|
||
pub fn detach(&mut self, ebpf: &mut Ebpf) -> Result<(), EbpfError> { | ||
let vfs_write: &mut KProbe = ebpf | ||
.program_mut("vfs_write") | ||
.ok_or(EbpfError::ProgramError( | ||
aya::programs::ProgramError::InvalidName { | ||
name: "vfs_write".to_string(), | ||
}, | ||
))? | ||
.try_into()?; | ||
|
||
if let Some(vfs_write_id) = self.vfs_write_id.take() { | ||
vfs_write.detach(vfs_write_id)?; | ||
} else { | ||
return Err(EbpfError::ProgramError( | ||
aya::programs::ProgramError::NotAttached, | ||
)); | ||
} | ||
|
||
let vfs_write_ret: &mut KProbe = ebpf | ||
.program_mut("vfs_write_ret") | ||
.ok_or(EbpfError::ProgramError( | ||
aya::programs::ProgramError::InvalidName { | ||
name: "vfs_write_ret".to_string(), | ||
}, | ||
))? | ||
.try_into()?; | ||
|
||
if let Some(vfs_write_ret_id) = self.vfs_write_ret_id.take() { | ||
vfs_write_ret.detach(vfs_write_ret_id)?; | ||
} else { | ||
return Err(EbpfError::ProgramError( | ||
aya::programs::ProgramError::NotAttached, | ||
)); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
// fn update(&mut self, ebpf: &mut Ebpf) { | ||
// // update pids that are attached | ||
// !todo!(); | ||
// } | ||
|
||
// pub fn events(&mut self, ebpf: &mut Ebpf) { | ||
// // return buffered stream of events | ||
// // will be discussed by Felix and Beni | ||
// } | ||
|
||
pub fn destroy(&mut self, ebpf: &mut Ebpf) -> Result<(), EbpfError> { | ||
// TODO Error handling | ||
let vfs_write: &mut KProbe = ebpf | ||
.program_mut("vfs_write") | ||
.ok_or(EbpfError::ProgramError( | ||
aya::programs::ProgramError::InvalidName { | ||
name: "vfs_write".to_string(), | ||
}, | ||
))? | ||
.try_into()?; | ||
vfs_write.unload()?; | ||
|
||
let vfs_write_ret: &mut KProbe = ebpf | ||
.program_mut("vfs_write_ret") | ||
.ok_or(EbpfError::ProgramError( | ||
aya::programs::ProgramError::InvalidName { | ||
name: "vfs_write_ret".to_string(), | ||
}, | ||
))? | ||
.try_into()?; | ||
vfs_write_ret.unload()?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters