transport.c 20 KB

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