0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/module.h>
0011 #include <net/tcp.h>
0012
0013
0014
0015
0016 static const struct hstcp_aimd_val {
0017 unsigned int cwnd;
0018 unsigned int md;
0019 } hstcp_aimd_vals[] = {
0020 { 38, 128, },
0021 { 118, 112, },
0022 { 221, 104, },
0023 { 347, 98, },
0024 { 495, 93, },
0025 { 663, 89, },
0026 { 851, 86, },
0027 { 1058, 83, },
0028 { 1284, 81, },
0029 { 1529, 78, },
0030 { 1793, 76, },
0031 { 2076, 74, },
0032 { 2378, 72, },
0033 { 2699, 71, },
0034 { 3039, 69, },
0035 { 3399, 68, },
0036 { 3778, 66, },
0037 { 4177, 65, },
0038 { 4596, 64, },
0039 { 5036, 62, },
0040 { 5497, 61, },
0041 { 5979, 60, },
0042 { 6483, 59, },
0043 { 7009, 58, },
0044 { 7558, 57, },
0045 { 8130, 56, },
0046 { 8726, 55, },
0047 { 9346, 54, },
0048 { 9991, 53, },
0049 { 10661, 52, },
0050 { 11358, 52, },
0051 { 12082, 51, },
0052 { 12834, 50, },
0053 { 13614, 49, },
0054 { 14424, 48, },
0055 { 15265, 48, },
0056 { 16137, 47, },
0057 { 17042, 46, },
0058 { 17981, 45, },
0059 { 18955, 45, },
0060 { 19965, 44, },
0061 { 21013, 43, },
0062 { 22101, 43, },
0063 { 23230, 42, },
0064 { 24402, 41, },
0065 { 25618, 41, },
0066 { 26881, 40, },
0067 { 28193, 39, },
0068 { 29557, 39, },
0069 { 30975, 38, },
0070 { 32450, 38, },
0071 { 33986, 37, },
0072 { 35586, 36, },
0073 { 37253, 36, },
0074 { 38992, 35, },
0075 { 40808, 35, },
0076 { 42707, 34, },
0077 { 44694, 33, },
0078 { 46776, 33, },
0079 { 48961, 32, },
0080 { 51258, 32, },
0081 { 53677, 31, },
0082 { 56230, 30, },
0083 { 58932, 30, },
0084 { 61799, 29, },
0085 { 64851, 28, },
0086 { 68113, 28, },
0087 { 71617, 27, },
0088 { 75401, 26, },
0089 { 79517, 26, },
0090 { 84035, 25, },
0091 { 89053, 24, },
0092 };
0093
0094 #define HSTCP_AIMD_MAX ARRAY_SIZE(hstcp_aimd_vals)
0095
0096 struct hstcp {
0097 u32 ai;
0098 };
0099
0100 static void hstcp_init(struct sock *sk)
0101 {
0102 struct tcp_sock *tp = tcp_sk(sk);
0103 struct hstcp *ca = inet_csk_ca(sk);
0104
0105 ca->ai = 0;
0106
0107
0108
0109 tp->snd_cwnd_clamp = min_t(u32, tp->snd_cwnd_clamp, 0xffffffff/128);
0110 }
0111
0112 static void hstcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
0113 {
0114 struct tcp_sock *tp = tcp_sk(sk);
0115 struct hstcp *ca = inet_csk_ca(sk);
0116
0117 if (!tcp_is_cwnd_limited(sk))
0118 return;
0119
0120 if (tcp_in_slow_start(tp))
0121 tcp_slow_start(tp, acked);
0122 else {
0123
0124
0125
0126
0127
0128
0129
0130 if (tcp_snd_cwnd(tp) > hstcp_aimd_vals[ca->ai].cwnd) {
0131 while (tcp_snd_cwnd(tp) > hstcp_aimd_vals[ca->ai].cwnd &&
0132 ca->ai < HSTCP_AIMD_MAX - 1)
0133 ca->ai++;
0134 } else if (ca->ai && tcp_snd_cwnd(tp) <= hstcp_aimd_vals[ca->ai-1].cwnd) {
0135 while (ca->ai && tcp_snd_cwnd(tp) <= hstcp_aimd_vals[ca->ai-1].cwnd)
0136 ca->ai--;
0137 }
0138
0139
0140 if (tcp_snd_cwnd(tp) < tp->snd_cwnd_clamp) {
0141
0142 tp->snd_cwnd_cnt += ca->ai + 1;
0143 if (tp->snd_cwnd_cnt >= tcp_snd_cwnd(tp)) {
0144 tp->snd_cwnd_cnt -= tcp_snd_cwnd(tp);
0145 tcp_snd_cwnd_set(tp, tcp_snd_cwnd(tp) + 1);
0146 }
0147 }
0148 }
0149 }
0150
0151 static u32 hstcp_ssthresh(struct sock *sk)
0152 {
0153 const struct tcp_sock *tp = tcp_sk(sk);
0154 struct hstcp *ca = inet_csk_ca(sk);
0155
0156
0157 return max(tcp_snd_cwnd(tp) - ((tcp_snd_cwnd(tp) * hstcp_aimd_vals[ca->ai].md) >> 8), 2U);
0158 }
0159
0160 static struct tcp_congestion_ops tcp_highspeed __read_mostly = {
0161 .init = hstcp_init,
0162 .ssthresh = hstcp_ssthresh,
0163 .undo_cwnd = tcp_reno_undo_cwnd,
0164 .cong_avoid = hstcp_cong_avoid,
0165
0166 .owner = THIS_MODULE,
0167 .name = "highspeed"
0168 };
0169
0170 static int __init hstcp_register(void)
0171 {
0172 BUILD_BUG_ON(sizeof(struct hstcp) > ICSK_CA_PRIV_SIZE);
0173 return tcp_register_congestion_control(&tcp_highspeed);
0174 }
0175
0176 static void __exit hstcp_unregister(void)
0177 {
0178 tcp_unregister_congestion_control(&tcp_highspeed);
0179 }
0180
0181 module_init(hstcp_register);
0182 module_exit(hstcp_unregister);
0183
0184 MODULE_AUTHOR("John Heffner");
0185 MODULE_LICENSE("GPL");
0186 MODULE_DESCRIPTION("High Speed TCP");