transport.c 21 KB

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