output.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. skb_queue_head_init(&packet->chunks);
  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;
  118. SCTP_DEBUG_PRINTK("%s: packet:%p\n", __FUNCTION__, packet);
  119. while ((chunk = (struct sctp_chunk *)__skb_dequeue(&packet->chunks)) != NULL)
  120. sctp_chunk_free(chunk);
  121. if (packet->malloced)
  122. kfree(packet);
  123. }
  124. /* This routine tries to append the chunk to the offered packet. If adding
  125. * the chunk causes the packet to exceed the path MTU and COOKIE_ECHO chunk
  126. * is not present in the packet, it transmits the input packet.
  127. * Data can be bundled with a packet containing a COOKIE_ECHO chunk as long
  128. * as it can fit in the packet, but any more data that does not fit in this
  129. * packet can be sent only after receiving the COOKIE_ACK.
  130. */
  131. sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *packet,
  132. struct sctp_chunk *chunk)
  133. {
  134. sctp_xmit_t retval;
  135. int error = 0;
  136. SCTP_DEBUG_PRINTK("%s: packet:%p chunk:%p\n", __FUNCTION__,
  137. packet, chunk);
  138. switch ((retval = (sctp_packet_append_chunk(packet, chunk)))) {
  139. case SCTP_XMIT_PMTU_FULL:
  140. if (!packet->has_cookie_echo) {
  141. error = sctp_packet_transmit(packet);
  142. if (error < 0)
  143. chunk->skb->sk->sk_err = -error;
  144. /* If we have an empty packet, then we can NOT ever
  145. * return PMTU_FULL.
  146. */
  147. retval = sctp_packet_append_chunk(packet, chunk);
  148. }
  149. break;
  150. case SCTP_XMIT_RWND_FULL:
  151. case SCTP_XMIT_OK:
  152. case SCTP_XMIT_NAGLE_DELAY:
  153. break;
  154. };
  155. return retval;
  156. }
  157. /* Try to bundle a SACK with the packet. */
  158. static sctp_xmit_t sctp_packet_bundle_sack(struct sctp_packet *pkt,
  159. struct sctp_chunk *chunk)
  160. {
  161. sctp_xmit_t retval = SCTP_XMIT_OK;
  162. /* If sending DATA and haven't aleady bundled a SACK, try to
  163. * bundle one in to the packet.
  164. */
  165. if (sctp_chunk_is_data(chunk) && !pkt->has_sack &&
  166. !pkt->has_cookie_echo) {
  167. struct sctp_association *asoc;
  168. asoc = pkt->transport->asoc;
  169. if (asoc->a_rwnd > asoc->rwnd) {
  170. struct sctp_chunk *sack;
  171. asoc->a_rwnd = asoc->rwnd;
  172. sack = sctp_make_sack(asoc);
  173. if (sack) {
  174. struct timer_list *timer;
  175. retval = sctp_packet_append_chunk(pkt, sack);
  176. asoc->peer.sack_needed = 0;
  177. timer = &asoc->timers[SCTP_EVENT_TIMEOUT_SACK];
  178. if (timer_pending(timer) && del_timer(timer))
  179. sctp_association_put(asoc);
  180. }
  181. }
  182. }
  183. return retval;
  184. }
  185. /* Append a chunk to the offered packet reporting back any inability to do
  186. * so.
  187. */
  188. sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *packet,
  189. struct sctp_chunk *chunk)
  190. {
  191. sctp_xmit_t retval = SCTP_XMIT_OK;
  192. __u16 chunk_len = WORD_ROUND(ntohs(chunk->chunk_hdr->length));
  193. size_t psize;
  194. size_t pmtu;
  195. int too_big;
  196. SCTP_DEBUG_PRINTK("%s: packet:%p chunk:%p\n", __FUNCTION__, packet,
  197. chunk);
  198. retval = sctp_packet_bundle_sack(packet, chunk);
  199. psize = packet->size;
  200. if (retval != SCTP_XMIT_OK)
  201. goto finish;
  202. pmtu = ((packet->transport->asoc) ?
  203. (packet->transport->asoc->pmtu) :
  204. (packet->transport->pmtu));
  205. too_big = (psize + chunk_len > pmtu);
  206. /* Decide if we need to fragment or resubmit later. */
  207. if (too_big) {
  208. /* Both control chunks and data chunks with TSNs are
  209. * non-fragmentable.
  210. */
  211. if (sctp_packet_empty(packet) || !sctp_chunk_is_data(chunk)) {
  212. /* We no longer do re-fragmentation.
  213. * Just fragment at the IP layer, if we
  214. * actually hit this condition
  215. */
  216. packet->ipfragok = 1;
  217. goto append;
  218. } else {
  219. retval = SCTP_XMIT_PMTU_FULL;
  220. goto finish;
  221. }
  222. }
  223. append:
  224. /* We believe that this chunk is OK to add to the packet (as
  225. * long as we have the cwnd for it).
  226. */
  227. /* DATA is a special case since we must examine both rwnd and cwnd
  228. * before we send DATA.
  229. */
  230. if (sctp_chunk_is_data(chunk)) {
  231. retval = sctp_packet_append_data(packet, chunk);
  232. /* Disallow SACK bundling after DATA. */
  233. packet->has_sack = 1;
  234. if (SCTP_XMIT_OK != retval)
  235. goto finish;
  236. } else if (SCTP_CID_COOKIE_ECHO == chunk->chunk_hdr->type)
  237. packet->has_cookie_echo = 1;
  238. else if (SCTP_CID_SACK == chunk->chunk_hdr->type)
  239. packet->has_sack = 1;
  240. /* It is OK to send this chunk. */
  241. __skb_queue_tail(&packet->chunks, (struct sk_buff *)chunk);
  242. packet->size += chunk_len;
  243. chunk->transport = packet->transport;
  244. finish:
  245. return retval;
  246. }
  247. /* All packets are sent to the network through this function from
  248. * sctp_outq_tail().
  249. *
  250. * The return value is a normal kernel error return value.
  251. */
  252. int sctp_packet_transmit(struct sctp_packet *packet)
  253. {
  254. struct sctp_transport *tp = packet->transport;
  255. struct sctp_association *asoc = tp->asoc;
  256. struct sctphdr *sh;
  257. __u32 crc32;
  258. struct sk_buff *nskb;
  259. struct sctp_chunk *chunk;
  260. struct sock *sk;
  261. int err = 0;
  262. int padding; /* How much padding do we need? */
  263. __u8 has_data = 0;
  264. struct dst_entry *dst;
  265. SCTP_DEBUG_PRINTK("%s: packet:%p\n", __FUNCTION__, packet);
  266. /* Do NOT generate a chunkless packet. */
  267. chunk = (struct sctp_chunk *)skb_peek(&packet->chunks);
  268. if (unlikely(!chunk))
  269. return err;
  270. /* Set up convenience variables... */
  271. sk = chunk->skb->sk;
  272. /* Allocate the new skb. */
  273. nskb = alloc_skb(packet->size + LL_MAX_HEADER, GFP_ATOMIC);
  274. if (!nskb)
  275. goto nomem;
  276. /* Make sure the outbound skb has enough header room reserved. */
  277. skb_reserve(nskb, packet->overhead + LL_MAX_HEADER);
  278. /* Set the owning socket so that we know where to get the
  279. * destination IP address.
  280. */
  281. skb_set_owner_w(nskb, sk);
  282. /* Build the SCTP header. */
  283. sh = (struct sctphdr *)skb_push(nskb, sizeof(struct sctphdr));
  284. sh->source = htons(packet->source_port);
  285. sh->dest = htons(packet->destination_port);
  286. /* From 6.8 Adler-32 Checksum Calculation:
  287. * After the packet is constructed (containing the SCTP common
  288. * header and one or more control or DATA chunks), the
  289. * transmitter shall:
  290. *
  291. * 1) Fill in the proper Verification Tag in the SCTP common
  292. * header and initialize the checksum field to 0's.
  293. */
  294. sh->vtag = htonl(packet->vtag);
  295. sh->checksum = 0;
  296. /* 2) Calculate the Adler-32 checksum of the whole packet,
  297. * including the SCTP common header and all the
  298. * chunks.
  299. *
  300. * Note: Adler-32 is no longer applicable, as has been replaced
  301. * by CRC32-C as described in <draft-ietf-tsvwg-sctpcsum-02.txt>.
  302. */
  303. crc32 = sctp_start_cksum((__u8 *)sh, sizeof(struct sctphdr));
  304. /**
  305. * 6.10 Bundling
  306. *
  307. * An endpoint bundles chunks by simply including multiple
  308. * chunks in one outbound SCTP packet. ...
  309. */
  310. /**
  311. * 3.2 Chunk Field Descriptions
  312. *
  313. * The total length of a chunk (including Type, Length and
  314. * Value fields) MUST be a multiple of 4 bytes. If the length
  315. * of the chunk is not a multiple of 4 bytes, the sender MUST
  316. * pad the chunk with all zero bytes and this padding is not
  317. * included in the chunk length field. The sender should
  318. * never pad with more than 3 bytes.
  319. *
  320. * [This whole comment explains WORD_ROUND() below.]
  321. */
  322. SCTP_DEBUG_PRINTK("***sctp_transmit_packet***\n");
  323. while ((chunk = (struct sctp_chunk *)__skb_dequeue(&packet->chunks)) != NULL) {
  324. if (sctp_chunk_is_data(chunk)) {
  325. if (!chunk->has_tsn) {
  326. sctp_chunk_assign_ssn(chunk);
  327. sctp_chunk_assign_tsn(chunk);
  328. /* 6.3.1 C4) When data is in flight and when allowed
  329. * by rule C5, a new RTT measurement MUST be made each
  330. * round trip. Furthermore, new RTT measurements
  331. * SHOULD be made no more than once per round-trip
  332. * for a given destination transport address.
  333. */
  334. if (!tp->rto_pending) {
  335. chunk->rtt_in_progress = 1;
  336. tp->rto_pending = 1;
  337. }
  338. } else
  339. chunk->resent = 1;
  340. chunk->sent_at = jiffies;
  341. has_data = 1;
  342. }
  343. padding = WORD_ROUND(chunk->skb->len) - chunk->skb->len;
  344. if (padding)
  345. memset(skb_put(chunk->skb, padding), 0, padding);
  346. crc32 = sctp_update_copy_cksum(skb_put(nskb, chunk->skb->len),
  347. chunk->skb->data,
  348. chunk->skb->len, crc32);
  349. SCTP_DEBUG_PRINTK("%s %p[%s] %s 0x%x, %s %d, %s %d, %s %d\n",
  350. "*** Chunk", chunk,
  351. sctp_cname(SCTP_ST_CHUNK(
  352. chunk->chunk_hdr->type)),
  353. chunk->has_tsn ? "TSN" : "No TSN",
  354. chunk->has_tsn ?
  355. ntohl(chunk->subh.data_hdr->tsn) : 0,
  356. "length", ntohs(chunk->chunk_hdr->length),
  357. "chunk->skb->len", chunk->skb->len,
  358. "rtt_in_progress", chunk->rtt_in_progress);
  359. /*
  360. * If this is a control chunk, this is our last
  361. * reference. Free data chunks after they've been
  362. * acknowledged or have failed.
  363. */
  364. if (!sctp_chunk_is_data(chunk))
  365. sctp_chunk_free(chunk);
  366. }
  367. /* Perform final transformation on checksum. */
  368. crc32 = sctp_end_cksum(crc32);
  369. /* 3) Put the resultant value into the checksum field in the
  370. * common header, and leave the rest of the bits unchanged.
  371. */
  372. sh->checksum = htonl(crc32);
  373. /* IP layer ECN support
  374. * From RFC 2481
  375. * "The ECN-Capable Transport (ECT) bit would be set by the
  376. * data sender to indicate that the end-points of the
  377. * transport protocol are ECN-capable."
  378. *
  379. * Now setting the ECT bit all the time, as it should not cause
  380. * any problems protocol-wise even if our peer ignores it.
  381. *
  382. * Note: The works for IPv6 layer checks this bit too later
  383. * in transmission. See IP6_ECN_flow_xmit().
  384. */
  385. INET_ECN_xmit(nskb->sk);
  386. /* Set up the IP options. */
  387. /* BUG: not implemented
  388. * For v4 this all lives somewhere in sk->sk_opt...
  389. */
  390. /* Dump that on IP! */
  391. if (asoc && asoc->peer.last_sent_to != tp) {
  392. /* Considering the multiple CPU scenario, this is a
  393. * "correcter" place for last_sent_to. --xguo
  394. */
  395. asoc->peer.last_sent_to = tp;
  396. }
  397. if (has_data) {
  398. struct timer_list *timer;
  399. unsigned long timeout;
  400. tp->last_time_used = jiffies;
  401. /* Restart the AUTOCLOSE timer when sending data. */
  402. if (sctp_state(asoc, ESTABLISHED) && asoc->autoclose) {
  403. timer = &asoc->timers[SCTP_EVENT_TIMEOUT_AUTOCLOSE];
  404. timeout = asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE];
  405. if (!mod_timer(timer, jiffies + timeout))
  406. sctp_association_hold(asoc);
  407. }
  408. }
  409. dst = tp->dst;
  410. /* The 'obsolete' field of dst is set to 2 when a dst is freed. */
  411. if (!dst || (dst->obsolete > 1)) {
  412. dst_release(dst);
  413. sctp_transport_route(tp, NULL, sctp_sk(sk));
  414. sctp_assoc_sync_pmtu(asoc);
  415. }
  416. nskb->dst = dst_clone(tp->dst);
  417. if (!nskb->dst)
  418. goto no_route;
  419. SCTP_DEBUG_PRINTK("***sctp_transmit_packet*** skb len %d\n",
  420. nskb->len);
  421. (*tp->af_specific->sctp_xmit)(nskb, tp, packet->ipfragok);
  422. out:
  423. packet->size = packet->overhead;
  424. return err;
  425. no_route:
  426. kfree_skb(nskb);
  427. IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES);
  428. /* FIXME: Returning the 'err' will effect all the associations
  429. * associated with a socket, although only one of the paths of the
  430. * association is unreachable.
  431. * The real failure of a transport or association can be passed on
  432. * to the user via notifications. So setting this error may not be
  433. * required.
  434. */
  435. /* err = -EHOSTUNREACH; */
  436. err:
  437. /* Control chunks are unreliable so just drop them. DATA chunks
  438. * will get resent or dropped later.
  439. */
  440. while ((chunk = (struct sctp_chunk *)__skb_dequeue(&packet->chunks)) != NULL) {
  441. if (!sctp_chunk_is_data(chunk))
  442. sctp_chunk_free(chunk);
  443. }
  444. goto out;
  445. nomem:
  446. err = -ENOMEM;
  447. goto err;
  448. }
  449. /********************************************************************
  450. * 2nd Level Abstractions
  451. ********************************************************************/
  452. /* This private function handles the specifics of appending DATA chunks. */
  453. static sctp_xmit_t sctp_packet_append_data(struct sctp_packet *packet,
  454. struct sctp_chunk *chunk)
  455. {
  456. sctp_xmit_t retval = SCTP_XMIT_OK;
  457. size_t datasize, rwnd, inflight;
  458. struct sctp_transport *transport = packet->transport;
  459. __u32 max_burst_bytes;
  460. struct sctp_association *asoc = transport->asoc;
  461. struct sctp_sock *sp = sctp_sk(asoc->base.sk);
  462. struct sctp_outq *q = &asoc->outqueue;
  463. /* RFC 2960 6.1 Transmission of DATA Chunks
  464. *
  465. * A) At any given time, the data sender MUST NOT transmit new data to
  466. * any destination transport address if its peer's rwnd indicates
  467. * that the peer has no buffer space (i.e. rwnd is 0, see Section
  468. * 6.2.1). However, regardless of the value of rwnd (including if it
  469. * is 0), the data sender can always have one DATA chunk in flight to
  470. * the receiver if allowed by cwnd (see rule B below). This rule
  471. * allows the sender to probe for a change in rwnd that the sender
  472. * missed due to the SACK having been lost in transit from the data
  473. * receiver to the data sender.
  474. */
  475. rwnd = asoc->peer.rwnd;
  476. inflight = asoc->outqueue.outstanding_bytes;
  477. datasize = sctp_data_size(chunk);
  478. if (datasize > rwnd) {
  479. if (inflight > 0) {
  480. /* We have (at least) one data chunk in flight,
  481. * so we can't fall back to rule 6.1 B).
  482. */
  483. retval = SCTP_XMIT_RWND_FULL;
  484. goto finish;
  485. }
  486. }
  487. /* sctpimpguide-05 2.14.2
  488. * D) When the time comes for the sender to
  489. * transmit new DATA chunks, the protocol parameter Max.Burst MUST
  490. * first be applied to limit how many new DATA chunks may be sent.
  491. * The limit is applied by adjusting cwnd as follows:
  492. * if ((flightsize + Max.Burst * MTU) < cwnd)
  493. * cwnd = flightsize + Max.Burst * MTU
  494. */
  495. max_burst_bytes = asoc->max_burst * asoc->pmtu;
  496. if ((transport->flight_size + max_burst_bytes) < transport->cwnd) {
  497. transport->cwnd = transport->flight_size + max_burst_bytes;
  498. SCTP_DEBUG_PRINTK("%s: cwnd limited by max_burst: "
  499. "transport: %p, cwnd: %d, "
  500. "ssthresh: %d, flight_size: %d, "
  501. "pba: %d\n",
  502. __FUNCTION__, transport,
  503. transport->cwnd,
  504. transport->ssthresh,
  505. transport->flight_size,
  506. transport->partial_bytes_acked);
  507. }
  508. /* RFC 2960 6.1 Transmission of DATA Chunks
  509. *
  510. * B) At any given time, the sender MUST NOT transmit new data
  511. * to a given transport address if it has cwnd or more bytes
  512. * of data outstanding to that transport address.
  513. */
  514. /* RFC 7.2.4 & the Implementers Guide 2.8.
  515. *
  516. * 3) ...
  517. * When a Fast Retransmit is being performed the sender SHOULD
  518. * ignore the value of cwnd and SHOULD NOT delay retransmission.
  519. */
  520. if (!chunk->fast_retransmit)
  521. if (transport->flight_size >= transport->cwnd) {
  522. retval = SCTP_XMIT_RWND_FULL;
  523. goto finish;
  524. }
  525. /* Nagle's algorithm to solve small-packet problem:
  526. * Inhibit the sending of new chunks when new outgoing data arrives
  527. * if any previously transmitted data on the connection remains
  528. * unacknowledged.
  529. */
  530. if (!sp->nodelay && sctp_packet_empty(packet) &&
  531. q->outstanding_bytes && sctp_state(asoc, ESTABLISHED)) {
  532. unsigned len = datasize + q->out_qlen;
  533. /* Check whether this chunk and all the rest of pending
  534. * data will fit or delay in hopes of bundling a full
  535. * sized packet.
  536. */
  537. if (len < asoc->pmtu - packet->overhead) {
  538. retval = SCTP_XMIT_NAGLE_DELAY;
  539. goto finish;
  540. }
  541. }
  542. /* Keep track of how many bytes are in flight over this transport. */
  543. transport->flight_size += datasize;
  544. /* Keep track of how many bytes are in flight to the receiver. */
  545. asoc->outqueue.outstanding_bytes += datasize;
  546. /* Update our view of the receiver's rwnd. */
  547. if (datasize < rwnd)
  548. rwnd -= datasize;
  549. else
  550. rwnd = 0;
  551. asoc->peer.rwnd = rwnd;
  552. /* Has been accepted for transmission. */
  553. if (!asoc->peer.prsctp_capable)
  554. chunk->msg->can_abandon = 0;
  555. finish:
  556. return retval;
  557. }