mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 01:10:04 +00:00
![Toke Høiland-Jørgensen](/assets/img/avatar_default.png)
Fix all files in samples/bpf to include libbpf header files with the bpf/
prefix, to be consistent with external users of the library. Also ensure
that all includes of exported libbpf header files (those that are exported
on 'make install' of the library) use bracketed includes instead of quoted.
To make sure no new files are introduced that doesn't include the bpf/
prefix in its include, remove tools/lib/bpf from the include path entirely,
and use tools/lib instead.
Fixes: 6910d7d386
("selftests/bpf: Ensure bpf_helper_defs.h are taken from selftests dir")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/157952560911.1683545.8795966751309534150.stgit@toke.dk
68 lines
1.3 KiB
C
68 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Refer to samples/bpf/tcp_bpf.readme for the instructions on
|
|
* how to run this sample program.
|
|
*/
|
|
#include <linux/bpf.h>
|
|
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_endian.h>
|
|
|
|
#define INTERVAL 1000000000ULL
|
|
|
|
int _version SEC("version") = 1;
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
struct {
|
|
__u32 type;
|
|
__u32 map_flags;
|
|
int *key;
|
|
__u64 *value;
|
|
} bpf_next_dump SEC(".maps") = {
|
|
.type = BPF_MAP_TYPE_SK_STORAGE,
|
|
.map_flags = BPF_F_NO_PREALLOC,
|
|
};
|
|
|
|
SEC("sockops")
|
|
int _sockops(struct bpf_sock_ops *ctx)
|
|
{
|
|
struct bpf_tcp_sock *tcp_sk;
|
|
struct bpf_sock *sk;
|
|
__u64 *next_dump;
|
|
__u64 now;
|
|
|
|
switch (ctx->op) {
|
|
case BPF_SOCK_OPS_TCP_CONNECT_CB:
|
|
bpf_sock_ops_cb_flags_set(ctx, BPF_SOCK_OPS_RTT_CB_FLAG);
|
|
return 1;
|
|
case BPF_SOCK_OPS_RTT_CB:
|
|
break;
|
|
default:
|
|
return 1;
|
|
}
|
|
|
|
sk = ctx->sk;
|
|
if (!sk)
|
|
return 1;
|
|
|
|
next_dump = bpf_sk_storage_get(&bpf_next_dump, sk, 0,
|
|
BPF_SK_STORAGE_GET_F_CREATE);
|
|
if (!next_dump)
|
|
return 1;
|
|
|
|
now = bpf_ktime_get_ns();
|
|
if (now < *next_dump)
|
|
return 1;
|
|
|
|
tcp_sk = bpf_tcp_sock(sk);
|
|
if (!tcp_sk)
|
|
return 1;
|
|
|
|
*next_dump = now + INTERVAL;
|
|
|
|
bpf_printk("dsack_dups=%u delivered=%u\n",
|
|
tcp_sk->dsack_dups, tcp_sk->delivered);
|
|
bpf_printk("delivered_ce=%u icsk_retransmits=%u\n",
|
|
tcp_sk->delivered_ce, tcp_sk->icsk_retransmits);
|
|
|
|
return 1;
|
|
}
|