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