transport.c 20 KB

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