sctp: Adjust PMTU updates to accomodate route invalidation.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / sctp / transport.c
CommitLineData
60c778b2 1/* SCTP kernel implementation
1da177e4
LT
2 * Copyright (c) 1999-2000 Cisco, Inc.
3 * Copyright (c) 1999-2001 Motorola, Inc.
4 * Copyright (c) 2001-2003 International Business Machines Corp.
5 * Copyright (c) 2001 Intel Corp.
6 * Copyright (c) 2001 La Monte H.P. Yarroll
7 *
60c778b2 8 * This file is part of the SCTP kernel implementation
1da177e4
LT
9 *
10 * This module provides the abstraction for an SCTP tranport representing
11 * a remote transport address. For local transport addresses, we just use
12 * union sctp_addr.
13 *
60c778b2 14 * This SCTP implementation is free software;
1da177e4
LT
15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
18 * any later version.
19 *
60c778b2 20 * This SCTP implementation is distributed in the hope that it
1da177e4
LT
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA.
30 *
31 * Please send any bug reports or fixes you make to the
32 * email address(es):
33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
34 *
35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp
37 *
38 * Written or modified by:
39 * La Monte H.P. Yarroll <piggy@acm.org>
40 * Karl Knutson <karl@athena.chicago.il.us>
41 * Jon Grimm <jgrimm@us.ibm.com>
42 * Xingang Guo <xingang.guo@intel.com>
43 * Hui Huang <hui.huang@nokia.com>
44 * Sridhar Samudrala <sri@us.ibm.com>
45 * Ardelle Fan <ardelle.fan@intel.com>
46 *
47 * Any bugs reported given to us we will try to fix... any fixes shared will
48 * be incorporated into the next SCTP release.
49 */
50
145ce502
JP
51#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
52
5a0e3ad6 53#include <linux/slab.h>
1da177e4 54#include <linux/types.h>
ad8fec17 55#include <linux/random.h>
1da177e4
LT
56#include <net/sctp/sctp.h>
57#include <net/sctp/sm.h>
58
59/* 1st Level Abstractions. */
60
61/* Initialize a new transport from provided memory. */
62static struct sctp_transport *sctp_transport_init(struct sctp_transport *peer,
63 const union sctp_addr *addr,
dd0fc66f 64 gfp_t gfp)
1da177e4
LT
65{
66 /* Copy in the address. */
67 peer->ipaddr = *addr;
68 peer->af_specific = sctp_get_af_specific(addr->sa.sa_family);
1da177e4
LT
69 memset(&peer->saddr, 0, sizeof(union sctp_addr));
70
4244854d
NH
71 peer->sack_generation = 0;
72
1da177e4
LT
73 /* From 6.3.1 RTO Calculation:
74 *
75 * C1) Until an RTT measurement has been made for a packet sent to the
76 * given destination transport address, set RTO to the protocol
77 * parameter 'RTO.Initial'.
78 */
5fdd4bae 79 peer->rto = msecs_to_jiffies(sctp_rto_initial);
1da177e4
LT
80
81 peer->last_time_heard = jiffies;
1da177e4
LT
82 peer->last_time_ecne_reduced = jiffies;
83
52ccb8e9
FF
84 peer->param_flags = SPP_HB_DISABLE |
85 SPP_PMTUD_ENABLE |
86 SPP_SACKDELAY_ENABLE;
1da177e4
LT
87
88 /* Initialize the default path max_retrans. */
52ccb8e9 89 peer->pathmaxrxt = sctp_max_retrans_path;
1da177e4
LT
90
91 INIT_LIST_HEAD(&peer->transmitted);
92 INIT_LIST_HEAD(&peer->send_ready);
93 INIT_LIST_HEAD(&peer->transports);
94
b24b8a24
PE
95 setup_timer(&peer->T3_rtx_timer, sctp_generate_t3_rtx_event,
96 (unsigned long)peer);
97 setup_timer(&peer->hb_timer, sctp_generate_heartbeat_event,
98 (unsigned long)peer);
50b5d6ad
VY
99 setup_timer(&peer->proto_unreach_timer,
100 sctp_generate_proto_unreach_event, (unsigned long)peer);
1da177e4 101
ad8fec17
SS
102 /* Initialize the 64-bit random nonce sent with heartbeat. */
103 get_random_bytes(&peer->hb_nonce, sizeof(peer->hb_nonce));
104
1da177e4 105 atomic_set(&peer->refcnt, 1);
1da177e4
LT
106
107 return peer;
108}
109
110/* Allocate and initialize a new transport. */
3182cd84 111struct sctp_transport *sctp_transport_new(const union sctp_addr *addr,
dd0fc66f 112 gfp_t gfp)
1da177e4 113{
d808ad9a 114 struct sctp_transport *transport;
1da177e4 115
d808ad9a 116 transport = t_new(struct sctp_transport, gfp);
1da177e4
LT
117 if (!transport)
118 goto fail;
119
120 if (!sctp_transport_init(transport, addr, gfp))
121 goto fail_init;
122
123 transport->malloced = 1;
124 SCTP_DBG_OBJCNT_INC(transport);
125
126 return transport;
127
128fail_init:
129 kfree(transport);
130
131fail:
132 return NULL;
133}
134
135/* This transport is no longer needed. Free up if possible, or
136 * delay until it last reference count.
137 */
138void sctp_transport_free(struct sctp_transport *transport)
139{
140 transport->dead = 1;
141
142 /* Try to delete the heartbeat timer. */
143 if (del_timer(&transport->hb_timer))
144 sctp_transport_put(transport);
145
146 /* Delete the T3_rtx timer if it's active.
147 * There is no point in not doing this now and letting
148 * structure hang around in memory since we know
149 * the tranport is going away.
150 */
151 if (timer_pending(&transport->T3_rtx_timer) &&
152 del_timer(&transport->T3_rtx_timer))
153 sctp_transport_put(transport);
154
55fa0cfd
WY
155 /* Delete the ICMP proto unreachable timer if it's active. */
156 if (timer_pending(&transport->proto_unreach_timer) &&
157 del_timer(&transport->proto_unreach_timer))
158 sctp_association_put(transport->asoc);
1da177e4
LT
159
160 sctp_transport_put(transport);
161}
162
163/* Destroy the transport data structure.
164 * Assumes there are no more users of this structure.
165 */
166static void sctp_transport_destroy(struct sctp_transport *transport)
167{
168 SCTP_ASSERT(transport->dead, "Transport is not dead", return);
169
170 if (transport->asoc)
171 sctp_association_put(transport->asoc);
172
d808ad9a 173 sctp_packet_free(&transport->packet);
1da177e4
LT
174
175 dst_release(transport->dst);
176 kfree(transport);
177 SCTP_DBG_OBJCNT_DEC(transport);
178}
179
180/* Start T3_rtx timer if it is not already running and update the heartbeat
181 * timer. This routine is called every time a DATA chunk is sent.
182 */
d9efc223 183void sctp_transport_reset_timers(struct sctp_transport *transport)
1da177e4
LT
184{
185 /* RFC 2960 6.3.2 Retransmission Timer Rules
186 *
187 * R1) Every time a DATA chunk is sent to any address(including a
188 * retransmission), if the T3-rtx timer of that address is not running
189 * start it running so that it will expire after the RTO of that
190 * address.
191 */
192
d9efc223 193 if (!timer_pending(&transport->T3_rtx_timer))
1da177e4
LT
194 if (!mod_timer(&transport->T3_rtx_timer,
195 jiffies + transport->rto))
196 sctp_transport_hold(transport);
197
198 /* When a data chunk is sent, reset the heartbeat interval. */
199 if (!mod_timer(&transport->hb_timer,
200 sctp_transport_timeout(transport)))
201 sctp_transport_hold(transport);
202}
203
204/* This transport has been assigned to an association.
205 * Initialize fields from the association or from the sock itself.
206 * Register the reference count in the association.
207 */
208void sctp_transport_set_owner(struct sctp_transport *transport,
209 struct sctp_association *asoc)
210{
211 transport->asoc = asoc;
212 sctp_association_hold(asoc);
213}
214
215/* Initialize the pmtu of a transport. */
9914ae3c 216void sctp_transport_pmtu(struct sctp_transport *transport, struct sock *sk)
1da177e4 217{
da0420be
VY
218 /* If we don't have a fresh route, look one up */
219 if (!transport->dst || transport->dst->obsolete > 1) {
220 dst_release(transport->dst);
221 transport->af_specific->get_dst(transport, &transport->saddr,
8663c938 222 &transport->fl, sk);
da0420be 223 }
1da177e4 224
da0420be
VY
225 if (transport->dst) {
226 transport->pathmtu = dst_mtu(transport->dst);
1da177e4 227 } else
52ccb8e9 228 transport->pathmtu = SCTP_DEFAULT_MAXSEGMENT;
1da177e4
LT
229}
230
02f3d4ce 231void sctp_transport_update_pmtu(struct sock *sk, struct sctp_transport *t, u32 pmtu)
c910b47e
VY
232{
233 struct dst_entry *dst;
234
235 if (unlikely(pmtu < SCTP_DEFAULT_MINSEGMENT)) {
145ce502
JP
236 pr_warn("%s: Reported pmtu %d too low, using default minimum of %d\n",
237 __func__, pmtu,
238 SCTP_DEFAULT_MINSEGMENT);
c910b47e
VY
239 /* Use default minimum segment size and disable
240 * pmtu discovery on this transport.
241 */
242 t->pathmtu = SCTP_DEFAULT_MINSEGMENT;
c910b47e
VY
243 } else {
244 t->pathmtu = pmtu;
245 }
246
247 dst = sctp_transport_dst_check(t);
02f3d4ce
DM
248 if (!dst)
249 t->af_specific->get_dst(t, &t->saddr, &t->fl, sk);
250
251 if (dst) {
c910b47e 252 dst->ops->update_pmtu(dst, pmtu);
02f3d4ce
DM
253
254 dst = sctp_transport_dst_check(t);
255 if (!dst)
256 t->af_specific->get_dst(t, &t->saddr, &t->fl, sk);
257 }
c910b47e
VY
258}
259
1da177e4
LT
260/* Caches the dst entry and source address for a transport's destination
261 * address.
262 */
263void sctp_transport_route(struct sctp_transport *transport,
264 union sctp_addr *saddr, struct sctp_sock *opt)
265{
266 struct sctp_association *asoc = transport->asoc;
267 struct sctp_af *af = transport->af_specific;
1da177e4 268
8663c938 269 af->get_dst(transport, saddr, &transport->fl, sctp_opt2sk(opt));
1da177e4
LT
270
271 if (saddr)
272 memcpy(&transport->saddr, saddr, sizeof(union sctp_addr));
273 else
8663c938 274 af->get_saddr(opt, transport, &transport->fl);
1da177e4 275
52ccb8e9
FF
276 if ((transport->param_flags & SPP_PMTUD_DISABLE) && transport->pathmtu) {
277 return;
278 }
da0420be
VY
279 if (transport->dst) {
280 transport->pathmtu = dst_mtu(transport->dst);
1da177e4
LT
281
282 /* Initialize sk->sk_rcv_saddr, if the transport is the
283 * association's active path for getsockname().
d808ad9a 284 */
a78102e7
VY
285 if (asoc && (!asoc->peer.primary_path ||
286 (transport == asoc->peer.active_path)))
bf031fff
NH
287 opt->pf->af->to_sk_saddr(&transport->saddr,
288 asoc->base.sk);
1da177e4 289 } else
52ccb8e9 290 transport->pathmtu = SCTP_DEFAULT_MAXSEGMENT;
1da177e4
LT
291}
292
293/* Hold a reference to a transport. */
294void sctp_transport_hold(struct sctp_transport *transport)
295{
296 atomic_inc(&transport->refcnt);
297}
298
299/* Release a reference to a transport and clean up
300 * if there are no more references.
301 */
302void sctp_transport_put(struct sctp_transport *transport)
303{
304 if (atomic_dec_and_test(&transport->refcnt))
305 sctp_transport_destroy(transport);
306}
307
308/* Update transport's RTO based on the newly calculated RTT. */
309void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
310{
311 /* Check for valid transport. */
312 SCTP_ASSERT(tp, "NULL transport", return);
313
314 /* We should not be doing any RTO updates unless rto_pending is set. */
315 SCTP_ASSERT(tp->rto_pending, "rto_pending not set", return);
316
317 if (tp->rttvar || tp->srtt) {
318 /* 6.3.1 C3) When a new RTT measurement R' is made, set
319 * RTTVAR <- (1 - RTO.Beta) * RTTVAR + RTO.Beta * |SRTT - R'|
320 * SRTT <- (1 - RTO.Alpha) * SRTT + RTO.Alpha * R'
321 */
322
323 /* Note: The above algorithm has been rewritten to
324 * express rto_beta and rto_alpha as inverse powers
325 * of two.
326 * For example, assuming the default value of RTO.Alpha of
327 * 1/8, rto_alpha would be expressed as 3.
328 */
329 tp->rttvar = tp->rttvar - (tp->rttvar >> sctp_rto_beta)
330 + ((abs(tp->srtt - rtt)) >> sctp_rto_beta);
331 tp->srtt = tp->srtt - (tp->srtt >> sctp_rto_alpha)
332 + (rtt >> sctp_rto_alpha);
333 } else {
334 /* 6.3.1 C2) When the first RTT measurement R is made, set
335 * SRTT <- R, RTTVAR <- R/2.
336 */
337 tp->srtt = rtt;
338 tp->rttvar = rtt >> 1;
339 }
340
341 /* 6.3.1 G1) Whenever RTTVAR is computed, if RTTVAR = 0, then
342 * adjust RTTVAR <- G, where G is the CLOCK GRANULARITY.
343 */
344 if (tp->rttvar == 0)
345 tp->rttvar = SCTP_CLOCK_GRANULARITY;
346
347 /* 6.3.1 C3) After the computation, update RTO <- SRTT + 4 * RTTVAR. */
348 tp->rto = tp->srtt + (tp->rttvar << 2);
349
350 /* 6.3.1 C6) Whenever RTO is computed, if it is less than RTO.Min
351 * seconds then it is rounded up to RTO.Min seconds.
352 */
353 if (tp->rto < tp->asoc->rto_min)
354 tp->rto = tp->asoc->rto_min;
355
356 /* 6.3.1 C7) A maximum value may be placed on RTO provided it is
357 * at least RTO.max seconds.
358 */
359 if (tp->rto > tp->asoc->rto_max)
360 tp->rto = tp->asoc->rto_max;
361
362 tp->rtt = rtt;
363
364 /* Reset rto_pending so that a new RTT measurement is started when a
365 * new data chunk is sent.
366 */
367 tp->rto_pending = 0;
368
369 SCTP_DEBUG_PRINTK("%s: transport: %p, rtt: %d, srtt: %d "
0dc47877 370 "rttvar: %d, rto: %ld\n", __func__,
1da177e4
LT
371 tp, rtt, tp->srtt, tp->rttvar, tp->rto);
372}
373
374/* This routine updates the transport's cwnd and partial_bytes_acked
375 * parameters based on the bytes acked in the received SACK.
376 */
377void sctp_transport_raise_cwnd(struct sctp_transport *transport,
378 __u32 sack_ctsn, __u32 bytes_acked)
379{
cf9b4812 380 struct sctp_association *asoc = transport->asoc;
1da177e4
LT
381 __u32 cwnd, ssthresh, flight_size, pba, pmtu;
382
383 cwnd = transport->cwnd;
384 flight_size = transport->flight_size;
385
a6465234 386 /* See if we need to exit Fast Recovery first */
cf9b4812
VY
387 if (asoc->fast_recovery &&
388 TSN_lte(asoc->fast_recovery_exit, sack_ctsn))
389 asoc->fast_recovery = 0;
a6465234 390
1da177e4 391 /* The appropriate cwnd increase algorithm is performed if, and only
a6465234 392 * if the cumulative TSN whould advanced and the congestion window is
1da177e4
LT
393 * being fully utilized.
394 */
a6465234 395 if (TSN_lte(sack_ctsn, transport->asoc->ctsn_ack_point) ||
1da177e4
LT
396 (flight_size < cwnd))
397 return;
398
399 ssthresh = transport->ssthresh;
400 pba = transport->partial_bytes_acked;
52ccb8e9 401 pmtu = transport->asoc->pathmtu;
1da177e4
LT
402
403 if (cwnd <= ssthresh) {
a6465234
VY
404 /* RFC 4960 7.2.1
405 * o When cwnd is less than or equal to ssthresh, an SCTP
406 * endpoint MUST use the slow-start algorithm to increase
407 * cwnd only if the current congestion window is being fully
408 * utilized, an incoming SACK advances the Cumulative TSN
409 * Ack Point, and the data sender is not in Fast Recovery.
410 * Only when these three conditions are met can the cwnd be
411 * increased; otherwise, the cwnd MUST not be increased.
412 * If these conditions are met, then cwnd MUST be increased
413 * by, at most, the lesser of 1) the total size of the
414 * previously outstanding DATA chunk(s) acknowledged, and
415 * 2) the destination's path MTU. This upper bound protects
416 * against the ACK-Splitting attack outlined in [SAVAGE99].
1da177e4 417 */
cf9b4812 418 if (asoc->fast_recovery)
a6465234
VY
419 return;
420
1da177e4
LT
421 if (bytes_acked > pmtu)
422 cwnd += pmtu;
423 else
424 cwnd += bytes_acked;
425 SCTP_DEBUG_PRINTK("%s: SLOW START: transport: %p, "
426 "bytes_acked: %d, cwnd: %d, ssthresh: %d, "
427 "flight_size: %d, pba: %d\n",
0dc47877 428 __func__,
1da177e4
LT
429 transport, bytes_acked, cwnd,
430 ssthresh, flight_size, pba);
431 } else {
432 /* RFC 2960 7.2.2 Whenever cwnd is greater than ssthresh,
433 * upon each SACK arrival that advances the Cumulative TSN Ack
434 * Point, increase partial_bytes_acked by the total number of
435 * bytes of all new chunks acknowledged in that SACK including
436 * chunks acknowledged by the new Cumulative TSN Ack and by
437 * Gap Ack Blocks.
438 *
439 * When partial_bytes_acked is equal to or greater than cwnd
440 * and before the arrival of the SACK the sender had cwnd or
441 * more bytes of data outstanding (i.e., before arrival of the
442 * SACK, flightsize was greater than or equal to cwnd),
443 * increase cwnd by MTU, and reset partial_bytes_acked to
444 * (partial_bytes_acked - cwnd).
445 */
446 pba += bytes_acked;
447 if (pba >= cwnd) {
448 cwnd += pmtu;
449 pba = ((cwnd < pba) ? (pba - cwnd) : 0);
450 }
451 SCTP_DEBUG_PRINTK("%s: CONGESTION AVOIDANCE: "
452 "transport: %p, bytes_acked: %d, cwnd: %d, "
453 "ssthresh: %d, flight_size: %d, pba: %d\n",
0dc47877 454 __func__,
1da177e4
LT
455 transport, bytes_acked, cwnd,
456 ssthresh, flight_size, pba);
457 }
458
459 transport->cwnd = cwnd;
460 transport->partial_bytes_acked = pba;
461}
462
463/* This routine is used to lower the transport's cwnd when congestion is
464 * detected.
465 */
466void sctp_transport_lower_cwnd(struct sctp_transport *transport,
467 sctp_lower_cwnd_t reason)
468{
cf9b4812
VY
469 struct sctp_association *asoc = transport->asoc;
470
1da177e4
LT
471 switch (reason) {
472 case SCTP_LOWER_CWND_T3_RTX:
473 /* RFC 2960 Section 7.2.3, sctpimpguide
474 * When the T3-rtx timer expires on an address, SCTP should
475 * perform slow start by:
476 * ssthresh = max(cwnd/2, 4*MTU)
477 * cwnd = 1*MTU
478 * partial_bytes_acked = 0
479 */
480 transport->ssthresh = max(transport->cwnd/2,
cf9b4812
VY
481 4*asoc->pathmtu);
482 transport->cwnd = asoc->pathmtu;
33ce8281 483
cf9b4812
VY
484 /* T3-rtx also clears fast recovery */
485 asoc->fast_recovery = 0;
1da177e4
LT
486 break;
487
488 case SCTP_LOWER_CWND_FAST_RTX:
489 /* RFC 2960 7.2.4 Adjust the ssthresh and cwnd of the
490 * destination address(es) to which the missing DATA chunks
491 * were last sent, according to the formula described in
492 * Section 7.2.3.
d808ad9a
YH
493 *
494 * RFC 2960 7.2.3, sctpimpguide Upon detection of packet
1da177e4
LT
495 * losses from SACK (see Section 7.2.4), An endpoint
496 * should do the following:
497 * ssthresh = max(cwnd/2, 4*MTU)
498 * cwnd = ssthresh
499 * partial_bytes_acked = 0
500 */
cf9b4812 501 if (asoc->fast_recovery)
a6465234
VY
502 return;
503
504 /* Mark Fast recovery */
cf9b4812
VY
505 asoc->fast_recovery = 1;
506 asoc->fast_recovery_exit = asoc->next_tsn - 1;
a6465234 507
1da177e4 508 transport->ssthresh = max(transport->cwnd/2,
cf9b4812 509 4*asoc->pathmtu);
1da177e4
LT
510 transport->cwnd = transport->ssthresh;
511 break;
512
513 case SCTP_LOWER_CWND_ECNE:
514 /* RFC 2481 Section 6.1.2.
515 * If the sender receives an ECN-Echo ACK packet
516 * then the sender knows that congestion was encountered in the
517 * network on the path from the sender to the receiver. The
518 * indication of congestion should be treated just as a
519 * congestion loss in non-ECN Capable TCP. That is, the TCP
520 * source halves the congestion window "cwnd" and reduces the
521 * slow start threshold "ssthresh".
522 * A critical condition is that TCP does not react to
523 * congestion indications more than once every window of
524 * data (or more loosely more than once every round-trip time).
525 */
f61f6f82
WY
526 if (time_after(jiffies, transport->last_time_ecne_reduced +
527 transport->rtt)) {
1da177e4 528 transport->ssthresh = max(transport->cwnd/2,
cf9b4812 529 4*asoc->pathmtu);
1da177e4
LT
530 transport->cwnd = transport->ssthresh;
531 transport->last_time_ecne_reduced = jiffies;
532 }
533 break;
534
535 case SCTP_LOWER_CWND_INACTIVE:
536 /* RFC 2960 Section 7.2.1, sctpimpguide
537 * When the endpoint does not transmit data on a given
538 * transport address, the cwnd of the transport address
539 * should be adjusted to max(cwnd/2, 4*MTU) per RTO.
540 * NOTE: Although the draft recommends that this check needs
541 * to be done every RTO interval, we do it every hearbeat
542 * interval.
543 */
245cba7e 544 transport->cwnd = max(transport->cwnd/2,
cf9b4812 545 4*asoc->pathmtu);
1da177e4 546 break;
3ff50b79 547 }
1da177e4
LT
548
549 transport->partial_bytes_acked = 0;
550 SCTP_DEBUG_PRINTK("%s: transport: %p reason: %d cwnd: "
0dc47877 551 "%d ssthresh: %d\n", __func__,
1da177e4
LT
552 transport, reason,
553 transport->cwnd, transport->ssthresh);
554}
555
46d5a808
VY
556/* Apply Max.Burst limit to the congestion window:
557 * sctpimpguide-05 2.14.2
558 * D) When the time comes for the sender to
559 * transmit new DATA chunks, the protocol parameter Max.Burst MUST
560 * first be applied to limit how many new DATA chunks may be sent.
561 * The limit is applied by adjusting cwnd as follows:
562 * if ((flightsize+ Max.Burst * MTU) < cwnd)
563 * cwnd = flightsize + Max.Burst * MTU
564 */
565
566void sctp_transport_burst_limited(struct sctp_transport *t)
567{
568 struct sctp_association *asoc = t->asoc;
569 u32 old_cwnd = t->cwnd;
570 u32 max_burst_bytes;
571
572 if (t->burst_limited)
573 return;
574
575 max_burst_bytes = t->flight_size + (asoc->max_burst * asoc->pathmtu);
576 if (max_burst_bytes < old_cwnd) {
577 t->cwnd = max_burst_bytes;
578 t->burst_limited = old_cwnd;
579 }
580}
581
582/* Restore the old cwnd congestion window, after the burst had it's
583 * desired effect.
584 */
585void sctp_transport_burst_reset(struct sctp_transport *t)
586{
587 if (t->burst_limited) {
588 t->cwnd = t->burst_limited;
589 t->burst_limited = 0;
590 }
591}
592
1da177e4
LT
593/* What is the next timeout value for this transport? */
594unsigned long sctp_transport_timeout(struct sctp_transport *t)
595{
596 unsigned long timeout;
ad8fec17
SS
597 timeout = t->rto + sctp_jitter(t->rto);
598 if (t->state != SCTP_UNCONFIRMED)
599 timeout += t->hbinterval;
1da177e4
LT
600 timeout += jiffies;
601 return timeout;
602}
749bf921
VY
603
604/* Reset transport variables to their initial values */
605void sctp_transport_reset(struct sctp_transport *t)
606{
607 struct sctp_association *asoc = t->asoc;
608
609 /* RFC 2960 (bis), Section 5.2.4
610 * All the congestion control parameters (e.g., cwnd, ssthresh)
611 * related to this peer MUST be reset to their initial values
612 * (see Section 6.2.1)
613 */
614 t->cwnd = min(4*asoc->pathmtu, max_t(__u32, 2*asoc->pathmtu, 4380));
46d5a808 615 t->burst_limited = 0;
289f4249 616 t->ssthresh = asoc->peer.i.a_rwnd;
5fdd4bae 617 t->rto = asoc->rto_initial;
749bf921
VY
618 t->rtt = 0;
619 t->srtt = 0;
620 t->rttvar = 0;
621
622 /* Reset these additional varibles so that we have a clean
623 * slate.
624 */
625 t->partial_bytes_acked = 0;
626 t->flight_size = 0;
627 t->error_count = 0;
628 t->rto_pending = 0;
faee47cd 629 t->hb_sent = 0;
749bf921
VY
630
631 /* Initialize the state information for SFR-CACC */
632 t->cacc.changeover_active = 0;
633 t->cacc.cycling_changeover = 0;
634 t->cacc.next_tsn_at_change = 0;
635 t->cacc.cacc_saw_newack = 0;
636}
ddc4bbee
MH
637
638/* Schedule retransmission on the given transport */
639void sctp_transport_immediate_rtx(struct sctp_transport *t)
640{
641 /* Stop pending T3_rtx_timer */
642 if (timer_pending(&t->T3_rtx_timer)) {
643 (void)del_timer(&t->T3_rtx_timer);
644 sctp_transport_put(t);
645 }
646 sctp_retransmit(&t->asoc->outqueue, t, SCTP_RTXR_T3_RTX);
647 if (!timer_pending(&t->T3_rtx_timer)) {
648 if (!mod_timer(&t->T3_rtx_timer, jiffies + t->rto))
649 sctp_transport_hold(t);
650 }
651 return;
652}