transport.c 20 KB

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