transport.c 20 KB

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