1
2
3
4
5
6
7
8
9
10#include <linux/module.h>
11#include <net/tcp.h>
12
13
14
15
16static const struct hstcp_aimd_val {
17 unsigned int cwnd;
18 unsigned int md;
19} hstcp_aimd_vals[] = {
20 { 38, 128, },
21 { 118, 112, },
22 { 221, 104, },
23 { 347, 98, },
24 { 495, 93, },
25 { 663, 89, },
26 { 851, 86, },
27 { 1058, 83, },
28 { 1284, 81, },
29 { 1529, 78, },
30 { 1793, 76, },
31 { 2076, 74, },
32 { 2378, 72, },
33 { 2699, 71, },
34 { 3039, 69, },
35 { 3399, 68, },
36 { 3778, 66, },
37 { 4177, 65, },
38 { 4596, 64, },
39 { 5036, 62, },
40 { 5497, 61, },
41 { 5979, 60, },
42 { 6483, 59, },
43 { 7009, 58, },
44 { 7558, 57, },
45 { 8130, 56, },
46 { 8726, 55, },
47 { 9346, 54, },
48 { 9991, 53, },
49 { 10661, 52, },
50 { 11358, 52, },
51 { 12082, 51, },
52 { 12834, 50, },
53 { 13614, 49, },
54 { 14424, 48, },
55 { 15265, 48, },
56 { 16137, 47, },
57 { 17042, 46, },
58 { 17981, 45, },
59 { 18955, 45, },
60 { 19965, 44, },
61 { 21013, 43, },
62 { 22101, 43, },
63 { 23230, 42, },
64 { 24402, 41, },
65 { 25618, 41, },
66 { 26881, 40, },
67 { 28193, 39, },
68 { 29557, 39, },
69 { 30975, 38, },
70 { 32450, 38, },
71 { 33986, 37, },
72 { 35586, 36, },
73 { 37253, 36, },
74 { 38992, 35, },
75 { 40808, 35, },
76 { 42707, 34, },
77 { 44694, 33, },
78 { 46776, 33, },
79 { 48961, 32, },
80 { 51258, 32, },
81 { 53677, 31, },
82 { 56230, 30, },
83 { 58932, 30, },
84 { 61799, 29, },
85 { 64851, 28, },
86 { 68113, 28, },
87 { 71617, 27, },
88 { 75401, 26, },
89 { 79517, 26, },
90 { 84035, 25, },
91 { 89053, 24, },
92};
93
94#define HSTCP_AIMD_MAX ARRAY_SIZE(hstcp_aimd_vals)
95
96struct hstcp {
97 u32 ai;
98};
99
100static void hstcp_init(struct sock *sk)
101{
102 struct tcp_sock *tp = tcp_sk(sk);
103 struct hstcp *ca = inet_csk_ca(sk);
104
105 ca->ai = 0;
106
107
108
109 tp->snd_cwnd_clamp = min_t(u32, tp->snd_cwnd_clamp, 0xffffffff/128);
110}
111
112static void hstcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
113{
114 struct tcp_sock *tp = tcp_sk(sk);
115 struct hstcp *ca = inet_csk_ca(sk);
116
117 if (!tcp_is_cwnd_limited(sk))
118 return;
119
120 if (tcp_in_slow_start(tp))
121 tcp_slow_start(tp, acked);
122 else {
123
124
125
126
127
128
129
130 if (tp->snd_cwnd > hstcp_aimd_vals[ca->ai].cwnd) {
131 while (tp->snd_cwnd > hstcp_aimd_vals[ca->ai].cwnd &&
132 ca->ai < HSTCP_AIMD_MAX - 1)
133 ca->ai++;
134 } else if (ca->ai && tp->snd_cwnd <= hstcp_aimd_vals[ca->ai-1].cwnd) {
135 while (ca->ai && tp->snd_cwnd <= hstcp_aimd_vals[ca->ai-1].cwnd)
136 ca->ai--;
137 }
138
139
140 if (tp->snd_cwnd < tp->snd_cwnd_clamp) {
141
142 tp->snd_cwnd_cnt += ca->ai + 1;
143 if (tp->snd_cwnd_cnt >= tp->snd_cwnd) {
144 tp->snd_cwnd_cnt -= tp->snd_cwnd;
145 tp->snd_cwnd++;
146 }
147 }
148 }
149}
150
151static u32 hstcp_ssthresh(struct sock *sk)
152{
153 const struct tcp_sock *tp = tcp_sk(sk);
154 struct hstcp *ca = inet_csk_ca(sk);
155
156
157 return max(tp->snd_cwnd - ((tp->snd_cwnd * hstcp_aimd_vals[ca->ai].md) >> 8), 2U);
158}
159
160static struct tcp_congestion_ops tcp_highspeed __read_mostly = {
161 .init = hstcp_init,
162 .ssthresh = hstcp_ssthresh,
163 .undo_cwnd = tcp_reno_undo_cwnd,
164 .cong_avoid = hstcp_cong_avoid,
165
166 .owner = THIS_MODULE,
167 .name = "highspeed"
168};
169
170static int __init hstcp_register(void)
171{
172 BUILD_BUG_ON(sizeof(struct hstcp) > ICSK_CA_PRIV_SIZE);
173 return tcp_register_congestion_control(&tcp_highspeed);
174}
175
176static void __exit hstcp_unregister(void)
177{
178 tcp_unregister_congestion_control(&tcp_highspeed);
179}
180
181module_init(hstcp_register);
182module_exit(hstcp_unregister);
183
184MODULE_AUTHOR("John Heffner");
185MODULE_LICENSE("GPL");
186MODULE_DESCRIPTION("High Speed TCP");
187