transport.c 20 KB

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