output.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /* SCTP kernel reference Implementation
  2. * (C) Copyright IBM Corp. 2001, 2004
  3. * Copyright (c) 1999-2000 Cisco, Inc.
  4. * Copyright (c) 1999-2001 Motorola, Inc.
  5. *
  6. * This file is part of the SCTP kernel reference Implementation
  7. *
  8. * These functions handle output processing.
  9. *
  10. * The SCTP reference implementation is free software;
  11. * you can redistribute it and/or modify it under the terms of
  12. * the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * The SCTP reference implementation is distributed in the hope that it
  17. * will be useful, but WITHOUT ANY WARRANTY; without even the implied
  18. * ************************
  19. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. * See the GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with GNU CC; see the file COPYING. If not, write to
  24. * the Free Software Foundation, 59 Temple Place - Suite 330,
  25. * Boston, MA 02111-1307, USA.
  26. *
  27. * Please send any bug reports or fixes you make to the
  28. * email address(es):
  29. * lksctp developers <lksctp-developers@lists.sourceforge.net>
  30. *
  31. * Or submit a bug report through the following website:
  32. * http://www.sf.net/projects/lksctp
  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@austin.ibm.com>
  38. * Sridhar Samudrala <sri@us.ibm.com>
  39. *
  40. * Any bugs reported given to us we will try to fix... any fixes shared will
  41. * be incorporated into the next SCTP release.
  42. */
  43. #include <linux/types.h>
  44. #include <linux/kernel.h>
  45. #include <linux/wait.h>
  46. #include <linux/time.h>
  47. #include <linux/ip.h>
  48. #include <linux/ipv6.h>
  49. #include <linux/init.h>
  50. #include <net/inet_ecn.h>
  51. #include <net/icmp.h>
  52. #ifndef TEST_FRAME
  53. #include <net/tcp.h>
  54. #endif /* TEST_FRAME (not defined) */
  55. #include <linux/socket.h> /* for sa_family_t */
  56. #include <net/sock.h>
  57. #include <net/sctp/sctp.h>
  58. #include <net/sctp/sm.h>
  59. /* Forward declarations for private helpers. */
  60. static sctp_xmit_t sctp_packet_append_data(struct sctp_packet *packet,
  61. struct sctp_chunk *chunk);
  62. /* Config a packet.
  63. * This appears to be a followup set of initializations.
  64. */
  65. struct sctp_packet *sctp_packet_config(struct sctp_packet *packet,
  66. __u32 vtag, int ecn_capable)
  67. {
  68. struct sctp_chunk *chunk = NULL;
  69. SCTP_DEBUG_PRINTK("%s: packet:%p vtag:0x%x\n", __FUNCTION__,
  70. packet, vtag);
  71. packet->vtag = vtag;
  72. packet->has_cookie_echo = 0;
  73. packet->has_sack = 0;
  74. packet->ipfragok = 0;
  75. if (ecn_capable && sctp_packet_empty(packet)) {
  76. chunk = sctp_get_ecne_prepend(packet->transport->asoc);
  77. /* If there a is a prepend chunk stick it on the list before
  78. * any other chunks get appended.
  79. */
  80. if (chunk)
  81. sctp_packet_append_chunk(packet, chunk);
  82. }
  83. return packet;
  84. }
  85. /* Initialize the packet structure. */
  86. struct sctp_packet *sctp_packet_init(struct sctp_packet *packet,
  87. struct sctp_transport *transport,
  88. __u16 sport, __u16 dport)
  89. {
  90. struct sctp_association *asoc = transport->asoc;
  91. size_t overhead;
  92. SCTP_DEBUG_PRINTK("%s: packet:%p transport:%p\n", __FUNCTION__,
  93. packet, transport);
  94. packet->transport = transport;
  95. packet->source_port = sport;
  96. packet->destination_port = dport;
  97. INIT_LIST_HEAD(&packet->chunk_list);
  98. if (asoc) {
  99. struct sctp_sock *sp = sctp_sk(asoc->base.sk);
  100. overhead = sp->pf->af->net_header_len;
  101. } else {
  102. overhead = sizeof(struct ipv6hdr);
  103. }
  104. overhead += sizeof(struct sctphdr);
  105. packet->overhead = overhead;
  106. packet->size = overhead;
  107. packet->vtag = 0;
  108. packet->has_cookie_echo = 0;
  109. packet->has_sack = 0;
  110. packet->ipfragok = 0;
  111. packet->malloced = 0;
  112. return packet;
  113. }
  114. /* Free a packet. */
  115. void sctp_packet_free(struct sctp_packet *packet)
  116. {
  117. struct sctp_chunk *chunk, *tmp;
  118. SCTP_DEBUG_PRINTK("%s: packet:%p\n", __FUNCTION__, packet);
  119. list_for_each_entry_safe(chunk, tmp, &packet->chunk_list, list) {
  120. list_del_init(&chunk->list);
  121. sctp_chunk_free(chunk);
  122. }
  123. if (packet->malloced)
  124. kfree(packet);
  125. }
  126. /* This routine tries to append the chunk to the offered packet. If adding
  127. * the chunk causes the packet to exceed the path MTU and COOKIE_ECHO chunk
  128. * is not present in the packet, it transmits the input packet.
  129. * Data can be bundled with a packet containing a COOKIE_ECHO chunk as long
  130. * as it can fit in the packet, but any more data that does not fit in this
  131. * packet can be sent only after receiving the COOKIE_ACK.
  132. */
  133. sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *packet,
  134. struct sctp_chunk *chunk)
  135. {
  136. sctp_xmit_t retval;
  137. int error = 0;
  138. SCTP_DEBUG_PRINTK("%s: packet:%p chunk:%p\n", __FUNCTION__,
  139. packet, chunk);
  140. switch ((retval = (sctp_packet_append_chunk(packet, chunk)))) {
  141. case SCTP_XMIT_PMTU_FULL:
  142. if (!packet->has_cookie_echo) {
  143. error = sctp_packet_transmit(packet);
  144. if (error < 0)
  145. chunk->skb->sk->sk_err = -error;
  146. /* If we have an empty packet, then we can NOT ever
  147. * return PMTU_FULL.
  148. */
  149. retval = sctp_packet_append_chunk(packet, chunk);
  150. }
  151. break;
  152. case SCTP_XMIT_RWND_FULL:
  153. case SCTP_XMIT_OK:
  154. case SCTP_XMIT_NAGLE_DELAY:
  155. break;
  156. };
  157. return retval;
  158. }
  159. /* Try to bundle a SACK with the packet. */
  160. static sctp_xmit_t sctp_packet_bundle_sack(struct sctp_packet *pkt,
  161. struct sctp_chunk *chunk)
  162. {
  163. sctp_xmit_t retval = SCTP_XMIT_OK;
  164. /* If sending DATA and haven't aleady bundled a SACK, try to
  165. * bundle one in to the packet.
  166. */
  167. if (sctp_chunk_is_data(chunk) && !pkt->has_sack &&
  168. !pkt->has_cookie_echo) {
  169. struct sctp_association *asoc;
  170. asoc = pkt->transport->asoc;
  171. if (asoc->a_rwnd > asoc->rwnd) {
  172. struct sctp_chunk *sack;
  173. asoc->a_rwnd = asoc->rwnd;
  174. sack = sctp_make_sack(asoc);
  175. if (sack) {
  176. struct timer_list *timer;
  177. retval = sctp_packet_append_chunk(pkt, sack);
  178. asoc->peer.sack_needed = 0;
  179. timer = &asoc->timers[SCTP_EVENT_TIMEOUT_SACK];
  180. if (timer_pending(timer) && del_timer(timer))
  181. sctp_association_put(asoc);
  182. }
  183. }
  184. }
  185. return retval;
  186. }
  187. /* Append a chunk to the offered packet reporting back any inability to do
  188. * so.
  189. */
  190. sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *packet,
  191. struct sctp_chunk *chunk)
  192. {
  193. sctp_xmit_t retval = SCTP_XMIT_OK;
  194. __u16 chunk_len = WORD_ROUND(ntohs(chunk->chunk_hdr->length));
  195. size_t psize;
  196. size_t pmtu;
  197. int too_big;
  198. SCTP_DEBUG_PRINTK("%s: packet:%p chunk:%p\n", __FUNCTION__, packet,
  199. chunk);
  200. retval = sctp_packet_bundle_sack(packet, chunk);
  201. psize = packet->size;
  202. if (retval != SCTP_XMIT_OK)
  203. goto finish;
  204. pmtu = ((packet->transport->asoc) ?
  205. (packet->transport->asoc->pathmtu) :
  206. (packet->transport->pathmtu));
  207. too_big = (psize + chunk_len > pmtu);
  208. /* Decide if we need to fragment or resubmit later. */
  209. if (too_big) {
  210. /* Both control chunks and data chunks with TSNs are
  211. * non-fragmentable.
  212. */
  213. if (sctp_packet_empty(packet) || !sctp_chunk_is_data(chunk)) {
  214. /* We no longer do re-fragmentation.
  215. * Just fragment at the IP layer, if we
  216. * actually hit this condition
  217. */
  218. packet->ipfragok = 1;
  219. goto append;
  220. } else {
  221. retval = SCTP_XMIT_PMTU_FULL;
  222. goto finish;
  223. }
  224. }
  225. append:
  226. /* We believe that this chunk is OK to add to the packet (as
  227. * long as we have the cwnd for it).
  228. */
  229. /* DATA is a special case since we must examine both rwnd and cwnd
  230. * before we send DATA.
  231. */
  232. if (sctp_chunk_is_data(chunk)) {
  233. retval = sctp_packet_append_data(packet, chunk);
  234. /* Disallow SACK bundling after DATA. */
  235. packet->has_sack = 1;
  236. if (SCTP_XMIT_OK != retval)
  237. goto finish;
  238. } else if (SCTP_CID_COOKIE_ECHO == chunk->chunk_hdr->type)
  239. packet->has_cookie_echo = 1;
  240. else if (SCTP_CID_SACK == chunk->chunk_hdr->type)
  241. packet->has_sack = 1;
  242. /* It is OK to send this chunk. */
  243. list_add_tail(&chunk->list, &packet->chunk_list);
  244. packet->size += chunk_len;
  245. chunk->transport = packet->transport;
  246. finish:
  247. return retval;
  248. }
  249. /* All packets are sent to the network through this function from
  250. * sctp_outq_tail().
  251. *
  252. * The return value is a normal kernel error return value.
  253. */
  254. int sctp_packet_transmit(struct sctp_packet *packet)
  255. {
  256. struct sctp_transport *tp = packet->transport;
  257. struct sctp_association *asoc = tp->asoc;
  258. struct sctphdr *sh;
  259. __u32 crc32 = 0;
  260. struct sk_buff *nskb;
  261. struct sctp_chunk *chunk, *tmp;
  262. struct sock *sk;
  263. int err = 0;
  264. int padding; /* How much padding do we need? */
  265. __u8 has_data = 0;
  266. struct dst_entry *dst = tp->dst;
  267. SCTP_DEBUG_PRINTK("%s: packet:%p\n", __FUNCTION__, packet);
  268. /* Do NOT generate a chunkless packet. */
  269. if (list_empty(&packet->chunk_list))
  270. return err;
  271. /* Set up convenience variables... */
  272. chunk = list_entry(packet->chunk_list.next, struct sctp_chunk, list);
  273. sk = chunk->skb->sk;
  274. /* Allocate the new skb. */
  275. nskb = alloc_skb(packet->size + LL_MAX_HEADER, GFP_ATOMIC);
  276. if (!nskb)
  277. goto nomem;
  278. /* Make sure the outbound skb has enough header room reserved. */
  279. skb_reserve(nskb, packet->overhead + LL_MAX_HEADER);
  280. /* Set the owning socket so that we know where to get the
  281. * destination IP address.
  282. */
  283. skb_set_owner_w(nskb, sk);
  284. /* The 'obsolete' field of dst is set to 2 when a dst is freed. */
  285. if (!dst || (dst->obsolete > 1)) {
  286. dst_release(dst);
  287. sctp_transport_route(tp, NULL, sctp_sk(sk));
  288. if (asoc && (asoc->param_flags & SPP_PMTUD_ENABLE)) {
  289. sctp_assoc_sync_pmtu(asoc);
  290. }
  291. }
  292. nskb->dst = dst_clone(tp->dst);
  293. if (!nskb->dst)
  294. goto no_route;
  295. dst = nskb->dst;
  296. /* Build the SCTP header. */
  297. sh = (struct sctphdr *)skb_push(nskb, sizeof(struct sctphdr));
  298. sh->source = htons(packet->source_port);
  299. sh->dest = htons(packet->destination_port);
  300. /* From 6.8 Adler-32 Checksum Calculation:
  301. * After the packet is constructed (containing the SCTP common
  302. * header and one or more control or DATA chunks), the
  303. * transmitter shall:
  304. *
  305. * 1) Fill in the proper Verification Tag in the SCTP common
  306. * header and initialize the checksum field to 0's.
  307. */
  308. sh->vtag = htonl(packet->vtag);
  309. sh->checksum = 0;
  310. /* 2) Calculate the Adler-32 checksum of the whole packet,
  311. * including the SCTP common header and all the
  312. * chunks.
  313. *
  314. * Note: Adler-32 is no longer applicable, as has been replaced
  315. * by CRC32-C as described in <draft-ietf-tsvwg-sctpcsum-02.txt>.
  316. */
  317. if (!(dst->dev->features & NETIF_F_NO_CSUM))
  318. crc32 = sctp_start_cksum((__u8 *)sh, sizeof(struct sctphdr));
  319. /**
  320. * 6.10 Bundling
  321. *
  322. * An endpoint bundles chunks by simply including multiple
  323. * chunks in one outbound SCTP packet. ...
  324. */
  325. /**
  326. * 3.2 Chunk Field Descriptions
  327. *
  328. * The total length of a chunk (including Type, Length and
  329. * Value fields) MUST be a multiple of 4 bytes. If the length
  330. * of the chunk is not a multiple of 4 bytes, the sender MUST
  331. * pad the chunk with all zero bytes and this padding is not
  332. * included in the chunk length field. The sender should
  333. * never pad with more than 3 bytes.
  334. *
  335. * [This whole comment explains WORD_ROUND() below.]
  336. */
  337. SCTP_DEBUG_PRINTK("***sctp_transmit_packet***\n");
  338. list_for_each_entry_safe(chunk, tmp, &packet->chunk_list, list) {
  339. list_del_init(&chunk->list);
  340. if (sctp_chunk_is_data(chunk)) {
  341. if (!chunk->has_tsn) {
  342. sctp_chunk_assign_ssn(chunk);
  343. sctp_chunk_assign_tsn(chunk);
  344. /* 6.3.1 C4) When data is in flight and when allowed
  345. * by rule C5, a new RTT measurement MUST be made each
  346. * round trip. Furthermore, new RTT measurements
  347. * SHOULD be made no more than once per round-trip
  348. * for a given destination transport address.
  349. */
  350. if (!tp->rto_pending) {
  351. chunk->rtt_in_progress = 1;
  352. tp->rto_pending = 1;
  353. }
  354. } else
  355. chunk->resent = 1;
  356. chunk->sent_at = jiffies;
  357. has_data = 1;
  358. }
  359. padding = WORD_ROUND(chunk->skb->len) - chunk->skb->len;
  360. if (padding)
  361. memset(skb_put(chunk->skb, padding), 0, padding);
  362. if (dst->dev->features & NETIF_F_NO_CSUM)
  363. memcpy(skb_put(nskb, chunk->skb->len),
  364. chunk->skb->data, chunk->skb->len);
  365. else
  366. crc32 = sctp_update_copy_cksum(skb_put(nskb,
  367. chunk->skb->len),
  368. chunk->skb->data,
  369. chunk->skb->len, crc32);
  370. SCTP_DEBUG_PRINTK("%s %p[%s] %s 0x%x, %s %d, %s %d, %s %d\n",
  371. "*** Chunk", chunk,
  372. sctp_cname(SCTP_ST_CHUNK(
  373. chunk->chunk_hdr->type)),
  374. chunk->has_tsn ? "TSN" : "No TSN",
  375. chunk->has_tsn ?
  376. ntohl(chunk->subh.data_hdr->tsn) : 0,
  377. "length", ntohs(chunk->chunk_hdr->length),
  378. "chunk->skb->len", chunk->skb->len,
  379. "rtt_in_progress", chunk->rtt_in_progress);
  380. /*
  381. * If this is a control chunk, this is our last
  382. * reference. Free data chunks after they've been
  383. * acknowledged or have failed.
  384. */
  385. if (!sctp_chunk_is_data(chunk))
  386. sctp_chunk_free(chunk);
  387. }
  388. /* Perform final transformation on checksum. */
  389. if (!(dst->dev->features & NETIF_F_NO_CSUM))
  390. crc32 = sctp_end_cksum(crc32);
  391. /* 3) Put the resultant value into the checksum field in the
  392. * common header, and leave the rest of the bits unchanged.
  393. */
  394. sh->checksum = htonl(crc32);
  395. /* IP layer ECN support
  396. * From RFC 2481
  397. * "The ECN-Capable Transport (ECT) bit would be set by the
  398. * data sender to indicate that the end-points of the
  399. * transport protocol are ECN-capable."
  400. *
  401. * Now setting the ECT bit all the time, as it should not cause
  402. * any problems protocol-wise even if our peer ignores it.
  403. *
  404. * Note: The works for IPv6 layer checks this bit too later
  405. * in transmission. See IP6_ECN_flow_xmit().
  406. */
  407. INET_ECN_xmit(nskb->sk);
  408. /* Set up the IP options. */
  409. /* BUG: not implemented
  410. * For v4 this all lives somewhere in sk->sk_opt...
  411. */
  412. /* Dump that on IP! */
  413. if (asoc && asoc->peer.last_sent_to != tp) {
  414. /* Considering the multiple CPU scenario, this is a
  415. * "correcter" place for last_sent_to. --xguo
  416. */
  417. asoc->peer.last_sent_to = tp;
  418. }
  419. if (has_data) {
  420. struct timer_list *timer;
  421. unsigned long timeout;
  422. tp->last_time_used = jiffies;
  423. /* Restart the AUTOCLOSE timer when sending data. */
  424. if (sctp_state(asoc, ESTABLISHED) && asoc->autoclose) {
  425. timer = &asoc->timers[SCTP_EVENT_TIMEOUT_AUTOCLOSE];
  426. timeout = asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE];
  427. if (!mod_timer(timer, jiffies + timeout))
  428. sctp_association_hold(asoc);
  429. }
  430. }
  431. SCTP_DEBUG_PRINTK("***sctp_transmit_packet*** skb len %d\n",
  432. nskb->len);
  433. if (tp->param_flags & SPP_PMTUD_ENABLE)
  434. (*tp->af_specific->sctp_xmit)(nskb, tp, packet->ipfragok);
  435. else
  436. (*tp->af_specific->sctp_xmit)(nskb, tp, 1);
  437. out:
  438. packet->size = packet->overhead;
  439. return err;
  440. no_route:
  441. kfree_skb(nskb);
  442. IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES);
  443. /* FIXME: Returning the 'err' will effect all the associations
  444. * associated with a socket, although only one of the paths of the
  445. * association is unreachable.
  446. * The real failure of a transport or association can be passed on
  447. * to the user via notifications. So setting this error may not be
  448. * required.
  449. */
  450. /* err = -EHOSTUNREACH; */
  451. err:
  452. /* Control chunks are unreliable so just drop them. DATA chunks
  453. * will get resent or dropped later.
  454. */
  455. list_for_each_entry_safe(chunk, tmp, &packet->chunk_list, list) {
  456. list_del_init(&chunk->list);
  457. if (!sctp_chunk_is_data(chunk))
  458. sctp_chunk_free(chunk);
  459. }
  460. goto out;
  461. nomem:
  462. err = -ENOMEM;
  463. goto err;
  464. }
  465. /********************************************************************
  466. * 2nd Level Abstractions
  467. ********************************************************************/
  468. /* This private function handles the specifics of appending DATA chunks. */
  469. static sctp_xmit_t sctp_packet_append_data(struct sctp_packet *packet,
  470. struct sctp_chunk *chunk)
  471. {
  472. sctp_xmit_t retval = SCTP_XMIT_OK;
  473. size_t datasize, rwnd, inflight;
  474. struct sctp_transport *transport = packet->transport;
  475. __u32 max_burst_bytes;
  476. struct sctp_association *asoc = transport->asoc;
  477. struct sctp_sock *sp = sctp_sk(asoc->base.sk);
  478. struct sctp_outq *q = &asoc->outqueue;
  479. /* RFC 2960 6.1 Transmission of DATA Chunks
  480. *
  481. * A) At any given time, the data sender MUST NOT transmit new data to
  482. * any destination transport address if its peer's rwnd indicates
  483. * that the peer has no buffer space (i.e. rwnd is 0, see Section
  484. * 6.2.1). However, regardless of the value of rwnd (including if it
  485. * is 0), the data sender can always have one DATA chunk in flight to
  486. * the receiver if allowed by cwnd (see rule B below). This rule
  487. * allows the sender to probe for a change in rwnd that the sender
  488. * missed due to the SACK having been lost in transit from the data
  489. * receiver to the data sender.
  490. */
  491. rwnd = asoc->peer.rwnd;
  492. inflight = asoc->outqueue.outstanding_bytes;
  493. datasize = sctp_data_size(chunk);
  494. if (datasize > rwnd) {
  495. if (inflight > 0) {
  496. /* We have (at least) one data chunk in flight,
  497. * so we can't fall back to rule 6.1 B).
  498. */
  499. retval = SCTP_XMIT_RWND_FULL;
  500. goto finish;
  501. }
  502. }
  503. /* sctpimpguide-05 2.14.2
  504. * D) When the time comes for the sender to
  505. * transmit new DATA chunks, the protocol parameter Max.Burst MUST
  506. * first be applied to limit how many new DATA chunks may be sent.
  507. * The limit is applied by adjusting cwnd as follows:
  508. * if ((flightsize + Max.Burst * MTU) < cwnd)
  509. * cwnd = flightsize + Max.Burst * MTU
  510. */
  511. max_burst_bytes = asoc->max_burst * asoc->pathmtu;
  512. if ((transport->flight_size + max_burst_bytes) < transport->cwnd) {
  513. transport->cwnd = transport->flight_size + max_burst_bytes;
  514. SCTP_DEBUG_PRINTK("%s: cwnd limited by max_burst: "
  515. "transport: %p, cwnd: %d, "
  516. "ssthresh: %d, flight_size: %d, "
  517. "pba: %d\n",
  518. __FUNCTION__, transport,
  519. transport->cwnd,
  520. transport->ssthresh,
  521. transport->flight_size,
  522. transport->partial_bytes_acked);
  523. }
  524. /* RFC 2960 6.1 Transmission of DATA Chunks
  525. *
  526. * B) At any given time, the sender MUST NOT transmit new data
  527. * to a given transport address if it has cwnd or more bytes
  528. * of data outstanding to that transport address.
  529. */
  530. /* RFC 7.2.4 & the Implementers Guide 2.8.
  531. *
  532. * 3) ...
  533. * When a Fast Retransmit is being performed the sender SHOULD
  534. * ignore the value of cwnd and SHOULD NOT delay retransmission.
  535. */
  536. if (chunk->fast_retransmit <= 0)
  537. if (transport->flight_size >= transport->cwnd) {
  538. retval = SCTP_XMIT_RWND_FULL;
  539. goto finish;
  540. }
  541. /* Nagle's algorithm to solve small-packet problem:
  542. * Inhibit the sending of new chunks when new outgoing data arrives
  543. * if any previously transmitted data on the connection remains
  544. * unacknowledged.
  545. */
  546. if (!sp->nodelay && sctp_packet_empty(packet) &&
  547. q->outstanding_bytes && sctp_state(asoc, ESTABLISHED)) {
  548. unsigned len = datasize + q->out_qlen;
  549. /* Check whether this chunk and all the rest of pending
  550. * data will fit or delay in hopes of bundling a full
  551. * sized packet.
  552. */
  553. if (len < asoc->frag_point) {
  554. retval = SCTP_XMIT_NAGLE_DELAY;
  555. goto finish;
  556. }
  557. }
  558. /* Keep track of how many bytes are in flight over this transport. */
  559. transport->flight_size += datasize;
  560. /* Keep track of how many bytes are in flight to the receiver. */
  561. asoc->outqueue.outstanding_bytes += datasize;
  562. /* Update our view of the receiver's rwnd. Include sk_buff overhead
  563. * while updating peer.rwnd so that it reduces the chances of a
  564. * receiver running out of receive buffer space even when receive
  565. * window is still open. This can happen when a sender is sending
  566. * sending small messages.
  567. */
  568. datasize += sizeof(struct sk_buff);
  569. if (datasize < rwnd)
  570. rwnd -= datasize;
  571. else
  572. rwnd = 0;
  573. asoc->peer.rwnd = rwnd;
  574. /* Has been accepted for transmission. */
  575. if (!asoc->peer.prsctp_capable)
  576. chunk->msg->can_abandon = 0;
  577. finish:
  578. return retval;
  579. }