transport.c 19 KB

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