Skip to content

Commit

Permalink
cleanup(modern): avoid to use an array with just one element
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <[email protected]>
Co-authored-by: Mauro Ezequiel Moltrasio <[email protected]>
  • Loading branch information
2 people authored and poiana committed May 16, 2024
1 parent ddfc61a commit 482e47f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,15 @@ int BPF_PROG(accept_x,
auxmap__store_socktuple_param(auxmap, (int32_t)ret, INBOUND, NULL);

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[1] = {0};
extract__network_args(args, 1, regs);
unsigned long socket_fd = 0;
extract__network_args(&socket_fd, 1, regs);

/* Perform some computations to get queue information. */
/* If the syscall is successful the `sockfd` will be >= 0. We want
/* If the syscall is successful the `socket_fd` will be >= 0. We want
* to extract information from the listening socket, not from the
* new one.
*/
int32_t sockfd = (int32_t)args[0];
struct file *file = extract__file_struct_from_fd(sockfd);
struct file *file = extract__file_struct_from_fd((int32_t)socket_fd);
struct socket *socket = get_sock_from_file(file);
if(socket != NULL)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,15 @@ int BPF_PROG(accept4_x,
auxmap__store_socktuple_param(auxmap, (int32_t)ret, INBOUND, NULL);

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[1] = {0};
extract__network_args(args, 1, regs);
unsigned long socket_fd = 0;
extract__network_args(&socket_fd, 1, regs);

/* Perform some computations to get queue information. */
/* If the syscall is successful the `sockfd` will be >= 0. We want
/* If the syscall is successful the `socket_fd` will be >= 0. We want
* to extract information from the listening socket, not from the
* new one.
*/
int32_t sockfd = (int32_t)args[0];
struct file *file = extract__file_struct_from_fd(sockfd);
struct file *file = extract__file_struct_from_fd((int32_t)socket_fd);
struct socket *socket = get_sock_from_file(file);
if(socket != NULL)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ int BPF_PROG(bind_e,
long id)
{
/* Collect parameters at the beginning to easily manage socketcalls */
unsigned long args[1] = {0};
extract__network_args(args, 1, regs);
unsigned long socket_fd = 0;
extract__network_args(&socket_fd, 1, regs);

struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, BIND_E_SIZE, PPME_SOCKET_BIND_E))
Expand All @@ -31,8 +31,7 @@ int BPF_PROG(bind_e,
/*=============================== COLLECT PARAMETERS ===========================*/

/* Parameter 1: fd (type: PT_FD) */
int32_t fd = (int32_t)args[0];
ringbuf__store_s64(&ringbuf, (int64_t)fd);
ringbuf__store_s64(&ringbuf, (int64_t)(int32_t)socket_fd);

/*=============================== COLLECT PARAMETERS ===========================*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,28 @@ int BPF_PROG(connect_x,

/*=============================== COLLECT PARAMETERS ===========================*/

unsigned long args[1] = {0};
extract__network_args(args, 1, regs);
unsigned long socket_fd = 0;
extract__network_args(&socket_fd, 1, regs);

/* Parameter 1: res (type: PT_ERRNO) */
auxmap__store_s64_param(auxmap, ret);

int32_t socket_fd = (int32_t)args[0];

/* Parameter 2: tuple (type: PT_SOCKTUPLE) */
/* We need a valid sockfd to extract source data.*/
if(ret == 0 || ret == -EINPROGRESS)
{
auxmap__store_socktuple_param(auxmap, socket_fd, OUTBOUND, NULL);
auxmap__store_socktuple_param(auxmap, (int32_t)socket_fd, OUTBOUND, NULL);
}
else
{
auxmap__store_empty_param(auxmap);
}

/* Parameter 3: fd (type: PT_FD)*/
auxmap__store_s64_param(auxmap, (int64_t)socket_fd);
/* We need the double cast to extract the first 4 bytes and then
* convert them to a signed integer on 64-bit
*/
auxmap__store_s64_param(auxmap, (int64_t)(int32_t)socket_fd);

/*=============================== COLLECT PARAMETERS ===========================*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ int BPF_PROG(recvmsg_e,
long id)
{
/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[1] = {0};
extract__network_args(args, 1, regs);
unsigned long socket_fd = 0;
extract__network_args(&socket_fd, 1, regs);

struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, RECVMSG_E_SIZE, PPME_SOCKET_RECVMSG_E))
Expand All @@ -31,8 +31,7 @@ int BPF_PROG(recvmsg_e,
/*=============================== COLLECT PARAMETERS ===========================*/

/* Parameter 1: fd (type: PT_FD)*/
int32_t fd = (int32_t)args[0];
ringbuf__store_s64(&ringbuf, (int64_t)fd);
ringbuf__store_s64(&ringbuf, (int64_t)(int32_t)socket_fd);

/*=============================== COLLECT PARAMETERS ===========================*/

Expand Down

0 comments on commit 482e47f

Please sign in to comment.