transport.c 21 KB

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