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