Skip to content

Commit

Permalink
sync_algoorithms: Reduce necessity to always monitor return for conne…
Browse files Browse the repository at this point in the history
…ction.
  • Loading branch information
thiagoftsm committed Sep 6, 2023
1 parent 005f6c7 commit 2eaad5f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/socket.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ int BPF_KRETPROBE(netdata_inet_csk_accept_kretprobe)
return netdata_common_inet_csk_accept(sk);
}

SEC("kprobe/tcp_v4_connect")
int BPF_KRETPROBE(netdata_tcp_v4_connect_kprobe)
{
struct inet_sock *is = (struct inet_sock *)((struct sock *)PT_REGS_PARM1(ctx));
return netdata_common_tcp_connect(is, 0, NETDATA_KEY_CALLS_TCP_CONNECT_IPV4,
NETDATA_KEY_ERROR_TCP_CONNECT_IPV4);
}

SEC("kretprobe/tcp_v4_connect")
int BPF_KRETPROBE(netdata_tcp_v4_connect_kretprobe)
{
Expand All @@ -419,14 +427,22 @@ int BPF_KRETPROBE(netdata_tcp_v4_connect_kretprobe)
NETDATA_KEY_ERROR_TCP_CONNECT_IPV4);
}

SEC("kprobe/tcp_v6_connect")
int BPF_KRETPROBE(netdata_tcp_v6_connect_kprobe)
{
struct inet_sock *is = (struct inet_sock *)((struct sock *)PT_REGS_PARM1(ctx));
return netdata_common_tcp_connect(is, 0, NETDATA_KEY_CALLS_TCP_CONNECT_IPV6,
NETDATA_KEY_ERROR_TCP_CONNECT_IPV6);
}

SEC("kretprobe/tcp_v6_connect")
int BPF_KRETPROBE(netdata_tcp_v6_connect_kretprobe)
{
int ret = (int)PT_REGS_RC(ctx);

struct inet_sock *is = (struct inet_sock *)((struct sock *)PT_REGS_PARM1(ctx));
return netdata_common_tcp_connect(is, ret, NETDATA_KEY_CALLS_TCP_CONNECT_IPV6,
NETDATA_KEY_ERROR_TCP_CONNECT_IPV4);
NETDATA_KEY_ERROR_TCP_CONNECT_IPV6);
}

SEC("kprobe/tcp_retransmit_skb")
Expand Down Expand Up @@ -528,6 +544,17 @@ int BPF_PROG(netdata_inet_csk_accept_fexit, struct sock *sk)
return netdata_common_inet_csk_accept(sk);
}

SEC("fentry/tcp_v4_connect")
int BPF_PROG(netdata_tcp_v4_connect_fentry, struct sock *sk, struct sockaddr *uaddr, int addr_len, int ret)
{
if (!sk)
return 0;

struct inet_sock *is = (struct inet_sock *)sk;
return netdata_common_tcp_connect(is, 0, NETDATA_KEY_CALLS_TCP_CONNECT_IPV4,
NETDATA_KEY_ERROR_TCP_CONNECT_IPV4);
}

SEC("fexit/tcp_v4_connect")
int BPF_PROG(netdata_tcp_v4_connect_fexit, struct sock *sk, struct sockaddr *uaddr, int addr_len, int ret)
{
Expand All @@ -539,6 +566,17 @@ int BPF_PROG(netdata_tcp_v4_connect_fexit, struct sock *sk, struct sockaddr *uad
NETDATA_KEY_ERROR_TCP_CONNECT_IPV4);
}

SEC("fentry/tcp_v6_connect")
int BPF_PROG(netdata_tcp_v6_connect_fentry, struct sock *sk, struct sockaddr *uaddr, int addr_len, int ret)
{
if (!sk)
return 0;

struct inet_sock *is = (struct inet_sock *)sk;
return netdata_common_tcp_connect(is, 0, NETDATA_KEY_CALLS_TCP_CONNECT_IPV6,
NETDATA_KEY_ERROR_TCP_CONNECT_IPV6);
}

SEC("fexit/tcp_v6_connect")
int BPF_PROG(netdata_tcp_v6_connect_fexit, struct sock *sk, struct sockaddr *uaddr, int addr_len, int ret)
{
Expand Down
22 changes: 22 additions & 0 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,24 @@ static int ebpf_attach_probes(struct socket_bpf *obj)
if (ret)
return -1;

obj->links.netdata_tcp_v4_connect_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_tcp_v4_connect_kprobe,
false, function_list[NETDATA_FCNT_TCP_V4_CONNECT]);
ret = libbpf_get_error(obj->links.netdata_tcp_v4_connect_kprobe);
if (ret)
return -1;

obj->links.netdata_tcp_v4_connect_kretprobe = bpf_program__attach_kprobe(obj->progs.netdata_tcp_v4_connect_kretprobe,
true, function_list[NETDATA_FCNT_TCP_V4_CONNECT]);
ret = libbpf_get_error(obj->links.netdata_tcp_v4_connect_kretprobe);
if (ret)
return -1;

obj->links.netdata_tcp_v6_connect_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_tcp_v6_connect_kprobe,
false, function_list[NETDATA_FCNT_TCP_V6_CONNECT]);
ret = libbpf_get_error(obj->links.netdata_tcp_v6_connect_kprobe);
if (ret)
return -1;

obj->links.netdata_tcp_v6_connect_kretprobe = bpf_program__attach_kprobe(obj->progs.netdata_tcp_v6_connect_kretprobe,
true, function_list[NETDATA_FCNT_TCP_V6_CONNECT]);
ret = libbpf_get_error(obj->links.netdata_tcp_v6_connect_kretprobe);
Expand Down Expand Up @@ -112,7 +124,9 @@ static int ebpf_attach_probes(struct socket_bpf *obj)
static void ebpf_disable_probes(struct socket_bpf *obj)
{
bpf_program__set_autoload(obj->progs.netdata_inet_csk_accept_kretprobe, false);
bpf_program__set_autoload(obj->progs.netdata_tcp_v4_connect_kprobe, false);
bpf_program__set_autoload(obj->progs.netdata_tcp_v4_connect_kretprobe, false);
bpf_program__set_autoload(obj->progs.netdata_tcp_v6_connect_kprobe, false);
bpf_program__set_autoload(obj->progs.netdata_tcp_v6_connect_kretprobe, false);
bpf_program__set_autoload(obj->progs.netdata_tcp_retransmit_skb_kprobe, false);
bpf_program__set_autoload(obj->progs.netdata_tcp_cleanup_rbuf_kprobe, false);
Expand All @@ -128,7 +142,9 @@ static void ebpf_disable_probes(struct socket_bpf *obj)
static void ebpf_disable_trampoline(struct socket_bpf *obj)
{
bpf_program__set_autoload(obj->progs.netdata_inet_csk_accept_fexit, false);
bpf_program__set_autoload(obj->progs.netdata_tcp_v4_connect_fentry, false);
bpf_program__set_autoload(obj->progs.netdata_tcp_v4_connect_fexit, false);
bpf_program__set_autoload(obj->progs.netdata_tcp_v6_connect_fentry, false);
bpf_program__set_autoload(obj->progs.netdata_tcp_v6_connect_fexit, false);
bpf_program__set_autoload(obj->progs.netdata_tcp_retransmit_skb_fentry, false);
bpf_program__set_autoload(obj->progs.netdata_tcp_cleanup_rbuf_fentry, false);
Expand All @@ -146,9 +162,15 @@ static void ebpf_set_trampoline_target(struct socket_bpf *obj)
bpf_program__set_attach_target(obj->progs.netdata_inet_csk_accept_fexit, 0,
function_list[NETDATA_FCNT_INET_CSK_ACCEPT]);

bpf_program__set_attach_target(obj->progs.netdata_tcp_v4_connect_fentry, 0,
function_list[NETDATA_FCNT_TCP_V4_CONNECT]);

bpf_program__set_attach_target(obj->progs.netdata_tcp_v4_connect_fexit, 0,
function_list[NETDATA_FCNT_TCP_V4_CONNECT]);

bpf_program__set_attach_target(obj->progs.netdata_tcp_v6_connect_fentry, 0,
function_list[NETDATA_FCNT_TCP_V6_CONNECT]);

bpf_program__set_attach_target(obj->progs.netdata_tcp_v6_connect_fexit, 0,
function_list[NETDATA_FCNT_TCP_V6_CONNECT]);

Expand Down

0 comments on commit 2eaad5f

Please sign in to comment.