treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / tcp_rtt.c
blob0cb3204ddb1829fcd5fa85c9df643c90602d83e9
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/bpf.h>
3 #include <bpf/bpf_helpers.h>
5 char _license[] SEC("license") = "GPL";
6 __u32 _version SEC("version") = 1;
8 struct tcp_rtt_storage {
9 __u32 invoked;
10 __u32 dsack_dups;
11 __u32 delivered;
12 __u32 delivered_ce;
13 __u32 icsk_retransmits;
16 struct {
17 __uint(type, BPF_MAP_TYPE_SK_STORAGE);
18 __uint(map_flags, BPF_F_NO_PREALLOC);
19 __type(key, int);
20 __type(value, struct tcp_rtt_storage);
21 } socket_storage_map SEC(".maps");
23 SEC("sockops")
24 int _sockops(struct bpf_sock_ops *ctx)
26 struct tcp_rtt_storage *storage;
27 struct bpf_tcp_sock *tcp_sk;
28 int op = (int) ctx->op;
29 struct bpf_sock *sk;
31 sk = ctx->sk;
32 if (!sk)
33 return 1;
35 storage = bpf_sk_storage_get(&socket_storage_map, sk, 0,
36 BPF_SK_STORAGE_GET_F_CREATE);
37 if (!storage)
38 return 1;
40 if (op == BPF_SOCK_OPS_TCP_CONNECT_CB) {
41 bpf_sock_ops_cb_flags_set(ctx, BPF_SOCK_OPS_RTT_CB_FLAG);
42 return 1;
45 if (op != BPF_SOCK_OPS_RTT_CB)
46 return 1;
48 tcp_sk = bpf_tcp_sock(sk);
49 if (!tcp_sk)
50 return 1;
52 storage->invoked++;
54 storage->dsack_dups = tcp_sk->dsack_dups;
55 storage->delivered = tcp_sk->delivered;
56 storage->delivered_ce = tcp_sk->delivered_ce;
57 storage->icsk_retransmits = tcp_sk->icsk_retransmits;
59 return 1;