libbpf-tools: fix fentry prog in tcprtt (#3757)
authorchendotjs <chendotjs@gmail.com>
Tue, 4 Jan 2022 19:26:15 +0000 (03:26 +0800)
committerGitHub <noreply@github.com>
Tue, 4 Jan 2022 19:26:15 +0000 (11:26 -0800)
This commit fixes judgement if tcp_rcv_established fentry exists and
fentry prog by introducing BPF_CORE_READ.

Signed-off-by: chendotjs <chendotjs@gmail.com>
libbpf-tools/tcprtt.bpf.c
libbpf-tools/tcprtt.c

index 52afad0af28203bbc5f5a78430b708bf1539b684..0b332e4e4b522d278854355f76e3ab379148beeb 100644 (file)
@@ -2,6 +2,7 @@
 // Copyright (c) 2021 Wenbo Zhang
 #include <vmlinux.h>
 #include <bpf/bpf_helpers.h>
+#include <bpf/bpf_core_read.h>
 #include <bpf/bpf_tracing.h>
 #include <bpf/bpf_endian.h>
 #include "tcprtt.h"
@@ -56,7 +57,7 @@ int BPF_PROG(tcp_rcv, struct sock *sk)
        if (!histp)
                return 0;
        ts = (struct tcp_sock *)(sk);
-       srtt = ts->srtt_us >> 3;
+       srtt = BPF_CORE_READ(ts, srtt_us) >> 3;
        if (targ_ms)
                srtt /= 1000U;
        slot = log2l(srtt);
index e847b8d2e9f8d5ef14a2aa0858bd2a45d9b867fc..bed6efa738a7648f679f147f054fc020c9518369 100644 (file)
@@ -243,7 +243,7 @@ int main(int argc, char **argv)
        obj->rodata->targ_daddr = env.raddr;
        obj->rodata->targ_ms = env.milliseconds;
 
-       if (!fentry_exists("tcp_rcv_established", NULL))
+       if (fentry_exists("tcp_rcv_established", NULL))
                bpf_program__set_autoload(obj->progs.tcp_rcv_kprobe, false);
        else
                bpf_program__set_autoload(obj->progs.tcp_rcv, false);