1 // SPDX-License-Identifier: GPL-2.0
4 #include <netinet/in.h>
6 #include <linux/if_ether.h>
7 #include <linux/if_packet.h>
9 #include <linux/ipv6.h>
10 #include <linux/types.h>
11 #include <linux/socket.h>
12 #include <linux/tcp.h>
13 #include <bpf/bpf_helpers.h>
14 #include <bpf/bpf_endian.h>
15 #include "test_tcpnotify.h"
18 __uint(type, BPF_MAP_TYPE_ARRAY);
19 __uint(max_entries, 4);
21 __type(value, struct tcpnotify_globals);
22 } global_map SEC(".maps");
25 __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
26 __uint(max_entries, 2);
29 } perf_event_map SEC(".maps");
32 int bpf_testcb(struct bpf_sock_ops *skops)
39 if (bpf_ntohl(skops->remote_port) != TESTPORT) {
45 case BPF_SOCK_OPS_TIMEOUT_INIT:
46 case BPF_SOCK_OPS_RWND_INIT:
47 case BPF_SOCK_OPS_NEEDS_ECN:
48 case BPF_SOCK_OPS_BASE_RTT:
49 case BPF_SOCK_OPS_RTO_CB:
53 case BPF_SOCK_OPS_TCP_CONNECT_CB:
54 case BPF_SOCK_OPS_TCP_LISTEN_CB:
55 case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:
56 case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB:
57 bpf_sock_ops_cb_flags_set(skops, (BPF_SOCK_OPS_RETRANS_CB_FLAG|
58 BPF_SOCK_OPS_RTO_CB_FLAG));
61 case BPF_SOCK_OPS_RETRANS_CB: {
63 struct tcpnotify_globals g, *gp;
64 struct tcp_notifier msg = {
74 gp = bpf_map_lookup_elem(&global_map, &key);
78 g.total_retrans = skops->total_retrans;
80 bpf_map_update_elem(&global_map, &key, &g,
82 bpf_perf_event_output(skops, &perf_event_map,
93 char _license[] SEC("license") = "GPL";