1 // SPDX-License-Identifier: GPL-2.0
2 /* Refer to samples/bpf/tcp_bpf.readme for the instructions on
3 * how to run this sample program.
7 #include <bpf/bpf_helpers.h>
8 #include <bpf/bpf_endian.h>
10 #define INTERVAL 1000000000ULL
12 int _version SEC("version") = 1;
13 char _license[] SEC("license") = "GPL";
20 } bpf_next_dump SEC(".maps") = {
21 .type = BPF_MAP_TYPE_SK_STORAGE,
22 .map_flags = BPF_F_NO_PREALLOC,
26 int _sockops(struct bpf_sock_ops *ctx)
28 struct bpf_tcp_sock *tcp_sk;
34 case BPF_SOCK_OPS_TCP_CONNECT_CB:
35 bpf_sock_ops_cb_flags_set(ctx, BPF_SOCK_OPS_RTT_CB_FLAG);
37 case BPF_SOCK_OPS_RTT_CB:
47 next_dump = bpf_sk_storage_get(&bpf_next_dump, sk, 0,
48 BPF_SK_STORAGE_GET_F_CREATE);
52 now = bpf_ktime_get_ns();
56 tcp_sk = bpf_tcp_sock(sk);
60 *next_dump = now + INTERVAL;
62 bpf_printk("dsack_dups=%u delivered=%u\n",
63 tcp_sk->dsack_dups, tcp_sk->delivered);
64 bpf_printk("delivered_ce=%u icsk_retransmits=%u\n",
65 tcp_sk->delivered_ce, tcp_sk->icsk_retransmits);