Loading...
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/bpf.h>
3#include <bpf/bpf_helpers.h>
4
5char _license[] SEC("license") = "GPL";
6
7struct tcp_rtt_storage {
8 __u32 invoked;
9 __u32 dsack_dups;
10 __u32 delivered;
11 __u32 delivered_ce;
12 __u32 icsk_retransmits;
13};
14
15struct {
16 __uint(type, BPF_MAP_TYPE_SK_STORAGE);
17 __uint(map_flags, BPF_F_NO_PREALLOC);
18 __type(key, int);
19 __type(value, struct tcp_rtt_storage);
20} socket_storage_map SEC(".maps");
21
22SEC("sockops")
23int _sockops(struct bpf_sock_ops *ctx)
24{
25 struct tcp_rtt_storage *storage;
26 struct bpf_tcp_sock *tcp_sk;
27 int op = (int) ctx->op;
28 struct bpf_sock *sk;
29
30 sk = ctx->sk;
31 if (!sk)
32 return 1;
33
34 storage = bpf_sk_storage_get(&socket_storage_map, sk, 0,
35 BPF_SK_STORAGE_GET_F_CREATE);
36 if (!storage)
37 return 1;
38
39 if (op == BPF_SOCK_OPS_TCP_CONNECT_CB) {
40 bpf_sock_ops_cb_flags_set(ctx, BPF_SOCK_OPS_RTT_CB_FLAG);
41 return 1;
42 }
43
44 if (op != BPF_SOCK_OPS_RTT_CB)
45 return 1;
46
47 tcp_sk = bpf_tcp_sock(sk);
48 if (!tcp_sk)
49 return 1;
50
51 storage->invoked++;
52
53 storage->dsack_dups = tcp_sk->dsack_dups;
54 storage->delivered = tcp_sk->delivered;
55 storage->delivered_ce = tcp_sk->delivered_ce;
56 storage->icsk_retransmits = tcp_sk->icsk_retransmits;
57
58 return 1;
59}
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/bpf.h>
3#include "bpf_helpers.h"
4
5char _license[] SEC("license") = "GPL";
6__u32 _version SEC("version") = 1;
7
8struct tcp_rtt_storage {
9 __u32 invoked;
10 __u32 dsack_dups;
11 __u32 delivered;
12 __u32 delivered_ce;
13 __u32 icsk_retransmits;
14};
15
16struct bpf_map_def SEC("maps") socket_storage_map = {
17 .type = BPF_MAP_TYPE_SK_STORAGE,
18 .key_size = sizeof(int),
19 .value_size = sizeof(struct tcp_rtt_storage),
20 .map_flags = BPF_F_NO_PREALLOC,
21};
22BPF_ANNOTATE_KV_PAIR(socket_storage_map, int, struct tcp_rtt_storage);
23
24SEC("sockops")
25int _sockops(struct bpf_sock_ops *ctx)
26{
27 struct tcp_rtt_storage *storage;
28 struct bpf_tcp_sock *tcp_sk;
29 int op = (int) ctx->op;
30 struct bpf_sock *sk;
31
32 sk = ctx->sk;
33 if (!sk)
34 return 1;
35
36 storage = bpf_sk_storage_get(&socket_storage_map, sk, 0,
37 BPF_SK_STORAGE_GET_F_CREATE);
38 if (!storage)
39 return 1;
40
41 if (op == BPF_SOCK_OPS_TCP_CONNECT_CB) {
42 bpf_sock_ops_cb_flags_set(ctx, BPF_SOCK_OPS_RTT_CB_FLAG);
43 return 1;
44 }
45
46 if (op != BPF_SOCK_OPS_RTT_CB)
47 return 1;
48
49 tcp_sk = bpf_tcp_sock(sk);
50 if (!tcp_sk)
51 return 1;
52
53 storage->invoked++;
54
55 storage->dsack_dups = tcp_sk->dsack_dups;
56 storage->delivered = tcp_sk->delivered;
57 storage->delivered_ce = tcp_sk->delivered_ce;
58 storage->icsk_retransmits = tcp_sk->icsk_retransmits;
59
60 return 1;
61}