diff --git a/kernel/network_viewer_kern.c b/kernel/network_viewer_kern.c index c496df17..883b2696 100644 --- a/kernel/network_viewer_kern.c +++ b/kernel/network_viewer_kern.c @@ -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 @@ -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; } @@ -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;