Skip to content

Commit

Permalink
fix(modern): move args declaration at the beginning
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <[email protected]>
  • Loading branch information
Andreagit97 authored and poiana committed Jan 7, 2025
1 parent 63f9cfb commit 4a8fd3c
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

SEC("tp_btf/sys_enter")
int BPF_PROG(bind_e, struct pt_regs *regs, long id) {
/* Collect parameters at the beginning to easily manage socketcalls */
/* We need to keep this at the beginning of the program because otherwise we alter the state of
* the ebpf registers causing a verifier issue.
*/
unsigned long socket_fd = 0;
extract__network_args(&socket_fd, 1, regs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

SEC("tp_btf/sys_enter")
int BPF_PROG(listen_e, struct pt_regs *regs, long id) {
/* Collect parameters at the beginning to manage socketcalls */
/* We need to keep this at the beginning of the program because otherwise we alter the state of
* the ebpf registers causing a verifier issue.
*/
unsigned long args[2] = {0};
extract__network_args(args, 2, regs);

Expand Down Expand Up @@ -46,7 +48,9 @@ int BPF_PROG(listen_e, struct pt_regs *regs, long id) {

SEC("tp_btf/sys_exit")
int BPF_PROG(listen_x, struct pt_regs *regs, long ret) {
/* Collect parameters at the beginning to manage socketcalls */
/* We need to keep this at the beginning of the program because otherwise we alter the state of
* the ebpf registers causing a verifier issue.
*/
unsigned long args[2] = {0};
extract__network_args(args, 2, regs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

SEC("tp_btf/sys_enter")
int BPF_PROG(recv_e, struct pt_regs *regs, long id) {
/* Collect parameters at the beginning to manage socketcalls */
/* We need to keep this at the beginning of the program because otherwise we alter the state of
* the ebpf registers causing a verifier issue.
*/
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

SEC("tp_btf/sys_enter")
int BPF_PROG(recvfrom_e, struct pt_regs *regs, long id) {
/* Collect parameters at the beginning to manage socketcalls */
/* We need to keep this at the beginning of the program because otherwise we alter the state of
* the ebpf registers causing a verifier issue.
*/
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

SEC("tp_btf/sys_enter")
int BPF_PROG(recvmsg_e, struct pt_regs *regs, long id) {
/* Collect parameters at the beginning to manage socketcalls */
/* We need to keep this at the beginning of the program because otherwise we alter the state of
* the ebpf registers causing a verifier issue.
*/
unsigned long socket_fd = 0;
extract__network_args(&socket_fd, 1, regs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

SEC("tp_btf/sys_enter")
int BPF_PROG(send_e, struct pt_regs *regs, long id) {
/* Collect parameters at the beginning to manage socketcalls */
/* We need to keep this at the beginning of the program because otherwise we alter the state of
* the ebpf registers causing a verifier issue.
*/
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

SEC("tp_btf/sys_enter")
int BPF_PROG(shutdown_e, struct pt_regs *regs, long id) {
/* Collect parameters at the beginning to easily manage socketcalls */
/* We need to keep this at the beginning of the program because otherwise we alter the state of
* the ebpf registers causing a verifier issue.
*/
unsigned long args[2] = {0};
extract__network_args(args, 2, regs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

SEC("tp_btf/sys_enter")
int BPF_PROG(socket_e, struct pt_regs *regs, long id) {
/* Collect parameters at the beginning so we can easily manage socketcalls */
/* We need to keep this at the beginning of the program because otherwise we alter the state of
* the ebpf registers causing a verifier issue.
*/
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

Expand Down Expand Up @@ -53,6 +55,12 @@ int BPF_PROG(socket_e, struct pt_regs *regs, long id) {

SEC("tp_btf/sys_exit")
int BPF_PROG(socket_x, struct pt_regs *regs, long ret) {
/* We need to keep this at the beginning of the program because otherwise we alter the state of
* the ebpf registers causing a verifier issue.
*/
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, SOCKET_X_SIZE, PPME_SOCKET_SOCKET_X)) {
return 0;
Expand Down Expand Up @@ -85,10 +93,6 @@ int BPF_PROG(socket_x, struct pt_regs *regs, long ret) {
}
}

/* Collect parameters at the beginning so we can easily manage socketcalls */
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

/* Parameter 2: domain (type: PT_ENUMFLAGS32) */
uint8_t domain = (uint8_t)args[0];
ringbuf__store_u32(&ringbuf, (uint32_t)socket_family_to_scap(domain));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

SEC("tp_btf/sys_enter")
int BPF_PROG(socketpair_e, struct pt_regs *regs, long id) {
/* Collect parameters at the beginning to manage socketcalls */
/* We need to keep this at the beginning of the program because otherwise we alter the state of
* the ebpf registers causing a verifier issue.
*/
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

Expand Down

0 comments on commit 4a8fd3c

Please sign in to comment.