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.
Merge pull request #102 from amosproj/TraceSendMsg
merge implementation of sendmsg and small fixes for vfs_write
- Loading branch information
Showing
6 changed files
with
133 additions
and
32 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,18 @@ | ||
|
||
<!-- | ||
SPDX-FileCopyrightText: 2024 Tom Weisshuhn <[email protected]> | ||
SPDX-License-Identifier: MIT | ||
--> | ||
|
||
# eBPF programs | ||
|
||
The entries in the maps are the structs defined in `../common/src/lib.rs`. | ||
|
||
## overview by hook name | ||
|
||
| |type | functions to hook |map | | ||
|-----------|-----------|---------------------------------------|-------------------| | ||
|vfs_write |KProbe |`vfs_write`, `vfs_write_ret` |`VFS_WRITE_MAP` | | ||
|sendmsg |Tracepoint |`sys_enter_sendmsg`, `sys_exit_sendmsg`|`SYS_SENDMSG_MAP` | | ||
|... |... |... |... | |
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
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,67 @@ | ||
// SPDX-FileCopyrightText: 2024 Tom Weisshuhn <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
use aya_ebpf::{macros::{tracepoint, map}, maps::{HashMap, RingBuf}, programs::{TracePointContext}, EbpfContext, helpers::gen::bpf_ktime_get_ns}; | ||
use backend_common::{generate_id, SysSendmsgCall}; | ||
|
||
#[map(name = "SYS_SENDMSG_MAP")] | ||
pub static SYS_SENDMSG_MAP: RingBuf = RingBuf::with_byte_size(1024, 0); | ||
|
||
|
||
#[map] | ||
static SYS_SENDMSG_TIMESTAMPS: HashMap<u64, SysSendmsgIntern> = HashMap::with_max_entries(1024, 0); | ||
|
||
|
||
struct SysSendmsgIntern { | ||
begin_time_stamp: u64, | ||
fd: i32, | ||
} | ||
|
||
#[tracepoint] | ||
pub fn sys_enter_sendmsg(ctx: TracePointContext) -> u32 { | ||
let id = generate_id(ctx.pid(), ctx.tgid()); | ||
|
||
let begin_time_stamp; | ||
let fd: i32; | ||
unsafe { | ||
begin_time_stamp = bpf_ktime_get_ns(); | ||
fd = match ctx.read_at(16) { | ||
Ok(arg) => arg, | ||
Err(_) => return 1, | ||
}; | ||
} | ||
|
||
let data: SysSendmsgIntern = SysSendmsgIntern {begin_time_stamp, fd}; | ||
|
||
match SYS_SENDMSG_TIMESTAMPS.insert(&id, &data, 0) { | ||
Ok(_) => 0, | ||
Err(_) => 1, | ||
} | ||
} | ||
|
||
|
||
#[tracepoint] | ||
pub fn sys_exit_sendmsg(ctx: TracePointContext) -> u32 { | ||
let pid = ctx.pid(); | ||
let tgid = ctx.tgid(); | ||
let call_id = generate_id(pid, tgid); | ||
let data = match unsafe { SYS_SENDMSG_TIMESTAMPS.get(&call_id) } { | ||
None => {return 1} | ||
Some(entry) => {entry} | ||
}; | ||
|
||
|
||
let result_data = SysSendmsgCall::new(pid, tgid, data.begin_time_stamp, data.fd); | ||
|
||
let mut entry = match SYS_SENDMSG_MAP.reserve::<SysSendmsgCall>(0) { | ||
Some(entry) => entry, | ||
None => return 1, | ||
}; | ||
|
||
entry.write(result_data); | ||
entry.submit(0); | ||
|
||
|
||
0 | ||
} |
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