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