~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/dccp/ccids/ccid2.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/dccp/ccids/ccid2.c (Version linux-6.11-rc3) and /net/dccp/ccids/ccid2.c (Version linux-4.12.14)


  1 // SPDX-License-Identifier: GPL-2.0-or-later   << 
  2 /*                                                  1 /*
  3  *  Copyright (c) 2005, 2006 Andrea Bittau <a.      2  *  Copyright (c) 2005, 2006 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
  4  *                                                  3  *
  5  *  Changes to meet Linux coding standards, an      4  *  Changes to meet Linux coding standards, and DCCP infrastructure fixes.
  6  *                                                  5  *
  7  *  Copyright (c) 2006 Arnaldo Carvalho de Mel      6  *  Copyright (c) 2006 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
                                                   >>   7  *
                                                   >>   8  *  This program is free software; you can redistribute it and/or modify
                                                   >>   9  *  it under the terms of the GNU General Public License as published by
                                                   >>  10  *  the Free Software Foundation; either version 2 of the License, or
                                                   >>  11  *  (at your option) any later version.
                                                   >>  12  *
                                                   >>  13  *  This program is distributed in the hope that it will be useful,
                                                   >>  14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
                                                   >>  15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                                                   >>  16  *  GNU General Public License for more details.
                                                   >>  17  *
                                                   >>  18  *  You should have received a copy of the GNU General Public License
                                                   >>  19  *  along with this program; if not, write to the Free Software
                                                   >>  20  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  8  */                                                21  */
  9                                                    22 
 10 /*                                                 23 /*
 11  * This implementation should follow RFC 4341      24  * This implementation should follow RFC 4341
 12  */                                                25  */
 13 #include <linux/slab.h>                            26 #include <linux/slab.h>
 14 #include "../feat.h"                               27 #include "../feat.h"
 15 #include "ccid2.h"                                 28 #include "ccid2.h"
 16                                                    29 
 17                                                    30 
 18 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG                  31 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG
 19 static bool ccid2_debug;                           32 static bool ccid2_debug;
 20 #define ccid2_pr_debug(format, a...)    DCCP_P     33 #define ccid2_pr_debug(format, a...)    DCCP_PR_DEBUG(ccid2_debug, format, ##a)
 21 #else                                              34 #else
 22 #define ccid2_pr_debug(format, a...)               35 #define ccid2_pr_debug(format, a...)
 23 #endif                                             36 #endif
 24                                                    37 
 25 static int ccid2_hc_tx_alloc_seq(struct ccid2_     38 static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hc)
 26 {                                                  39 {
 27         struct ccid2_seq *seqp;                    40         struct ccid2_seq *seqp;
 28         int i;                                     41         int i;
 29                                                    42 
 30         /* check if we have space to preserve      43         /* check if we have space to preserve the pointer to the buffer */
 31         if (hc->tx_seqbufc >= (sizeof(hc->tx_s     44         if (hc->tx_seqbufc >= (sizeof(hc->tx_seqbuf) /
 32                                sizeof(struct c     45                                sizeof(struct ccid2_seq *)))
 33                 return -ENOMEM;                    46                 return -ENOMEM;
 34                                                    47 
 35         /* allocate buffer and initialize link     48         /* allocate buffer and initialize linked list */
 36         seqp = kmalloc_array(CCID2_SEQBUF_LEN, !!  49         seqp = kmalloc(CCID2_SEQBUF_LEN * sizeof(struct ccid2_seq), gfp_any());
 37                              gfp_any());       << 
 38         if (seqp == NULL)                          50         if (seqp == NULL)
 39                 return -ENOMEM;                    51                 return -ENOMEM;
 40                                                    52 
 41         for (i = 0; i < (CCID2_SEQBUF_LEN - 1)     53         for (i = 0; i < (CCID2_SEQBUF_LEN - 1); i++) {
 42                 seqp[i].ccid2s_next = &seqp[i      54                 seqp[i].ccid2s_next = &seqp[i + 1];
 43                 seqp[i + 1].ccid2s_prev = &seq     55                 seqp[i + 1].ccid2s_prev = &seqp[i];
 44         }                                          56         }
 45         seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next     57         seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = seqp;
 46         seqp->ccid2s_prev = &seqp[CCID2_SEQBUF     58         seqp->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1];
 47                                                    59 
 48         /* This is the first allocation.  Init     60         /* This is the first allocation.  Initiate the head and tail.  */
 49         if (hc->tx_seqbufc == 0)                   61         if (hc->tx_seqbufc == 0)
 50                 hc->tx_seqh = hc->tx_seqt = se     62                 hc->tx_seqh = hc->tx_seqt = seqp;
 51         else {                                     63         else {
 52                 /* link the existing list with     64                 /* link the existing list with the one we just created */
 53                 hc->tx_seqh->ccid2s_next = seq     65                 hc->tx_seqh->ccid2s_next = seqp;
 54                 seqp->ccid2s_prev = hc->tx_seq     66                 seqp->ccid2s_prev = hc->tx_seqh;
 55                                                    67 
 56                 hc->tx_seqt->ccid2s_prev = &se     68                 hc->tx_seqt->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1];
 57                 seqp[CCID2_SEQBUF_LEN - 1].cci     69                 seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = hc->tx_seqt;
 58         }                                          70         }
 59                                                    71 
 60         /* store the original pointer to the b     72         /* store the original pointer to the buffer so we can free it */
 61         hc->tx_seqbuf[hc->tx_seqbufc] = seqp;      73         hc->tx_seqbuf[hc->tx_seqbufc] = seqp;
 62         hc->tx_seqbufc++;                          74         hc->tx_seqbufc++;
 63                                                    75 
 64         return 0;                                  76         return 0;
 65 }                                                  77 }
 66                                                    78 
 67 static int ccid2_hc_tx_send_packet(struct sock     79 static int ccid2_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
 68 {                                                  80 {
 69         if (ccid2_cwnd_network_limited(ccid2_h     81         if (ccid2_cwnd_network_limited(ccid2_hc_tx_sk(sk)))
 70                 return CCID_PACKET_WILL_DEQUEU     82                 return CCID_PACKET_WILL_DEQUEUE_LATER;
 71         return CCID_PACKET_SEND_AT_ONCE;           83         return CCID_PACKET_SEND_AT_ONCE;
 72 }                                                  84 }
 73                                                    85 
 74 static void ccid2_change_l_ack_ratio(struct so     86 static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val)
 75 {                                                  87 {
 76         u32 max_ratio = DIV_ROUND_UP(ccid2_hc_     88         u32 max_ratio = DIV_ROUND_UP(ccid2_hc_tx_sk(sk)->tx_cwnd, 2);
 77                                                    89 
 78         /*                                         90         /*
 79          * Ensure that Ack Ratio does not exce     91          * Ensure that Ack Ratio does not exceed ceil(cwnd/2), which is (2) from
 80          * RFC 4341, 6.1.2. We ignore the stat     92          * RFC 4341, 6.1.2. We ignore the statement that Ack Ratio 2 is always
 81          * acceptable since this causes starva     93          * acceptable since this causes starvation/deadlock whenever cwnd < 2.
 82          * The same problem arises when Ack Ra     94          * The same problem arises when Ack Ratio is 0 (ie. Ack Ratio disabled).
 83          */                                        95          */
 84         if (val == 0 || val > max_ratio) {         96         if (val == 0 || val > max_ratio) {
 85                 DCCP_WARN("Limiting Ack Ratio      97                 DCCP_WARN("Limiting Ack Ratio (%u) to %u\n", val, max_ratio);
 86                 val = max_ratio;                   98                 val = max_ratio;
 87         }                                          99         }
 88         dccp_feat_signal_nn_change(sk, DCCPF_A    100         dccp_feat_signal_nn_change(sk, DCCPF_ACK_RATIO,
 89                                    min_t(u32,     101                                    min_t(u32, val, DCCPF_ACK_RATIO_MAX));
 90 }                                                 102 }
 91                                                   103 
 92 static void ccid2_check_l_ack_ratio(struct soc    104 static void ccid2_check_l_ack_ratio(struct sock *sk)
 93 {                                                 105 {
 94         struct ccid2_hc_tx_sock *hc = ccid2_hc    106         struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
 95                                                   107 
 96         /*                                        108         /*
 97          * After a loss, idle period, applicat    109          * After a loss, idle period, application limited period, or RTO we
 98          * need to check that the ack ratio is    110          * need to check that the ack ratio is still less than the congestion
 99          * window. Otherwise, we will send an     111          * window. Otherwise, we will send an entire congestion window of
100          * packets and got no response because    112          * packets and got no response because we haven't sent ack ratio
101          * packets yet.                           113          * packets yet.
102          * If the ack ratio does need to be re    114          * If the ack ratio does need to be reduced, we reduce it to half of
103          * the congestion window (or 1 if that    115          * the congestion window (or 1 if that's zero) instead of to the
104          * congestion window. This prevents pr    116          * congestion window. This prevents problems if one ack is lost.
105          */                                       117          */
106         if (dccp_feat_nn_get(sk, DCCPF_ACK_RAT    118         if (dccp_feat_nn_get(sk, DCCPF_ACK_RATIO) > hc->tx_cwnd)
107                 ccid2_change_l_ack_ratio(sk, h    119                 ccid2_change_l_ack_ratio(sk, hc->tx_cwnd/2 ? : 1U);
108 }                                                 120 }
109                                                   121 
110 static void ccid2_change_l_seq_window(struct s    122 static void ccid2_change_l_seq_window(struct sock *sk, u64 val)
111 {                                                 123 {
112         dccp_feat_signal_nn_change(sk, DCCPF_S    124         dccp_feat_signal_nn_change(sk, DCCPF_SEQUENCE_WINDOW,
113                                    clamp_val(v    125                                    clamp_val(val, DCCPF_SEQ_WMIN,
114                                                   126                                                   DCCPF_SEQ_WMAX));
115 }                                                 127 }
116                                                   128 
117 static void dccp_tasklet_schedule(struct sock  !! 129 static void ccid2_hc_tx_rto_expire(unsigned long data)
118 {                                              << 
119         struct tasklet_struct *t = &dccp_sk(sk << 
120                                                << 
121         if (!test_and_set_bit(TASKLET_STATE_SC << 
122                 sock_hold(sk);                 << 
123                 __tasklet_schedule(t);         << 
124         }                                      << 
125 }                                              << 
126                                                << 
127 static void ccid2_hc_tx_rto_expire(struct time << 
128 {                                                 130 {
129         struct ccid2_hc_tx_sock *hc = from_tim !! 131         struct sock *sk = (struct sock *)data;
130         struct sock *sk = hc->sk;              !! 132         struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
131         const bool sender_was_blocked = ccid2_    133         const bool sender_was_blocked = ccid2_cwnd_network_limited(hc);
132                                                   134 
133         bh_lock_sock(sk);                         135         bh_lock_sock(sk);
134         if (sock_owned_by_user(sk)) {             136         if (sock_owned_by_user(sk)) {
135                 sk_reset_timer(sk, &hc->tx_rto    137                 sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + HZ / 5);
136                 goto out;                         138                 goto out;
137         }                                         139         }
138                                                   140 
139         ccid2_pr_debug("RTO_EXPIRE\n");           141         ccid2_pr_debug("RTO_EXPIRE\n");
140                                                   142 
141         if (sk->sk_state == DCCP_CLOSED)       << 
142                 goto out;                      << 
143                                                << 
144         /* back-off timer */                      143         /* back-off timer */
145         hc->tx_rto <<= 1;                         144         hc->tx_rto <<= 1;
146         if (hc->tx_rto > DCCP_RTO_MAX)            145         if (hc->tx_rto > DCCP_RTO_MAX)
147                 hc->tx_rto = DCCP_RTO_MAX;        146                 hc->tx_rto = DCCP_RTO_MAX;
148                                                   147 
149         /* adjust pipe, cwnd etc */               148         /* adjust pipe, cwnd etc */
150         hc->tx_ssthresh = hc->tx_cwnd / 2;        149         hc->tx_ssthresh = hc->tx_cwnd / 2;
151         if (hc->tx_ssthresh < 2)                  150         if (hc->tx_ssthresh < 2)
152                 hc->tx_ssthresh = 2;              151                 hc->tx_ssthresh = 2;
153         hc->tx_cwnd     = 1;                      152         hc->tx_cwnd     = 1;
154         hc->tx_pipe     = 0;                      153         hc->tx_pipe     = 0;
155                                                   154 
156         /* clear state about stuff we sent */     155         /* clear state about stuff we sent */
157         hc->tx_seqt = hc->tx_seqh;                156         hc->tx_seqt = hc->tx_seqh;
158         hc->tx_packets_acked = 0;                 157         hc->tx_packets_acked = 0;
159                                                   158 
160         /* clear ack ratio state. */              159         /* clear ack ratio state. */
161         hc->tx_rpseq    = 0;                      160         hc->tx_rpseq    = 0;
162         hc->tx_rpdupack = -1;                     161         hc->tx_rpdupack = -1;
163         ccid2_change_l_ack_ratio(sk, 1);          162         ccid2_change_l_ack_ratio(sk, 1);
164                                                   163 
165         /* if we were blocked before, we may n    164         /* if we were blocked before, we may now send cwnd=1 packet */
166         if (sender_was_blocked)                   165         if (sender_was_blocked)
167                 dccp_tasklet_schedule(sk);     !! 166                 tasklet_schedule(&dccp_sk(sk)->dccps_xmitlet);
168         /* restart backed-off timer */            167         /* restart backed-off timer */
169         sk_reset_timer(sk, &hc->tx_rtotimer, j    168         sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + hc->tx_rto);
170 out:                                              169 out:
171         bh_unlock_sock(sk);                       170         bh_unlock_sock(sk);
172         sock_put(sk);                             171         sock_put(sk);
173 }                                                 172 }
174                                                   173 
175 /*                                                174 /*
176  *      Congestion window validation (RFC 2861    175  *      Congestion window validation (RFC 2861).
177  */                                               176  */
178 static bool ccid2_do_cwv = true;                  177 static bool ccid2_do_cwv = true;
179 module_param(ccid2_do_cwv, bool, 0644);           178 module_param(ccid2_do_cwv, bool, 0644);
180 MODULE_PARM_DESC(ccid2_do_cwv, "Perform RFC286    179 MODULE_PARM_DESC(ccid2_do_cwv, "Perform RFC2861 Congestion Window Validation");
181                                                   180 
182 /**                                               181 /**
183  * ccid2_update_used_window  -  Track how much    182  * ccid2_update_used_window  -  Track how much of cwnd is actually used
184  * @hc: socket to update window                << 
185  * @new_wnd: new window values to add into the << 
186  *                                             << 
187  * This is done in addition to CWV. The sender    183  * This is done in addition to CWV. The sender needs to have an idea of how many
188  * packets may be in flight, to set the local     184  * packets may be in flight, to set the local Sequence Window value accordingly
189  * (RFC 4340, 7.5.2). The CWV mechanism is exp    185  * (RFC 4340, 7.5.2). The CWV mechanism is exploited to keep track of the
190  * maximum-used window. We use an EWMA low-pas    186  * maximum-used window. We use an EWMA low-pass filter to filter out noise.
191  */                                               187  */
192 static void ccid2_update_used_window(struct cc    188 static void ccid2_update_used_window(struct ccid2_hc_tx_sock *hc, u32 new_wnd)
193 {                                                 189 {
194         hc->tx_expected_wnd = (3 * hc->tx_expe    190         hc->tx_expected_wnd = (3 * hc->tx_expected_wnd + new_wnd) / 4;
195 }                                                 191 }
196                                                   192 
197 /* This borrows the code of tcp_cwnd_applicati    193 /* This borrows the code of tcp_cwnd_application_limited() */
198 static void ccid2_cwnd_application_limited(str    194 static void ccid2_cwnd_application_limited(struct sock *sk, const u32 now)
199 {                                                 195 {
200         struct ccid2_hc_tx_sock *hc = ccid2_hc    196         struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
201         /* don't reduce cwnd below the initial    197         /* don't reduce cwnd below the initial window (IW) */
202         u32 init_win = rfc3390_bytes_to_packet    198         u32 init_win = rfc3390_bytes_to_packets(dccp_sk(sk)->dccps_mss_cache),
203             win_used = max(hc->tx_cwnd_used, i    199             win_used = max(hc->tx_cwnd_used, init_win);
204                                                   200 
205         if (win_used < hc->tx_cwnd) {             201         if (win_used < hc->tx_cwnd) {
206                 hc->tx_ssthresh = max(hc->tx_s    202                 hc->tx_ssthresh = max(hc->tx_ssthresh,
207                                      (hc->tx_c    203                                      (hc->tx_cwnd >> 1) + (hc->tx_cwnd >> 2));
208                 hc->tx_cwnd = (hc->tx_cwnd + w    204                 hc->tx_cwnd = (hc->tx_cwnd + win_used) >> 1;
209         }                                         205         }
210         hc->tx_cwnd_used  = 0;                    206         hc->tx_cwnd_used  = 0;
211         hc->tx_cwnd_stamp = now;                  207         hc->tx_cwnd_stamp = now;
212                                                   208 
213         ccid2_check_l_ack_ratio(sk);              209         ccid2_check_l_ack_ratio(sk);
214 }                                                 210 }
215                                                   211 
216 /* This borrows the code of tcp_cwnd_restart()    212 /* This borrows the code of tcp_cwnd_restart() */
217 static void ccid2_cwnd_restart(struct sock *sk    213 static void ccid2_cwnd_restart(struct sock *sk, const u32 now)
218 {                                                 214 {
219         struct ccid2_hc_tx_sock *hc = ccid2_hc    215         struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
220         u32 cwnd = hc->tx_cwnd, restart_cwnd,     216         u32 cwnd = hc->tx_cwnd, restart_cwnd,
221             iwnd = rfc3390_bytes_to_packets(dc    217             iwnd = rfc3390_bytes_to_packets(dccp_sk(sk)->dccps_mss_cache);
222         s32 delta = now - hc->tx_lsndtime;     << 
223                                                   218 
224         hc->tx_ssthresh = max(hc->tx_ssthresh,    219         hc->tx_ssthresh = max(hc->tx_ssthresh, (cwnd >> 1) + (cwnd >> 2));
225                                                   220 
226         /* don't reduce cwnd below the initial    221         /* don't reduce cwnd below the initial window (IW) */
227         restart_cwnd = min(cwnd, iwnd);           222         restart_cwnd = min(cwnd, iwnd);
228                                                !! 223         cwnd >>= (now - hc->tx_lsndtime) / hc->tx_rto;
229         while ((delta -= hc->tx_rto) >= 0 && c << 
230                 cwnd >>= 1;                    << 
231         hc->tx_cwnd = max(cwnd, restart_cwnd);    224         hc->tx_cwnd = max(cwnd, restart_cwnd);
                                                   >> 225 
232         hc->tx_cwnd_stamp = now;                  226         hc->tx_cwnd_stamp = now;
233         hc->tx_cwnd_used  = 0;                    227         hc->tx_cwnd_used  = 0;
234                                                   228 
235         ccid2_check_l_ack_ratio(sk);              229         ccid2_check_l_ack_ratio(sk);
236 }                                                 230 }
237                                                   231 
238 static void ccid2_hc_tx_packet_sent(struct soc    232 static void ccid2_hc_tx_packet_sent(struct sock *sk, unsigned int len)
239 {                                                 233 {
240         struct dccp_sock *dp = dccp_sk(sk);       234         struct dccp_sock *dp = dccp_sk(sk);
241         struct ccid2_hc_tx_sock *hc = ccid2_hc    235         struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
242         const u32 now = ccid2_jiffies32;       !! 236         const u32 now = ccid2_time_stamp;
243         struct ccid2_seq *next;                   237         struct ccid2_seq *next;
244                                                   238 
245         /* slow-start after idle periods (RFC     239         /* slow-start after idle periods (RFC 2581, RFC 2861) */
246         if (ccid2_do_cwv && !hc->tx_pipe &&       240         if (ccid2_do_cwv && !hc->tx_pipe &&
247             (s32)(now - hc->tx_lsndtime) >= hc    241             (s32)(now - hc->tx_lsndtime) >= hc->tx_rto)
248                 ccid2_cwnd_restart(sk, now);      242                 ccid2_cwnd_restart(sk, now);
249                                                   243 
250         hc->tx_lsndtime = now;                    244         hc->tx_lsndtime = now;
251         hc->tx_pipe    += 1;                      245         hc->tx_pipe    += 1;
252                                                   246 
253         /* see whether cwnd was fully used (RF    247         /* see whether cwnd was fully used (RFC 2861), update expected window */
254         if (ccid2_cwnd_network_limited(hc)) {     248         if (ccid2_cwnd_network_limited(hc)) {
255                 ccid2_update_used_window(hc, h    249                 ccid2_update_used_window(hc, hc->tx_cwnd);
256                 hc->tx_cwnd_used  = 0;            250                 hc->tx_cwnd_used  = 0;
257                 hc->tx_cwnd_stamp = now;          251                 hc->tx_cwnd_stamp = now;
258         } else {                                  252         } else {
259                 if (hc->tx_pipe > hc->tx_cwnd_    253                 if (hc->tx_pipe > hc->tx_cwnd_used)
260                         hc->tx_cwnd_used = hc-    254                         hc->tx_cwnd_used = hc->tx_pipe;
261                                                   255 
262                 ccid2_update_used_window(hc, h    256                 ccid2_update_used_window(hc, hc->tx_cwnd_used);
263                                                   257 
264                 if (ccid2_do_cwv && (s32)(now     258                 if (ccid2_do_cwv && (s32)(now - hc->tx_cwnd_stamp) >= hc->tx_rto)
265                         ccid2_cwnd_application    259                         ccid2_cwnd_application_limited(sk, now);
266         }                                         260         }
267                                                   261 
268         hc->tx_seqh->ccid2s_seq   = dp->dccps_    262         hc->tx_seqh->ccid2s_seq   = dp->dccps_gss;
269         hc->tx_seqh->ccid2s_acked = 0;            263         hc->tx_seqh->ccid2s_acked = 0;
270         hc->tx_seqh->ccid2s_sent  = now;          264         hc->tx_seqh->ccid2s_sent  = now;
271                                                   265 
272         next = hc->tx_seqh->ccid2s_next;          266         next = hc->tx_seqh->ccid2s_next;
273         /* check if we need to alloc more spac    267         /* check if we need to alloc more space */
274         if (next == hc->tx_seqt) {                268         if (next == hc->tx_seqt) {
275                 if (ccid2_hc_tx_alloc_seq(hc))    269                 if (ccid2_hc_tx_alloc_seq(hc)) {
276                         DCCP_CRIT("packet hist    270                         DCCP_CRIT("packet history - out of memory!");
277                         /* FIXME: find a more     271                         /* FIXME: find a more graceful way to bail out */
278                         return;                   272                         return;
279                 }                                 273                 }
280                 next = hc->tx_seqh->ccid2s_nex    274                 next = hc->tx_seqh->ccid2s_next;
281                 BUG_ON(next == hc->tx_seqt);      275                 BUG_ON(next == hc->tx_seqt);
282         }                                         276         }
283         hc->tx_seqh = next;                       277         hc->tx_seqh = next;
284                                                   278 
285         ccid2_pr_debug("cwnd=%d pipe=%d\n", hc    279         ccid2_pr_debug("cwnd=%d pipe=%d\n", hc->tx_cwnd, hc->tx_pipe);
286                                                   280 
287         /*                                        281         /*
288          * FIXME: The code below is broken and    282          * FIXME: The code below is broken and the variables have been removed
289          * from the socket struct. The `acklos    283          * from the socket struct. The `ackloss' variable was always set to 0,
290          * and with arsent there are several p    284          * and with arsent there are several problems:
291          *  (i) it doesn't just count the numb    285          *  (i) it doesn't just count the number of Acks, but all sent packets;
292          *  (ii) it is expressed in # of packe    286          *  (ii) it is expressed in # of packets, not # of windows, so the
293          *  comparison below uses the wrong fo    287          *  comparison below uses the wrong formula: Appendix A of RFC 4341
294          *  comes up with the number K = cwnd     288          *  comes up with the number K = cwnd / (R^2 - R) of consecutive windows
295          *  of data with no lost or marked Ack    289          *  of data with no lost or marked Ack packets. If arsent were the # of
296          *  consecutive Acks received without     290          *  consecutive Acks received without loss, then Ack Ratio needs to be
297          *  decreased by 1 when                   291          *  decreased by 1 when
298          *            arsent >=  K * cwnd / R     292          *            arsent >=  K * cwnd / R  =  cwnd^2 / (R^3 - R^2)
299          *  where cwnd / R is the number of Ac    293          *  where cwnd / R is the number of Acks received per window of data
300          *  (cf. RFC 4341, App. A). The proble    294          *  (cf. RFC 4341, App. A). The problems are that
301          *  - arsent counts other packets as w    295          *  - arsent counts other packets as well;
302          *  - the comparison uses a formula di    296          *  - the comparison uses a formula different from RFC 4341;
303          *  - computing a cubic/quadratic equa    297          *  - computing a cubic/quadratic equation each time is too complicated.
304          *  Hence a different algorithm is nee    298          *  Hence a different algorithm is needed.
305          */                                       299          */
306 #if 0                                             300 #if 0
307         /* Ack Ratio.  Need to maintain a conc    301         /* Ack Ratio.  Need to maintain a concept of how many windows we sent */
308         hc->tx_arsent++;                          302         hc->tx_arsent++;
309         /* We had an ack loss in this window..    303         /* We had an ack loss in this window... */
310         if (hc->tx_ackloss) {                     304         if (hc->tx_ackloss) {
311                 if (hc->tx_arsent >= hc->tx_cw    305                 if (hc->tx_arsent >= hc->tx_cwnd) {
312                         hc->tx_arsent  = 0;       306                         hc->tx_arsent  = 0;
313                         hc->tx_ackloss = 0;       307                         hc->tx_ackloss = 0;
314                 }                                 308                 }
315         } else {                                  309         } else {
316                 /* No acks lost up to now... *    310                 /* No acks lost up to now... */
317                 /* decrease ack ratio if enoug    311                 /* decrease ack ratio if enough packets were sent */
318                 if (dp->dccps_l_ack_ratio > 1)    312                 if (dp->dccps_l_ack_ratio > 1) {
319                         /* XXX don't calculate    313                         /* XXX don't calculate denominator each time */
320                         int denom = dp->dccps_    314                         int denom = dp->dccps_l_ack_ratio * dp->dccps_l_ack_ratio -
321                                     dp->dccps_    315                                     dp->dccps_l_ack_ratio;
322                                                   316 
323                         denom = hc->tx_cwnd *     317                         denom = hc->tx_cwnd * hc->tx_cwnd / denom;
324                                                   318 
325                         if (hc->tx_arsent >= d    319                         if (hc->tx_arsent >= denom) {
326                                 ccid2_change_l    320                                 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1);
327                                 hc->tx_arsent     321                                 hc->tx_arsent = 0;
328                         }                         322                         }
329                 } else {                          323                 } else {
330                         /* we can't increase a    324                         /* we can't increase ack ratio further [1] */
331                         hc->tx_arsent = 0; /*     325                         hc->tx_arsent = 0; /* or maybe set it to cwnd*/
332                 }                                 326                 }
333         }                                         327         }
334 #endif                                            328 #endif
335                                                   329 
336         sk_reset_timer(sk, &hc->tx_rtotimer, j    330         sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + hc->tx_rto);
337                                                   331 
338 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG                 332 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG
339         do {                                      333         do {
340                 struct ccid2_seq *seqp = hc->t    334                 struct ccid2_seq *seqp = hc->tx_seqt;
341                                                   335 
342                 while (seqp != hc->tx_seqh) {     336                 while (seqp != hc->tx_seqh) {
343                         ccid2_pr_debug("out se    337                         ccid2_pr_debug("out seq=%llu acked=%d time=%u\n",
344                                        (unsign    338                                        (unsigned long long)seqp->ccid2s_seq,
345                                        seqp->c    339                                        seqp->ccid2s_acked, seqp->ccid2s_sent);
346                         seqp = seqp->ccid2s_ne    340                         seqp = seqp->ccid2s_next;
347                 }                                 341                 }
348         } while (0);                              342         } while (0);
349         ccid2_pr_debug("=========\n");            343         ccid2_pr_debug("=========\n");
350 #endif                                            344 #endif
351 }                                                 345 }
352                                                   346 
353 /**                                               347 /**
354  * ccid2_rtt_estimator - Sample RTT and comput    348  * ccid2_rtt_estimator - Sample RTT and compute RTO using RFC2988 algorithm
355  * @sk: socket to perform estimator on         << 
356  * @mrtt: measured RTT                         << 
357  *                                             << 
358  * This code is almost identical with TCP's tc    349  * This code is almost identical with TCP's tcp_rtt_estimator(), since
359  * - it has a higher sampling frequency (recom    350  * - it has a higher sampling frequency (recommended by RFC 1323),
360  * - the RTO does not collapse into RTT due to    351  * - the RTO does not collapse into RTT due to RTTVAR going towards zero,
361  * - it is simple (cf. more complex proposals     352  * - it is simple (cf. more complex proposals such as Eifel timer or research
362  *   which suggests that the gain should be se    353  *   which suggests that the gain should be set according to window size),
363  * - in tests it was found to work well with C    354  * - in tests it was found to work well with CCID2 [gerrit].
364  */                                               355  */
365 static void ccid2_rtt_estimator(struct sock *s    356 static void ccid2_rtt_estimator(struct sock *sk, const long mrtt)
366 {                                                 357 {
367         struct ccid2_hc_tx_sock *hc = ccid2_hc    358         struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
368         long m = mrtt ? : 1;                      359         long m = mrtt ? : 1;
369                                                   360 
370         if (hc->tx_srtt == 0) {                   361         if (hc->tx_srtt == 0) {
371                 /* First measurement m */         362                 /* First measurement m */
372                 hc->tx_srtt = m << 3;             363                 hc->tx_srtt = m << 3;
373                 hc->tx_mdev = m << 1;             364                 hc->tx_mdev = m << 1;
374                                                   365 
375                 hc->tx_mdev_max = max(hc->tx_m    366                 hc->tx_mdev_max = max(hc->tx_mdev, tcp_rto_min(sk));
376                 hc->tx_rttvar   = hc->tx_mdev_    367                 hc->tx_rttvar   = hc->tx_mdev_max;
377                                                   368 
378                 hc->tx_rtt_seq  = dccp_sk(sk)-    369                 hc->tx_rtt_seq  = dccp_sk(sk)->dccps_gss;
379         } else {                                  370         } else {
380                 /* Update scaled SRTT as SRTT     371                 /* Update scaled SRTT as SRTT += 1/8 * (m - SRTT) */
381                 m -= (hc->tx_srtt >> 3);          372                 m -= (hc->tx_srtt >> 3);
382                 hc->tx_srtt += m;                 373                 hc->tx_srtt += m;
383                                                   374 
384                 /* Similarly, update scaled md    375                 /* Similarly, update scaled mdev with regard to |m| */
385                 if (m < 0) {                      376                 if (m < 0) {
386                         m = -m;                   377                         m = -m;
387                         m -= (hc->tx_mdev >> 2    378                         m -= (hc->tx_mdev >> 2);
388                         /*                        379                         /*
389                          * This neutralises RT    380                          * This neutralises RTO increase when RTT < SRTT - mdev
390                          * (see P. Sarolahti,     381                          * (see P. Sarolahti, A. Kuznetsov,"Congestion Control
391                          * in Linux TCP", USEN    382                          * in Linux TCP", USENIX 2002, pp. 49-62).
392                          */                       383                          */
393                         if (m > 0)                384                         if (m > 0)
394                                 m >>= 3;          385                                 m >>= 3;
395                 } else {                          386                 } else {
396                         m -= (hc->tx_mdev >> 2    387                         m -= (hc->tx_mdev >> 2);
397                 }                                 388                 }
398                 hc->tx_mdev += m;                 389                 hc->tx_mdev += m;
399                                                   390 
400                 if (hc->tx_mdev > hc->tx_mdev_    391                 if (hc->tx_mdev > hc->tx_mdev_max) {
401                         hc->tx_mdev_max = hc->    392                         hc->tx_mdev_max = hc->tx_mdev;
402                         if (hc->tx_mdev_max >     393                         if (hc->tx_mdev_max > hc->tx_rttvar)
403                                 hc->tx_rttvar     394                                 hc->tx_rttvar = hc->tx_mdev_max;
404                 }                                 395                 }
405                                                   396 
406                 /*                                397                 /*
407                  * Decay RTTVAR at most once p    398                  * Decay RTTVAR at most once per flight, exploiting that
408                  *  1) pipe <= cwnd <= Sequenc    399                  *  1) pipe <= cwnd <= Sequence_Window = W  (RFC 4340, 7.5.2)
409                  *  2) AWL = GSS-W+1 <= GAR <=    400                  *  2) AWL = GSS-W+1 <= GAR <= GSS          (RFC 4340, 7.5.1)
410                  * GAR is a useful bound for F    401                  * GAR is a useful bound for FlightSize = pipe.
411                  * AWL is probably too low her    402                  * AWL is probably too low here, as it over-estimates pipe.
412                  */                               403                  */
413                 if (after48(dccp_sk(sk)->dccps    404                 if (after48(dccp_sk(sk)->dccps_gar, hc->tx_rtt_seq)) {
414                         if (hc->tx_mdev_max <     405                         if (hc->tx_mdev_max < hc->tx_rttvar)
415                                 hc->tx_rttvar     406                                 hc->tx_rttvar -= (hc->tx_rttvar -
416                                                   407                                                   hc->tx_mdev_max) >> 2;
417                         hc->tx_rtt_seq  = dccp    408                         hc->tx_rtt_seq  = dccp_sk(sk)->dccps_gss;
418                         hc->tx_mdev_max = tcp_    409                         hc->tx_mdev_max = tcp_rto_min(sk);
419                 }                                 410                 }
420         }                                         411         }
421                                                   412 
422         /*                                        413         /*
423          * Set RTO from SRTT and RTTVAR           414          * Set RTO from SRTT and RTTVAR
424          * As in TCP, 4 * RTTVAR >= TCP_RTO_MI    415          * As in TCP, 4 * RTTVAR >= TCP_RTO_MIN, giving a minimum RTO of 200 ms.
425          * This agrees with RFC 4341, 5:          416          * This agrees with RFC 4341, 5:
426          *      "Because DCCP does not retrans    417          *      "Because DCCP does not retransmit data, DCCP does not require
427          *       TCP's recommended minimum tim    418          *       TCP's recommended minimum timeout of one second".
428          */                                       419          */
429         hc->tx_rto = (hc->tx_srtt >> 3) + hc->    420         hc->tx_rto = (hc->tx_srtt >> 3) + hc->tx_rttvar;
430                                                   421 
431         if (hc->tx_rto > DCCP_RTO_MAX)            422         if (hc->tx_rto > DCCP_RTO_MAX)
432                 hc->tx_rto = DCCP_RTO_MAX;        423                 hc->tx_rto = DCCP_RTO_MAX;
433 }                                                 424 }
434                                                   425 
435 static void ccid2_new_ack(struct sock *sk, str    426 static void ccid2_new_ack(struct sock *sk, struct ccid2_seq *seqp,
436                           unsigned int *maxinc    427                           unsigned int *maxincr)
437 {                                                 428 {
438         struct ccid2_hc_tx_sock *hc = ccid2_hc    429         struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
439         struct dccp_sock *dp = dccp_sk(sk);       430         struct dccp_sock *dp = dccp_sk(sk);
440         int r_seq_used = hc->tx_cwnd / dp->dcc    431         int r_seq_used = hc->tx_cwnd / dp->dccps_l_ack_ratio;
441                                                   432 
442         if (hc->tx_cwnd < dp->dccps_l_seq_win     433         if (hc->tx_cwnd < dp->dccps_l_seq_win &&
443             r_seq_used < dp->dccps_r_seq_win)     434             r_seq_used < dp->dccps_r_seq_win) {
444                 if (hc->tx_cwnd < hc->tx_ssthr    435                 if (hc->tx_cwnd < hc->tx_ssthresh) {
445                         if (*maxincr > 0 && ++    436                         if (*maxincr > 0 && ++hc->tx_packets_acked >= 2) {
446                                 hc->tx_cwnd +=    437                                 hc->tx_cwnd += 1;
447                                 *maxincr    -=    438                                 *maxincr    -= 1;
448                                 hc->tx_packets    439                                 hc->tx_packets_acked = 0;
449                         }                         440                         }
450                 } else if (++hc->tx_packets_ac    441                 } else if (++hc->tx_packets_acked >= hc->tx_cwnd) {
451                         hc->tx_cwnd += 1;         442                         hc->tx_cwnd += 1;
452                         hc->tx_packets_acked =    443                         hc->tx_packets_acked = 0;
453                 }                                 444                 }
454         }                                         445         }
455                                                   446 
456         /*                                        447         /*
457          * Adjust the local sequence window an    448          * Adjust the local sequence window and the ack ratio to allow about
458          * 5 times the number of packets in th    449          * 5 times the number of packets in the network (RFC 4340 7.5.2)
459          */                                       450          */
460         if (r_seq_used * CCID2_WIN_CHANGE_FACT    451         if (r_seq_used * CCID2_WIN_CHANGE_FACTOR >= dp->dccps_r_seq_win)
461                 ccid2_change_l_ack_ratio(sk, d    452                 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio * 2);
462         else if (r_seq_used * CCID2_WIN_CHANGE    453         else if (r_seq_used * CCID2_WIN_CHANGE_FACTOR < dp->dccps_r_seq_win/2)
463                 ccid2_change_l_ack_ratio(sk, d    454                 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio / 2 ? : 1U);
464                                                   455 
465         if (hc->tx_cwnd * CCID2_WIN_CHANGE_FAC    456         if (hc->tx_cwnd * CCID2_WIN_CHANGE_FACTOR >= dp->dccps_l_seq_win)
466                 ccid2_change_l_seq_window(sk,     457                 ccid2_change_l_seq_window(sk, dp->dccps_l_seq_win * 2);
467         else if (hc->tx_cwnd * CCID2_WIN_CHANG    458         else if (hc->tx_cwnd * CCID2_WIN_CHANGE_FACTOR < dp->dccps_l_seq_win/2)
468                 ccid2_change_l_seq_window(sk,     459                 ccid2_change_l_seq_window(sk, dp->dccps_l_seq_win / 2);
469                                                   460 
470         /*                                        461         /*
471          * FIXME: RTT is sampled several times    462          * FIXME: RTT is sampled several times per acknowledgment (for each
472          * entry in the Ack Vector), instead o    463          * entry in the Ack Vector), instead of once per Ack (as in TCP SACK).
473          * This causes the RTT to be over-esti    464          * This causes the RTT to be over-estimated, since the older entries
474          * in the Ack Vector have earlier send    465          * in the Ack Vector have earlier sending times.
475          * The cleanest solution is to not use    466          * The cleanest solution is to not use the ccid2s_sent field at all
476          * and instead use DCCP timestamps: re    467          * and instead use DCCP timestamps: requires changes in other places.
477          */                                       468          */
478         ccid2_rtt_estimator(sk, ccid2_jiffies3 !! 469         ccid2_rtt_estimator(sk, ccid2_time_stamp - seqp->ccid2s_sent);
479 }                                                 470 }
480                                                   471 
481 static void ccid2_congestion_event(struct sock    472 static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp)
482 {                                                 473 {
483         struct ccid2_hc_tx_sock *hc = ccid2_hc    474         struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
484                                                   475 
485         if ((s32)(seqp->ccid2s_sent - hc->tx_l    476         if ((s32)(seqp->ccid2s_sent - hc->tx_last_cong) < 0) {
486                 ccid2_pr_debug("Multiple losse    477                 ccid2_pr_debug("Multiple losses in an RTT---treating as one\n");
487                 return;                           478                 return;
488         }                                         479         }
489                                                   480 
490         hc->tx_last_cong = ccid2_jiffies32;    !! 481         hc->tx_last_cong = ccid2_time_stamp;
491                                                   482 
492         hc->tx_cwnd      = hc->tx_cwnd / 2 ? :    483         hc->tx_cwnd      = hc->tx_cwnd / 2 ? : 1U;
493         hc->tx_ssthresh  = max(hc->tx_cwnd, 2U    484         hc->tx_ssthresh  = max(hc->tx_cwnd, 2U);
494                                                   485 
495         ccid2_check_l_ack_ratio(sk);              486         ccid2_check_l_ack_ratio(sk);
496 }                                                 487 }
497                                                   488 
498 static int ccid2_hc_tx_parse_options(struct so    489 static int ccid2_hc_tx_parse_options(struct sock *sk, u8 packet_type,
499                                      u8 option    490                                      u8 option, u8 *optval, u8 optlen)
500 {                                                 491 {
501         struct ccid2_hc_tx_sock *hc = ccid2_hc    492         struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
502                                                   493 
503         switch (option) {                         494         switch (option) {
504         case DCCPO_ACK_VECTOR_0:                  495         case DCCPO_ACK_VECTOR_0:
505         case DCCPO_ACK_VECTOR_1:                  496         case DCCPO_ACK_VECTOR_1:
506                 return dccp_ackvec_parsed_add(    497                 return dccp_ackvec_parsed_add(&hc->tx_av_chunks, optval, optlen,
507                                                   498                                               option - DCCPO_ACK_VECTOR_0);
508         }                                         499         }
509         return 0;                                 500         return 0;
510 }                                                 501 }
511                                                   502 
512 static void ccid2_hc_tx_packet_recv(struct soc    503 static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
513 {                                                 504 {
514         struct dccp_sock *dp = dccp_sk(sk);       505         struct dccp_sock *dp = dccp_sk(sk);
515         struct ccid2_hc_tx_sock *hc = ccid2_hc    506         struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
516         const bool sender_was_blocked = ccid2_    507         const bool sender_was_blocked = ccid2_cwnd_network_limited(hc);
517         struct dccp_ackvec_parsed *avp;           508         struct dccp_ackvec_parsed *avp;
518         u64 ackno, seqno;                         509         u64 ackno, seqno;
519         struct ccid2_seq *seqp;                   510         struct ccid2_seq *seqp;
520         int done = 0;                             511         int done = 0;
521         unsigned int maxincr = 0;                 512         unsigned int maxincr = 0;
522                                                   513 
523         /* check reverse path congestion */       514         /* check reverse path congestion */
524         seqno = DCCP_SKB_CB(skb)->dccpd_seq;      515         seqno = DCCP_SKB_CB(skb)->dccpd_seq;
525                                                   516 
526         /* XXX this whole "algorithm" is broke    517         /* XXX this whole "algorithm" is broken.  Need to fix it to keep track
527          * of the seqnos of the dupacks so tha    518          * of the seqnos of the dupacks so that rpseq and rpdupack are correct
528          * -sorbo.                                519          * -sorbo.
529          */                                       520          */
530         /* need to bootstrap */                   521         /* need to bootstrap */
531         if (hc->tx_rpdupack == -1) {              522         if (hc->tx_rpdupack == -1) {
532                 hc->tx_rpdupack = 0;              523                 hc->tx_rpdupack = 0;
533                 hc->tx_rpseq    = seqno;          524                 hc->tx_rpseq    = seqno;
534         } else {                                  525         } else {
535                 /* check if packet is consecut    526                 /* check if packet is consecutive */
536                 if (dccp_delta_seqno(hc->tx_rp    527                 if (dccp_delta_seqno(hc->tx_rpseq, seqno) == 1)
537                         hc->tx_rpseq = seqno;     528                         hc->tx_rpseq = seqno;
538                 /* it's a later packet */         529                 /* it's a later packet */
539                 else if (after48(seqno, hc->tx    530                 else if (after48(seqno, hc->tx_rpseq)) {
540                         hc->tx_rpdupack++;        531                         hc->tx_rpdupack++;
541                                                   532 
542                         /* check if we got eno    533                         /* check if we got enough dupacks */
543                         if (hc->tx_rpdupack >=    534                         if (hc->tx_rpdupack >= NUMDUPACK) {
544                                 hc->tx_rpdupac    535                                 hc->tx_rpdupack = -1; /* XXX lame */
545                                 hc->tx_rpseq      536                                 hc->tx_rpseq    = 0;
546 #ifdef __CCID2_COPES_GRACEFULLY_WITH_ACK_CONGE    537 #ifdef __CCID2_COPES_GRACEFULLY_WITH_ACK_CONGESTION_CONTROL__
547                                 /*                538                                 /*
548                                  * FIXME: Ack     539                                  * FIXME: Ack Congestion Control is broken; in
549                                  * the current    540                                  * the current state instabilities occurred with
550                                  * Ack Ratios     541                                  * Ack Ratios greater than 1; causing hang-ups
551                                  * and long RT    542                                  * and long RTO timeouts. This needs to be fixed
552                                  * before open    543                                  * before opening up dynamic changes. -- gerrit
553                                  */               544                                  */
554                                 ccid2_change_l    545                                 ccid2_change_l_ack_ratio(sk, 2 * dp->dccps_l_ack_ratio);
555 #endif                                            546 #endif
556                         }                         547                         }
557                 }                                 548                 }
558         }                                         549         }
559                                                   550 
560         /* check forward path congestion */       551         /* check forward path congestion */
561         if (dccp_packet_without_ack(skb))         552         if (dccp_packet_without_ack(skb))
562                 return;                           553                 return;
563                                                   554 
564         /* still didn't send out new data pack    555         /* still didn't send out new data packets */
565         if (hc->tx_seqh == hc->tx_seqt)           556         if (hc->tx_seqh == hc->tx_seqt)
566                 goto done;                        557                 goto done;
567                                                   558 
568         ackno = DCCP_SKB_CB(skb)->dccpd_ack_se    559         ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
569         if (after48(ackno, hc->tx_high_ack))      560         if (after48(ackno, hc->tx_high_ack))
570                 hc->tx_high_ack = ackno;          561                 hc->tx_high_ack = ackno;
571                                                   562 
572         seqp = hc->tx_seqt;                       563         seqp = hc->tx_seqt;
573         while (before48(seqp->ccid2s_seq, ackn    564         while (before48(seqp->ccid2s_seq, ackno)) {
574                 seqp = seqp->ccid2s_next;         565                 seqp = seqp->ccid2s_next;
575                 if (seqp == hc->tx_seqh) {        566                 if (seqp == hc->tx_seqh) {
576                         seqp = hc->tx_seqh->cc    567                         seqp = hc->tx_seqh->ccid2s_prev;
577                         break;                    568                         break;
578                 }                                 569                 }
579         }                                         570         }
580                                                   571 
581         /*                                        572         /*
582          * In slow-start, cwnd can increase up    573          * In slow-start, cwnd can increase up to a maximum of Ack Ratio/2
583          * packets per acknowledgement. Roundi    574          * packets per acknowledgement. Rounding up avoids that cwnd is not
584          * advanced when Ack Ratio is 1 and gi    575          * advanced when Ack Ratio is 1 and gives a slight edge otherwise.
585          */                                       576          */
586         if (hc->tx_cwnd < hc->tx_ssthresh)        577         if (hc->tx_cwnd < hc->tx_ssthresh)
587                 maxincr = DIV_ROUND_UP(dp->dcc    578                 maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2);
588                                                   579 
589         /* go through all ack vectors */          580         /* go through all ack vectors */
590         list_for_each_entry(avp, &hc->tx_av_ch    581         list_for_each_entry(avp, &hc->tx_av_chunks, node) {
591                 /* go through this ack vector     582                 /* go through this ack vector */
592                 for (; avp->len--; avp->vec++)    583                 for (; avp->len--; avp->vec++) {
593                         u64 ackno_end_rl = SUB    584                         u64 ackno_end_rl = SUB48(ackno,
594                                                   585                                                  dccp_ackvec_runlen(avp->vec));
595                                                   586 
596                         ccid2_pr_debug("ackvec    587                         ccid2_pr_debug("ackvec %llu |%u,%u|\n",
597                                        (unsign    588                                        (unsigned long long)ackno,
598                                        dccp_ac    589                                        dccp_ackvec_state(avp->vec) >> 6,
599                                        dccp_ac    590                                        dccp_ackvec_runlen(avp->vec));
600                         /* if the seqno we are    591                         /* if the seqno we are analyzing is larger than the
601                          * current ackno, then    592                          * current ackno, then move towards the tail of our
602                          * seqnos.                593                          * seqnos.
603                          */                       594                          */
604                         while (after48(seqp->c    595                         while (after48(seqp->ccid2s_seq, ackno)) {
605                                 if (seqp == hc    596                                 if (seqp == hc->tx_seqt) {
606                                         done =    597                                         done = 1;
607                                         break;    598                                         break;
608                                 }                 599                                 }
609                                 seqp = seqp->c    600                                 seqp = seqp->ccid2s_prev;
610                         }                         601                         }
611                         if (done)                 602                         if (done)
612                                 break;            603                                 break;
613                                                   604 
614                         /* check all seqnos in    605                         /* check all seqnos in the range of the vector
615                          * run length             606                          * run length
616                          */                       607                          */
617                         while (between48(seqp-    608                         while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) {
618                                 const u8 state    609                                 const u8 state = dccp_ackvec_state(avp->vec);
619                                                   610 
620                                 /* new packet     611                                 /* new packet received or marked */
621                                 if (state != D    612                                 if (state != DCCPAV_NOT_RECEIVED &&
622                                     !seqp->cci    613                                     !seqp->ccid2s_acked) {
623                                         if (st    614                                         if (state == DCCPAV_ECN_MARKED)
624                                                   615                                                 ccid2_congestion_event(sk,
625                                                   616                                                                        seqp);
626                                         else      617                                         else
627                                                   618                                                 ccid2_new_ack(sk, seqp,
628                                                   619                                                               &maxincr);
629                                                   620 
630                                         seqp->    621                                         seqp->ccid2s_acked = 1;
631                                         ccid2_    622                                         ccid2_pr_debug("Got ack for %llu\n",
632                                                   623                                                        (unsigned long long)seqp->ccid2s_seq);
633                                         hc->tx    624                                         hc->tx_pipe--;
634                                 }                 625                                 }
635                                 if (seqp == hc    626                                 if (seqp == hc->tx_seqt) {
636                                         done =    627                                         done = 1;
637                                         break;    628                                         break;
638                                 }                 629                                 }
639                                 seqp = seqp->c    630                                 seqp = seqp->ccid2s_prev;
640                         }                         631                         }
641                         if (done)                 632                         if (done)
642                                 break;            633                                 break;
643                                                   634 
644                         ackno = SUB48(ackno_en    635                         ackno = SUB48(ackno_end_rl, 1);
645                 }                                 636                 }
646                 if (done)                         637                 if (done)
647                         break;                    638                         break;
648         }                                         639         }
649                                                   640 
650         /* The state about what is acked shoul    641         /* The state about what is acked should be correct now
651          * Check for NUMDUPACK                    642          * Check for NUMDUPACK
652          */                                       643          */
653         seqp = hc->tx_seqt;                       644         seqp = hc->tx_seqt;
654         while (before48(seqp->ccid2s_seq, hc->    645         while (before48(seqp->ccid2s_seq, hc->tx_high_ack)) {
655                 seqp = seqp->ccid2s_next;         646                 seqp = seqp->ccid2s_next;
656                 if (seqp == hc->tx_seqh) {        647                 if (seqp == hc->tx_seqh) {
657                         seqp = hc->tx_seqh->cc    648                         seqp = hc->tx_seqh->ccid2s_prev;
658                         break;                    649                         break;
659                 }                                 650                 }
660         }                                         651         }
661         done = 0;                                 652         done = 0;
662         while (1) {                               653         while (1) {
663                 if (seqp->ccid2s_acked) {         654                 if (seqp->ccid2s_acked) {
664                         done++;                   655                         done++;
665                         if (done == NUMDUPACK)    656                         if (done == NUMDUPACK)
666                                 break;            657                                 break;
667                 }                                 658                 }
668                 if (seqp == hc->tx_seqt)          659                 if (seqp == hc->tx_seqt)
669                         break;                    660                         break;
670                 seqp = seqp->ccid2s_prev;         661                 seqp = seqp->ccid2s_prev;
671         }                                         662         }
672                                                   663 
673         /* If there are at least 3 acknowledge    664         /* If there are at least 3 acknowledgements, anything unacknowledged
674          * below the last sequence number is c    665          * below the last sequence number is considered lost
675          */                                       666          */
676         if (done == NUMDUPACK) {                  667         if (done == NUMDUPACK) {
677                 struct ccid2_seq *last_acked =    668                 struct ccid2_seq *last_acked = seqp;
678                                                   669 
679                 /* check for lost packets */      670                 /* check for lost packets */
680                 while (1) {                       671                 while (1) {
681                         if (!seqp->ccid2s_acke    672                         if (!seqp->ccid2s_acked) {
682                                 ccid2_pr_debug    673                                 ccid2_pr_debug("Packet lost: %llu\n",
683                                                   674                                                (unsigned long long)seqp->ccid2s_seq);
684                                 /* XXX need to    675                                 /* XXX need to traverse from tail -> head in
685                                  * order to de    676                                  * order to detect multiple congestion events in
686                                  * one ack vec    677                                  * one ack vector.
687                                  */               678                                  */
688                                 ccid2_congesti    679                                 ccid2_congestion_event(sk, seqp);
689                                 hc->tx_pipe--;    680                                 hc->tx_pipe--;
690                         }                         681                         }
691                         if (seqp == hc->tx_seq    682                         if (seqp == hc->tx_seqt)
692                                 break;            683                                 break;
693                         seqp = seqp->ccid2s_pr    684                         seqp = seqp->ccid2s_prev;
694                 }                                 685                 }
695                                                   686 
696                 hc->tx_seqt = last_acked;         687                 hc->tx_seqt = last_acked;
697         }                                         688         }
698                                                   689 
699         /* trim acked packets in tail */          690         /* trim acked packets in tail */
700         while (hc->tx_seqt != hc->tx_seqh) {      691         while (hc->tx_seqt != hc->tx_seqh) {
701                 if (!hc->tx_seqt->ccid2s_acked    692                 if (!hc->tx_seqt->ccid2s_acked)
702                         break;                    693                         break;
703                                                   694 
704                 hc->tx_seqt = hc->tx_seqt->cci    695                 hc->tx_seqt = hc->tx_seqt->ccid2s_next;
705         }                                         696         }
706                                                   697 
707         /* restart RTO timer if not all outsta    698         /* restart RTO timer if not all outstanding data has been acked */
708         if (hc->tx_pipe == 0)                     699         if (hc->tx_pipe == 0)
709                 sk_stop_timer(sk, &hc->tx_rtot    700                 sk_stop_timer(sk, &hc->tx_rtotimer);
710         else                                      701         else
711                 sk_reset_timer(sk, &hc->tx_rto    702                 sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + hc->tx_rto);
712 done:                                             703 done:
713         /* check if incoming Acks allow pendin    704         /* check if incoming Acks allow pending packets to be sent */
714         if (sender_was_blocked && !ccid2_cwnd_    705         if (sender_was_blocked && !ccid2_cwnd_network_limited(hc))
715                 dccp_tasklet_schedule(sk);     !! 706                 tasklet_schedule(&dccp_sk(sk)->dccps_xmitlet);
716         dccp_ackvec_parsed_cleanup(&hc->tx_av_    707         dccp_ackvec_parsed_cleanup(&hc->tx_av_chunks);
717 }                                                 708 }
718                                                   709 
719 static int ccid2_hc_tx_init(struct ccid *ccid,    710 static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
720 {                                                 711 {
721         struct ccid2_hc_tx_sock *hc = ccid_pri    712         struct ccid2_hc_tx_sock *hc = ccid_priv(ccid);
722         struct dccp_sock *dp = dccp_sk(sk);       713         struct dccp_sock *dp = dccp_sk(sk);
723         u32 max_ratio;                            714         u32 max_ratio;
724                                                   715 
725         /* RFC 4341, 5: initialise ssthresh to    716         /* RFC 4341, 5: initialise ssthresh to arbitrarily high (max) value */
726         hc->tx_ssthresh = ~0U;                    717         hc->tx_ssthresh = ~0U;
727                                                   718 
728         /* Use larger initial windows (RFC 434    719         /* Use larger initial windows (RFC 4341, section 5). */
729         hc->tx_cwnd = rfc3390_bytes_to_packets    720         hc->tx_cwnd = rfc3390_bytes_to_packets(dp->dccps_mss_cache);
730         hc->tx_expected_wnd = hc->tx_cwnd;        721         hc->tx_expected_wnd = hc->tx_cwnd;
731                                                   722 
732         /* Make sure that Ack Ratio is enabled    723         /* Make sure that Ack Ratio is enabled and within bounds. */
733         max_ratio = DIV_ROUND_UP(hc->tx_cwnd,     724         max_ratio = DIV_ROUND_UP(hc->tx_cwnd, 2);
734         if (dp->dccps_l_ack_ratio == 0 || dp->    725         if (dp->dccps_l_ack_ratio == 0 || dp->dccps_l_ack_ratio > max_ratio)
735                 dp->dccps_l_ack_ratio = max_ra    726                 dp->dccps_l_ack_ratio = max_ratio;
736                                                   727 
737         /* XXX init ~ to window size... */        728         /* XXX init ~ to window size... */
738         if (ccid2_hc_tx_alloc_seq(hc))            729         if (ccid2_hc_tx_alloc_seq(hc))
739                 return -ENOMEM;                   730                 return -ENOMEM;
740                                                   731 
741         hc->tx_rto       = DCCP_TIMEOUT_INIT;     732         hc->tx_rto       = DCCP_TIMEOUT_INIT;
742         hc->tx_rpdupack  = -1;                    733         hc->tx_rpdupack  = -1;
743         hc->tx_last_cong = hc->tx_lsndtime = h !! 734         hc->tx_last_cong = hc->tx_lsndtime = hc->tx_cwnd_stamp = ccid2_time_stamp;
744         hc->tx_cwnd_used = 0;                     735         hc->tx_cwnd_used = 0;
745         hc->sk           = sk;                 !! 736         setup_timer(&hc->tx_rtotimer, ccid2_hc_tx_rto_expire,
746         timer_setup(&hc->tx_rtotimer, ccid2_hc !! 737                         (unsigned long)sk);
747         INIT_LIST_HEAD(&hc->tx_av_chunks);        738         INIT_LIST_HEAD(&hc->tx_av_chunks);
748         return 0;                                 739         return 0;
749 }                                                 740 }
750                                                   741 
751 static void ccid2_hc_tx_exit(struct sock *sk)     742 static void ccid2_hc_tx_exit(struct sock *sk)
752 {                                                 743 {
753         struct ccid2_hc_tx_sock *hc = ccid2_hc    744         struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
754         int i;                                    745         int i;
755                                                   746 
756         sk_stop_timer(sk, &hc->tx_rtotimer);      747         sk_stop_timer(sk, &hc->tx_rtotimer);
757                                                   748 
758         for (i = 0; i < hc->tx_seqbufc; i++)      749         for (i = 0; i < hc->tx_seqbufc; i++)
759                 kfree(hc->tx_seqbuf[i]);          750                 kfree(hc->tx_seqbuf[i]);
760         hc->tx_seqbufc = 0;                       751         hc->tx_seqbufc = 0;
761         dccp_ackvec_parsed_cleanup(&hc->tx_av_    752         dccp_ackvec_parsed_cleanup(&hc->tx_av_chunks);
762 }                                                 753 }
763                                                   754 
764 static void ccid2_hc_rx_packet_recv(struct soc    755 static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
765 {                                                 756 {
766         struct ccid2_hc_rx_sock *hc = ccid2_hc    757         struct ccid2_hc_rx_sock *hc = ccid2_hc_rx_sk(sk);
767                                                   758 
768         if (!dccp_data_packet(skb))               759         if (!dccp_data_packet(skb))
769                 return;                           760                 return;
770                                                   761 
771         if (++hc->rx_num_data_pkts >= dccp_sk(    762         if (++hc->rx_num_data_pkts >= dccp_sk(sk)->dccps_r_ack_ratio) {
772                 dccp_send_ack(sk);                763                 dccp_send_ack(sk);
773                 hc->rx_num_data_pkts = 0;         764                 hc->rx_num_data_pkts = 0;
774         }                                         765         }
775 }                                                 766 }
776                                                   767 
777 struct ccid_operations ccid2_ops = {              768 struct ccid_operations ccid2_ops = {
778         .ccid_id                  = DCCPC_CCID    769         .ccid_id                  = DCCPC_CCID2,
779         .ccid_name                = "TCP-like"    770         .ccid_name                = "TCP-like",
780         .ccid_hc_tx_obj_size      = sizeof(str    771         .ccid_hc_tx_obj_size      = sizeof(struct ccid2_hc_tx_sock),
781         .ccid_hc_tx_init          = ccid2_hc_t    772         .ccid_hc_tx_init          = ccid2_hc_tx_init,
782         .ccid_hc_tx_exit          = ccid2_hc_t    773         .ccid_hc_tx_exit          = ccid2_hc_tx_exit,
783         .ccid_hc_tx_send_packet   = ccid2_hc_t    774         .ccid_hc_tx_send_packet   = ccid2_hc_tx_send_packet,
784         .ccid_hc_tx_packet_sent   = ccid2_hc_t    775         .ccid_hc_tx_packet_sent   = ccid2_hc_tx_packet_sent,
785         .ccid_hc_tx_parse_options = ccid2_hc_t    776         .ccid_hc_tx_parse_options = ccid2_hc_tx_parse_options,
786         .ccid_hc_tx_packet_recv   = ccid2_hc_t    777         .ccid_hc_tx_packet_recv   = ccid2_hc_tx_packet_recv,
787         .ccid_hc_rx_obj_size      = sizeof(str    778         .ccid_hc_rx_obj_size      = sizeof(struct ccid2_hc_rx_sock),
788         .ccid_hc_rx_packet_recv   = ccid2_hc_r    779         .ccid_hc_rx_packet_recv   = ccid2_hc_rx_packet_recv,
789 };                                                780 };
790                                                   781 
791 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG                 782 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG
792 module_param(ccid2_debug, bool, 0644);            783 module_param(ccid2_debug, bool, 0644);
793 MODULE_PARM_DESC(ccid2_debug, "Enable CCID-2 d    784 MODULE_PARM_DESC(ccid2_debug, "Enable CCID-2 debug messages");
794 #endif                                            785 #endif
795                                                   786 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php