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