1*06da9f3bSKui-Feng Lee // SPDX-License-Identifier: GPL-2.0
2*06da9f3bSKui-Feng Lee 
3*06da9f3bSKui-Feng Lee #include "vmlinux.h"
4*06da9f3bSKui-Feng Lee 
5*06da9f3bSKui-Feng Lee #include <bpf/bpf_helpers.h>
6*06da9f3bSKui-Feng Lee #include <bpf/bpf_tracing.h>
7*06da9f3bSKui-Feng Lee 
8*06da9f3bSKui-Feng Lee char _license[] SEC("license") = "GPL";
9*06da9f3bSKui-Feng Lee 
10*06da9f3bSKui-Feng Lee int ca1_cnt = 0;
11*06da9f3bSKui-Feng Lee int ca2_cnt = 0;
12*06da9f3bSKui-Feng Lee 
tcp_sk(const struct sock * sk)13*06da9f3bSKui-Feng Lee static inline struct tcp_sock *tcp_sk(const struct sock *sk)
14*06da9f3bSKui-Feng Lee {
15*06da9f3bSKui-Feng Lee 	return (struct tcp_sock *)sk;
16*06da9f3bSKui-Feng Lee }
17*06da9f3bSKui-Feng Lee 
18*06da9f3bSKui-Feng Lee SEC("struct_ops/ca_update_1_init")
BPF_PROG(ca_update_1_init,struct sock * sk)19*06da9f3bSKui-Feng Lee void BPF_PROG(ca_update_1_init, struct sock *sk)
20*06da9f3bSKui-Feng Lee {
21*06da9f3bSKui-Feng Lee 	ca1_cnt++;
22*06da9f3bSKui-Feng Lee }
23*06da9f3bSKui-Feng Lee 
24*06da9f3bSKui-Feng Lee SEC("struct_ops/ca_update_2_init")
BPF_PROG(ca_update_2_init,struct sock * sk)25*06da9f3bSKui-Feng Lee void BPF_PROG(ca_update_2_init, struct sock *sk)
26*06da9f3bSKui-Feng Lee {
27*06da9f3bSKui-Feng Lee 	ca2_cnt++;
28*06da9f3bSKui-Feng Lee }
29*06da9f3bSKui-Feng Lee 
30*06da9f3bSKui-Feng Lee SEC("struct_ops/ca_update_cong_control")
BPF_PROG(ca_update_cong_control,struct sock * sk,const struct rate_sample * rs)31*06da9f3bSKui-Feng Lee void BPF_PROG(ca_update_cong_control, struct sock *sk,
32*06da9f3bSKui-Feng Lee 	      const struct rate_sample *rs)
33*06da9f3bSKui-Feng Lee {
34*06da9f3bSKui-Feng Lee }
35*06da9f3bSKui-Feng Lee 
36*06da9f3bSKui-Feng Lee SEC("struct_ops/ca_update_ssthresh")
BPF_PROG(ca_update_ssthresh,struct sock * sk)37*06da9f3bSKui-Feng Lee __u32 BPF_PROG(ca_update_ssthresh, struct sock *sk)
38*06da9f3bSKui-Feng Lee {
39*06da9f3bSKui-Feng Lee 	return tcp_sk(sk)->snd_ssthresh;
40*06da9f3bSKui-Feng Lee }
41*06da9f3bSKui-Feng Lee 
42*06da9f3bSKui-Feng Lee SEC("struct_ops/ca_update_undo_cwnd")
BPF_PROG(ca_update_undo_cwnd,struct sock * sk)43*06da9f3bSKui-Feng Lee __u32 BPF_PROG(ca_update_undo_cwnd, struct sock *sk)
44*06da9f3bSKui-Feng Lee {
45*06da9f3bSKui-Feng Lee 	return tcp_sk(sk)->snd_cwnd;
46*06da9f3bSKui-Feng Lee }
47*06da9f3bSKui-Feng Lee 
48*06da9f3bSKui-Feng Lee SEC(".struct_ops.link")
49*06da9f3bSKui-Feng Lee struct tcp_congestion_ops ca_update_1 = {
50*06da9f3bSKui-Feng Lee 	.init = (void *)ca_update_1_init,
51*06da9f3bSKui-Feng Lee 	.cong_control = (void *)ca_update_cong_control,
52*06da9f3bSKui-Feng Lee 	.ssthresh = (void *)ca_update_ssthresh,
53*06da9f3bSKui-Feng Lee 	.undo_cwnd = (void *)ca_update_undo_cwnd,
54*06da9f3bSKui-Feng Lee 	.name = "tcp_ca_update",
55*06da9f3bSKui-Feng Lee };
56*06da9f3bSKui-Feng Lee 
57*06da9f3bSKui-Feng Lee SEC(".struct_ops.link")
58*06da9f3bSKui-Feng Lee struct tcp_congestion_ops ca_update_2 = {
59*06da9f3bSKui-Feng Lee 	.init = (void *)ca_update_2_init,
60*06da9f3bSKui-Feng Lee 	.cong_control = (void *)ca_update_cong_control,
61*06da9f3bSKui-Feng Lee 	.ssthresh = (void *)ca_update_ssthresh,
62*06da9f3bSKui-Feng Lee 	.undo_cwnd = (void *)ca_update_undo_cwnd,
63*06da9f3bSKui-Feng Lee 	.name = "tcp_ca_update",
64*06da9f3bSKui-Feng Lee };
65*06da9f3bSKui-Feng Lee 
66*06da9f3bSKui-Feng Lee SEC(".struct_ops.link")
67*06da9f3bSKui-Feng Lee struct tcp_congestion_ops ca_wrong = {
68*06da9f3bSKui-Feng Lee 	.cong_control = (void *)ca_update_cong_control,
69*06da9f3bSKui-Feng Lee 	.ssthresh = (void *)ca_update_ssthresh,
70*06da9f3bSKui-Feng Lee 	.undo_cwnd = (void *)ca_update_undo_cwnd,
71*06da9f3bSKui-Feng Lee 	.name = "tcp_ca_wrong",
72*06da9f3bSKui-Feng Lee };
73*06da9f3bSKui-Feng Lee 
74*06da9f3bSKui-Feng Lee SEC(".struct_ops")
75*06da9f3bSKui-Feng Lee struct tcp_congestion_ops ca_no_link = {
76*06da9f3bSKui-Feng Lee 	.cong_control = (void *)ca_update_cong_control,
77*06da9f3bSKui-Feng Lee 	.ssthresh = (void *)ca_update_ssthresh,
78*06da9f3bSKui-Feng Lee 	.undo_cwnd = (void *)ca_update_undo_cwnd,
79*06da9f3bSKui-Feng Lee 	.name = "tcp_ca_no_link",
80*06da9f3bSKui-Feng Lee };
81