OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [net/] [sctp/] [outqueue.c] - Diff between revs 1275 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 1275 Rev 1765
/* SCTP kernel reference Implementation
/* SCTP kernel reference Implementation
 * Copyright (c) 1999-2000 Cisco, Inc.
 * Copyright (c) 1999-2000 Cisco, Inc.
 * Copyright (c) 1999-2001 Motorola, Inc.
 * Copyright (c) 1999-2001 Motorola, Inc.
 * Copyright (c) 2001-2003 Intel Corp.
 * Copyright (c) 2001-2003 Intel Corp.
 * Copyright (c) 2001-2003 International Business Machines Corp.
 * Copyright (c) 2001-2003 International Business Machines Corp.
 *
 *
 * This file is part of the SCTP kernel reference Implementation
 * This file is part of the SCTP kernel reference Implementation
 *
 *
 * These functions implement the sctp_outq class.   The outqueue handles
 * These functions implement the sctp_outq class.   The outqueue handles
 * bundling and queueing of outgoing SCTP chunks.
 * bundling and queueing of outgoing SCTP chunks.
 *
 *
 * The SCTP reference implementation is free software;
 * The SCTP reference implementation is free software;
 * you can redistribute it and/or modify it under the terms of
 * you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by
 * the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 * any later version.
 *
 *
 * The SCTP reference implementation is distributed in the hope that it
 * The SCTP reference implementation is distributed in the hope that it
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
 *                 ************************
 *                 ************************
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * See the GNU General Public License for more details.
 *
 *
 * You should have received a copy of the GNU General Public License
 * You should have received a copy of the GNU General Public License
 * along with GNU CC; see the file COPYING.  If not, write to
 * along with GNU CC; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330,
 * the Free Software Foundation, 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 * Boston, MA 02111-1307, USA.
 *
 *
 * Please send any bug reports or fixes you make to the
 * Please send any bug reports or fixes you make to the
 * email address(es):
 * email address(es):
 *    lksctp developers <lksctp-developers@lists.sourceforge.net>
 *    lksctp developers <lksctp-developers@lists.sourceforge.net>
 *
 *
 * Or submit a bug report through the following website:
 * Or submit a bug report through the following website:
 *    http://www.sf.net/projects/lksctp
 *    http://www.sf.net/projects/lksctp
 *
 *
 * Written or modified by:
 * Written or modified by:
 *    La Monte H.P. Yarroll <piggy@acm.org>
 *    La Monte H.P. Yarroll <piggy@acm.org>
 *    Karl Knutson          <karl@athena.chicago.il.us>
 *    Karl Knutson          <karl@athena.chicago.il.us>
 *    Perry Melange         <pmelange@null.cc.uic.edu>
 *    Perry Melange         <pmelange@null.cc.uic.edu>
 *    Xingang Guo           <xingang.guo@intel.com>
 *    Xingang Guo           <xingang.guo@intel.com>
 *    Hui Huang             <hui.huang@nokia.com>
 *    Hui Huang             <hui.huang@nokia.com>
 *    Sridhar Samudrala     <sri@us.ibm.com>
 *    Sridhar Samudrala     <sri@us.ibm.com>
 *    Jon Grimm             <jgrimm@us.ibm.com>
 *    Jon Grimm             <jgrimm@us.ibm.com>
 *
 *
 * Any bugs reported given to us we will try to fix... any fixes shared will
 * Any bugs reported given to us we will try to fix... any fixes shared will
 * be incorporated into the next SCTP release.
 * be incorporated into the next SCTP release.
 */
 */
 
 
#include <linux/types.h>
#include <linux/types.h>
#include <linux/list.h>   /* For struct list_head */
#include <linux/list.h>   /* For struct list_head */
#include <linux/socket.h>
#include <linux/socket.h>
#include <linux/ip.h>
#include <linux/ip.h>
#include <net/sock.h>     /* For skb_set_owner_w */
#include <net/sock.h>     /* For skb_set_owner_w */
 
 
#include <net/sctp/sctp.h>
#include <net/sctp/sctp.h>
#include <net/sctp/sm.h>
#include <net/sctp/sm.h>
 
 
/* Declare internal functions here.  */
/* Declare internal functions here.  */
static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn);
static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn);
static void sctp_check_transmitted(struct sctp_outq *q,
static void sctp_check_transmitted(struct sctp_outq *q,
                                   struct list_head *transmitted_queue,
                                   struct list_head *transmitted_queue,
                                   struct sctp_transport *transport,
                                   struct sctp_transport *transport,
                                   struct sctp_sackhdr *sack,
                                   struct sctp_sackhdr *sack,
                                   __u32 highest_new_tsn);
                                   __u32 highest_new_tsn);
 
 
static void sctp_mark_missing(struct sctp_outq *q,
static void sctp_mark_missing(struct sctp_outq *q,
                              struct list_head *transmitted_queue,
                              struct list_head *transmitted_queue,
                              struct sctp_transport *transport,
                              struct sctp_transport *transport,
                              __u32 highest_new_tsn,
                              __u32 highest_new_tsn,
                              int count_of_newacks);
                              int count_of_newacks);
 
 
/* Add data to the front of the queue. */
/* Add data to the front of the queue. */
static inline void sctp_outq_head_data(struct sctp_outq *q,
static inline void sctp_outq_head_data(struct sctp_outq *q,
                                        struct sctp_chunk *ch)
                                        struct sctp_chunk *ch)
{
{
        __skb_queue_head(&q->out, (struct sk_buff *)ch);
        __skb_queue_head(&q->out, (struct sk_buff *)ch);
        q->out_qlen += ch->skb->len;
        q->out_qlen += ch->skb->len;
        return;
        return;
}
}
 
 
/* Take data from the front of the queue. */
/* Take data from the front of the queue. */
static inline struct sctp_chunk *sctp_outq_dequeue_data(struct sctp_outq *q)
static inline struct sctp_chunk *sctp_outq_dequeue_data(struct sctp_outq *q)
{
{
        struct sctp_chunk *ch;
        struct sctp_chunk *ch;
        ch = (struct sctp_chunk *)__skb_dequeue(&q->out);
        ch = (struct sctp_chunk *)__skb_dequeue(&q->out);
        if (ch)
        if (ch)
                q->out_qlen -= ch->skb->len;
                q->out_qlen -= ch->skb->len;
        return ch;
        return ch;
}
}
/* Add data chunk to the end of the queue. */
/* Add data chunk to the end of the queue. */
static inline void sctp_outq_tail_data(struct sctp_outq *q,
static inline void sctp_outq_tail_data(struct sctp_outq *q,
                                       struct sctp_chunk *ch)
                                       struct sctp_chunk *ch)
{
{
        __skb_queue_tail(&q->out, (struct sk_buff *)ch);
        __skb_queue_tail(&q->out, (struct sk_buff *)ch);
        q->out_qlen += ch->skb->len;
        q->out_qlen += ch->skb->len;
        return;
        return;
}
}
 
 
/* Insert a chunk behind chunk 'pos'. */
/* Insert a chunk behind chunk 'pos'. */
static inline void sctp_outq_insert_data(struct sctp_outq *q,
static inline void sctp_outq_insert_data(struct sctp_outq *q,
                                         struct sctp_chunk *ch,
                                         struct sctp_chunk *ch,
                                         struct sctp_chunk *pos)
                                         struct sctp_chunk *pos)
{
{
        __skb_insert((struct sk_buff *)ch, (struct sk_buff *)pos->prev,
        __skb_insert((struct sk_buff *)ch, (struct sk_buff *)pos->prev,
                     (struct sk_buff *)pos, pos->list);
                     (struct sk_buff *)pos, pos->list);
        q->out_qlen += ch->skb->len;
        q->out_qlen += ch->skb->len;
}
}
 
 
/*
/*
 * SFR-CACC algorithm:
 * SFR-CACC algorithm:
 * D) If count_of_newacks is greater than or equal to 2
 * D) If count_of_newacks is greater than or equal to 2
 * and t was not sent to the current primary then the
 * and t was not sent to the current primary then the
 * sender MUST NOT increment missing report count for t.
 * sender MUST NOT increment missing report count for t.
 */
 */
static inline int sctp_cacc_skip_3_1_d(struct sctp_transport *primary,
static inline int sctp_cacc_skip_3_1_d(struct sctp_transport *primary,
                                       struct sctp_transport *transport,
                                       struct sctp_transport *transport,
                                       int count_of_newacks)
                                       int count_of_newacks)
{
{
        if (count_of_newacks >=2 && transport != primary)
        if (count_of_newacks >=2 && transport != primary)
                return 1;
                return 1;
        return 0;
        return 0;
}
}
 
 
/*
/*
 * SFR-CACC algorithm:
 * SFR-CACC algorithm:
 * F) If count_of_newacks is less than 2, let d be the
 * F) If count_of_newacks is less than 2, let d be the
 * destination to which t was sent. If cacc_saw_newack
 * destination to which t was sent. If cacc_saw_newack
 * is 0 for destination d, then the sender MUST NOT
 * is 0 for destination d, then the sender MUST NOT
 * increment missing report count for t.
 * increment missing report count for t.
 */
 */
static inline int sctp_cacc_skip_3_1_f(struct sctp_transport *transport,
static inline int sctp_cacc_skip_3_1_f(struct sctp_transport *transport,
                                       int count_of_newacks)
                                       int count_of_newacks)
{
{
        if (count_of_newacks < 2 && !transport->cacc.cacc_saw_newack)
        if (count_of_newacks < 2 && !transport->cacc.cacc_saw_newack)
                return 1;
                return 1;
        return 0;
        return 0;
}
}
 
 
/*
/*
 * SFR-CACC algorithm:
 * SFR-CACC algorithm:
 * 3.1) If CYCLING_CHANGEOVER is 0, the sender SHOULD
 * 3.1) If CYCLING_CHANGEOVER is 0, the sender SHOULD
 * execute steps C, D, F.
 * execute steps C, D, F.
 *
 *
 * C has been implemented in sctp_outq_sack
 * C has been implemented in sctp_outq_sack
 */
 */
static inline int sctp_cacc_skip_3_1(struct sctp_transport *primary,
static inline int sctp_cacc_skip_3_1(struct sctp_transport *primary,
                                     struct sctp_transport *transport,
                                     struct sctp_transport *transport,
                                     int count_of_newacks)
                                     int count_of_newacks)
{
{
        if (!primary->cacc.cycling_changeover) {
        if (!primary->cacc.cycling_changeover) {
                if (sctp_cacc_skip_3_1_d(primary, transport, count_of_newacks))
                if (sctp_cacc_skip_3_1_d(primary, transport, count_of_newacks))
                        return 1;
                        return 1;
                if (sctp_cacc_skip_3_1_f(transport, count_of_newacks))
                if (sctp_cacc_skip_3_1_f(transport, count_of_newacks))
                        return 1;
                        return 1;
                return 0;
                return 0;
        }
        }
        return 0;
        return 0;
}
}
 
 
/*
/*
 * SFR-CACC algorithm:
 * SFR-CACC algorithm:
 * 3.2) Else if CYCLING_CHANGEOVER is 1, and t is less
 * 3.2) Else if CYCLING_CHANGEOVER is 1, and t is less
 * than next_tsn_at_change of the current primary, then
 * than next_tsn_at_change of the current primary, then
 * the sender MUST NOT increment missing report count
 * the sender MUST NOT increment missing report count
 * for t.
 * for t.
 */
 */
static inline int sctp_cacc_skip_3_2(struct sctp_transport *primary, __u32 tsn)
static inline int sctp_cacc_skip_3_2(struct sctp_transport *primary, __u32 tsn)
{
{
        if (primary->cacc.cycling_changeover &&
        if (primary->cacc.cycling_changeover &&
            TSN_lt(tsn, primary->cacc.next_tsn_at_change))
            TSN_lt(tsn, primary->cacc.next_tsn_at_change))
                return 1;
                return 1;
        return 0;
        return 0;
}
}
 
 
/*
/*
 * SFR-CACC algorithm:
 * SFR-CACC algorithm:
 * 3) If the missing report count for TSN t is to be
 * 3) If the missing report count for TSN t is to be
 * incremented according to [RFC2960] and
 * incremented according to [RFC2960] and
 * [SCTP_STEWART-2002], and CHANGEOVER_ACTIVE is set,
 * [SCTP_STEWART-2002], and CHANGEOVER_ACTIVE is set,
 * then the sender MUST futher execute steps 3.1 and
 * then the sender MUST futher execute steps 3.1 and
 * 3.2 to determine if the missing report count for
 * 3.2 to determine if the missing report count for
 * TSN t SHOULD NOT be incremented.
 * TSN t SHOULD NOT be incremented.
 *
 *
 * 3.3) If 3.1 and 3.2 do not dictate that the missing
 * 3.3) If 3.1 and 3.2 do not dictate that the missing
 * report count for t should not be incremented, then
 * report count for t should not be incremented, then
 * the sender SOULD increment missing report count for
 * the sender SOULD increment missing report count for
 * t (according to [RFC2960] and [SCTP_STEWART_2002]).
 * t (according to [RFC2960] and [SCTP_STEWART_2002]).
 */
 */
static inline int sctp_cacc_skip(struct sctp_transport *primary,
static inline int sctp_cacc_skip(struct sctp_transport *primary,
                                 struct sctp_transport *transport,
                                 struct sctp_transport *transport,
                                 int count_of_newacks,
                                 int count_of_newacks,
                                 __u32 tsn)
                                 __u32 tsn)
{
{
        if (primary->cacc.changeover_active &&
        if (primary->cacc.changeover_active &&
            (sctp_cacc_skip_3_1(primary, transport, count_of_newacks)
            (sctp_cacc_skip_3_1(primary, transport, count_of_newacks)
             || sctp_cacc_skip_3_2(primary, tsn)))
             || sctp_cacc_skip_3_2(primary, tsn)))
                return 1;
                return 1;
        return 0;
        return 0;
}
}
 
 
/* Generate a new outqueue.  */
/* Generate a new outqueue.  */
struct sctp_outq *sctp_outq_new(struct sctp_association *asoc)
struct sctp_outq *sctp_outq_new(struct sctp_association *asoc)
{
{
        struct sctp_outq *q;
        struct sctp_outq *q;
 
 
        q = t_new(struct sctp_outq, GFP_KERNEL);
        q = t_new(struct sctp_outq, GFP_KERNEL);
        if (q) {
        if (q) {
                sctp_outq_init(asoc, q);
                sctp_outq_init(asoc, q);
                q->malloced = 1;
                q->malloced = 1;
        }
        }
        return q;
        return q;
}
}
 
 
/* Initialize an existing sctp_outq.  This does the boring stuff.
/* Initialize an existing sctp_outq.  This does the boring stuff.
 * You still need to define handlers if you really want to DO
 * You still need to define handlers if you really want to DO
 * something with this structure...
 * something with this structure...
 */
 */
void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
{
{
        q->asoc = asoc;
        q->asoc = asoc;
        skb_queue_head_init(&q->out);
        skb_queue_head_init(&q->out);
        skb_queue_head_init(&q->control);
        skb_queue_head_init(&q->control);
        INIT_LIST_HEAD(&q->retransmit);
        INIT_LIST_HEAD(&q->retransmit);
        INIT_LIST_HEAD(&q->sacked);
        INIT_LIST_HEAD(&q->sacked);
 
 
        q->init_output = NULL;
        q->init_output = NULL;
        q->config_output = NULL;
        q->config_output = NULL;
        q->append_output = NULL;
        q->append_output = NULL;
        q->build_output = NULL;
        q->build_output = NULL;
        q->force_output = NULL;
        q->force_output = NULL;
 
 
        q->outstanding_bytes = 0;
        q->outstanding_bytes = 0;
        q->empty = 1;
        q->empty = 1;
        q->cork  = 0;
        q->cork  = 0;
 
 
        q->malloced = 0;
        q->malloced = 0;
        q->out_qlen = 0;
        q->out_qlen = 0;
}
}
 
 
/* Free the outqueue structure and any related pending chunks.
/* Free the outqueue structure and any related pending chunks.
 */
 */
void sctp_outq_teardown(struct sctp_outq *q)
void sctp_outq_teardown(struct sctp_outq *q)
{
{
        struct sctp_transport *transport;
        struct sctp_transport *transport;
        struct list_head *lchunk, *pos, *temp;
        struct list_head *lchunk, *pos, *temp;
        struct sctp_chunk *chunk;
        struct sctp_chunk *chunk;
 
 
        /* Throw away unacknowledged chunks. */
        /* Throw away unacknowledged chunks. */
        list_for_each(pos, &q->asoc->peer.transport_addr_list) {
        list_for_each(pos, &q->asoc->peer.transport_addr_list) {
                transport = list_entry(pos, struct sctp_transport, transports);
                transport = list_entry(pos, struct sctp_transport, transports);
                while ((lchunk = sctp_list_dequeue(&transport->transmitted))) {
                while ((lchunk = sctp_list_dequeue(&transport->transmitted))) {
                        chunk = list_entry(lchunk, struct sctp_chunk,
                        chunk = list_entry(lchunk, struct sctp_chunk,
                                           transmitted_list);
                                           transmitted_list);
                        /* Mark as part of a failed message. */
                        /* Mark as part of a failed message. */
                        sctp_datamsg_fail(chunk, q->error);
                        sctp_datamsg_fail(chunk, q->error);
                        sctp_chunk_free(chunk);
                        sctp_chunk_free(chunk);
                }
                }
        }
        }
 
 
        /* Throw away chunks that have been gap ACKed.  */
        /* Throw away chunks that have been gap ACKed.  */
        list_for_each_safe(lchunk, temp, &q->sacked) {
        list_for_each_safe(lchunk, temp, &q->sacked) {
                list_del_init(lchunk);
                list_del_init(lchunk);
                chunk = list_entry(lchunk, struct sctp_chunk,
                chunk = list_entry(lchunk, struct sctp_chunk,
                                   transmitted_list);
                                   transmitted_list);
                sctp_datamsg_fail(chunk, q->error);
                sctp_datamsg_fail(chunk, q->error);
                sctp_chunk_free(chunk);
                sctp_chunk_free(chunk);
        }
        }
 
 
        /* Throw away any chunks in the retransmit queue. */
        /* Throw away any chunks in the retransmit queue. */
        list_for_each_safe(lchunk, temp, &q->retransmit) {
        list_for_each_safe(lchunk, temp, &q->retransmit) {
                list_del_init(lchunk);
                list_del_init(lchunk);
                chunk = list_entry(lchunk, struct sctp_chunk,
                chunk = list_entry(lchunk, struct sctp_chunk,
                                   transmitted_list);
                                   transmitted_list);
                sctp_datamsg_fail(chunk, q->error);
                sctp_datamsg_fail(chunk, q->error);
                sctp_chunk_free(chunk);
                sctp_chunk_free(chunk);
        }
        }
 
 
        /* Throw away any leftover data chunks. */
        /* Throw away any leftover data chunks. */
        while ((chunk = sctp_outq_dequeue_data(q))) {
        while ((chunk = sctp_outq_dequeue_data(q))) {
 
 
                /* Mark as send failure. */
                /* Mark as send failure. */
                sctp_datamsg_fail(chunk, q->error);
                sctp_datamsg_fail(chunk, q->error);
                sctp_chunk_free(chunk);
                sctp_chunk_free(chunk);
        }
        }
 
 
        q->error = 0;
        q->error = 0;
 
 
        /* Throw away any leftover control chunks. */
        /* Throw away any leftover control chunks. */
        while ((chunk = (struct sctp_chunk *) skb_dequeue(&q->control)))
        while ((chunk = (struct sctp_chunk *) skb_dequeue(&q->control)))
                sctp_chunk_free(chunk);
                sctp_chunk_free(chunk);
}
}
 
 
/* Free the outqueue structure and any related pending chunks.  */
/* Free the outqueue structure and any related pending chunks.  */
void sctp_outq_free(struct sctp_outq *q)
void sctp_outq_free(struct sctp_outq *q)
{
{
        /* Throw away leftover chunks. */
        /* Throw away leftover chunks. */
        sctp_outq_teardown(q);
        sctp_outq_teardown(q);
 
 
        /* If we were kmalloc()'d, free the memory.  */
        /* If we were kmalloc()'d, free the memory.  */
        if (q->malloced)
        if (q->malloced)
                kfree(q);
                kfree(q);
}
}
 
 
/* Put a new chunk in an sctp_outq.  */
/* Put a new chunk in an sctp_outq.  */
int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk)
int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk)
{
{
        int error = 0;
        int error = 0;
 
 
        SCTP_DEBUG_PRINTK("sctp_outq_tail(%p, %p[%s])\n",
        SCTP_DEBUG_PRINTK("sctp_outq_tail(%p, %p[%s])\n",
                          q, chunk, chunk && chunk->chunk_hdr ?
                          q, chunk, chunk && chunk->chunk_hdr ?
                          sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type))
                          sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type))
                          : "Illegal Chunk");
                          : "Illegal Chunk");
 
 
        /* If it is data, queue it up, otherwise, send it
        /* If it is data, queue it up, otherwise, send it
         * immediately.
         * immediately.
         */
         */
        if (SCTP_CID_DATA == chunk->chunk_hdr->type) {
        if (SCTP_CID_DATA == chunk->chunk_hdr->type) {
                /* Is it OK to queue data chunks?  */
                /* Is it OK to queue data chunks?  */
                /* From 9. Termination of Association
                /* From 9. Termination of Association
                 *
                 *
                 * When either endpoint performs a shutdown, the
                 * When either endpoint performs a shutdown, the
                 * association on each peer will stop accepting new
                 * association on each peer will stop accepting new
                 * data from its user and only deliver data in queue
                 * data from its user and only deliver data in queue
                 * at the time of sending or receiving the SHUTDOWN
                 * at the time of sending or receiving the SHUTDOWN
                 * chunk.
                 * chunk.
                 */
                 */
                switch (q->asoc->state) {
                switch (q->asoc->state) {
                case SCTP_STATE_EMPTY:
                case SCTP_STATE_EMPTY:
                case SCTP_STATE_CLOSED:
                case SCTP_STATE_CLOSED:
                case SCTP_STATE_SHUTDOWN_PENDING:
                case SCTP_STATE_SHUTDOWN_PENDING:
                case SCTP_STATE_SHUTDOWN_SENT:
                case SCTP_STATE_SHUTDOWN_SENT:
                case SCTP_STATE_SHUTDOWN_RECEIVED:
                case SCTP_STATE_SHUTDOWN_RECEIVED:
                case SCTP_STATE_SHUTDOWN_ACK_SENT:
                case SCTP_STATE_SHUTDOWN_ACK_SENT:
                        /* Cannot send after transport endpoint shutdown */
                        /* Cannot send after transport endpoint shutdown */
                        error = -ESHUTDOWN;
                        error = -ESHUTDOWN;
                        break;
                        break;
 
 
                default:
                default:
                        SCTP_DEBUG_PRINTK("outqueueing (%p, %p[%s])\n",
                        SCTP_DEBUG_PRINTK("outqueueing (%p, %p[%s])\n",
                          q, chunk, chunk && chunk->chunk_hdr ?
                          q, chunk, chunk && chunk->chunk_hdr ?
                          sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type))
                          sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type))
                          : "Illegal Chunk");
                          : "Illegal Chunk");
 
 
                        sctp_outq_tail_data(q, chunk);
                        sctp_outq_tail_data(q, chunk);
                        if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
                        if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
                                SCTP_INC_STATS(SctpOutUnorderChunks);
                                SCTP_INC_STATS(SctpOutUnorderChunks);
                        else
                        else
                                SCTP_INC_STATS(SctpOutOrderChunks);
                                SCTP_INC_STATS(SctpOutOrderChunks);
                        q->empty = 0;
                        q->empty = 0;
                        break;
                        break;
                };
                };
        } else {
        } else {
                __skb_queue_tail(&q->control, (struct sk_buff *) chunk);
                __skb_queue_tail(&q->control, (struct sk_buff *) chunk);
                SCTP_INC_STATS(SctpOutCtrlChunks);
                SCTP_INC_STATS(SctpOutCtrlChunks);
        }
        }
 
 
        if (error < 0)
        if (error < 0)
                return error;
                return error;
 
 
        if (!q->cork)
        if (!q->cork)
                error = sctp_outq_flush(q, 0);
                error = sctp_outq_flush(q, 0);
 
 
        return error;
        return error;
}
}
 
 
/* Insert a chunk into the retransmit queue.  Chunks on the retransmit
/* Insert a chunk into the retransmit queue.  Chunks on the retransmit
 * queue are kept in order, based on the TSNs.
 * queue are kept in order, based on the TSNs.
 */
 */
void sctp_retransmit_insert(struct list_head *tlchunk, struct sctp_outq *q)
void sctp_retransmit_insert(struct list_head *tlchunk, struct sctp_outq *q)
{
{
        struct list_head *rlchunk;
        struct list_head *rlchunk;
        struct sctp_chunk *tchunk, *rchunk;
        struct sctp_chunk *tchunk, *rchunk;
        __u32 ttsn, rtsn;
        __u32 ttsn, rtsn;
        int done = 0;
        int done = 0;
 
 
        tchunk = list_entry(tlchunk, struct sctp_chunk, transmitted_list);
        tchunk = list_entry(tlchunk, struct sctp_chunk, transmitted_list);
        ttsn = ntohl(tchunk->subh.data_hdr->tsn);
        ttsn = ntohl(tchunk->subh.data_hdr->tsn);
 
 
        list_for_each(rlchunk, &q->retransmit) {
        list_for_each(rlchunk, &q->retransmit) {
                rchunk = list_entry(rlchunk, struct sctp_chunk,
                rchunk = list_entry(rlchunk, struct sctp_chunk,
                                    transmitted_list);
                                    transmitted_list);
                rtsn = ntohl(rchunk->subh.data_hdr->tsn);
                rtsn = ntohl(rchunk->subh.data_hdr->tsn);
                if (TSN_lt(ttsn, rtsn)) {
                if (TSN_lt(ttsn, rtsn)) {
                        list_add(tlchunk, rlchunk->prev);
                        list_add(tlchunk, rlchunk->prev);
                        done = 1;
                        done = 1;
                        break;
                        break;
                }
                }
        }
        }
        if (!done) {
        if (!done) {
                list_add_tail(tlchunk, &q->retransmit);
                list_add_tail(tlchunk, &q->retransmit);
        }
        }
}
}
 
 
/* Mark all the eligible packets on a transport for retransmission.  */
/* Mark all the eligible packets on a transport for retransmission.  */
void sctp_retransmit_mark(struct sctp_outq *q,
void sctp_retransmit_mark(struct sctp_outq *q,
                          struct sctp_transport *transport,
                          struct sctp_transport *transport,
                          __u8 fast_retransmit)
                          __u8 fast_retransmit)
{
{
        struct list_head *lchunk, *ltemp;
        struct list_head *lchunk, *ltemp;
        struct sctp_chunk *chunk;
        struct sctp_chunk *chunk;
 
 
        /* Walk through the specified transmitted queue.  */
        /* Walk through the specified transmitted queue.  */
        list_for_each_safe(lchunk, ltemp, &transport->transmitted) {
        list_for_each_safe(lchunk, ltemp, &transport->transmitted) {
                chunk = list_entry(lchunk, struct sctp_chunk,
                chunk = list_entry(lchunk, struct sctp_chunk,
                                   transmitted_list);
                                   transmitted_list);
 
 
                /* If we are doing retransmission due to a fast retransmit,
                /* If we are doing retransmission due to a fast retransmit,
                 * only the chunk's that are marked for fast retransmit
                 * only the chunk's that are marked for fast retransmit
                 * should be added to the retransmit queue.  If we are doing
                 * should be added to the retransmit queue.  If we are doing
                 * retransmission due to a timeout or pmtu discovery, only the
                 * retransmission due to a timeout or pmtu discovery, only the
                 * chunks that are not yet acked should be added to the
                 * chunks that are not yet acked should be added to the
                 * retransmit queue.
                 * retransmit queue.
                 */
                 */
                if ((fast_retransmit && chunk->fast_retransmit) ||
                if ((fast_retransmit && chunk->fast_retransmit) ||
                   (!fast_retransmit && !chunk->tsn_gap_acked)) {
                   (!fast_retransmit && !chunk->tsn_gap_acked)) {
                        /* RFC 2960 6.2.1 Processing a Received SACK
                        /* RFC 2960 6.2.1 Processing a Received SACK
                         *
                         *
                         * C) Any time a DATA chunk is marked for
                         * C) Any time a DATA chunk is marked for
                         * retransmission (via either T3-rtx timer expiration
                         * retransmission (via either T3-rtx timer expiration
                         * (Section 6.3.3) or via fast retransmit
                         * (Section 6.3.3) or via fast retransmit
                         * (Section 7.2.4)), add the data size of those
                         * (Section 7.2.4)), add the data size of those
                         * chunks to the rwnd.
                         * chunks to the rwnd.
                         */
                         */
                        q->asoc->peer.rwnd += sctp_data_size(chunk);
                        q->asoc->peer.rwnd += sctp_data_size(chunk);
                        q->outstanding_bytes -= sctp_data_size(chunk);
                        q->outstanding_bytes -= sctp_data_size(chunk);
                        transport->flight_size -= sctp_data_size(chunk);
                        transport->flight_size -= sctp_data_size(chunk);
 
 
                        /* sctpimpguide-05 Section 2.8.2
                        /* sctpimpguide-05 Section 2.8.2
                         * M5) If a T3-rtx timer expires, the
                         * M5) If a T3-rtx timer expires, the
                         * 'TSN.Missing.Report' of all affected TSNs is set
                         * 'TSN.Missing.Report' of all affected TSNs is set
                         * to 0.
                         * to 0.
                         */
                         */
                        chunk->tsn_missing_report = 0;
                        chunk->tsn_missing_report = 0;
 
 
                        /* If a chunk that is being used for RTT measurement
                        /* If a chunk that is being used for RTT measurement
                         * has to be retransmitted, we cannot use this chunk
                         * has to be retransmitted, we cannot use this chunk
                         * anymore for RTT measurements. Reset rto_pending so
                         * anymore for RTT measurements. Reset rto_pending so
                         * that a new RTT measurement is started when a new
                         * that a new RTT measurement is started when a new
                         * data chunk is sent.
                         * data chunk is sent.
                         */
                         */
                        if (chunk->rtt_in_progress) {
                        if (chunk->rtt_in_progress) {
                                chunk->rtt_in_progress = 0;
                                chunk->rtt_in_progress = 0;
                                transport->rto_pending = 0;
                                transport->rto_pending = 0;
                        }
                        }
 
 
                        /* Move the chunk to the retransmit queue. The chunks
                        /* Move the chunk to the retransmit queue. The chunks
                         * on the retransmit queue is always kept in order.
                         * on the retransmit queue is always kept in order.
                         */
                         */
                        list_del_init(lchunk);
                        list_del_init(lchunk);
                        sctp_retransmit_insert(lchunk, q);
                        sctp_retransmit_insert(lchunk, q);
                }
                }
        }
        }
 
 
        SCTP_DEBUG_PRINTK("%s: transport: %p, fast_retransmit: %d, "
        SCTP_DEBUG_PRINTK("%s: transport: %p, fast_retransmit: %d, "
                          "cwnd: %d, ssthresh: %d, flight_size: %d, "
                          "cwnd: %d, ssthresh: %d, flight_size: %d, "
                          "pba: %d\n", __FUNCTION__,
                          "pba: %d\n", __FUNCTION__,
                          transport, fast_retransmit,
                          transport, fast_retransmit,
                          transport->cwnd, transport->ssthresh,
                          transport->cwnd, transport->ssthresh,
                          transport->flight_size,
                          transport->flight_size,
                          transport->partial_bytes_acked);
                          transport->partial_bytes_acked);
 
 
}
}
 
 
/* Mark all the eligible packets on a transport for retransmission and force
/* Mark all the eligible packets on a transport for retransmission and force
 * one packet out.
 * one packet out.
 */
 */
void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
                     sctp_retransmit_reason_t reason)
                     sctp_retransmit_reason_t reason)
{
{
        int error = 0;
        int error = 0;
        __u8 fast_retransmit = 0;
        __u8 fast_retransmit = 0;
 
 
        switch(reason) {
        switch(reason) {
        case SCTP_RTXR_T3_RTX:
        case SCTP_RTXR_T3_RTX:
                sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX);
                sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX);
                /* Update the retran path if the T3-rtx timer has expired for
                /* Update the retran path if the T3-rtx timer has expired for
                 * the current retran path.
                 * the current retran path.
                 */
                 */
                if (transport == transport->asoc->peer.retran_path)
                if (transport == transport->asoc->peer.retran_path)
                        sctp_assoc_update_retran_path(transport->asoc);
                        sctp_assoc_update_retran_path(transport->asoc);
                break;
                break;
        case SCTP_RTXR_FAST_RTX:
        case SCTP_RTXR_FAST_RTX:
                sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_FAST_RTX);
                sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_FAST_RTX);
                fast_retransmit = 1;
                fast_retransmit = 1;
                break;
                break;
        case SCTP_RTXR_PMTUD:
        case SCTP_RTXR_PMTUD:
        default:
        default:
                break;
                break;
        }
        }
 
 
        sctp_retransmit_mark(q, transport, fast_retransmit);
        sctp_retransmit_mark(q, transport, fast_retransmit);
 
 
        error = sctp_outq_flush(q, /* rtx_timeout */ 1);
        error = sctp_outq_flush(q, /* rtx_timeout */ 1);
 
 
        if (error)
        if (error)
                q->asoc->base.sk->sk_err = -error;
                q->asoc->base.sk->sk_err = -error;
}
}
 
 
/*
/*
 * Transmit DATA chunks on the retransmit queue.  Upon return from
 * Transmit DATA chunks on the retransmit queue.  Upon return from
 * sctp_outq_flush_rtx() the packet 'pkt' may contain chunks which
 * sctp_outq_flush_rtx() the packet 'pkt' may contain chunks which
 * need to be transmitted by the caller.
 * need to be transmitted by the caller.
 * We assume that pkt->transport has already been set.
 * We assume that pkt->transport has already been set.
 *
 *
 * The return value is a normal kernel error return value.
 * The return value is a normal kernel error return value.
 */
 */
static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
                               int rtx_timeout, int *start_timer)
                               int rtx_timeout, int *start_timer)
{
{
        struct list_head *lqueue;
        struct list_head *lqueue;
        struct list_head *lchunk;
        struct list_head *lchunk;
        struct sctp_transport *transport = pkt->transport;
        struct sctp_transport *transport = pkt->transport;
        sctp_xmit_t status;
        sctp_xmit_t status;
        struct sctp_chunk *chunk;
        struct sctp_chunk *chunk;
        struct sctp_association *asoc;
        struct sctp_association *asoc;
        int error = 0;
        int error = 0;
 
 
        asoc = q->asoc;
        asoc = q->asoc;
        lqueue = &q->retransmit;
        lqueue = &q->retransmit;
 
 
        /* RFC 2960 6.3.3 Handle T3-rtx Expiration
        /* RFC 2960 6.3.3 Handle T3-rtx Expiration
         *
         *
         * E3) Determine how many of the earliest (i.e., lowest TSN)
         * E3) Determine how many of the earliest (i.e., lowest TSN)
         * outstanding DATA chunks for the address for which the
         * outstanding DATA chunks for the address for which the
         * T3-rtx has expired will fit into a single packet, subject
         * T3-rtx has expired will fit into a single packet, subject
         * to the MTU constraint for the path corresponding to the
         * to the MTU constraint for the path corresponding to the
         * destination transport address to which the retransmission
         * destination transport address to which the retransmission
         * is being sent (this may be different from the address for
         * is being sent (this may be different from the address for
         * which the timer expires [see Section 6.4]). Call this value
         * which the timer expires [see Section 6.4]). Call this value
         * K. Bundle and retransmit those K DATA chunks in a single
         * K. Bundle and retransmit those K DATA chunks in a single
         * packet to the destination endpoint.
         * packet to the destination endpoint.
         *
         *
         * [Just to be painfully clear, if we are retransmitting
         * [Just to be painfully clear, if we are retransmitting
         * because a timeout just happened, we should send only ONE
         * because a timeout just happened, we should send only ONE
         * packet of retransmitted data.]
         * packet of retransmitted data.]
         */
         */
        lchunk = sctp_list_dequeue(lqueue);
        lchunk = sctp_list_dequeue(lqueue);
 
 
        while (lchunk) {
        while (lchunk) {
                chunk = list_entry(lchunk, struct sctp_chunk,
                chunk = list_entry(lchunk, struct sctp_chunk,
                                   transmitted_list);
                                   transmitted_list);
 
 
                /* Make sure that Gap Acked TSNs are not retransmitted.  A
                /* Make sure that Gap Acked TSNs are not retransmitted.  A
                 * simple approach is just to move such TSNs out of the
                 * simple approach is just to move such TSNs out of the
                 * way and into a 'transmitted' queue and skip to the
                 * way and into a 'transmitted' queue and skip to the
                 * next chunk.
                 * next chunk.
                 */
                 */
                if (chunk->tsn_gap_acked) {
                if (chunk->tsn_gap_acked) {
                        list_add_tail(lchunk, &transport->transmitted);
                        list_add_tail(lchunk, &transport->transmitted);
                        lchunk = sctp_list_dequeue(lqueue);
                        lchunk = sctp_list_dequeue(lqueue);
                        continue;
                        continue;
                }
                }
 
 
                /* Attempt to append this chunk to the packet. */
                /* Attempt to append this chunk to the packet. */
                status = (*q->append_output)(pkt, chunk);
                status = (*q->append_output)(pkt, chunk);
 
 
                switch (status) {
                switch (status) {
                case SCTP_XMIT_PMTU_FULL:
                case SCTP_XMIT_PMTU_FULL:
                        /* Send this packet.  */
                        /* Send this packet.  */
                        if ((error = (*q->force_output)(pkt)) == 0)
                        if ((error = (*q->force_output)(pkt)) == 0)
                                *start_timer = 1;
                                *start_timer = 1;
 
 
                        /* If we are retransmitting, we should only
                        /* If we are retransmitting, we should only
                         * send a single packet.
                         * send a single packet.
                         */
                         */
                        if (rtx_timeout) {
                        if (rtx_timeout) {
                                list_add(lchunk, lqueue);
                                list_add(lchunk, lqueue);
                                lchunk = NULL;
                                lchunk = NULL;
                        }
                        }
 
 
                        /* Bundle lchunk in the next round.  */
                        /* Bundle lchunk in the next round.  */
                        break;
                        break;
 
 
                case SCTP_XMIT_RWND_FULL:
                case SCTP_XMIT_RWND_FULL:
                        /* Send this packet. */
                        /* Send this packet. */
                        if ((error = (*q->force_output)(pkt)) == 0)
                        if ((error = (*q->force_output)(pkt)) == 0)
                                *start_timer = 1;
                                *start_timer = 1;
 
 
                        /* Stop sending DATA as there is no more room
                        /* Stop sending DATA as there is no more room
                         * at the receiver.
                         * at the receiver.
                         */
                         */
                        list_add(lchunk, lqueue);
                        list_add(lchunk, lqueue);
                        lchunk = NULL;
                        lchunk = NULL;
                        break;
                        break;
 
 
                default:
                default:
                        /* The append was successful, so add this chunk to
                        /* The append was successful, so add this chunk to
                         * the transmitted list.
                         * the transmitted list.
                         */
                         */
                        list_add_tail(lchunk, &transport->transmitted);
                        list_add_tail(lchunk, &transport->transmitted);
                        *start_timer = 1;
                        *start_timer = 1;
                        q->empty = 0;
                        q->empty = 0;
 
 
                        /* Retrieve a new chunk to bundle. */
                        /* Retrieve a new chunk to bundle. */
                        lchunk = sctp_list_dequeue(lqueue);
                        lchunk = sctp_list_dequeue(lqueue);
                        break;
                        break;
                };
                };
        }
        }
 
 
        return error;
        return error;
}
}
 
 
/* Cork the outqueue so queued chunks are really queued. */
/* Cork the outqueue so queued chunks are really queued. */
int sctp_outq_uncork(struct sctp_outq *q)
int sctp_outq_uncork(struct sctp_outq *q)
{
{
        int error = 0;
        int error = 0;
        if (q->cork) {
        if (q->cork) {
                q->cork = 0;
                q->cork = 0;
                error = sctp_outq_flush(q, 0);
                error = sctp_outq_flush(q, 0);
        }
        }
        return error;
        return error;
}
}
 
 
/*
/*
 * Try to flush an outqueue.
 * Try to flush an outqueue.
 *
 *
 * Description: Send everything in q which we legally can, subject to
 * Description: Send everything in q which we legally can, subject to
 * congestion limitations.
 * congestion limitations.
 * * Note: This function can be called from multiple contexts so appropriate
 * * Note: This function can be called from multiple contexts so appropriate
 * locking concerns must be made.  Today we use the sock lock to protect
 * locking concerns must be made.  Today we use the sock lock to protect
 * this function.
 * this function.
 */
 */
int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
{
{
        struct sctp_packet *packet;
        struct sctp_packet *packet;
        struct sctp_packet singleton;
        struct sctp_packet singleton;
        struct sctp_association *asoc = q->asoc;
        struct sctp_association *asoc = q->asoc;
        int ecn_capable = asoc->peer.ecn_capable;
        int ecn_capable = asoc->peer.ecn_capable;
        __u16 sport = asoc->base.bind_addr.port;
        __u16 sport = asoc->base.bind_addr.port;
        __u16 dport = asoc->peer.port;
        __u16 dport = asoc->peer.port;
        __u32 vtag = asoc->peer.i.init_tag;
        __u32 vtag = asoc->peer.i.init_tag;
        /* This is the ECNE handler for singleton packets.  */
        /* This is the ECNE handler for singleton packets.  */
        sctp_packet_phandler_t *s_ecne_handler = NULL;
        sctp_packet_phandler_t *s_ecne_handler = NULL;
        sctp_packet_phandler_t *ecne_handler = NULL;
        sctp_packet_phandler_t *ecne_handler = NULL;
        struct sk_buff_head *queue;
        struct sk_buff_head *queue;
        struct sctp_transport *transport = NULL;
        struct sctp_transport *transport = NULL;
        struct sctp_transport *new_transport;
        struct sctp_transport *new_transport;
        struct sctp_chunk *chunk;
        struct sctp_chunk *chunk;
        sctp_xmit_t status;
        sctp_xmit_t status;
        int error = 0;
        int error = 0;
        int start_timer = 0;
        int start_timer = 0;
 
 
        /* These transports have chunks to send. */
        /* These transports have chunks to send. */
        struct list_head transport_list;
        struct list_head transport_list;
        struct list_head *ltransport;
        struct list_head *ltransport;
 
 
        INIT_LIST_HEAD(&transport_list);
        INIT_LIST_HEAD(&transport_list);
        packet = NULL;
        packet = NULL;
 
 
        /*
        /*
         * 6.10 Bundling
         * 6.10 Bundling
         *   ...
         *   ...
         *   When bundling control chunks with DATA chunks, an
         *   When bundling control chunks with DATA chunks, an
         *   endpoint MUST place control chunks first in the outbound
         *   endpoint MUST place control chunks first in the outbound
         *   SCTP packet.  The transmitter MUST transmit DATA chunks
         *   SCTP packet.  The transmitter MUST transmit DATA chunks
         *   within a SCTP packet in increasing order of TSN.
         *   within a SCTP packet in increasing order of TSN.
         *   ...
         *   ...
         */
         */
        if (ecn_capable) {
        if (ecn_capable) {
                s_ecne_handler = &sctp_get_no_prepend;
                s_ecne_handler = &sctp_get_no_prepend;
                ecne_handler = &sctp_get_ecne_prepend;
                ecne_handler = &sctp_get_ecne_prepend;
        }
        }
 
 
        queue = &q->control;
        queue = &q->control;
        while ((chunk = (struct sctp_chunk *)skb_dequeue(queue))) {
        while ((chunk = (struct sctp_chunk *)skb_dequeue(queue))) {
                /* Pick the right transport to use. */
                /* Pick the right transport to use. */
                new_transport = chunk->transport;
                new_transport = chunk->transport;
 
 
                if (!new_transport) {
                if (!new_transport) {
                        new_transport = asoc->peer.active_path;
                        new_transport = asoc->peer.active_path;
                } else if (!new_transport->active) {
                } else if (!new_transport->active) {
                        /* If the chunk is Heartbeat, send it to
                        /* If the chunk is Heartbeat, send it to
                         * chunk->transport, even it's inactive.
                         * chunk->transport, even it's inactive.
                         */
                         */
                        if (chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT)
                        if (chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT)
                                new_transport = asoc->peer.active_path;
                                new_transport = asoc->peer.active_path;
                }
                }
 
 
                /* Are we switching transports?
                /* Are we switching transports?
                 * Take care of transport locks.
                 * Take care of transport locks.
                 */
                 */
                if (new_transport != transport) {
                if (new_transport != transport) {
                        transport = new_transport;
                        transport = new_transport;
                        if (list_empty(&transport->send_ready)) {
                        if (list_empty(&transport->send_ready)) {
                                list_add_tail(&transport->send_ready,
                                list_add_tail(&transport->send_ready,
                                              &transport_list);
                                              &transport_list);
                        }
                        }
                        packet = &transport->packet;
                        packet = &transport->packet;
                        (*q->config_output)(packet, vtag,
                        (*q->config_output)(packet, vtag,
                                            ecn_capable, ecne_handler);
                                            ecn_capable, ecne_handler);
                }
                }
 
 
                switch (chunk->chunk_hdr->type) {
                switch (chunk->chunk_hdr->type) {
                /*
                /*
                 * 6.10 Bundling
                 * 6.10 Bundling
                 *   ...
                 *   ...
                 *   An endpoint MUST NOT bundle INIT, INIT ACK or SHUTDOWN
                 *   An endpoint MUST NOT bundle INIT, INIT ACK or SHUTDOWN
                 *   COMPLETE with any other chunks.  [Send them immediately.]
                 *   COMPLETE with any other chunks.  [Send them immediately.]
                 */
                 */
                case SCTP_CID_INIT:
                case SCTP_CID_INIT:
                case SCTP_CID_INIT_ACK:
                case SCTP_CID_INIT_ACK:
                case SCTP_CID_SHUTDOWN_COMPLETE:
                case SCTP_CID_SHUTDOWN_COMPLETE:
                        (*q->init_output)(&singleton, transport, sport, dport);
                        (*q->init_output)(&singleton, transport, sport, dport);
                        (*q->config_output)(&singleton, vtag, ecn_capable,
                        (*q->config_output)(&singleton, vtag, ecn_capable,
                                            s_ecne_handler);
                                            s_ecne_handler);
                        (void) (*q->build_output)(&singleton, chunk);
                        (void) (*q->build_output)(&singleton, chunk);
                        error = (*q->force_output)(&singleton);
                        error = (*q->force_output)(&singleton);
                        if (error < 0)
                        if (error < 0)
                                return error;
                                return error;
                        break;
                        break;
 
 
                case SCTP_CID_ABORT:
                case SCTP_CID_ABORT:
                case SCTP_CID_SACK:
                case SCTP_CID_SACK:
                case SCTP_CID_HEARTBEAT:
                case SCTP_CID_HEARTBEAT:
                case SCTP_CID_HEARTBEAT_ACK:
                case SCTP_CID_HEARTBEAT_ACK:
                case SCTP_CID_SHUTDOWN:
                case SCTP_CID_SHUTDOWN:
                case SCTP_CID_SHUTDOWN_ACK:
                case SCTP_CID_SHUTDOWN_ACK:
                case SCTP_CID_ERROR:
                case SCTP_CID_ERROR:
                case SCTP_CID_COOKIE_ECHO:
                case SCTP_CID_COOKIE_ECHO:
                case SCTP_CID_COOKIE_ACK:
                case SCTP_CID_COOKIE_ACK:
                case SCTP_CID_ECN_ECNE:
                case SCTP_CID_ECN_ECNE:
                case SCTP_CID_ECN_CWR:
                case SCTP_CID_ECN_CWR:
                        (void) (*q->build_output)(packet, chunk);
                        (void) (*q->build_output)(packet, chunk);
                        break;
                        break;
 
 
                case SCTP_CID_ASCONF:
                case SCTP_CID_ASCONF:
                case SCTP_CID_ASCONF_ACK:
                case SCTP_CID_ASCONF_ACK:
                        (void) (*q->build_output)(packet, chunk);
                        (void) (*q->build_output)(packet, chunk);
                        break;
                        break;
 
 
                default:
                default:
                        /* We built a chunk with an illegal type! */
                        /* We built a chunk with an illegal type! */
                        BUG();
                        BUG();
                };
                };
        }
        }
 
 
        /* Is it OK to send data chunks?  */
        /* Is it OK to send data chunks?  */
        switch (asoc->state) {
        switch (asoc->state) {
        case SCTP_STATE_COOKIE_ECHOED:
        case SCTP_STATE_COOKIE_ECHOED:
                /* Only allow bundling when this packet has a COOKIE-ECHO
                /* Only allow bundling when this packet has a COOKIE-ECHO
                 * chunk.
                 * chunk.
                 */
                 */
                if (!packet || !packet->has_cookie_echo)
                if (!packet || !packet->has_cookie_echo)
                        break;
                        break;
 
 
                /* fallthru */
                /* fallthru */
        case SCTP_STATE_ESTABLISHED:
        case SCTP_STATE_ESTABLISHED:
        case SCTP_STATE_SHUTDOWN_PENDING:
        case SCTP_STATE_SHUTDOWN_PENDING:
        case SCTP_STATE_SHUTDOWN_RECEIVED:
        case SCTP_STATE_SHUTDOWN_RECEIVED:
                /*
                /*
                 * RFC 2960 6.1  Transmission of DATA Chunks
                 * RFC 2960 6.1  Transmission of DATA Chunks
                 *
                 *
                 * C) When the time comes for the sender to transmit,
                 * C) When the time comes for the sender to transmit,
                 * before sending new DATA chunks, the sender MUST
                 * before sending new DATA chunks, the sender MUST
                 * first transmit any outstanding DATA chunks which
                 * first transmit any outstanding DATA chunks which
                 * are marked for retransmission (limited by the
                 * are marked for retransmission (limited by the
                 * current cwnd).
                 * current cwnd).
                 */
                 */
                if (!list_empty(&q->retransmit)) {
                if (!list_empty(&q->retransmit)) {
                        if (transport == asoc->peer.retran_path)
                        if (transport == asoc->peer.retran_path)
                                goto retran;
                                goto retran;
 
 
                        /* Switch transports & prepare the packet.  */
                        /* Switch transports & prepare the packet.  */
 
 
                        transport = asoc->peer.retran_path;
                        transport = asoc->peer.retran_path;
 
 
                        if (list_empty(&transport->send_ready)) {
                        if (list_empty(&transport->send_ready)) {
                                list_add_tail(&transport->send_ready,
                                list_add_tail(&transport->send_ready,
                                              &transport_list);
                                              &transport_list);
                        }
                        }
 
 
                        packet = &transport->packet;
                        packet = &transport->packet;
                        (*q->config_output)(packet, vtag,
                        (*q->config_output)(packet, vtag,
                                            ecn_capable, ecne_handler);
                                            ecn_capable, ecne_handler);
                retran:
                retran:
                        error = sctp_outq_flush_rtx(q, packet,
                        error = sctp_outq_flush_rtx(q, packet,
                                                    rtx_timeout, &start_timer);
                                                    rtx_timeout, &start_timer);
 
 
                        if (start_timer)
                        if (start_timer)
                                sctp_transport_reset_timers(transport);
                                sctp_transport_reset_timers(transport);
 
 
                        /* This can happen on COOKIE-ECHO resend.  Only
                        /* This can happen on COOKIE-ECHO resend.  Only
                         * one chunk can get bundled with a COOKIE-ECHO.
                         * one chunk can get bundled with a COOKIE-ECHO.
                         */
                         */
                        if (packet->has_cookie_echo)
                        if (packet->has_cookie_echo)
                                goto sctp_flush_out;
                                goto sctp_flush_out;
 
 
                        /* Don't send new data if there is still data
                        /* Don't send new data if there is still data
                         * waiting to retransmit.
                         * waiting to retransmit.
                         */
                         */
                        if (!list_empty(&q->retransmit))
                        if (!list_empty(&q->retransmit))
                                goto sctp_flush_out;
                                goto sctp_flush_out;
                }
                }
 
 
                /* Finally, transmit new packets.  */
                /* Finally, transmit new packets.  */
                start_timer = 0;
                start_timer = 0;
                queue = &q->out;
                queue = &q->out;
 
 
                while ((chunk = sctp_outq_dequeue_data(q))) {
                while ((chunk = sctp_outq_dequeue_data(q))) {
                        /* RFC 2960 6.5 Every DATA chunk MUST carry a valid
                        /* RFC 2960 6.5 Every DATA chunk MUST carry a valid
                         * stream identifier.
                         * stream identifier.
                         */
                         */
                        if (chunk->sinfo.sinfo_stream >=
                        if (chunk->sinfo.sinfo_stream >=
                            asoc->c.sinit_num_ostreams) {
                            asoc->c.sinit_num_ostreams) {
 
 
                                /* Mark as s failed send. */
                                /* Mark as s failed send. */
                                sctp_datamsg_fail(chunk, SCTP_ERROR_INV_STRM);
                                sctp_datamsg_fail(chunk, SCTP_ERROR_INV_STRM);
                                sctp_chunk_free(chunk);
                                sctp_chunk_free(chunk);
                                continue;
                                continue;
                        }
                        }
 
 
                        /* Has this chunk expired? */
                        /* Has this chunk expired? */
                        if (sctp_datamsg_expires(chunk)) {
                        if (sctp_datamsg_expires(chunk)) {
                                sctp_datamsg_fail(chunk, 0);
                                sctp_datamsg_fail(chunk, 0);
                                sctp_chunk_free(chunk);
                                sctp_chunk_free(chunk);
                                continue;
                                continue;
                        }
                        }
 
 
                        /* If there is a specified transport, use it.
                        /* If there is a specified transport, use it.
                         * Otherwise, we want to use the active path.
                         * Otherwise, we want to use the active path.
                         */
                         */
                        new_transport = chunk->transport;
                        new_transport = chunk->transport;
                        if (!new_transport || !new_transport->active)
                        if (!new_transport || !new_transport->active)
                                new_transport = asoc->peer.active_path;
                                new_transport = asoc->peer.active_path;
 
 
                        /* Change packets if necessary.  */
                        /* Change packets if necessary.  */
                        if (new_transport != transport) {
                        if (new_transport != transport) {
                                transport = new_transport;
                                transport = new_transport;
 
 
                                /* Schedule to have this transport's
                                /* Schedule to have this transport's
                                 * packet flushed.
                                 * packet flushed.
                                 */
                                 */
                                if (list_empty(&transport->send_ready)) {
                                if (list_empty(&transport->send_ready)) {
                                        list_add_tail(&transport->send_ready,
                                        list_add_tail(&transport->send_ready,
                                                      &transport_list);
                                                      &transport_list);
                                }
                                }
 
 
                                packet = &transport->packet;
                                packet = &transport->packet;
                                (*q->config_output)(packet, vtag,
                                (*q->config_output)(packet, vtag,
                                                    ecn_capable, ecne_handler);
                                                    ecn_capable, ecne_handler);
                        }
                        }
 
 
                        SCTP_DEBUG_PRINTK("sctp_transmit_packet(%p, %p[%s]), ",
                        SCTP_DEBUG_PRINTK("sctp_transmit_packet(%p, %p[%s]), ",
                                          q, chunk,
                                          q, chunk,
                                          chunk && chunk->chunk_hdr ?
                                          chunk && chunk->chunk_hdr ?
                                          sctp_cname(SCTP_ST_CHUNK(
                                          sctp_cname(SCTP_ST_CHUNK(
                                                  chunk->chunk_hdr->type))
                                                  chunk->chunk_hdr->type))
                                          : "Illegal Chunk");
                                          : "Illegal Chunk");
 
 
                        SCTP_DEBUG_PRINTK("TX TSN 0x%x skb->head "
                        SCTP_DEBUG_PRINTK("TX TSN 0x%x skb->head "
                                        "%p skb->users %d.\n",
                                        "%p skb->users %d.\n",
                                        ntohl(chunk->subh.data_hdr->tsn),
                                        ntohl(chunk->subh.data_hdr->tsn),
                                        chunk->skb ?chunk->skb->head : 0,
                                        chunk->skb ?chunk->skb->head : 0,
                                        chunk->skb ?
                                        chunk->skb ?
                                        atomic_read(&chunk->skb->users) : -1);
                                        atomic_read(&chunk->skb->users) : -1);
 
 
                        /* Add the chunk to the packet.  */
                        /* Add the chunk to the packet.  */
                        status = (*q->build_output)(packet, chunk);
                        status = (*q->build_output)(packet, chunk);
 
 
                        switch (status) {
                        switch (status) {
                        case SCTP_XMIT_PMTU_FULL:
                        case SCTP_XMIT_PMTU_FULL:
                        case SCTP_XMIT_RWND_FULL:
                        case SCTP_XMIT_RWND_FULL:
                        case SCTP_XMIT_NAGLE_DELAY:
                        case SCTP_XMIT_NAGLE_DELAY:
                                /* We could not append this chunk, so put
                                /* We could not append this chunk, so put
                                 * the chunk back on the output queue.
                                 * the chunk back on the output queue.
                                 */
                                 */
                                SCTP_DEBUG_PRINTK("sctp_outq_flush: could "
                                SCTP_DEBUG_PRINTK("sctp_outq_flush: could "
                                        "not transmit TSN: 0x%x, status: %d\n",
                                        "not transmit TSN: 0x%x, status: %d\n",
                                        ntohl(chunk->subh.data_hdr->tsn),
                                        ntohl(chunk->subh.data_hdr->tsn),
                                        status);
                                        status);
                                sctp_outq_head_data(q, chunk);
                                sctp_outq_head_data(q, chunk);
                                goto sctp_flush_out;
                                goto sctp_flush_out;
                                break;
                                break;
 
 
                        case SCTP_XMIT_OK:
                        case SCTP_XMIT_OK:
                                break;
                                break;
 
 
                        default:
                        default:
                                BUG();
                                BUG();
                        }
                        }
 
 
                        /* BUG: We assume that the (*q->force_output())
                        /* BUG: We assume that the (*q->force_output())
                         * call below will succeed all the time and add the
                         * call below will succeed all the time and add the
                         * chunk to the transmitted list and restart the
                         * chunk to the transmitted list and restart the
                         * timers.
                         * timers.
                         * It is possible that the call can fail under OOM
                         * It is possible that the call can fail under OOM
                         * conditions.
                         * conditions.
                         *
                         *
                         * Is this really a problem?  Won't this behave
                         * Is this really a problem?  Won't this behave
                         * like a lost TSN?
                         * like a lost TSN?
                         */
                         */
                        list_add_tail(&chunk->transmitted_list,
                        list_add_tail(&chunk->transmitted_list,
                                      &transport->transmitted);
                                      &transport->transmitted);
 
 
                        sctp_transport_reset_timers(transport);
                        sctp_transport_reset_timers(transport);
 
 
                        q->empty = 0;
                        q->empty = 0;
 
 
                        /* Only let one DATA chunk get bundled with a
                        /* Only let one DATA chunk get bundled with a
                         * COOKIE-ECHO chunk.
                         * COOKIE-ECHO chunk.
                         */
                         */
                        if (packet->has_cookie_echo)
                        if (packet->has_cookie_echo)
                                goto sctp_flush_out;
                                goto sctp_flush_out;
                }
                }
                break;
                break;
 
 
        default:
        default:
                /* Do nothing.  */
                /* Do nothing.  */
                break;
                break;
        }
        }
 
 
sctp_flush_out:
sctp_flush_out:
 
 
        /* Before returning, examine all the transports touched in
        /* Before returning, examine all the transports touched in
         * this call.  Right now, we bluntly force clear all the
         * this call.  Right now, we bluntly force clear all the
         * transports.  Things might change after we implement Nagle.
         * transports.  Things might change after we implement Nagle.
         * But such an examination is still required.
         * But such an examination is still required.
         *
         *
         * --xguo
         * --xguo
         */
         */
        while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL ) {
        while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL ) {
                struct sctp_transport *t = list_entry(ltransport,
                struct sctp_transport *t = list_entry(ltransport,
                                                      struct sctp_transport,
                                                      struct sctp_transport,
                                                      send_ready);
                                                      send_ready);
                if (t != transport)
                if (t != transport)
                        transport = t;
                        transport = t;
 
 
                packet = &transport->packet;
                packet = &transport->packet;
                if (packet->size != SCTP_IP_OVERHEAD)
                if (packet->size != SCTP_IP_OVERHEAD)
                        error = (*q->force_output)(packet);
                        error = (*q->force_output)(packet);
        }
        }
 
 
        return error;
        return error;
}
}
 
 
/* Set the various output handling callbacks.  */
/* Set the various output handling callbacks.  */
int sctp_outq_set_output_handlers(struct sctp_outq *q,
int sctp_outq_set_output_handlers(struct sctp_outq *q,
                                      sctp_outq_ohandler_init_t init,
                                      sctp_outq_ohandler_init_t init,
                                      sctp_outq_ohandler_config_t config,
                                      sctp_outq_ohandler_config_t config,
                                      sctp_outq_ohandler_t append,
                                      sctp_outq_ohandler_t append,
                                      sctp_outq_ohandler_t build,
                                      sctp_outq_ohandler_t build,
                                      sctp_outq_ohandler_force_t force)
                                      sctp_outq_ohandler_force_t force)
{
{
        q->init_output = init;
        q->init_output = init;
        q->config_output = config;
        q->config_output = config;
        q->append_output = append;
        q->append_output = append;
        q->build_output = build;
        q->build_output = build;
        q->force_output = force;
        q->force_output = force;
        return 0;
        return 0;
}
}
 
 
/* Update unack_data based on the incoming SACK chunk */
/* Update unack_data based on the incoming SACK chunk */
static void sctp_sack_update_unack_data(struct sctp_association *assoc,
static void sctp_sack_update_unack_data(struct sctp_association *assoc,
                                        struct sctp_sackhdr *sack)
                                        struct sctp_sackhdr *sack)
{
{
        sctp_sack_variable_t *frags;
        sctp_sack_variable_t *frags;
        __u16 unack_data;
        __u16 unack_data;
        int i;
        int i;
 
 
        unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1;
        unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1;
 
 
        frags = sack->variable;
        frags = sack->variable;
        for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
        for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
                unack_data -= ((ntohs(frags[i].gab.end) -
                unack_data -= ((ntohs(frags[i].gab.end) -
                                ntohs(frags[i].gab.start) + 1));
                                ntohs(frags[i].gab.start) + 1));
        }
        }
 
 
        assoc->unack_data = unack_data;
        assoc->unack_data = unack_data;
}
}
 
 
/* Return the highest new tsn that is acknowledged by the given SACK chunk. */
/* Return the highest new tsn that is acknowledged by the given SACK chunk. */
static __u32 sctp_highest_new_tsn(struct sctp_sackhdr *sack,
static __u32 sctp_highest_new_tsn(struct sctp_sackhdr *sack,
                                  struct sctp_association *asoc)
                                  struct sctp_association *asoc)
{
{
        struct list_head *ltransport, *lchunk;
        struct list_head *ltransport, *lchunk;
        struct sctp_transport *transport;
        struct sctp_transport *transport;
        struct sctp_chunk *chunk;
        struct sctp_chunk *chunk;
        __u32 highest_new_tsn, tsn;
        __u32 highest_new_tsn, tsn;
        struct list_head *transport_list = &asoc->peer.transport_addr_list;
        struct list_head *transport_list = &asoc->peer.transport_addr_list;
 
 
        highest_new_tsn = ntohl(sack->cum_tsn_ack);
        highest_new_tsn = ntohl(sack->cum_tsn_ack);
 
 
        list_for_each(ltransport, transport_list) {
        list_for_each(ltransport, transport_list) {
                transport = list_entry(ltransport, struct sctp_transport,
                transport = list_entry(ltransport, struct sctp_transport,
                                       transports);
                                       transports);
                list_for_each(lchunk, &transport->transmitted) {
                list_for_each(lchunk, &transport->transmitted) {
                        chunk = list_entry(lchunk, struct sctp_chunk,
                        chunk = list_entry(lchunk, struct sctp_chunk,
                                           transmitted_list);
                                           transmitted_list);
                        tsn = ntohl(chunk->subh.data_hdr->tsn);
                        tsn = ntohl(chunk->subh.data_hdr->tsn);
 
 
                        if (!chunk->tsn_gap_acked &&
                        if (!chunk->tsn_gap_acked &&
                            TSN_lt(highest_new_tsn, tsn) &&
                            TSN_lt(highest_new_tsn, tsn) &&
                            sctp_acked(sack, tsn))
                            sctp_acked(sack, tsn))
                                highest_new_tsn = tsn;
                                highest_new_tsn = tsn;
                }
                }
        }
        }
 
 
        return highest_new_tsn;
        return highest_new_tsn;
}
}
 
 
/* This is where we REALLY process a SACK.
/* This is where we REALLY process a SACK.
 *
 *
 * Process the SACK against the outqueue.  Mostly, this just frees
 * Process the SACK against the outqueue.  Mostly, this just frees
 * things off the transmitted queue.
 * things off the transmitted queue.
 */
 */
int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
{
{
        struct sctp_association *asoc = q->asoc;
        struct sctp_association *asoc = q->asoc;
        struct sctp_transport *transport;
        struct sctp_transport *transport;
        struct sctp_chunk *tchunk;
        struct sctp_chunk *tchunk;
        struct list_head *lchunk, *transport_list, *pos, *temp;
        struct list_head *lchunk, *transport_list, *pos, *temp;
        sctp_sack_variable_t *frags = sack->variable;
        sctp_sack_variable_t *frags = sack->variable;
        __u32 sack_ctsn, ctsn, tsn;
        __u32 sack_ctsn, ctsn, tsn;
        __u32 highest_tsn, highest_new_tsn;
        __u32 highest_tsn, highest_new_tsn;
        __u32 sack_a_rwnd;
        __u32 sack_a_rwnd;
        unsigned outstanding;
        unsigned outstanding;
        struct sctp_transport *primary = asoc->peer.primary_path;
        struct sctp_transport *primary = asoc->peer.primary_path;
        int count_of_newacks = 0;
        int count_of_newacks = 0;
 
 
        /* Grab the association's destination address list. */
        /* Grab the association's destination address list. */
        transport_list = &asoc->peer.transport_addr_list;
        transport_list = &asoc->peer.transport_addr_list;
 
 
        sack_ctsn = ntohl(sack->cum_tsn_ack);
        sack_ctsn = ntohl(sack->cum_tsn_ack);
 
 
        /*
        /*
         * SFR-CACC algorithm:
         * SFR-CACC algorithm:
         * On receipt of a SACK the sender SHOULD execute the
         * On receipt of a SACK the sender SHOULD execute the
         * following statements.
         * following statements.
         *
         *
         * 1) If the cumulative ack in the SACK passes next tsn_at_change
         * 1) If the cumulative ack in the SACK passes next tsn_at_change
         * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be
         * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be
         * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for
         * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for
         * all destinations.
         * all destinations.
         */
         */
        if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) {
        if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) {
                primary->cacc.changeover_active = 0;
                primary->cacc.changeover_active = 0;
                list_for_each(pos, transport_list) {
                list_for_each(pos, transport_list) {
                        transport = list_entry(pos, struct sctp_transport,
                        transport = list_entry(pos, struct sctp_transport,
                                        transports);
                                        transports);
                        transport->cacc.cycling_changeover = 0;
                        transport->cacc.cycling_changeover = 0;
                }
                }
        }
        }
 
 
        /*
        /*
         * SFR-CACC algorithm:
         * SFR-CACC algorithm:
         * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE
         * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE
         * is set the receiver of the SACK MUST take the following actions:
         * is set the receiver of the SACK MUST take the following actions:
         *
         *
         * A) Initialize the cacc_saw_newack to 0 for all destination
         * A) Initialize the cacc_saw_newack to 0 for all destination
         * addresses.
         * addresses.
         */
         */
        if (sack->num_gap_ack_blocks > 0 &&
        if (sack->num_gap_ack_blocks > 0 &&
            primary->cacc.changeover_active) {
            primary->cacc.changeover_active) {
                list_for_each(pos, transport_list) {
                list_for_each(pos, transport_list) {
                        transport = list_entry(pos, struct sctp_transport,
                        transport = list_entry(pos, struct sctp_transport,
                                        transports);
                                        transports);
                        transport->cacc.cacc_saw_newack = 0;
                        transport->cacc.cacc_saw_newack = 0;
                }
                }
        }
        }
 
 
        /* Get the highest TSN in the sack. */
        /* Get the highest TSN in the sack. */
        highest_tsn = sack_ctsn +
        highest_tsn = sack_ctsn +
                ntohs(frags[ntohs(sack->num_gap_ack_blocks) - 1].gab.end);
                ntohs(frags[ntohs(sack->num_gap_ack_blocks) - 1].gab.end);
 
 
        if (TSN_lt(asoc->highest_sacked, highest_tsn)) {
        if (TSN_lt(asoc->highest_sacked, highest_tsn)) {
                highest_new_tsn = highest_tsn;
                highest_new_tsn = highest_tsn;
                asoc->highest_sacked = highest_tsn;
                asoc->highest_sacked = highest_tsn;
        } else {
        } else {
                highest_new_tsn = sctp_highest_new_tsn(sack, asoc);
                highest_new_tsn = sctp_highest_new_tsn(sack, asoc);
        }
        }
 
 
        /* Run through the retransmit queue.  Credit bytes received
        /* Run through the retransmit queue.  Credit bytes received
         * and free those chunks that we can.
         * and free those chunks that we can.
         */
         */
        sctp_check_transmitted(q, &q->retransmit, NULL, sack, highest_new_tsn);
        sctp_check_transmitted(q, &q->retransmit, NULL, sack, highest_new_tsn);
        sctp_mark_missing(q, &q->retransmit, NULL, highest_new_tsn, 0);
        sctp_mark_missing(q, &q->retransmit, NULL, highest_new_tsn, 0);
 
 
        /* Run through the transmitted queue.
        /* Run through the transmitted queue.
         * Credit bytes received and free those chunks which we can.
         * Credit bytes received and free those chunks which we can.
         *
         *
         * This is a MASSIVE candidate for optimization.
         * This is a MASSIVE candidate for optimization.
         */
         */
        list_for_each(pos, transport_list) {
        list_for_each(pos, transport_list) {
                transport  = list_entry(pos, struct sctp_transport,
                transport  = list_entry(pos, struct sctp_transport,
                                        transports);
                                        transports);
                sctp_check_transmitted(q, &transport->transmitted,
                sctp_check_transmitted(q, &transport->transmitted,
                                       transport, sack, highest_new_tsn);
                                       transport, sack, highest_new_tsn);
                /*
                /*
                 * SFR-CACC algorithm:
                 * SFR-CACC algorithm:
                 * C) Let count_of_newacks be the number of
                 * C) Let count_of_newacks be the number of
                 * destinations for which cacc_saw_newack is set.
                 * destinations for which cacc_saw_newack is set.
                 */
                 */
                if (transport->cacc.cacc_saw_newack)
                if (transport->cacc.cacc_saw_newack)
                        count_of_newacks ++;
                        count_of_newacks ++;
        }
        }
 
 
        list_for_each(pos, transport_list) {
        list_for_each(pos, transport_list) {
                transport  = list_entry(pos, struct sctp_transport,
                transport  = list_entry(pos, struct sctp_transport,
                                        transports);
                                        transports);
                sctp_mark_missing(q, &transport->transmitted, transport,
                sctp_mark_missing(q, &transport->transmitted, transport,
                                  highest_new_tsn, count_of_newacks);
                                  highest_new_tsn, count_of_newacks);
        }
        }
 
 
        /* Move the Cumulative TSN Ack Point if appropriate.  */
        /* Move the Cumulative TSN Ack Point if appropriate.  */
        if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn))
        if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn))
                asoc->ctsn_ack_point = sack_ctsn;
                asoc->ctsn_ack_point = sack_ctsn;
 
 
        /* Update unack_data field in the assoc. */
        /* Update unack_data field in the assoc. */
        sctp_sack_update_unack_data(asoc, sack);
        sctp_sack_update_unack_data(asoc, sack);
 
 
        ctsn = asoc->ctsn_ack_point;
        ctsn = asoc->ctsn_ack_point;
 
 
        SCTP_DEBUG_PRINTK("%s: sack Cumulative TSN Ack is 0x%x.\n",
        SCTP_DEBUG_PRINTK("%s: sack Cumulative TSN Ack is 0x%x.\n",
                          __FUNCTION__, sack_ctsn);
                          __FUNCTION__, sack_ctsn);
        SCTP_DEBUG_PRINTK("%s: Cumulative TSN Ack of association "
        SCTP_DEBUG_PRINTK("%s: Cumulative TSN Ack of association "
                          "%p is 0x%x.\n", __FUNCTION__, asoc, ctsn);
                          "%p is 0x%x.\n", __FUNCTION__, asoc, ctsn);
 
 
        /* Throw away stuff rotting on the sack queue.  */
        /* Throw away stuff rotting on the sack queue.  */
        list_for_each_safe(lchunk, temp, &q->sacked) {
        list_for_each_safe(lchunk, temp, &q->sacked) {
                tchunk = list_entry(lchunk, struct sctp_chunk,
                tchunk = list_entry(lchunk, struct sctp_chunk,
                                    transmitted_list);
                                    transmitted_list);
                tsn = ntohl(tchunk->subh.data_hdr->tsn);
                tsn = ntohl(tchunk->subh.data_hdr->tsn);
                if (TSN_lte(tsn, ctsn))
                if (TSN_lte(tsn, ctsn))
                        sctp_chunk_free(tchunk);
                        sctp_chunk_free(tchunk);
        }
        }
 
 
        /* ii) Set rwnd equal to the newly received a_rwnd minus the
        /* ii) Set rwnd equal to the newly received a_rwnd minus the
         *     number of bytes still outstanding after processing the
         *     number of bytes still outstanding after processing the
         *     Cumulative TSN Ack and the Gap Ack Blocks.
         *     Cumulative TSN Ack and the Gap Ack Blocks.
         */
         */
 
 
        sack_a_rwnd = ntohl(sack->a_rwnd);
        sack_a_rwnd = ntohl(sack->a_rwnd);
        outstanding = q->outstanding_bytes;
        outstanding = q->outstanding_bytes;
 
 
        if (outstanding < sack_a_rwnd)
        if (outstanding < sack_a_rwnd)
                sack_a_rwnd -= outstanding;
                sack_a_rwnd -= outstanding;
        else
        else
                sack_a_rwnd = 0;
                sack_a_rwnd = 0;
 
 
        asoc->peer.rwnd = sack_a_rwnd;
        asoc->peer.rwnd = sack_a_rwnd;
 
 
        /* See if all chunks are acked.
        /* See if all chunks are acked.
         * Make sure the empty queue handler will get run later.
         * Make sure the empty queue handler will get run later.
         */
         */
        q->empty = skb_queue_empty(&q->out) && list_empty(&q->retransmit);
        q->empty = skb_queue_empty(&q->out) && list_empty(&q->retransmit);
        if (!q->empty)
        if (!q->empty)
                goto finish;
                goto finish;
 
 
        list_for_each(pos, transport_list) {
        list_for_each(pos, transport_list) {
                transport  = list_entry(pos, struct sctp_transport,
                transport  = list_entry(pos, struct sctp_transport,
                                        transports);
                                        transports);
                q->empty = q->empty && list_empty(&transport->transmitted);
                q->empty = q->empty && list_empty(&transport->transmitted);
                if (!q->empty)
                if (!q->empty)
                        goto finish;
                        goto finish;
        }
        }
 
 
        SCTP_DEBUG_PRINTK("sack queue is empty.\n");
        SCTP_DEBUG_PRINTK("sack queue is empty.\n");
finish:
finish:
        return q->empty;
        return q->empty;
}
}
 
 
/* Is the outqueue empty?  */
/* Is the outqueue empty?  */
int sctp_outq_is_empty(const struct sctp_outq *q)
int sctp_outq_is_empty(const struct sctp_outq *q)
{
{
        return q->empty;
        return q->empty;
}
}
 
 
/********************************************************************
/********************************************************************
 * 2nd Level Abstractions
 * 2nd Level Abstractions
 ********************************************************************/
 ********************************************************************/
 
 
/* Go through a transport's transmitted list or the association's retransmit
/* Go through a transport's transmitted list or the association's retransmit
 * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked.
 * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked.
 * The retransmit list will not have an associated transport.
 * The retransmit list will not have an associated transport.
 *
 *
 * I added coherent debug information output.   --xguo
 * I added coherent debug information output.   --xguo
 *
 *
 * Instead of printing 'sacked' or 'kept' for each TSN on the
 * Instead of printing 'sacked' or 'kept' for each TSN on the
 * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5.
 * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5.
 * KEPT TSN6-TSN7, etc.
 * KEPT TSN6-TSN7, etc.
 */
 */
static void sctp_check_transmitted(struct sctp_outq *q,
static void sctp_check_transmitted(struct sctp_outq *q,
                                   struct list_head *transmitted_queue,
                                   struct list_head *transmitted_queue,
                                   struct sctp_transport *transport,
                                   struct sctp_transport *transport,
                                   struct sctp_sackhdr *sack,
                                   struct sctp_sackhdr *sack,
                                   __u32 highest_new_tsn_in_sack)
                                   __u32 highest_new_tsn_in_sack)
{
{
        struct list_head *lchunk;
        struct list_head *lchunk;
        struct sctp_chunk *tchunk;
        struct sctp_chunk *tchunk;
        struct list_head tlist;
        struct list_head tlist;
        __u32 tsn;
        __u32 tsn;
        __u32 sack_ctsn;
        __u32 sack_ctsn;
        __u32 rtt;
        __u32 rtt;
        __u8 restart_timer = 0;
        __u8 restart_timer = 0;
        int bytes_acked = 0;
        int bytes_acked = 0;
 
 
        /* These state variables are for coherent debug output. --xguo */
        /* These state variables are for coherent debug output. --xguo */
 
 
#if SCTP_DEBUG
#if SCTP_DEBUG
        __u32 dbg_ack_tsn = 0;   /* An ACKed TSN range starts here... */
        __u32 dbg_ack_tsn = 0;   /* An ACKed TSN range starts here... */
        __u32 dbg_last_ack_tsn = 0;  /* ...and finishes here.         */
        __u32 dbg_last_ack_tsn = 0;  /* ...and finishes here.         */
        __u32 dbg_kept_tsn = 0;  /* An un-ACKed range starts here...  */
        __u32 dbg_kept_tsn = 0;  /* An un-ACKed range starts here...  */
        __u32 dbg_last_kept_tsn = 0; /* ...and finishes here.         */
        __u32 dbg_last_kept_tsn = 0; /* ...and finishes here.         */
 
 
        /* 0 : The last TSN was ACKed.
        /* 0 : The last TSN was ACKed.
         * 1 : The last TSN was NOT ACKed (i.e. KEPT).
         * 1 : The last TSN was NOT ACKed (i.e. KEPT).
         * -1: We need to initialize.
         * -1: We need to initialize.
         */
         */
        int dbg_prt_state = -1;
        int dbg_prt_state = -1;
#endif /* SCTP_DEBUG */
#endif /* SCTP_DEBUG */
 
 
        sack_ctsn = ntohl(sack->cum_tsn_ack);
        sack_ctsn = ntohl(sack->cum_tsn_ack);
 
 
        INIT_LIST_HEAD(&tlist);
        INIT_LIST_HEAD(&tlist);
 
 
        /* The while loop will skip empty transmitted queues. */
        /* The while loop will skip empty transmitted queues. */
        while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) {
        while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) {
                tchunk = list_entry(lchunk, struct sctp_chunk,
                tchunk = list_entry(lchunk, struct sctp_chunk,
                                    transmitted_list);
                                    transmitted_list);
 
 
                tsn = ntohl(tchunk->subh.data_hdr->tsn);
                tsn = ntohl(tchunk->subh.data_hdr->tsn);
                if (sctp_acked(sack, tsn)) {
                if (sctp_acked(sack, tsn)) {
                        /* If this queue is the retransmit queue, the
                        /* If this queue is the retransmit queue, the
                         * retransmit timer has already reclaimed
                         * retransmit timer has already reclaimed
                         * the outstanding bytes for this chunk, so only
                         * the outstanding bytes for this chunk, so only
                         * count bytes associated with a transport.
                         * count bytes associated with a transport.
                         */
                         */
                        if (transport) {
                        if (transport) {
                                /* If this chunk is being used for RTT
                                /* If this chunk is being used for RTT
                                 * measurement, calculate the RTT and update
                                 * measurement, calculate the RTT and update
                                 * the RTO using this value.
                                 * the RTO using this value.
                                 *
                                 *
                                 * 6.3.1 C5) Karn's algorithm: RTT measurements
                                 * 6.3.1 C5) Karn's algorithm: RTT measurements
                                 * MUST NOT be made using packets that were
                                 * MUST NOT be made using packets that were
                                 * retransmitted (and thus for which it is
                                 * retransmitted (and thus for which it is
                                 * ambiguous whether the reply was for the
                                 * ambiguous whether the reply was for the
                                 * first instance of the packet or a later
                                 * first instance of the packet or a later
                                 * instance).
                                 * instance).
                                 */
                                 */
                                if (!tchunk->tsn_gap_acked &&
                                if (!tchunk->tsn_gap_acked &&
                                    !tchunk->resent &&
                                    !tchunk->resent &&
                                    tchunk->rtt_in_progress) {
                                    tchunk->rtt_in_progress) {
                                        rtt = jiffies - tchunk->sent_at;
                                        rtt = jiffies - tchunk->sent_at;
                                        sctp_transport_update_rto(transport,
                                        sctp_transport_update_rto(transport,
                                                                  rtt);
                                                                  rtt);
                                }
                                }
                        }
                        }
                        if (TSN_lte(tsn, sack_ctsn)) {
                        if (TSN_lte(tsn, sack_ctsn)) {
                                /* RFC 2960  6.3.2 Retransmission Timer Rules
                                /* RFC 2960  6.3.2 Retransmission Timer Rules
                                 *
                                 *
                                 * R3) Whenever a SACK is received
                                 * R3) Whenever a SACK is received
                                 * that acknowledges the DATA chunk
                                 * that acknowledges the DATA chunk
                                 * with the earliest outstanding TSN
                                 * with the earliest outstanding TSN
                                 * for that address, restart T3-rtx
                                 * for that address, restart T3-rtx
                                 * timer for that address with its
                                 * timer for that address with its
                                 * current RTO.
                                 * current RTO.
                                 */
                                 */
                                restart_timer = 1;
                                restart_timer = 1;
 
 
                                if (!tchunk->tsn_gap_acked) {
                                if (!tchunk->tsn_gap_acked) {
                                        tchunk->tsn_gap_acked = 1;
                                        tchunk->tsn_gap_acked = 1;
                                        bytes_acked += sctp_data_size(tchunk);
                                        bytes_acked += sctp_data_size(tchunk);
                                        /*
                                        /*
                                         * SFR-CACC algorithm:
                                         * SFR-CACC algorithm:
                                         * 2) If the SACK contains gap acks
                                         * 2) If the SACK contains gap acks
                                         * and the flag CHANGEOVER_ACTIVE is
                                         * and the flag CHANGEOVER_ACTIVE is
                                         * set the receiver of the SACK MUST
                                         * set the receiver of the SACK MUST
                                         * take the following action:
                                         * take the following action:
                                         *
                                         *
                                         * B) For each TSN t being acked that
                                         * B) For each TSN t being acked that
                                         * has not been acked in any SACK so
                                         * has not been acked in any SACK so
                                         * far, set cacc_saw_newack to 1 for
                                         * far, set cacc_saw_newack to 1 for
                                         * the destination that the TSN was
                                         * the destination that the TSN was
                                         * sent to.
                                         * sent to.
                                         */
                                         */
                                        if (transport &&
                                        if (transport &&
                                            sack->num_gap_ack_blocks &&
                                            sack->num_gap_ack_blocks &&
                                            q->asoc->peer.primary_path->cacc.
                                            q->asoc->peer.primary_path->cacc.
                                            changeover_active)
                                            changeover_active)
                                                transport->cacc.cacc_saw_newack
                                                transport->cacc.cacc_saw_newack
                                                        = 1;
                                                        = 1;
                                }
                                }
 
 
                                list_add_tail(&tchunk->transmitted_list,
                                list_add_tail(&tchunk->transmitted_list,
                                              &q->sacked);
                                              &q->sacked);
                        } else {
                        } else {
                                /* RFC2960 7.2.4, sctpimpguide-05 2.8.2
                                /* RFC2960 7.2.4, sctpimpguide-05 2.8.2
                                 * M2) Each time a SACK arrives reporting
                                 * M2) Each time a SACK arrives reporting
                                 * 'Stray DATA chunk(s)' record the highest TSN
                                 * 'Stray DATA chunk(s)' record the highest TSN
                                 * reported as newly acknowledged, call this
                                 * reported as newly acknowledged, call this
                                 * value 'HighestTSNinSack'. A newly
                                 * value 'HighestTSNinSack'. A newly
                                 * acknowledged DATA chunk is one not
                                 * acknowledged DATA chunk is one not
                                 * previously acknowledged in a SACK.
                                 * previously acknowledged in a SACK.
                                 *
                                 *
                                 * When the SCTP sender of data receives a SACK
                                 * When the SCTP sender of data receives a SACK
                                 * chunk that acknowledges, for the first time,
                                 * chunk that acknowledges, for the first time,
                                 * the receipt of a DATA chunk, all the still
                                 * the receipt of a DATA chunk, all the still
                                 * unacknowledged DATA chunks whose TSN is
                                 * unacknowledged DATA chunks whose TSN is
                                 * older than that newly acknowledged DATA
                                 * older than that newly acknowledged DATA
                                 * chunk, are qualified as 'Stray DATA chunks'.
                                 * chunk, are qualified as 'Stray DATA chunks'.
                                 */
                                 */
                                if (!tchunk->tsn_gap_acked) {
                                if (!tchunk->tsn_gap_acked) {
                                        tchunk->tsn_gap_acked = 1;
                                        tchunk->tsn_gap_acked = 1;
                                        bytes_acked += sctp_data_size(tchunk);
                                        bytes_acked += sctp_data_size(tchunk);
                                }
                                }
                                list_add_tail(lchunk, &tlist);
                                list_add_tail(lchunk, &tlist);
                        }
                        }
 
 
#if SCTP_DEBUG
#if SCTP_DEBUG
                        switch (dbg_prt_state) {
                        switch (dbg_prt_state) {
                        case 0:  /* last TSN was ACKed */
                        case 0:  /* last TSN was ACKed */
                                if (dbg_last_ack_tsn + 1 == tsn) {
                                if (dbg_last_ack_tsn + 1 == tsn) {
                                        /* This TSN belongs to the
                                        /* This TSN belongs to the
                                         * current ACK range.
                                         * current ACK range.
                                         */
                                         */
                                        break;
                                        break;
                                }
                                }
 
 
                                if (dbg_last_ack_tsn != dbg_ack_tsn) {
                                if (dbg_last_ack_tsn != dbg_ack_tsn) {
                                        /* Display the end of the
                                        /* Display the end of the
                                         * current range.
                                         * current range.
                                         */
                                         */
                                        SCTP_DEBUG_PRINTK("-%08x",
                                        SCTP_DEBUG_PRINTK("-%08x",
                                                          dbg_last_ack_tsn);
                                                          dbg_last_ack_tsn);
                                }
                                }
 
 
                                /* Start a new range.  */
                                /* Start a new range.  */
                                SCTP_DEBUG_PRINTK(",%08x", tsn);
                                SCTP_DEBUG_PRINTK(",%08x", tsn);
                                dbg_ack_tsn = tsn;
                                dbg_ack_tsn = tsn;
                                break;
                                break;
 
 
                        case 1: /* The last TSN was NOT ACKed. */
                        case 1: /* The last TSN was NOT ACKed. */
                                if (dbg_last_kept_tsn != dbg_kept_tsn) {
                                if (dbg_last_kept_tsn != dbg_kept_tsn) {
                                        /* Display the end of current range. */
                                        /* Display the end of current range. */
                                        SCTP_DEBUG_PRINTK("-%08x",
                                        SCTP_DEBUG_PRINTK("-%08x",
                                                          dbg_last_kept_tsn);
                                                          dbg_last_kept_tsn);
                                }
                                }
 
 
                                SCTP_DEBUG_PRINTK("\n");
                                SCTP_DEBUG_PRINTK("\n");
 
 
                                /* FALL THROUGH... */
                                /* FALL THROUGH... */
                        default:
                        default:
                                /* This is the first-ever TSN we examined.  */
                                /* This is the first-ever TSN we examined.  */
                                /* Start a new range of ACK-ed TSNs.  */
                                /* Start a new range of ACK-ed TSNs.  */
                                SCTP_DEBUG_PRINTK("ACKed: %08x", tsn);
                                SCTP_DEBUG_PRINTK("ACKed: %08x", tsn);
                                dbg_prt_state = 0;
                                dbg_prt_state = 0;
                                dbg_ack_tsn = tsn;
                                dbg_ack_tsn = tsn;
                        };
                        };
 
 
                        dbg_last_ack_tsn = tsn;
                        dbg_last_ack_tsn = tsn;
#endif /* SCTP_DEBUG */
#endif /* SCTP_DEBUG */
 
 
                } else {
                } else {
                        if (tchunk->tsn_gap_acked) {
                        if (tchunk->tsn_gap_acked) {
                                SCTP_DEBUG_PRINTK("%s: Receiver reneged on "
                                SCTP_DEBUG_PRINTK("%s: Receiver reneged on "
                                                  "data TSN: 0x%x\n",
                                                  "data TSN: 0x%x\n",
                                                  __FUNCTION__,
                                                  __FUNCTION__,
                                                  tsn);
                                                  tsn);
                                tchunk->tsn_gap_acked = 0;
                                tchunk->tsn_gap_acked = 0;
 
 
                                bytes_acked -= sctp_data_size(tchunk);
                                bytes_acked -= sctp_data_size(tchunk);
 
 
                                /* RFC 2960 6.3.2 Retransmission Timer Rules
                                /* RFC 2960 6.3.2 Retransmission Timer Rules
                                 *
                                 *
                                 * R4) Whenever a SACK is received missing a
                                 * R4) Whenever a SACK is received missing a
                                 * TSN that was previously acknowledged via a
                                 * TSN that was previously acknowledged via a
                                 * Gap Ack Block, start T3-rtx for the
                                 * Gap Ack Block, start T3-rtx for the
                                 * destination address to which the DATA
                                 * destination address to which the DATA
                                 * chunk was originally
                                 * chunk was originally
                                 * transmitted if it is not already running.
                                 * transmitted if it is not already running.
                                 */
                                 */
                                restart_timer = 1;
                                restart_timer = 1;
                        }
                        }
 
 
                        list_add_tail(lchunk, &tlist);
                        list_add_tail(lchunk, &tlist);
 
 
#if SCTP_DEBUG
#if SCTP_DEBUG
                        /* See the above comments on ACK-ed TSNs. */
                        /* See the above comments on ACK-ed TSNs. */
                        switch (dbg_prt_state) {
                        switch (dbg_prt_state) {
                        case 1:
                        case 1:
                                if (dbg_last_kept_tsn + 1 == tsn)
                                if (dbg_last_kept_tsn + 1 == tsn)
                                        break;
                                        break;
 
 
                                if (dbg_last_kept_tsn != dbg_kept_tsn)
                                if (dbg_last_kept_tsn != dbg_kept_tsn)
                                        SCTP_DEBUG_PRINTK("-%08x",
                                        SCTP_DEBUG_PRINTK("-%08x",
                                                          dbg_last_kept_tsn);
                                                          dbg_last_kept_tsn);
 
 
                                SCTP_DEBUG_PRINTK(",%08x", tsn);
                                SCTP_DEBUG_PRINTK(",%08x", tsn);
                                dbg_kept_tsn = tsn;
                                dbg_kept_tsn = tsn;
                                break;
                                break;
 
 
                        case 0:
                        case 0:
                                if (dbg_last_ack_tsn != dbg_ack_tsn)
                                if (dbg_last_ack_tsn != dbg_ack_tsn)
                                        SCTP_DEBUG_PRINTK("-%08x",
                                        SCTP_DEBUG_PRINTK("-%08x",
                                                          dbg_last_ack_tsn);
                                                          dbg_last_ack_tsn);
                                SCTP_DEBUG_PRINTK("\n");
                                SCTP_DEBUG_PRINTK("\n");
 
 
                                /* FALL THROUGH... */
                                /* FALL THROUGH... */
                        default:
                        default:
                                SCTP_DEBUG_PRINTK("KEPT: %08x",tsn);
                                SCTP_DEBUG_PRINTK("KEPT: %08x",tsn);
                                dbg_prt_state = 1;
                                dbg_prt_state = 1;
                                dbg_kept_tsn = tsn;
                                dbg_kept_tsn = tsn;
                        };
                        };
 
 
                        dbg_last_kept_tsn = tsn;
                        dbg_last_kept_tsn = tsn;
#endif /* SCTP_DEBUG */
#endif /* SCTP_DEBUG */
                }
                }
        }
        }
 
 
#if SCTP_DEBUG
#if SCTP_DEBUG
        /* Finish off the last range, displaying its ending TSN.  */
        /* Finish off the last range, displaying its ending TSN.  */
        switch (dbg_prt_state) {
        switch (dbg_prt_state) {
        case 0:
        case 0:
                if (dbg_last_ack_tsn != dbg_ack_tsn) {
                if (dbg_last_ack_tsn != dbg_ack_tsn) {
                        SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_ack_tsn);
                        SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_ack_tsn);
                } else {
                } else {
                        SCTP_DEBUG_PRINTK("\n");
                        SCTP_DEBUG_PRINTK("\n");
                }
                }
        break;
        break;
 
 
        case 1:
        case 1:
                if (dbg_last_kept_tsn != dbg_kept_tsn) {
                if (dbg_last_kept_tsn != dbg_kept_tsn) {
                        SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_kept_tsn);
                        SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_kept_tsn);
                } else {
                } else {
                        SCTP_DEBUG_PRINTK("\n");
                        SCTP_DEBUG_PRINTK("\n");
                }
                }
        };
        };
#endif /* SCTP_DEBUG */
#endif /* SCTP_DEBUG */
        if (transport) {
        if (transport) {
                if (bytes_acked) {
                if (bytes_acked) {
                        /* 8.2. When an outstanding TSN is acknowledged,
                        /* 8.2. When an outstanding TSN is acknowledged,
                         * the endpoint shall clear the error counter of
                         * the endpoint shall clear the error counter of
                         * the destination transport address to which the
                         * the destination transport address to which the
                         * DATA chunk was last sent.
                         * DATA chunk was last sent.
                         * The association's overall error counter is
                         * The association's overall error counter is
                         * also cleared.
                         * also cleared.
                         */
                         */
                        transport->error_count = 0;
                        transport->error_count = 0;
                        transport->asoc->overall_error_count = 0;
                        transport->asoc->overall_error_count = 0;
 
 
                        /* Mark the destination transport address as
                        /* Mark the destination transport address as
                         * active if it is not so marked.
                         * active if it is not so marked.
                         */
                         */
                        if (!transport->active) {
                        if (!transport->active) {
                                sctp_assoc_control_transport(
                                sctp_assoc_control_transport(
                                        transport->asoc,
                                        transport->asoc,
                                        transport,
                                        transport,
                                        SCTP_TRANSPORT_UP,
                                        SCTP_TRANSPORT_UP,
                                        SCTP_RECEIVED_SACK);
                                        SCTP_RECEIVED_SACK);
                        }
                        }
 
 
                        sctp_transport_raise_cwnd(transport, sack_ctsn,
                        sctp_transport_raise_cwnd(transport, sack_ctsn,
                                                  bytes_acked);
                                                  bytes_acked);
 
 
                        transport->flight_size -= bytes_acked;
                        transport->flight_size -= bytes_acked;
                        q->outstanding_bytes -= bytes_acked;
                        q->outstanding_bytes -= bytes_acked;
                } else {
                } else {
                        /* RFC 2960 6.1, sctpimpguide-06 2.15.2
                        /* RFC 2960 6.1, sctpimpguide-06 2.15.2
                         * When a sender is doing zero window probing, it
                         * When a sender is doing zero window probing, it
                         * should not timeout the association if it continues
                         * should not timeout the association if it continues
                         * to receive new packets from the receiver. The
                         * to receive new packets from the receiver. The
                         * reason is that the receiver MAY keep its window
                         * reason is that the receiver MAY keep its window
                         * closed for an indefinite time.
                         * closed for an indefinite time.
                         * A sender is doing zero window probing when the
                         * A sender is doing zero window probing when the
                         * receiver's advertised window is zero, and there is
                         * receiver's advertised window is zero, and there is
                         * only one data chunk in flight to the receiver.
                         * only one data chunk in flight to the receiver.
                         */
                         */
                        if (!q->asoc->peer.rwnd &&
                        if (!q->asoc->peer.rwnd &&
                            !list_empty(&tlist) &&
                            !list_empty(&tlist) &&
                            (sack_ctsn+2 == q->asoc->next_tsn)) {
                            (sack_ctsn+2 == q->asoc->next_tsn)) {
                                SCTP_DEBUG_PRINTK("%s: SACK received for zero "
                                SCTP_DEBUG_PRINTK("%s: SACK received for zero "
                                                  "window probe: %u\n",
                                                  "window probe: %u\n",
                                                  __FUNCTION__, sack_ctsn);
                                                  __FUNCTION__, sack_ctsn);
                                q->asoc->overall_error_count = 0;
                                q->asoc->overall_error_count = 0;
                                transport->error_count = 0;
                                transport->error_count = 0;
                        }
                        }
                }
                }
 
 
                /* RFC 2960 6.3.2 Retransmission Timer Rules
                /* RFC 2960 6.3.2 Retransmission Timer Rules
                 *
                 *
                 * R2) Whenever all outstanding data sent to an address have
                 * R2) Whenever all outstanding data sent to an address have
                 * been acknowledged, turn off the T3-rtx timer of that
                 * been acknowledged, turn off the T3-rtx timer of that
                 * address.
                 * address.
                 */
                 */
                if (!transport->flight_size) {
                if (!transport->flight_size) {
                        if (timer_pending(&transport->T3_rtx_timer) &&
                        if (timer_pending(&transport->T3_rtx_timer) &&
                            del_timer(&transport->T3_rtx_timer)) {
                            del_timer(&transport->T3_rtx_timer)) {
                                sctp_transport_put(transport);
                                sctp_transport_put(transport);
                        }
                        }
                } else if (restart_timer) {
                } else if (restart_timer) {
                        if (!mod_timer(&transport->T3_rtx_timer,
                        if (!mod_timer(&transport->T3_rtx_timer,
                                       jiffies + transport->rto))
                                       jiffies + transport->rto))
                                sctp_transport_hold(transport);
                                sctp_transport_hold(transport);
                }
                }
        }
        }
 
 
        list_splice(&tlist, transmitted_queue);
        list_splice(&tlist, transmitted_queue);
}
}
 
 
/* Mark chunks as missing and consequently may get retransmitted. */
/* Mark chunks as missing and consequently may get retransmitted. */
static void sctp_mark_missing(struct sctp_outq *q,
static void sctp_mark_missing(struct sctp_outq *q,
                              struct list_head *transmitted_queue,
                              struct list_head *transmitted_queue,
                              struct sctp_transport *transport,
                              struct sctp_transport *transport,
                              __u32 highest_new_tsn_in_sack,
                              __u32 highest_new_tsn_in_sack,
                              int count_of_newacks)
                              int count_of_newacks)
{
{
        struct sctp_chunk *chunk;
        struct sctp_chunk *chunk;
        struct list_head *pos;
        struct list_head *pos;
        __u32 tsn;
        __u32 tsn;
        char do_fast_retransmit = 0;
        char do_fast_retransmit = 0;
        struct sctp_transport *primary = q->asoc->peer.primary_path;
        struct sctp_transport *primary = q->asoc->peer.primary_path;
 
 
        list_for_each(pos, transmitted_queue) {
        list_for_each(pos, transmitted_queue) {
 
 
                chunk = list_entry(pos, struct sctp_chunk, transmitted_list);
                chunk = list_entry(pos, struct sctp_chunk, transmitted_list);
                tsn = ntohl(chunk->subh.data_hdr->tsn);
                tsn = ntohl(chunk->subh.data_hdr->tsn);
 
 
                /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all
                /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all
                 * 'Unacknowledged TSN's', if the TSN number of an
                 * 'Unacknowledged TSN's', if the TSN number of an
                 * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack'
                 * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack'
                 * value, increment the 'TSN.Missing.Report' count on that
                 * value, increment the 'TSN.Missing.Report' count on that
                 * chunk if it has NOT been fast retransmitted or marked for
                 * chunk if it has NOT been fast retransmitted or marked for
                 * fast retransmit already.
                 * fast retransmit already.
                 */
                 */
                if (!chunk->fast_retransmit &&
                if (!chunk->fast_retransmit &&
                    !chunk->tsn_gap_acked &&
                    !chunk->tsn_gap_acked &&
                    TSN_lt(tsn, highest_new_tsn_in_sack)) {
                    TSN_lt(tsn, highest_new_tsn_in_sack)) {
 
 
                        /* SFR-CACC may require us to skip marking
                        /* SFR-CACC may require us to skip marking
                         * this chunk as missing.
                         * this chunk as missing.
                         */
                         */
                        if (!transport || !sctp_cacc_skip(primary, transport,
                        if (!transport || !sctp_cacc_skip(primary, transport,
                                            count_of_newacks, tsn)) {
                                            count_of_newacks, tsn)) {
                                chunk->tsn_missing_report++;
                                chunk->tsn_missing_report++;
 
 
                                SCTP_DEBUG_PRINTK(
                                SCTP_DEBUG_PRINTK(
                                        "%s: TSN 0x%x missing counter: %d\n",
                                        "%s: TSN 0x%x missing counter: %d\n",
                                        __FUNCTION__, tsn,
                                        __FUNCTION__, tsn,
                                        chunk->tsn_missing_report);
                                        chunk->tsn_missing_report);
                        }
                        }
                }
                }
                /*
                /*
                 * M4) If any DATA chunk is found to have a
                 * M4) If any DATA chunk is found to have a
                 * 'TSN.Missing.Report'
                 * 'TSN.Missing.Report'
                 * value larger than or equal to 4, mark that chunk for
                 * value larger than or equal to 4, mark that chunk for
                 * retransmission and start the fast retransmit procedure.
                 * retransmission and start the fast retransmit procedure.
                 */
                 */
 
 
                if (chunk->tsn_missing_report >= 4) {
                if (chunk->tsn_missing_report >= 4) {
                        chunk->fast_retransmit = 1;
                        chunk->fast_retransmit = 1;
                        do_fast_retransmit = 1;
                        do_fast_retransmit = 1;
                }
                }
        }
        }
 
 
        if (transport) {
        if (transport) {
                if (do_fast_retransmit)
                if (do_fast_retransmit)
                        sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX);
                        sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX);
 
 
                SCTP_DEBUG_PRINTK("%s: transport: %p, cwnd: %d, "
                SCTP_DEBUG_PRINTK("%s: transport: %p, cwnd: %d, "
                                  "ssthresh: %d, flight_size: %d, pba: %d\n",
                                  "ssthresh: %d, flight_size: %d, pba: %d\n",
                                  __FUNCTION__, transport, transport->cwnd,
                                  __FUNCTION__, transport, transport->cwnd,
                                  transport->ssthresh, transport->flight_size,
                                  transport->ssthresh, transport->flight_size,
                                  transport->partial_bytes_acked);
                                  transport->partial_bytes_acked);
        }
        }
}
}
 
 
/* Is the given TSN acked by this packet?  */
/* Is the given TSN acked by this packet?  */
static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
{
{
        int i;
        int i;
        sctp_sack_variable_t *frags;
        sctp_sack_variable_t *frags;
        __u16 gap;
        __u16 gap;
        __u32 ctsn = ntohl(sack->cum_tsn_ack);
        __u32 ctsn = ntohl(sack->cum_tsn_ack);
 
 
        if (TSN_lte(tsn, ctsn))
        if (TSN_lte(tsn, ctsn))
                goto pass;
                goto pass;
 
 
        /* 3.3.4 Selective Acknowledgement (SACK) (3):
        /* 3.3.4 Selective Acknowledgement (SACK) (3):
         *
         *
         * Gap Ack Blocks:
         * Gap Ack Blocks:
         *  These fields contain the Gap Ack Blocks. They are repeated
         *  These fields contain the Gap Ack Blocks. They are repeated
         *  for each Gap Ack Block up to the number of Gap Ack Blocks
         *  for each Gap Ack Block up to the number of Gap Ack Blocks
         *  defined in the Number of Gap Ack Blocks field. All DATA
         *  defined in the Number of Gap Ack Blocks field. All DATA
         *  chunks with TSNs greater than or equal to (Cumulative TSN
         *  chunks with TSNs greater than or equal to (Cumulative TSN
         *  Ack + Gap Ack Block Start) and less than or equal to
         *  Ack + Gap Ack Block Start) and less than or equal to
         *  (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack
         *  (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack
         *  Block are assumed to have been received correctly.
         *  Block are assumed to have been received correctly.
         */
         */
 
 
        frags = sack->variable;
        frags = sack->variable;
        gap = tsn - ctsn;
        gap = tsn - ctsn;
        for (i = 0; i < ntohs(sack->num_gap_ack_blocks); ++i) {
        for (i = 0; i < ntohs(sack->num_gap_ack_blocks); ++i) {
                if (TSN_lte(ntohs(frags[i].gab.start), gap) &&
                if (TSN_lte(ntohs(frags[i].gab.start), gap) &&
                    TSN_lte(gap, ntohs(frags[i].gab.end)))
                    TSN_lte(gap, ntohs(frags[i].gab.end)))
                        goto pass;
                        goto pass;
        }
        }
 
 
        return 0;
        return 0;
pass:
pass:
        return 1;
        return 1;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.