Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: write_and_close -> write_close #138

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kunai-common/src/bpf_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ pub enum Type {
FileRename,
#[str("file_unlink")]
FileUnlink,
#[str("write_and_close")]
WriteAndClose,
#[str("write_close")]
WriteClose,

// specific userland events
// those should never be used in eBPF
Expand Down
8 changes: 3 additions & 5 deletions kunai-common/src/bpf_events/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ const fn max_bpf_event_size() -> usize {
Type::Connect => ConnectEvent::size_of(),
Type::DnsQuery => DnsQueryEvent::size_of(),
Type::SendData => SendEntropyEvent::size_of(),
Type::Read
| Type::ReadConfig
| Type::Write
| Type::WriteConfig
| Type::WriteAndClose => FileEvent::size_of(),
Type::Read | Type::ReadConfig | Type::Write | Type::WriteConfig | Type::WriteClose => {
FileEvent::size_of()
}
Type::FileRename => FileRenameEvent::size_of(),
Type::FileUnlink => UnlinkEvent::size_of(),
Type::Error => ErrorEvent::size_of(),
Expand Down
4 changes: 2 additions & 2 deletions kunai-ebpf/src/probes/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ pub fn fs_enter_fput_sync(ctx: ProbeContext) -> u32 {

unsafe fn try_enter_fput(ctx: &ProbeContext) -> ProbeResult<()> {
// if event is disabled we return early
if get_cfg!().map(|c| c.is_event_disabled(Type::WriteAndClose))? {
if get_cfg!().map(|c| c.is_event_disabled(Type::WriteClose))? {
return Ok(());
}

Expand All @@ -432,7 +432,7 @@ unsafe fn try_enter_fput(ctx: &ProbeContext) -> ProbeResult<()> {

let event = alloc::alloc_zero::<FileEvent>()?;

event.init_from_current_task(Type::WriteAndClose)?;
event.init_from_current_task(Type::WriteClose)?;

ignore_result!(inspect_err!(
event.data.path.core_resolve_file(&file, MAX_PATH_DEPTH),
Expand Down
20 changes: 9 additions & 11 deletions kunai/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,17 +1793,15 @@ impl<'s> EventConsumer<'s> {
Err(e) => error!("failed to decode {} event: {:?}", etype, e),
},

Type::WriteConfig
| Type::Write
| Type::ReadConfig
| Type::Read
| Type::WriteAndClose => match event!(enc_event, bpf_events::FileEvent) {
Ok(e) => {
let mut e = self.file_event(std_info, e);
self.scan_and_print(&mut e);
Type::WriteConfig | Type::Write | Type::ReadConfig | Type::Read | Type::WriteClose => {
match event!(enc_event, bpf_events::FileEvent) {
Ok(e) => {
let mut e = self.file_event(std_info, e);
self.scan_and_print(&mut e);
}
Err(e) => error!("failed to decode {} event: {:?}", etype, e),
}
Err(e) => error!("failed to decode {} event: {:?}", etype, e),
},
}

Type::FileUnlink => match event!(enc_event, bpf_events::UnlinkEvent) {
Ok(e) => {
Expand Down Expand Up @@ -2576,7 +2574,7 @@ impl Command {
| Type::Write
| Type::ReadConfig
| Type::Read
| Type::WriteAndClose => {
| Type::WriteClose => {
scan_event!(p, FileData)
}
Type::FileUnlink => scan_event!(p, UnlinkData),
Expand Down
2 changes: 1 addition & 1 deletion kunai/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Default for Config {
// some events get disabled by default because there are too many
let en = !matches!(
v,
bpf_events::Type::Read | bpf_events::Type::Write | bpf_events::Type::WriteAndClose
bpf_events::Type::Read | bpf_events::Type::Write | bpf_events::Type::WriteClose
);

if v.is_configurable() {
Expand Down
Loading