transport.c 20 KB

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