1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* SCTP kernel implementation
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2003 International Business Machines Corp.
6 * Copyright (c) 2001 Intel Corp.
7 * Copyright (c) 2001 La Monte H.P. Yarroll
9 * This file is part of the SCTP kernel implementation
11 * This module provides the abstraction for an SCTP transport representing
12 * a remote transport address. For local transport addresses, we just use
15 * Please send any bug reports or fixes you make to the
17 * lksctp developers <linux-sctp@vger.kernel.org>
19 * Written or modified by:
20 * La Monte H.P. Yarroll <piggy@acm.org>
21 * Karl Knutson <karl@athena.chicago.il.us>
22 * Jon Grimm <jgrimm@us.ibm.com>
23 * Xingang Guo <xingang.guo@intel.com>
24 * Hui Huang <hui.huang@nokia.com>
25 * Sridhar Samudrala <sri@us.ibm.com>
26 * Ardelle Fan <ardelle.fan@intel.com>
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/slab.h>
32 #include <linux/types.h>
33 #include <linux/random.h>
34 #include <net/sctp/sctp.h>
35 #include <net/sctp/sm.h>
37 /* 1st Level Abstractions. */
39 /* Initialize a new transport from provided memory. */
40 static struct sctp_transport *sctp_transport_init(struct net *net,
41 struct sctp_transport *peer,
42 const union sctp_addr *addr,
45 /* Copy in the address. */
46 peer->af_specific = sctp_get_af_specific(addr->sa.sa_family);
47 memcpy(&peer->ipaddr, addr, peer->af_specific->sockaddr_len);
48 memset(&peer->saddr, 0, sizeof(union sctp_addr));
50 peer->sack_generation = 0;
52 /* From 6.3.1 RTO Calculation:
54 * C1) Until an RTT measurement has been made for a packet sent to the
55 * given destination transport address, set RTO to the protocol
56 * parameter 'RTO.Initial'.
58 peer->rto = msecs_to_jiffies(net->sctp.rto_initial);
60 peer->last_time_heard = 0;
61 peer->last_time_ecne_reduced = jiffies;
63 peer->param_flags = SPP_HB_DISABLE |
67 /* Initialize the default path max_retrans. */
68 peer->pathmaxrxt = net->sctp.max_retrans_path;
69 peer->pf_retrans = net->sctp.pf_retrans;
71 INIT_LIST_HEAD(&peer->transmitted);
72 INIT_LIST_HEAD(&peer->send_ready);
73 INIT_LIST_HEAD(&peer->transports);
75 timer_setup(&peer->T3_rtx_timer, sctp_generate_t3_rtx_event, 0);
76 timer_setup(&peer->hb_timer, sctp_generate_heartbeat_event, 0);
77 timer_setup(&peer->reconf_timer, sctp_generate_reconf_event, 0);
78 timer_setup(&peer->probe_timer, sctp_generate_probe_event, 0);
79 timer_setup(&peer->proto_unreach_timer,
80 sctp_generate_proto_unreach_event, 0);
82 /* Initialize the 64-bit random nonce sent with heartbeat. */
83 get_random_bytes(&peer->hb_nonce, sizeof(peer->hb_nonce));
85 refcount_set(&peer->refcnt, 1);
90 /* Allocate and initialize a new transport. */
91 struct sctp_transport *sctp_transport_new(struct net *net,
92 const union sctp_addr *addr,
95 struct sctp_transport *transport;
97 transport = kzalloc(sizeof(*transport), gfp);
101 if (!sctp_transport_init(net, transport, addr, gfp))
104 SCTP_DBG_OBJCNT_INC(transport);
115 /* This transport is no longer needed. Free up if possible, or
116 * delay until it last reference count.
118 void sctp_transport_free(struct sctp_transport *transport)
120 /* Try to delete the heartbeat timer. */
121 if (del_timer(&transport->hb_timer))
122 sctp_transport_put(transport);
124 /* Delete the T3_rtx timer if it's active.
125 * There is no point in not doing this now and letting
126 * structure hang around in memory since we know
127 * the transport is going away.
129 if (del_timer(&transport->T3_rtx_timer))
130 sctp_transport_put(transport);
132 if (del_timer(&transport->reconf_timer))
133 sctp_transport_put(transport);
135 if (del_timer(&transport->probe_timer))
136 sctp_transport_put(transport);
138 /* Delete the ICMP proto unreachable timer if it's active. */
139 if (del_timer(&transport->proto_unreach_timer))
140 sctp_transport_put(transport);
142 sctp_transport_put(transport);
145 static void sctp_transport_destroy_rcu(struct rcu_head *head)
147 struct sctp_transport *transport;
149 transport = container_of(head, struct sctp_transport, rcu);
151 dst_release(transport->dst);
153 SCTP_DBG_OBJCNT_DEC(transport);
156 /* Destroy the transport data structure.
157 * Assumes there are no more users of this structure.
159 static void sctp_transport_destroy(struct sctp_transport *transport)
161 if (unlikely(refcount_read(&transport->refcnt))) {
162 WARN(1, "Attempt to destroy undead transport %p!\n", transport);
166 sctp_packet_free(&transport->packet);
169 sctp_association_put(transport->asoc);
171 call_rcu(&transport->rcu, sctp_transport_destroy_rcu);
174 /* Start T3_rtx timer if it is not already running and update the heartbeat
175 * timer. This routine is called every time a DATA chunk is sent.
177 void sctp_transport_reset_t3_rtx(struct sctp_transport *transport)
179 /* RFC 2960 6.3.2 Retransmission Timer Rules
181 * R1) Every time a DATA chunk is sent to any address(including a
182 * retransmission), if the T3-rtx timer of that address is not running
183 * start it running so that it will expire after the RTO of that
187 if (!timer_pending(&transport->T3_rtx_timer))
188 if (!mod_timer(&transport->T3_rtx_timer,
189 jiffies + transport->rto))
190 sctp_transport_hold(transport);
193 void sctp_transport_reset_hb_timer(struct sctp_transport *transport)
195 unsigned long expires;
197 /* When a data chunk is sent, reset the heartbeat interval. */
198 expires = jiffies + sctp_transport_timeout(transport);
199 if ((time_before(transport->hb_timer.expires, expires) ||
200 !timer_pending(&transport->hb_timer)) &&
201 !mod_timer(&transport->hb_timer,
202 expires + prandom_u32_max(transport->rto)))
203 sctp_transport_hold(transport);
206 void sctp_transport_reset_reconf_timer(struct sctp_transport *transport)
208 if (!timer_pending(&transport->reconf_timer))
209 if (!mod_timer(&transport->reconf_timer,
210 jiffies + transport->rto))
211 sctp_transport_hold(transport);
214 void sctp_transport_reset_probe_timer(struct sctp_transport *transport)
218 if (timer_pending(&transport->probe_timer))
220 if (transport->pl.state == SCTP_PL_COMPLETE &&
221 transport->pl.probe_count == 1)
222 scale = 30; /* works as PMTU_RAISE_TIMER */
223 if (!mod_timer(&transport->probe_timer,
224 jiffies + transport->probe_interval * scale))
225 sctp_transport_hold(transport);
228 /* This transport has been assigned to an association.
229 * Initialize fields from the association or from the sock itself.
230 * Register the reference count in the association.
232 void sctp_transport_set_owner(struct sctp_transport *transport,
233 struct sctp_association *asoc)
235 transport->asoc = asoc;
236 sctp_association_hold(asoc);
239 /* Initialize the pmtu of a transport. */
240 void sctp_transport_pmtu(struct sctp_transport *transport, struct sock *sk)
242 /* If we don't have a fresh route, look one up */
243 if (!transport->dst || transport->dst->obsolete) {
244 sctp_transport_dst_release(transport);
245 transport->af_specific->get_dst(transport, &transport->saddr,
249 if (transport->param_flags & SPP_PMTUD_DISABLE) {
250 struct sctp_association *asoc = transport->asoc;
252 if (!transport->pathmtu && asoc && asoc->pathmtu)
253 transport->pathmtu = asoc->pathmtu;
254 if (transport->pathmtu)
259 transport->pathmtu = sctp_dst_mtu(transport->dst);
261 transport->pathmtu = SCTP_DEFAULT_MAXSEGMENT;
264 void sctp_transport_pl_send(struct sctp_transport *t)
266 pr_debug("%s: PLPMTUD: transport: %p, state: %d, pmtu: %d, size: %d, high: %d\n",
267 __func__, t, t->pl.state, t->pl.pmtu, t->pl.probe_size, t->pl.probe_high);
269 if (t->pl.probe_count < SCTP_MAX_PROBES) {
274 if (t->pl.state == SCTP_PL_BASE) {
275 if (t->pl.probe_size == SCTP_BASE_PLPMTU) { /* BASE_PLPMTU Confirmation Failed */
276 t->pl.state = SCTP_PL_ERROR; /* Base -> Error */
278 t->pl.pmtu = SCTP_MIN_PLPMTU;
279 t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t);
280 sctp_assoc_sync_pmtu(t->asoc);
282 } else if (t->pl.state == SCTP_PL_SEARCH) {
283 if (t->pl.pmtu == t->pl.probe_size) { /* Black Hole Detected */
284 t->pl.state = SCTP_PL_BASE; /* Search -> Base */
285 t->pl.probe_size = SCTP_BASE_PLPMTU;
286 t->pl.probe_high = 0;
288 t->pl.pmtu = SCTP_BASE_PLPMTU;
289 t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t);
290 sctp_assoc_sync_pmtu(t->asoc);
291 } else { /* Normal probe failure. */
292 t->pl.probe_high = t->pl.probe_size;
293 t->pl.probe_size = t->pl.pmtu;
295 } else if (t->pl.state == SCTP_PL_COMPLETE) {
296 if (t->pl.pmtu == t->pl.probe_size) { /* Black Hole Detected */
297 t->pl.state = SCTP_PL_BASE; /* Search Complete -> Base */
298 t->pl.probe_size = SCTP_BASE_PLPMTU;
300 t->pl.pmtu = SCTP_BASE_PLPMTU;
301 t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t);
302 sctp_assoc_sync_pmtu(t->asoc);
305 t->pl.probe_count = 1;
308 void sctp_transport_pl_recv(struct sctp_transport *t)
310 pr_debug("%s: PLPMTUD: transport: %p, state: %d, pmtu: %d, size: %d, high: %d\n",
311 __func__, t, t->pl.state, t->pl.pmtu, t->pl.probe_size, t->pl.probe_high);
313 t->pl.pmtu = t->pl.probe_size;
314 t->pl.probe_count = 0;
315 if (t->pl.state == SCTP_PL_BASE) {
316 t->pl.state = SCTP_PL_SEARCH; /* Base -> Search */
317 t->pl.probe_size += SCTP_PL_BIG_STEP;
318 } else if (t->pl.state == SCTP_PL_ERROR) {
319 t->pl.state = SCTP_PL_SEARCH; /* Error -> Search */
321 t->pl.pmtu = t->pl.probe_size;
322 t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t);
323 sctp_assoc_sync_pmtu(t->asoc);
324 t->pl.probe_size += SCTP_PL_BIG_STEP;
325 } else if (t->pl.state == SCTP_PL_SEARCH) {
326 if (!t->pl.probe_high) {
327 t->pl.probe_size = min(t->pl.probe_size + SCTP_PL_BIG_STEP,
331 t->pl.probe_size += SCTP_PL_MIN_STEP;
332 if (t->pl.probe_size >= t->pl.probe_high) {
333 t->pl.probe_high = 0;
334 t->pl.state = SCTP_PL_COMPLETE; /* Search -> Search Complete */
336 t->pl.probe_size = t->pl.pmtu;
337 t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t);
338 sctp_assoc_sync_pmtu(t->asoc);
340 } else if (t->pl.state == SCTP_PL_COMPLETE) {
341 t->pl.state = SCTP_PL_SEARCH; /* Search Complete -> Search */
342 t->pl.probe_size += SCTP_PL_MIN_STEP;
346 bool sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu)
348 struct dst_entry *dst = sctp_transport_dst_check(t);
349 struct sock *sk = t->asoc->base.sk;
352 if (unlikely(pmtu < SCTP_DEFAULT_MINSEGMENT)) {
353 pr_warn_ratelimited("%s: Reported pmtu %d too low, using default minimum of %d\n",
354 __func__, pmtu, SCTP_DEFAULT_MINSEGMENT);
355 /* Use default minimum segment instead */
356 pmtu = SCTP_DEFAULT_MINSEGMENT;
358 pmtu = SCTP_TRUNC4(pmtu);
361 struct sctp_pf *pf = sctp_get_pf_specific(dst->ops->family);
362 union sctp_addr addr;
364 pf->af->from_sk(&addr, sk);
365 pf->to_sk_daddr(&t->ipaddr, sk);
366 dst->ops->update_pmtu(dst, sk, NULL, pmtu, true);
367 pf->to_sk_daddr(&addr, sk);
369 dst = sctp_transport_dst_check(t);
373 t->af_specific->get_dst(t, &t->saddr, &t->fl, sk);
378 /* Re-fetch, as under layers may have a higher minimum size */
379 pmtu = sctp_dst_mtu(dst);
380 change = t->pathmtu != pmtu;
387 /* Caches the dst entry and source address for a transport's destination
390 void sctp_transport_route(struct sctp_transport *transport,
391 union sctp_addr *saddr, struct sctp_sock *opt)
393 struct sctp_association *asoc = transport->asoc;
394 struct sctp_af *af = transport->af_specific;
396 sctp_transport_dst_release(transport);
397 af->get_dst(transport, saddr, &transport->fl, sctp_opt2sk(opt));
400 memcpy(&transport->saddr, saddr, sizeof(union sctp_addr));
402 af->get_saddr(opt, transport, &transport->fl);
404 sctp_transport_pmtu(transport, sctp_opt2sk(opt));
406 /* Initialize sk->sk_rcv_saddr, if the transport is the
407 * association's active path for getsockname().
409 if (transport->dst && asoc &&
410 (!asoc->peer.primary_path || transport == asoc->peer.active_path))
411 opt->pf->to_sk_saddr(&transport->saddr, asoc->base.sk);
414 /* Hold a reference to a transport. */
415 int sctp_transport_hold(struct sctp_transport *transport)
417 return refcount_inc_not_zero(&transport->refcnt);
420 /* Release a reference to a transport and clean up
421 * if there are no more references.
423 void sctp_transport_put(struct sctp_transport *transport)
425 if (refcount_dec_and_test(&transport->refcnt))
426 sctp_transport_destroy(transport);
429 /* Update transport's RTO based on the newly calculated RTT. */
430 void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
432 if (unlikely(!tp->rto_pending))
433 /* We should not be doing any RTO updates unless rto_pending is set. */
434 pr_debug("%s: rto_pending not set on transport %p!\n", __func__, tp);
436 if (tp->rttvar || tp->srtt) {
437 struct net *net = tp->asoc->base.net;
438 /* 6.3.1 C3) When a new RTT measurement R' is made, set
439 * RTTVAR <- (1 - RTO.Beta) * RTTVAR + RTO.Beta * |SRTT - R'|
440 * SRTT <- (1 - RTO.Alpha) * SRTT + RTO.Alpha * R'
443 /* Note: The above algorithm has been rewritten to
444 * express rto_beta and rto_alpha as inverse powers
446 * For example, assuming the default value of RTO.Alpha of
447 * 1/8, rto_alpha would be expressed as 3.
449 tp->rttvar = tp->rttvar - (tp->rttvar >> net->sctp.rto_beta)
450 + (((__u32)abs((__s64)tp->srtt - (__s64)rtt)) >> net->sctp.rto_beta);
451 tp->srtt = tp->srtt - (tp->srtt >> net->sctp.rto_alpha)
452 + (rtt >> net->sctp.rto_alpha);
454 /* 6.3.1 C2) When the first RTT measurement R is made, set
455 * SRTT <- R, RTTVAR <- R/2.
458 tp->rttvar = rtt >> 1;
461 /* 6.3.1 G1) Whenever RTTVAR is computed, if RTTVAR = 0, then
462 * adjust RTTVAR <- G, where G is the CLOCK GRANULARITY.
465 tp->rttvar = SCTP_CLOCK_GRANULARITY;
467 /* 6.3.1 C3) After the computation, update RTO <- SRTT + 4 * RTTVAR. */
468 tp->rto = tp->srtt + (tp->rttvar << 2);
470 /* 6.3.1 C6) Whenever RTO is computed, if it is less than RTO.Min
471 * seconds then it is rounded up to RTO.Min seconds.
473 if (tp->rto < tp->asoc->rto_min)
474 tp->rto = tp->asoc->rto_min;
476 /* 6.3.1 C7) A maximum value may be placed on RTO provided it is
477 * at least RTO.max seconds.
479 if (tp->rto > tp->asoc->rto_max)
480 tp->rto = tp->asoc->rto_max;
482 sctp_max_rto(tp->asoc, tp);
485 /* Reset rto_pending so that a new RTT measurement is started when a
486 * new data chunk is sent.
490 pr_debug("%s: transport:%p, rtt:%d, srtt:%d rttvar:%d, rto:%ld\n",
491 __func__, tp, rtt, tp->srtt, tp->rttvar, tp->rto);
494 /* This routine updates the transport's cwnd and partial_bytes_acked
495 * parameters based on the bytes acked in the received SACK.
497 void sctp_transport_raise_cwnd(struct sctp_transport *transport,
498 __u32 sack_ctsn, __u32 bytes_acked)
500 struct sctp_association *asoc = transport->asoc;
501 __u32 cwnd, ssthresh, flight_size, pba, pmtu;
503 cwnd = transport->cwnd;
504 flight_size = transport->flight_size;
506 /* See if we need to exit Fast Recovery first */
507 if (asoc->fast_recovery &&
508 TSN_lte(asoc->fast_recovery_exit, sack_ctsn))
509 asoc->fast_recovery = 0;
511 ssthresh = transport->ssthresh;
512 pba = transport->partial_bytes_acked;
513 pmtu = transport->asoc->pathmtu;
515 if (cwnd <= ssthresh) {
517 * o When cwnd is less than or equal to ssthresh, an SCTP
518 * endpoint MUST use the slow-start algorithm to increase
519 * cwnd only if the current congestion window is being fully
520 * utilized, an incoming SACK advances the Cumulative TSN
521 * Ack Point, and the data sender is not in Fast Recovery.
522 * Only when these three conditions are met can the cwnd be
523 * increased; otherwise, the cwnd MUST not be increased.
524 * If these conditions are met, then cwnd MUST be increased
525 * by, at most, the lesser of 1) the total size of the
526 * previously outstanding DATA chunk(s) acknowledged, and
527 * 2) the destination's path MTU. This upper bound protects
528 * against the ACK-Splitting attack outlined in [SAVAGE99].
530 if (asoc->fast_recovery)
533 /* The appropriate cwnd increase algorithm is performed
534 * if, and only if the congestion window is being fully
535 * utilized. Note that RFC4960 Errata 3.22 removed the
536 * other condition on ctsn moving.
538 if (flight_size < cwnd)
541 if (bytes_acked > pmtu)
546 pr_debug("%s: slow start: transport:%p, bytes_acked:%d, "
547 "cwnd:%d, ssthresh:%d, flight_size:%d, pba:%d\n",
548 __func__, transport, bytes_acked, cwnd, ssthresh,
551 /* RFC 2960 7.2.2 Whenever cwnd is greater than ssthresh,
552 * upon each SACK arrival, increase partial_bytes_acked
553 * by the total number of bytes of all new chunks
554 * acknowledged in that SACK including chunks
555 * acknowledged by the new Cumulative TSN Ack and by Gap
556 * Ack Blocks. (updated by RFC4960 Errata 3.22)
558 * When partial_bytes_acked is greater than cwnd and
559 * before the arrival of the SACK the sender had less
560 * bytes of data outstanding than cwnd (i.e., before
561 * arrival of the SACK, flightsize was less than cwnd),
562 * reset partial_bytes_acked to cwnd. (RFC 4960 Errata
565 * When partial_bytes_acked is equal to or greater than
566 * cwnd and before the arrival of the SACK the sender
567 * had cwnd or more bytes of data outstanding (i.e.,
568 * before arrival of the SACK, flightsize was greater
569 * than or equal to cwnd), partial_bytes_acked is reset
570 * to (partial_bytes_acked - cwnd). Next, cwnd is
571 * increased by MTU. (RFC 4960 Errata 3.12)
574 if (pba > cwnd && flight_size < cwnd)
576 if (pba >= cwnd && flight_size >= cwnd) {
581 pr_debug("%s: congestion avoidance: transport:%p, "
582 "bytes_acked:%d, cwnd:%d, ssthresh:%d, "
583 "flight_size:%d, pba:%d\n", __func__,
584 transport, bytes_acked, cwnd, ssthresh,
588 transport->cwnd = cwnd;
589 transport->partial_bytes_acked = pba;
592 /* This routine is used to lower the transport's cwnd when congestion is
595 void sctp_transport_lower_cwnd(struct sctp_transport *transport,
596 enum sctp_lower_cwnd reason)
598 struct sctp_association *asoc = transport->asoc;
601 case SCTP_LOWER_CWND_T3_RTX:
602 /* RFC 2960 Section 7.2.3, sctpimpguide
603 * When the T3-rtx timer expires on an address, SCTP should
604 * perform slow start by:
605 * ssthresh = max(cwnd/2, 4*MTU)
607 * partial_bytes_acked = 0
609 transport->ssthresh = max(transport->cwnd/2,
611 transport->cwnd = asoc->pathmtu;
613 /* T3-rtx also clears fast recovery */
614 asoc->fast_recovery = 0;
617 case SCTP_LOWER_CWND_FAST_RTX:
618 /* RFC 2960 7.2.4 Adjust the ssthresh and cwnd of the
619 * destination address(es) to which the missing DATA chunks
620 * were last sent, according to the formula described in
623 * RFC 2960 7.2.3, sctpimpguide Upon detection of packet
624 * losses from SACK (see Section 7.2.4), An endpoint
625 * should do the following:
626 * ssthresh = max(cwnd/2, 4*MTU)
628 * partial_bytes_acked = 0
630 if (asoc->fast_recovery)
633 /* Mark Fast recovery */
634 asoc->fast_recovery = 1;
635 asoc->fast_recovery_exit = asoc->next_tsn - 1;
637 transport->ssthresh = max(transport->cwnd/2,
639 transport->cwnd = transport->ssthresh;
642 case SCTP_LOWER_CWND_ECNE:
643 /* RFC 2481 Section 6.1.2.
644 * If the sender receives an ECN-Echo ACK packet
645 * then the sender knows that congestion was encountered in the
646 * network on the path from the sender to the receiver. The
647 * indication of congestion should be treated just as a
648 * congestion loss in non-ECN Capable TCP. That is, the TCP
649 * source halves the congestion window "cwnd" and reduces the
650 * slow start threshold "ssthresh".
651 * A critical condition is that TCP does not react to
652 * congestion indications more than once every window of
653 * data (or more loosely more than once every round-trip time).
655 if (time_after(jiffies, transport->last_time_ecne_reduced +
657 transport->ssthresh = max(transport->cwnd/2,
659 transport->cwnd = transport->ssthresh;
660 transport->last_time_ecne_reduced = jiffies;
664 case SCTP_LOWER_CWND_INACTIVE:
665 /* RFC 2960 Section 7.2.1, sctpimpguide
666 * When the endpoint does not transmit data on a given
667 * transport address, the cwnd of the transport address
668 * should be adjusted to max(cwnd/2, 4*MTU) per RTO.
669 * NOTE: Although the draft recommends that this check needs
670 * to be done every RTO interval, we do it every hearbeat
673 transport->cwnd = max(transport->cwnd/2,
675 /* RFC 4960 Errata 3.27.2: also adjust sshthresh */
676 transport->ssthresh = transport->cwnd;
680 transport->partial_bytes_acked = 0;
682 pr_debug("%s: transport:%p, reason:%d, cwnd:%d, ssthresh:%d\n",
683 __func__, transport, reason, transport->cwnd,
684 transport->ssthresh);
687 /* Apply Max.Burst limit to the congestion window:
688 * sctpimpguide-05 2.14.2
689 * D) When the time comes for the sender to
690 * transmit new DATA chunks, the protocol parameter Max.Burst MUST
691 * first be applied to limit how many new DATA chunks may be sent.
692 * The limit is applied by adjusting cwnd as follows:
693 * if ((flightsize+ Max.Burst * MTU) < cwnd)
694 * cwnd = flightsize + Max.Burst * MTU
697 void sctp_transport_burst_limited(struct sctp_transport *t)
699 struct sctp_association *asoc = t->asoc;
700 u32 old_cwnd = t->cwnd;
703 if (t->burst_limited || asoc->max_burst == 0)
706 max_burst_bytes = t->flight_size + (asoc->max_burst * asoc->pathmtu);
707 if (max_burst_bytes < old_cwnd) {
708 t->cwnd = max_burst_bytes;
709 t->burst_limited = old_cwnd;
713 /* Restore the old cwnd congestion window, after the burst had it's
716 void sctp_transport_burst_reset(struct sctp_transport *t)
718 if (t->burst_limited) {
719 t->cwnd = t->burst_limited;
720 t->burst_limited = 0;
724 /* What is the next timeout value for this transport? */
725 unsigned long sctp_transport_timeout(struct sctp_transport *trans)
727 /* RTO + timer slack +/- 50% of RTO */
728 unsigned long timeout = trans->rto >> 1;
730 if (trans->state != SCTP_UNCONFIRMED &&
731 trans->state != SCTP_PF)
732 timeout += trans->hbinterval;
734 return max_t(unsigned long, timeout, HZ / 5);
737 /* Reset transport variables to their initial values */
738 void sctp_transport_reset(struct sctp_transport *t)
740 struct sctp_association *asoc = t->asoc;
742 /* RFC 2960 (bis), Section 5.2.4
743 * All the congestion control parameters (e.g., cwnd, ssthresh)
744 * related to this peer MUST be reset to their initial values
745 * (see Section 6.2.1)
747 t->cwnd = min(4*asoc->pathmtu, max_t(__u32, 2*asoc->pathmtu, 4380));
748 t->burst_limited = 0;
749 t->ssthresh = asoc->peer.i.a_rwnd;
750 t->rto = asoc->rto_initial;
751 sctp_max_rto(asoc, t);
756 /* Reset these additional variables so that we have a clean slate. */
757 t->partial_bytes_acked = 0;
763 /* Initialize the state information for SFR-CACC */
764 t->cacc.changeover_active = 0;
765 t->cacc.cycling_changeover = 0;
766 t->cacc.next_tsn_at_change = 0;
767 t->cacc.cacc_saw_newack = 0;
770 /* Schedule retransmission on the given transport */
771 void sctp_transport_immediate_rtx(struct sctp_transport *t)
773 /* Stop pending T3_rtx_timer */
774 if (del_timer(&t->T3_rtx_timer))
775 sctp_transport_put(t);
777 sctp_retransmit(&t->asoc->outqueue, t, SCTP_RTXR_T3_RTX);
778 if (!timer_pending(&t->T3_rtx_timer)) {
779 if (!mod_timer(&t->T3_rtx_timer, jiffies + t->rto))
780 sctp_transport_hold(t);
785 void sctp_transport_dst_release(struct sctp_transport *t)
789 t->dst_pending_confirm = 0;
792 /* Schedule neighbour confirm */
793 void sctp_transport_dst_confirm(struct sctp_transport *t)
795 t->dst_pending_confirm = 1;