Skip to content

Commit

Permalink
set_direction: Define when socket was closed to clean table
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoftsm committed Mar 4, 2024
1 parent ea6c655 commit 75903f3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions kernel/network_viewer_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,25 @@ int netdata_tcp_v6_connect(struct pt_regs* ctx)
return 0;
}

SEC("kprobe/tcp_close")
int netdata_tcp_close(struct pt_regs* ctx)
{
struct sock *sk = (struct sock *)PT_REGS_PARM1(ctx);
if (!sk || sk == (void *)1)
return 0;

netdata_nv_idx_t idx = {};
__u16 family = set_nv_idx_value(&idx, sk);
NETDATA_SOCKET_DIRECTION direction = NETDATA_SOCKET_DIRECTION_OUTBOUND;
netdata_nv_data_t *val = (netdata_nv_data_t *) bpf_map_lookup_elem(&tbl_nv_socket, &idx);
if (!val)
return 0;

val->closed = 1;

return 0;
}

/************************************************************************************
*
* UDP Section
Expand All @@ -463,6 +482,9 @@ int trace_udp_recvmsg(struct pt_regs* ctx)
netdata_nv_data_t *val = (netdata_nv_data_t *) bpf_map_lookup_elem(&tbl_nv_socket, &idx);
if (val) {
set_common_udp_nv_data(val, sk, family, direction);
if (direction != NETDATA_SOCKET_DIRECTION_LISTEN)
val->closed = 1;

return 0;
}

Expand All @@ -472,6 +494,7 @@ int trace_udp_recvmsg(struct pt_regs* ctx)
netdata_nv_data_t data = { };
set_common_udp_nv_data(&data, sk, family, direction);


bpf_map_update_elem(&tbl_nv_socket, &idx, &data, BPF_ANY);

return 0;
Expand Down

0 comments on commit 75903f3

Please sign in to comment.