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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [net/] [sctp/] [sm_statefuns.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
 * (C) Copyright IBM Corp. 2001, 2004
 * (C) Copyright IBM Corp. 2001, 2004
 * 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-2002 Intel Corp.
 * Copyright (c) 2001-2002 Intel Corp.
 * Copyright (c) 2002      Nokia Corp.
 * Copyright (c) 2002      Nokia Corp.
 *
 *
 * This file is part of the SCTP kernel reference Implementation
 * This file is part of the SCTP kernel reference Implementation
 *
 *
 * This is part of the SCTP Linux Kernel Reference Implementation.
 * This is part of the SCTP Linux Kernel Reference Implementation.
 *
 *
 * These are the state functions for the state machine.
 * These are the state functions for the state machine.
 *
 *
 * 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>
 *    Mathew Kotowsky       <kotowsky@sctp.org>
 *    Mathew Kotowsky       <kotowsky@sctp.org>
 *    Sridhar Samudrala     <samudrala@us.ibm.com>
 *    Sridhar Samudrala     <samudrala@us.ibm.com>
 *    Jon Grimm             <jgrimm@us.ibm.com>
 *    Jon Grimm             <jgrimm@us.ibm.com>
 *    Hui Huang             <hui.huang@nokia.com>
 *    Hui Huang             <hui.huang@nokia.com>
 *    Dajiang Zhang         <dajiang.zhang@nokia.com>
 *    Dajiang Zhang         <dajiang.zhang@nokia.com>
 *    Daisy Chang           <daisyc@us.ibm.com>
 *    Daisy Chang           <daisyc@us.ibm.com>
 *    Ardelle Fan           <ardelle.fan@intel.com>
 *    Ardelle Fan           <ardelle.fan@intel.com>
 *    Ryan Layer            <rmlayer@us.ibm.com>
 *    Ryan Layer            <rmlayer@us.ibm.com>
 *    Kevin Gao             <kevin.gao@intel.com>
 *    Kevin Gao             <kevin.gao@intel.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/kernel.h>
#include <linux/kernel.h>
#include <linux/ip.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/ipv6.h>
#include <linux/net.h>
#include <linux/net.h>
#include <linux/inet.h>
#include <linux/inet.h>
#include <net/sock.h>
#include <net/sock.h>
#include <net/inet_ecn.h>
#include <net/inet_ecn.h>
#include <linux/skbuff.h>
#include <linux/skbuff.h>
#include <net/sctp/sctp.h>
#include <net/sctp/sctp.h>
#include <net/sctp/sm.h>
#include <net/sctp/sm.h>
#include <net/sctp/structs.h>
#include <net/sctp/structs.h>
 
 
/**********************************************************
/**********************************************************
 * These are the state functions for handling chunk events.
 * These are the state functions for handling chunk events.
 **********************************************************/
 **********************************************************/
 
 
/*
/*
 * Process the final SHUTDOWN COMPLETE.
 * Process the final SHUTDOWN COMPLETE.
 *
 *
 * Section: 4 (C) (diagram), 9.2
 * Section: 4 (C) (diagram), 9.2
 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
 * should stop the T2-shutdown timer and remove all knowledge of the
 * should stop the T2-shutdown timer and remove all knowledge of the
 * association (and thus the association enters the CLOSED state).
 * association (and thus the association enters the CLOSED state).
 *
 *
 * Verification Tag: 8.5.1(C)
 * Verification Tag: 8.5.1(C)
 * C) Rules for packet carrying SHUTDOWN COMPLETE:
 * C) Rules for packet carrying SHUTDOWN COMPLETE:
 * ...
 * ...
 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet if the
 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet if the
 *   Verification Tag field of the packet matches its own tag OR it is
 *   Verification Tag field of the packet matches its own tag OR it is
 *   set to its peer's tag and the T bit is set in the Chunk Flags.
 *   set to its peer's tag and the T bit is set in the Chunk Flags.
 *   Otherwise, the receiver MUST silently discard the packet and take
 *   Otherwise, the receiver MUST silently discard the packet and take
 *   no further action. An endpoint MUST ignore the SHUTDOWN COMPLETE if
 *   no further action. An endpoint MUST ignore the SHUTDOWN COMPLETE if
 *   it is not in the SHUTDOWN-ACK-SENT state.
 *   it is not in the SHUTDOWN-ACK-SENT state.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep,
                                  const struct sctp_association *asoc,
                                  const struct sctp_association *asoc,
                                  const sctp_subtype_t type,
                                  const sctp_subtype_t type,
                                  void *arg,
                                  void *arg,
                                  sctp_cmd_seq_t *commands)
                                  sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        struct sctp_ulpevent *ev;
        struct sctp_ulpevent *ev;
 
 
        /* RFC 2960 6.10 Bundling
        /* RFC 2960 6.10 Bundling
         *
         *
         * An endpoint MUST NOT bundle INIT, INIT ACK or
         * An endpoint MUST NOT bundle INIT, INIT ACK or
         * SHUTDOWN COMPLETE with any other chunks.
         * SHUTDOWN COMPLETE with any other chunks.
         */
         */
        if (!chunk->singleton)
        if (!chunk->singleton)
                return SCTP_DISPOSITION_VIOLATION;
                return SCTP_DISPOSITION_VIOLATION;
 
 
        if (!sctp_vtag_verify_either(chunk, asoc))
        if (!sctp_vtag_verify_either(chunk, asoc))
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
        /* RFC 2960 10.2 SCTP-to-ULP
        /* RFC 2960 10.2 SCTP-to-ULP
         *
         *
         * H) SHUTDOWN COMPLETE notification
         * H) SHUTDOWN COMPLETE notification
         *
         *
         * When SCTP completes the shutdown procedures (section 9.2) this
         * When SCTP completes the shutdown procedures (section 9.2) this
         * notification is passed to the upper layer.
         * notification is passed to the upper layer.
         */
         */
        ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
        ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
                                             0, 0, 0, GFP_ATOMIC);
                                             0, 0, 0, GFP_ATOMIC);
        if (!ev)
        if (!ev)
                goto nomem;
                goto nomem;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
 
 
        /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
        /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
         * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
         * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
         * not the chunk should be discarded. If the endpoint is in
         * not the chunk should be discarded. If the endpoint is in
         * the SHUTDOWN-ACK-SENT state the endpoint should stop the
         * the SHUTDOWN-ACK-SENT state the endpoint should stop the
         * T2-shutdown timer and remove all knowledge of the
         * T2-shutdown timer and remove all knowledge of the
         * association (and thus the association enters the CLOSED
         * association (and thus the association enters the CLOSED
         * state).
         * state).
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_CLOSED));
                        SCTP_STATE(SCTP_STATE_CLOSED));
 
 
        SCTP_INC_STATS(SctpShutdowns);
        SCTP_INC_STATS(SctpShutdowns);
        SCTP_DEC_STATS(SctpCurrEstab);
        SCTP_DEC_STATS(SctpCurrEstab);
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
 
 
        return SCTP_DISPOSITION_DELETE_TCB;
        return SCTP_DISPOSITION_DELETE_TCB;
 
 
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Respond to a normal INIT chunk.
 * Respond to a normal INIT chunk.
 * We are the side that is being asked for an association.
 * We are the side that is being asked for an association.
 *
 *
 * Section: 5.1 Normal Establishment of an Association, B
 * Section: 5.1 Normal Establishment of an Association, B
 * B) "Z" shall respond immediately with an INIT ACK chunk.  The
 * B) "Z" shall respond immediately with an INIT ACK chunk.  The
 *    destination IP address of the INIT ACK MUST be set to the source
 *    destination IP address of the INIT ACK MUST be set to the source
 *    IP address of the INIT to which this INIT ACK is responding.  In
 *    IP address of the INIT to which this INIT ACK is responding.  In
 *    the response, besides filling in other parameters, "Z" must set the
 *    the response, besides filling in other parameters, "Z" must set the
 *    Verification Tag field to Tag_A, and also provide its own
 *    Verification Tag field to Tag_A, and also provide its own
 *    Verification Tag (Tag_Z) in the Initiate Tag field.
 *    Verification Tag (Tag_Z) in the Initiate Tag field.
 *
 *
 * Verification Tag: No checking.
 * Verification Tag: No checking.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *repl;
        struct sctp_chunk *repl;
        struct sctp_association *new_asoc;
        struct sctp_association *new_asoc;
        struct sctp_chunk *err_chunk;
        struct sctp_chunk *err_chunk;
        struct sctp_packet *packet;
        struct sctp_packet *packet;
        sctp_unrecognized_param_t *unk_param;
        sctp_unrecognized_param_t *unk_param;
        struct sock *sk;
        struct sock *sk;
        int len;
        int len;
 
 
        /* 6.10 Bundling
        /* 6.10 Bundling
         * An endpoint MUST NOT bundle INIT, INIT ACK or
         * An endpoint MUST NOT bundle INIT, INIT ACK or
         * SHUTDOWN COMPLETE with any other chunks.
         * SHUTDOWN COMPLETE with any other chunks.
         */
         */
        if (!chunk->singleton)
        if (!chunk->singleton)
                return SCTP_DISPOSITION_VIOLATION;
                return SCTP_DISPOSITION_VIOLATION;
 
 
        /* If the packet is an OOTB packet which is temporarily on the
        /* If the packet is an OOTB packet which is temporarily on the
         * control endpoint, respond with an ABORT.
         * control endpoint, respond with an ABORT.
         */
         */
        if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
        if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
                return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
                return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
 
 
        sk = ep->base.sk;
        sk = ep->base.sk;
        /* If the endpoint is not listening or if the number of associations
        /* If the endpoint is not listening or if the number of associations
         * on the TCP-style socket exceed the max backlog, respond with an
         * on the TCP-style socket exceed the max backlog, respond with an
         * ABORT.
         * ABORT.
         */
         */
        if (!sctp_sstate(sk, LISTENING) ||
        if (!sctp_sstate(sk, LISTENING) ||
            (sctp_style(sk, TCP) &&
            (sctp_style(sk, TCP) &&
             (sk->sk_ack_backlog >= sk->sk_max_ack_backlog)))
             (sk->sk_ack_backlog >= sk->sk_max_ack_backlog)))
                return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
                return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
 
 
        /* Verify the INIT chunk before processing it. */
        /* Verify the INIT chunk before processing it. */
        err_chunk = NULL;
        err_chunk = NULL;
        if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
        if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
                              (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
                              (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
                              &err_chunk)) {
                              &err_chunk)) {
                /* This chunk contains fatal error. It is to be discarded.
                /* This chunk contains fatal error. It is to be discarded.
                 * Send an ABORT, with causes if there is any.
                 * Send an ABORT, with causes if there is any.
                 */
                 */
                if (err_chunk) {
                if (err_chunk) {
                        packet = sctp_abort_pkt_new(ep, asoc, arg,
                        packet = sctp_abort_pkt_new(ep, asoc, arg,
                                        (__u8 *)(err_chunk->chunk_hdr) +
                                        (__u8 *)(err_chunk->chunk_hdr) +
                                        sizeof(sctp_chunkhdr_t),
                                        sizeof(sctp_chunkhdr_t),
                                        ntohs(err_chunk->chunk_hdr->length) -
                                        ntohs(err_chunk->chunk_hdr->length) -
                                        sizeof(sctp_chunkhdr_t));
                                        sizeof(sctp_chunkhdr_t));
 
 
                        sctp_chunk_free(err_chunk);
                        sctp_chunk_free(err_chunk);
 
 
                        if (packet) {
                        if (packet) {
                                sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
                                sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
                                                SCTP_PACKET(packet));
                                                SCTP_PACKET(packet));
                                SCTP_INC_STATS(SctpOutCtrlChunks);
                                SCTP_INC_STATS(SctpOutCtrlChunks);
                                return SCTP_DISPOSITION_CONSUME;
                                return SCTP_DISPOSITION_CONSUME;
                        } else {
                        } else {
                                return SCTP_DISPOSITION_NOMEM;
                                return SCTP_DISPOSITION_NOMEM;
                        }
                        }
                } else {
                } else {
                        return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
                        return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
                                                    commands);
                                                    commands);
                }
                }
        }
        }
 
 
        /* Grab the INIT header.  */
        /* Grab the INIT header.  */
        chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
        chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
 
 
        /* Tag the variable length parameters.  */
        /* Tag the variable length parameters.  */
        chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
        chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
 
 
        new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
        new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
        if (!new_asoc)
        if (!new_asoc)
                goto nomem;
                goto nomem;
 
 
        /* The call, sctp_process_init(), can fail on memory allocation.  */
        /* The call, sctp_process_init(), can fail on memory allocation.  */
        if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
        if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
                               sctp_source(chunk),
                               sctp_source(chunk),
                               (sctp_init_chunk_t *)chunk->chunk_hdr,
                               (sctp_init_chunk_t *)chunk->chunk_hdr,
                               GFP_ATOMIC))
                               GFP_ATOMIC))
                goto nomem_init;
                goto nomem_init;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
 
 
        /* B) "Z" shall respond immediately with an INIT ACK chunk.  */
        /* B) "Z" shall respond immediately with an INIT ACK chunk.  */
 
 
        /* If there are errors need to be reported for unknown parameters,
        /* If there are errors need to be reported for unknown parameters,
         * make sure to reserve enough room in the INIT ACK for them.
         * make sure to reserve enough room in the INIT ACK for them.
         */
         */
        len = 0;
        len = 0;
        if (err_chunk)
        if (err_chunk)
                len = ntohs(err_chunk->chunk_hdr->length) -
                len = ntohs(err_chunk->chunk_hdr->length) -
                        sizeof(sctp_chunkhdr_t);
                        sizeof(sctp_chunkhdr_t);
 
 
        if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
        if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
                goto nomem_ack;
                goto nomem_ack;
 
 
        repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
        repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
        if (!repl)
        if (!repl)
                goto nomem_ack;
                goto nomem_ack;
 
 
        /* If there are errors need to be reported for unknown parameters,
        /* If there are errors need to be reported for unknown parameters,
         * include them in the outgoing INIT ACK as "Unrecognized parameter"
         * include them in the outgoing INIT ACK as "Unrecognized parameter"
         * parameter.
         * parameter.
         */
         */
        if (err_chunk) {
        if (err_chunk) {
                /* Get the "Unrecognized parameter" parameter(s) out of the
                /* Get the "Unrecognized parameter" parameter(s) out of the
                 * ERROR chunk generated by sctp_verify_init(). Since the
                 * ERROR chunk generated by sctp_verify_init(). Since the
                 * error cause code for "unknown parameter" and the
                 * error cause code for "unknown parameter" and the
                 * "Unrecognized parameter" type is the same, we can
                 * "Unrecognized parameter" type is the same, we can
                 * construct the parameters in INIT ACK by copying the
                 * construct the parameters in INIT ACK by copying the
                 * ERROR causes over.
                 * ERROR causes over.
                 */
                 */
                unk_param = (sctp_unrecognized_param_t *)
                unk_param = (sctp_unrecognized_param_t *)
                            ((__u8 *)(err_chunk->chunk_hdr) +
                            ((__u8 *)(err_chunk->chunk_hdr) +
                            sizeof(sctp_chunkhdr_t));
                            sizeof(sctp_chunkhdr_t));
                /* Replace the cause code with the "Unrecognized parameter"
                /* Replace the cause code with the "Unrecognized parameter"
                 * parameter type.
                 * parameter type.
                 */
                 */
                sctp_addto_chunk(repl, len, unk_param);
                sctp_addto_chunk(repl, len, unk_param);
                sctp_chunk_free(err_chunk);
                sctp_chunk_free(err_chunk);
        }
        }
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
 
 
        /*
        /*
         * Note:  After sending out INIT ACK with the State Cookie parameter,
         * Note:  After sending out INIT ACK with the State Cookie parameter,
         * "Z" MUST NOT allocate any resources, nor keep any states for the
         * "Z" MUST NOT allocate any resources, nor keep any states for the
         * new association.  Otherwise, "Z" will be vulnerable to resource
         * new association.  Otherwise, "Z" will be vulnerable to resource
         * attacks.
         * attacks.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
 
 
        return SCTP_DISPOSITION_DELETE_TCB;
        return SCTP_DISPOSITION_DELETE_TCB;
 
 
nomem_ack:
nomem_ack:
        if (err_chunk)
        if (err_chunk)
                sctp_chunk_free(err_chunk);
                sctp_chunk_free(err_chunk);
nomem_init:
nomem_init:
        sctp_association_free(new_asoc);
        sctp_association_free(new_asoc);
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Respond to a normal INIT ACK chunk.
 * Respond to a normal INIT ACK chunk.
 * We are the side that is initiating the association.
 * We are the side that is initiating the association.
 *
 *
 * Section: 5.1 Normal Establishment of an Association, C
 * Section: 5.1 Normal Establishment of an Association, C
 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
 *    timer and leave COOKIE-WAIT state. "A" shall then send the State
 *    timer and leave COOKIE-WAIT state. "A" shall then send the State
 *    Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
 *    Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
 *    the T1-cookie timer, and enter the COOKIE-ECHOED state.
 *    the T1-cookie timer, and enter the COOKIE-ECHOED state.
 *
 *
 *    Note: The COOKIE ECHO chunk can be bundled with any pending outbound
 *    Note: The COOKIE ECHO chunk can be bundled with any pending outbound
 *    DATA chunks, but it MUST be the first chunk in the packet and
 *    DATA chunks, but it MUST be the first chunk in the packet and
 *    until the COOKIE ACK is returned the sender MUST NOT send any
 *    until the COOKIE ACK is returned the sender MUST NOT send any
 *    other packets to the peer.
 *    other packets to the peer.
 *
 *
 * Verification Tag: 3.3.3
 * Verification Tag: 3.3.3
 *   If the value of the Initiate Tag in a received INIT ACK chunk is
 *   If the value of the Initiate Tag in a received INIT ACK chunk is
 *   found to be 0, the receiver MUST treat it as an error and close the
 *   found to be 0, the receiver MUST treat it as an error and close the
 *   association by transmitting an ABORT.
 *   association by transmitting an ABORT.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
                                       const struct sctp_association *asoc,
                                       const struct sctp_association *asoc,
                                       const sctp_subtype_t type,
                                       const sctp_subtype_t type,
                                       void *arg,
                                       void *arg,
                                       sctp_cmd_seq_t *commands)
                                       sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        sctp_init_chunk_t *initchunk;
        sctp_init_chunk_t *initchunk;
        __u32 init_tag;
        __u32 init_tag;
        struct sctp_chunk *err_chunk;
        struct sctp_chunk *err_chunk;
        struct sctp_packet *packet;
        struct sctp_packet *packet;
        sctp_disposition_t ret;
        sctp_disposition_t ret;
 
 
        /* 6.10 Bundling
        /* 6.10 Bundling
         * An endpoint MUST NOT bundle INIT, INIT ACK or
         * An endpoint MUST NOT bundle INIT, INIT ACK or
         * SHUTDOWN COMPLETE with any other chunks.
         * SHUTDOWN COMPLETE with any other chunks.
         */
         */
        if (!chunk->singleton)
        if (!chunk->singleton)
                return SCTP_DISPOSITION_VIOLATION;
                return SCTP_DISPOSITION_VIOLATION;
 
 
        /* Grab the INIT header.  */
        /* Grab the INIT header.  */
        chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
        chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
 
 
        init_tag = ntohl(chunk->subh.init_hdr->init_tag);
        init_tag = ntohl(chunk->subh.init_hdr->init_tag);
 
 
        /* Verification Tag: 3.3.3
        /* Verification Tag: 3.3.3
         *   If the value of the Initiate Tag in a received INIT ACK
         *   If the value of the Initiate Tag in a received INIT ACK
         *   chunk is found to be 0, the receiver MUST treat it as an
         *   chunk is found to be 0, the receiver MUST treat it as an
         *   error and close the association by transmitting an ABORT.
         *   error and close the association by transmitting an ABORT.
         */
         */
        if (!init_tag) {
        if (!init_tag) {
                struct sctp_chunk *reply = sctp_make_abort(asoc, chunk, 0);
                struct sctp_chunk *reply = sctp_make_abort(asoc, chunk, 0);
                if (!reply)
                if (!reply)
                        goto nomem;
                        goto nomem;
 
 
                sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
                sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
                sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                                SCTP_STATE(SCTP_STATE_CLOSED));
                                SCTP_STATE(SCTP_STATE_CLOSED));
                SCTP_INC_STATS(SctpAborteds);
                SCTP_INC_STATS(SctpAborteds);
                sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
                sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
                return SCTP_DISPOSITION_DELETE_TCB;
                return SCTP_DISPOSITION_DELETE_TCB;
        }
        }
 
 
        /* Verify the INIT chunk before processing it. */
        /* Verify the INIT chunk before processing it. */
        err_chunk = NULL;
        err_chunk = NULL;
        if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
        if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
                              (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
                              (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
                              &err_chunk)) {
                              &err_chunk)) {
 
 
                SCTP_INC_STATS(SctpAborteds);
                SCTP_INC_STATS(SctpAborteds);
 
 
                /* This chunk contains fatal error. It is to be discarded.
                /* This chunk contains fatal error. It is to be discarded.
                 * Send an ABORT, with causes if there is any.
                 * Send an ABORT, with causes if there is any.
                 */
                 */
                if (err_chunk) {
                if (err_chunk) {
                        packet = sctp_abort_pkt_new(ep, asoc, arg,
                        packet = sctp_abort_pkt_new(ep, asoc, arg,
                                        (__u8 *)(err_chunk->chunk_hdr) +
                                        (__u8 *)(err_chunk->chunk_hdr) +
                                        sizeof(sctp_chunkhdr_t),
                                        sizeof(sctp_chunkhdr_t),
                                        ntohs(err_chunk->chunk_hdr->length) -
                                        ntohs(err_chunk->chunk_hdr->length) -
                                        sizeof(sctp_chunkhdr_t));
                                        sizeof(sctp_chunkhdr_t));
 
 
                        sctp_chunk_free(err_chunk);
                        sctp_chunk_free(err_chunk);
 
 
                        if (packet) {
                        if (packet) {
                                sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
                                sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
                                                SCTP_PACKET(packet));
                                                SCTP_PACKET(packet));
                                SCTP_INC_STATS(SctpOutCtrlChunks);
                                SCTP_INC_STATS(SctpOutCtrlChunks);
                                sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                                sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                                                SCTP_STATE(SCTP_STATE_CLOSED));
                                                SCTP_STATE(SCTP_STATE_CLOSED));
                                sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
                                sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
                                                SCTP_NULL());
                                                SCTP_NULL());
                                return SCTP_DISPOSITION_CONSUME;
                                return SCTP_DISPOSITION_CONSUME;
                        } else {
                        } else {
                                sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                                sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                                                SCTP_STATE(SCTP_STATE_CLOSED));
                                                SCTP_STATE(SCTP_STATE_CLOSED));
                                sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
                                sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
                                                SCTP_NULL());
                                                SCTP_NULL());
                                return SCTP_DISPOSITION_NOMEM;
                                return SCTP_DISPOSITION_NOMEM;
                        }
                        }
                } else {
                } else {
                        ret = sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
                        ret = sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
                                                   commands);
                                                   commands);
                        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                                        SCTP_STATE(SCTP_STATE_CLOSED));
                                        SCTP_STATE(SCTP_STATE_CLOSED));
                        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
                        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
                                        SCTP_NULL());
                                        SCTP_NULL());
                        return ret;
                        return ret;
                }
                }
        }
        }
 
 
        /* Tag the variable length parameters.  Note that we never
        /* Tag the variable length parameters.  Note that we never
         * convert the parameters in an INIT chunk.
         * convert the parameters in an INIT chunk.
         */
         */
        chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
        chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
 
 
        initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
        initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
        sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
                        SCTP_PEER_INIT(initchunk));
                        SCTP_PEER_INIT(initchunk));
 
 
        /* 5.1 C) "A" shall stop the T1-init timer and leave
        /* 5.1 C) "A" shall stop the T1-init timer and leave
         * COOKIE-WAIT state.  "A" shall then ... start the T1-cookie
         * COOKIE-WAIT state.  "A" shall then ... start the T1-cookie
         * timer, and enter the COOKIE-ECHOED state.
         * timer, and enter the COOKIE-ECHOED state.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
        sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_RESET,
        sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_RESET,
                        SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
                        SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
                        SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
 
 
        /* 5.1 C) "A" shall then send the State Cookie received in the
        /* 5.1 C) "A" shall then send the State Cookie received in the
         * INIT ACK chunk in a COOKIE ECHO chunk, ...
         * INIT ACK chunk in a COOKIE ECHO chunk, ...
         */
         */
        /* If there is any errors to report, send the ERROR chunk generated
        /* If there is any errors to report, send the ERROR chunk generated
         * for unknown parameters as well.
         * for unknown parameters as well.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
        sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
                        SCTP_CHUNK(err_chunk));
                        SCTP_CHUNK(err_chunk));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Respond to a normal COOKIE ECHO chunk.
 * Respond to a normal COOKIE ECHO chunk.
 * We are the side that is being asked for an association.
 * We are the side that is being asked for an association.
 *
 *
 * Section: 5.1 Normal Establishment of an Association, D
 * Section: 5.1 Normal Establishment of an Association, D
 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
 *    with a COOKIE ACK chunk after building a TCB and moving to
 *    with a COOKIE ACK chunk after building a TCB and moving to
 *    the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
 *    the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
 *    any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
 *    any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
 *    chunk MUST be the first chunk in the packet.
 *    chunk MUST be the first chunk in the packet.
 *
 *
 *   IMPLEMENTATION NOTE: An implementation may choose to send the
 *   IMPLEMENTATION NOTE: An implementation may choose to send the
 *   Communication Up notification to the SCTP user upon reception
 *   Communication Up notification to the SCTP user upon reception
 *   of a valid COOKIE ECHO chunk.
 *   of a valid COOKIE ECHO chunk.
 *
 *
 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
 * D) Rules for packet carrying a COOKIE ECHO
 * D) Rules for packet carrying a COOKIE ECHO
 *
 *
 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
 *   Initial Tag received in the INIT ACK.
 *   Initial Tag received in the INIT ACK.
 *
 *
 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
                                      const struct sctp_association *asoc,
                                      const struct sctp_association *asoc,
                                      const sctp_subtype_t type, void *arg,
                                      const sctp_subtype_t type, void *arg,
                                      sctp_cmd_seq_t *commands)
                                      sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        struct sctp_association *new_asoc;
        struct sctp_association *new_asoc;
        sctp_init_chunk_t *peer_init;
        sctp_init_chunk_t *peer_init;
        struct sctp_chunk *repl;
        struct sctp_chunk *repl;
        struct sctp_ulpevent *ev;
        struct sctp_ulpevent *ev;
        int error = 0;
        int error = 0;
        struct sctp_chunk *err_chk_p;
        struct sctp_chunk *err_chk_p;
 
 
        /* If the packet is an OOTB packet which is temporarily on the
        /* If the packet is an OOTB packet which is temporarily on the
         * control endpoint, respond with an ABORT.
         * control endpoint, respond with an ABORT.
         */
         */
        if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
        if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
                return sctp_sf_ootb(ep, asoc, type, arg, commands);
                return sctp_sf_ootb(ep, asoc, type, arg, commands);
 
 
        /* "Decode" the chunk.  We have no optional parameters so we
        /* "Decode" the chunk.  We have no optional parameters so we
         * are in good shape.
         * are in good shape.
         */
         */
        chunk->subh.cookie_hdr =
        chunk->subh.cookie_hdr =
                (struct sctp_signed_cookie *)chunk->skb->data;
                (struct sctp_signed_cookie *)chunk->skb->data;
        skb_pull(chunk->skb,
        skb_pull(chunk->skb,
                 ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t));
                 ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t));
 
 
        /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
        /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
         * "Z" will reply with a COOKIE ACK chunk after building a TCB
         * "Z" will reply with a COOKIE ACK chunk after building a TCB
         * and moving to the ESTABLISHED state.
         * and moving to the ESTABLISHED state.
         */
         */
        new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
        new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
                                      &err_chk_p);
                                      &err_chk_p);
 
 
        /* FIXME:
        /* FIXME:
         * If the re-build failed, what is the proper error path
         * If the re-build failed, what is the proper error path
         * from here?
         * from here?
         *
         *
         * [We should abort the association. --piggy]
         * [We should abort the association. --piggy]
         */
         */
        if (!new_asoc) {
        if (!new_asoc) {
                /* FIXME: Several errors are possible.  A bad cookie should
                /* FIXME: Several errors are possible.  A bad cookie should
                 * be silently discarded, but think about logging it too.
                 * be silently discarded, but think about logging it too.
                 */
                 */
                switch (error) {
                switch (error) {
                case -SCTP_IERROR_NOMEM:
                case -SCTP_IERROR_NOMEM:
                        goto nomem;
                        goto nomem;
 
 
                case -SCTP_IERROR_STALE_COOKIE:
                case -SCTP_IERROR_STALE_COOKIE:
                        sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
                        sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
                                                   err_chk_p);
                                                   err_chk_p);
                        return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                        return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
                case -SCTP_IERROR_BAD_SIG:
                case -SCTP_IERROR_BAD_SIG:
                default:
                default:
                        return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                        return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                };
                };
        }
        }
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_ESTABLISHED));
                        SCTP_STATE(SCTP_STATE_ESTABLISHED));
        SCTP_INC_STATS(SctpCurrEstab);
        SCTP_INC_STATS(SctpCurrEstab);
        SCTP_INC_STATS(SctpPassiveEstabs);
        SCTP_INC_STATS(SctpPassiveEstabs);
        sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
 
 
        if (new_asoc->autoclose)
        if (new_asoc->autoclose)
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
                                SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
                                SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
 
 
        /* Re-build the bind address for the association is done in
        /* Re-build the bind address for the association is done in
         * the sctp_unpack_cookie() already.
         * the sctp_unpack_cookie() already.
         */
         */
        /* This is a brand-new association, so these are not yet side
        /* This is a brand-new association, so these are not yet side
         * effects--it is safe to run them here.
         * effects--it is safe to run them here.
         */
         */
        peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
        peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
 
 
        if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
        if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
                               &chunk->subh.cookie_hdr->c.peer_addr,
                               &chunk->subh.cookie_hdr->c.peer_addr,
                               peer_init, GFP_ATOMIC))
                               peer_init, GFP_ATOMIC))
                goto nomem_init;
                goto nomem_init;
 
 
        repl = sctp_make_cookie_ack(new_asoc, chunk);
        repl = sctp_make_cookie_ack(new_asoc, chunk);
        if (!repl)
        if (!repl)
                goto nomem_repl;
                goto nomem_repl;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
 
 
        /* RFC 2960 5.1 Normal Establishment of an Association
        /* RFC 2960 5.1 Normal Establishment of an Association
         *
         *
         * D) IMPLEMENTATION NOTE: An implementation may choose to
         * D) IMPLEMENTATION NOTE: An implementation may choose to
         * send the Communication Up notification to the SCTP user
         * send the Communication Up notification to the SCTP user
         * upon reception of a valid COOKIE ECHO chunk.
         * upon reception of a valid COOKIE ECHO chunk.
         */
         */
        ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
        ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
                                             new_asoc->c.sinit_num_ostreams,
                                             new_asoc->c.sinit_num_ostreams,
                                             new_asoc->c.sinit_max_instreams,
                                             new_asoc->c.sinit_max_instreams,
                                             GFP_ATOMIC);
                                             GFP_ATOMIC);
        if (!ev)
        if (!ev)
                goto nomem_ev;
                goto nomem_ev;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem_ev:
nomem_ev:
        sctp_chunk_free(repl);
        sctp_chunk_free(repl);
nomem_repl:
nomem_repl:
nomem_init:
nomem_init:
        sctp_association_free(new_asoc);
        sctp_association_free(new_asoc);
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Respond to a normal COOKIE ACK chunk.
 * Respond to a normal COOKIE ACK chunk.
 * We are the side that is being asked for an association.
 * We are the side that is being asked for an association.
 *
 *
 * RFC 2960 5.1 Normal Establishment of an Association
 * RFC 2960 5.1 Normal Establishment of an Association
 *
 *
 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
 *    COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
 *    COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
 *    timer. It may also notify its ULP about the successful
 *    timer. It may also notify its ULP about the successful
 *    establishment of the association with a Communication Up
 *    establishment of the association with a Communication Up
 *    notification (see Section 10).
 *    notification (see Section 10).
 *
 *
 * Verification Tag:
 * Verification Tag:
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
                                      const struct sctp_association *asoc,
                                      const struct sctp_association *asoc,
                                      const sctp_subtype_t type, void *arg,
                                      const sctp_subtype_t type, void *arg,
                                      sctp_cmd_seq_t *commands)
                                      sctp_cmd_seq_t *commands)
{
{
        struct sctp_ulpevent *ev;
        struct sctp_ulpevent *ev;
 
 
        /* RFC 2960 5.1 Normal Establishment of an Association
        /* RFC 2960 5.1 Normal Establishment of an Association
         *
         *
         * E) Upon reception of the COOKIE ACK, endpoint "A" will move
         * E) Upon reception of the COOKIE ACK, endpoint "A" will move
         * from the COOKIE-ECHOED state to the ESTABLISHED state,
         * from the COOKIE-ECHOED state to the ESTABLISHED state,
         * stopping the T1-cookie timer.
         * stopping the T1-cookie timer.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_ESTABLISHED));
                        SCTP_STATE(SCTP_STATE_ESTABLISHED));
        SCTP_INC_STATS(SctpCurrEstab);
        SCTP_INC_STATS(SctpCurrEstab);
        SCTP_INC_STATS(SctpActiveEstabs);
        SCTP_INC_STATS(SctpActiveEstabs);
        sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
        if (asoc->autoclose)
        if (asoc->autoclose)
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
                                SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
                                SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
        sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
 
 
        /* It may also notify its ULP about the successful
        /* It may also notify its ULP about the successful
         * establishment of the association with a Communication Up
         * establishment of the association with a Communication Up
         * notification (see Section 10).
         * notification (see Section 10).
         */
         */
        ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
        ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
                                             0, asoc->c.sinit_num_ostreams,
                                             0, asoc->c.sinit_num_ostreams,
                                             asoc->c.sinit_max_instreams,
                                             asoc->c.sinit_max_instreams,
                                             GFP_ATOMIC);
                                             GFP_ATOMIC);
 
 
        if (!ev)
        if (!ev)
                goto nomem;
                goto nomem;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/* Generate and sendout a heartbeat packet.  */
/* Generate and sendout a heartbeat packet.  */
sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
                                     const struct sctp_association *asoc,
                                     const struct sctp_association *asoc,
                                     const sctp_subtype_t type,
                                     const sctp_subtype_t type,
                                     void *arg,
                                     void *arg,
                                     sctp_cmd_seq_t *commands)
                                     sctp_cmd_seq_t *commands)
{
{
        struct sctp_transport *transport = (struct sctp_transport *) arg;
        struct sctp_transport *transport = (struct sctp_transport *) arg;
        struct sctp_chunk *reply;
        struct sctp_chunk *reply;
        sctp_sender_hb_info_t hbinfo;
        sctp_sender_hb_info_t hbinfo;
        size_t paylen = 0;
        size_t paylen = 0;
 
 
        hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
        hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
        hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
        hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
        hbinfo.daddr = transport->ipaddr;
        hbinfo.daddr = transport->ipaddr;
        hbinfo.sent_at = jiffies;
        hbinfo.sent_at = jiffies;
 
 
        /* Send a heartbeat to our peer.  */
        /* Send a heartbeat to our peer.  */
        paylen = sizeof(sctp_sender_hb_info_t);
        paylen = sizeof(sctp_sender_hb_info_t);
        reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
        reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
        if (!reply)
        if (!reply)
                return SCTP_DISPOSITION_NOMEM;
                return SCTP_DISPOSITION_NOMEM;
 
 
        /* Set rto_pending indicating that an RTT measurement
        /* Set rto_pending indicating that an RTT measurement
         * is started with this heartbeat chunk.
         * is started with this heartbeat chunk.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
        sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
                        SCTP_TRANSPORT(transport));
                        SCTP_TRANSPORT(transport));
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/* Generate a HEARTBEAT packet on the given transport.  */
/* Generate a HEARTBEAT packet on the given transport.  */
sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_transport *transport = (struct sctp_transport *) arg;
        struct sctp_transport *transport = (struct sctp_transport *) arg;
 
 
        if (asoc->overall_error_count > asoc->max_retrans) {
        if (asoc->overall_error_count > asoc->max_retrans) {
                /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
                /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                                SCTP_U32(SCTP_ERROR_NO_ERROR));
                                SCTP_U32(SCTP_ERROR_NO_ERROR));
                SCTP_INC_STATS(SctpAborteds);
                SCTP_INC_STATS(SctpAborteds);
                SCTP_DEC_STATS(SctpCurrEstab);
                SCTP_DEC_STATS(SctpCurrEstab);
                return SCTP_DISPOSITION_DELETE_TCB;
                return SCTP_DISPOSITION_DELETE_TCB;
        }
        }
 
 
        /* Section 3.3.5.
        /* Section 3.3.5.
         * The Sender-specific Heartbeat Info field should normally include
         * The Sender-specific Heartbeat Info field should normally include
         * information about the sender's current time when this HEARTBEAT
         * information about the sender's current time when this HEARTBEAT
         * chunk is sent and the destination transport address to which this
         * chunk is sent and the destination transport address to which this
         * HEARTBEAT is sent (see Section 8.3).
         * HEARTBEAT is sent (see Section 8.3).
         */
         */
 
 
        if (transport->hb_allowed) {
        if (transport->hb_allowed) {
                if (SCTP_DISPOSITION_NOMEM ==
                if (SCTP_DISPOSITION_NOMEM ==
                                sctp_sf_heartbeat(ep, asoc, type, arg,
                                sctp_sf_heartbeat(ep, asoc, type, arg,
                                                  commands))
                                                  commands))
                        return SCTP_DISPOSITION_NOMEM;
                        return SCTP_DISPOSITION_NOMEM;
                /* Set transport error counter and association error counter
                /* Set transport error counter and association error counter
                 * when sending heartbeat.
                 * when sending heartbeat.
                 */
                 */
                sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
                sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
                                SCTP_TRANSPORT(transport));
                                SCTP_TRANSPORT(transport));
        }
        }
        sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
                        SCTP_TRANSPORT(transport));
                        SCTP_TRANSPORT(transport));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/*
/*
 * Process an heartbeat request.
 * Process an heartbeat request.
 *
 *
 * Section: 8.3 Path Heartbeat
 * Section: 8.3 Path Heartbeat
 * The receiver of the HEARTBEAT should immediately respond with a
 * The receiver of the HEARTBEAT should immediately respond with a
 * HEARTBEAT ACK that contains the Heartbeat Information field copied
 * HEARTBEAT ACK that contains the Heartbeat Information field copied
 * from the received HEARTBEAT chunk.
 * from the received HEARTBEAT chunk.
 *
 *
 * Verification Tag:  8.5 Verification Tag [Normal verification]
 * Verification Tag:  8.5 Verification Tag [Normal verification]
 * When receiving an SCTP packet, the endpoint MUST ensure that the
 * When receiving an SCTP packet, the endpoint MUST ensure that the
 * value in the Verification Tag field of the received SCTP packet
 * value in the Verification Tag field of the received SCTP packet
 * matches its own Tag. If the received Verification Tag value does not
 * matches its own Tag. If the received Verification Tag value does not
 * match the receiver's own tag value, the receiver shall silently
 * match the receiver's own tag value, the receiver shall silently
 * discard the packet and shall not process it any further except for
 * discard the packet and shall not process it any further except for
 * those cases listed in Section 8.5.1 below.
 * those cases listed in Section 8.5.1 below.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
                                    const struct sctp_association *asoc,
                                    const struct sctp_association *asoc,
                                    const sctp_subtype_t type,
                                    const sctp_subtype_t type,
                                    void *arg,
                                    void *arg,
                                    sctp_cmd_seq_t *commands)
                                    sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *reply;
        struct sctp_chunk *reply;
        size_t paylen = 0;
        size_t paylen = 0;
 
 
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
         * that the value in the Verification Tag field of the
         * that the value in the Verification Tag field of the
         * received SCTP packet matches its own Tag. If the received
         * received SCTP packet matches its own Tag. If the received
         * Verification Tag value does not match the receiver's own
         * Verification Tag value does not match the receiver's own
         * tag value, the receiver shall silently discard the packet...
         * tag value, the receiver shall silently discard the packet...
         */
         */
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
        /* 8.3 The receiver of the HEARTBEAT should immediately
        /* 8.3 The receiver of the HEARTBEAT should immediately
         * respond with a HEARTBEAT ACK that contains the Heartbeat
         * respond with a HEARTBEAT ACK that contains the Heartbeat
         * Information field copied from the received HEARTBEAT chunk.
         * Information field copied from the received HEARTBEAT chunk.
         */
         */
        chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
        chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
        paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
        paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
        skb_pull(chunk->skb, paylen);
        skb_pull(chunk->skb, paylen);
 
 
        reply = sctp_make_heartbeat_ack(asoc, chunk,
        reply = sctp_make_heartbeat_ack(asoc, chunk,
                                        chunk->subh.hb_hdr, paylen);
                                        chunk->subh.hb_hdr, paylen);
        if (!reply)
        if (!reply)
                goto nomem;
                goto nomem;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Process the returning HEARTBEAT ACK.
 * Process the returning HEARTBEAT ACK.
 *
 *
 * Section: 8.3 Path Heartbeat
 * Section: 8.3 Path Heartbeat
 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
 * should clear the error counter of the destination transport
 * should clear the error counter of the destination transport
 * address to which the HEARTBEAT was sent, and mark the destination
 * address to which the HEARTBEAT was sent, and mark the destination
 * transport address as active if it is not so marked. The endpoint may
 * transport address as active if it is not so marked. The endpoint may
 * optionally report to the upper layer when an inactive destination
 * optionally report to the upper layer when an inactive destination
 * address is marked as active due to the reception of the latest
 * address is marked as active due to the reception of the latest
 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
 * clear the association overall error count as well (as defined
 * clear the association overall error count as well (as defined
 * in section 8.1).
 * in section 8.1).
 *
 *
 * The receiver of the HEARTBEAT ACK should also perform an RTT
 * The receiver of the HEARTBEAT ACK should also perform an RTT
 * measurement for that destination transport address using the time
 * measurement for that destination transport address using the time
 * value carried in the HEARTBEAT ACK chunk.
 * value carried in the HEARTBEAT ACK chunk.
 *
 *
 * Verification Tag:  8.5 Verification Tag [Normal verification]
 * Verification Tag:  8.5 Verification Tag [Normal verification]
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        union sctp_addr from_addr;
        union sctp_addr from_addr;
        struct sctp_transport *link;
        struct sctp_transport *link;
        sctp_sender_hb_info_t *hbinfo;
        sctp_sender_hb_info_t *hbinfo;
        unsigned long max_interval;
        unsigned long max_interval;
 
 
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
         * that the value in the Verification Tag field of the
         * that the value in the Verification Tag field of the
         * received SCTP packet matches its own Tag. ...
         * received SCTP packet matches its own Tag. ...
         */
         */
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
        hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
        hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
        from_addr = hbinfo->daddr;
        from_addr = hbinfo->daddr;
        link = sctp_assoc_lookup_paddr(asoc, &from_addr);
        link = sctp_assoc_lookup_paddr(asoc, &from_addr);
 
 
        /* This should never happen, but lets log it if so.  */
        /* This should never happen, but lets log it if so.  */
        if (!link) {
        if (!link) {
                printk(KERN_WARNING
                printk(KERN_WARNING
                       "%s: Could not find address %d.%d.%d.%d\n",
                       "%s: Could not find address %d.%d.%d.%d\n",
                       __FUNCTION__, NIPQUAD(from_addr.v4.sin_addr));
                       __FUNCTION__, NIPQUAD(from_addr.v4.sin_addr));
                return SCTP_DISPOSITION_DISCARD;
                return SCTP_DISPOSITION_DISCARD;
        }
        }
 
 
        max_interval = link->hb_interval + link->rto;
        max_interval = link->hb_interval + link->rto;
 
 
        /* Check if the timestamp looks valid.  */
        /* Check if the timestamp looks valid.  */
        if (time_after(hbinfo->sent_at, jiffies) ||
        if (time_after(hbinfo->sent_at, jiffies) ||
            time_after(jiffies, hbinfo->sent_at + max_interval)) {
            time_after(jiffies, hbinfo->sent_at + max_interval)) {
                SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
                SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
                                  "received for transport: %p\n",
                                  "received for transport: %p\n",
                                   __FUNCTION__, link);
                                   __FUNCTION__, link);
                return SCTP_DISPOSITION_DISCARD;
                return SCTP_DISPOSITION_DISCARD;
        }
        }
 
 
        /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
        /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
         * the HEARTBEAT should clear the error counter of the
         * the HEARTBEAT should clear the error counter of the
         * destination transport address to which the HEARTBEAT was
         * destination transport address to which the HEARTBEAT was
         * sent and mark the destination transport address as active if
         * sent and mark the destination transport address as active if
         * it is not so marked.
         * it is not so marked.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
        sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/* Helper function to send out an abort for the restart
/* Helper function to send out an abort for the restart
 * condition.
 * condition.
 */
 */
static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
                                      struct sctp_chunk *init,
                                      struct sctp_chunk *init,
                                      sctp_cmd_seq_t *commands)
                                      sctp_cmd_seq_t *commands)
{
{
        int len;
        int len;
        struct sctp_packet *pkt;
        struct sctp_packet *pkt;
        union sctp_addr_param *addrparm;
        union sctp_addr_param *addrparm;
        struct sctp_errhdr *errhdr;
        struct sctp_errhdr *errhdr;
        struct sctp_endpoint *ep;
        struct sctp_endpoint *ep;
        char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
        char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
        struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
        struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
 
 
        /* Build the error on the stack.   We are way to malloc crazy
        /* Build the error on the stack.   We are way to malloc crazy
         * throughout the code today.
         * throughout the code today.
         */
         */
        errhdr = (struct sctp_errhdr *)buffer;
        errhdr = (struct sctp_errhdr *)buffer;
        addrparm = (union sctp_addr_param *)errhdr->variable;
        addrparm = (union sctp_addr_param *)errhdr->variable;
 
 
        /* Copy into a parm format. */
        /* Copy into a parm format. */
        len = af->to_addr_param(ssa, addrparm);
        len = af->to_addr_param(ssa, addrparm);
        len += sizeof(sctp_errhdr_t);
        len += sizeof(sctp_errhdr_t);
 
 
        errhdr->cause = SCTP_ERROR_RESTART;
        errhdr->cause = SCTP_ERROR_RESTART;
        errhdr->length = htons(len);
        errhdr->length = htons(len);
 
 
        /* Assign to the control socket. */
        /* Assign to the control socket. */
        ep = sctp_sk((sctp_get_ctl_sock()))->ep;
        ep = sctp_sk((sctp_get_ctl_sock()))->ep;
 
 
        /* Association is NULL since this may be a restart attack and we
        /* Association is NULL since this may be a restart attack and we
         * want to send back the attacker's vtag.
         * want to send back the attacker's vtag.
         */
         */
        pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
        pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
 
 
        if (!pkt)
        if (!pkt)
                goto out;
                goto out;
        sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
        sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
 
 
        SCTP_INC_STATS(SctpOutCtrlChunks);
        SCTP_INC_STATS(SctpOutCtrlChunks);
 
 
        /* Discard the rest of the inbound packet. */
        /* Discard the rest of the inbound packet. */
        sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
 
 
out:
out:
        /* Even if there is no memory, treat as a failure so
        /* Even if there is no memory, treat as a failure so
         * the packet will get dropped.
         * the packet will get dropped.
         */
         */
        return 0;
        return 0;
}
}
 
 
/* A restart is occurring, check to make sure no new addresses
/* A restart is occurring, check to make sure no new addresses
 * are being added as we may be under a takeover attack.
 * are being added as we may be under a takeover attack.
 */
 */
static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
                                       const struct sctp_association *asoc,
                                       const struct sctp_association *asoc,
                                       struct sctp_chunk *init,
                                       struct sctp_chunk *init,
                                       sctp_cmd_seq_t *commands)
                                       sctp_cmd_seq_t *commands)
{
{
        struct sctp_transport *new_addr, *addr;
        struct sctp_transport *new_addr, *addr;
        struct list_head *pos, *pos2;
        struct list_head *pos, *pos2;
        int found;
        int found;
 
 
        /* Implementor's Guide - Sectin 5.2.2
        /* Implementor's Guide - Sectin 5.2.2
         * ...
         * ...
         * Before responding the endpoint MUST check to see if the
         * Before responding the endpoint MUST check to see if the
         * unexpected INIT adds new addresses to the association. If new
         * unexpected INIT adds new addresses to the association. If new
         * addresses are added to the association, the endpoint MUST respond
         * addresses are added to the association, the endpoint MUST respond
         * with an ABORT..
         * with an ABORT..
         */
         */
 
 
        /* Search through all current addresses and make sure
        /* Search through all current addresses and make sure
         * we aren't adding any new ones.
         * we aren't adding any new ones.
         */
         */
        new_addr = 0;
        new_addr = 0;
        found = 0;
        found = 0;
 
 
        list_for_each(pos, &new_asoc->peer.transport_addr_list) {
        list_for_each(pos, &new_asoc->peer.transport_addr_list) {
                new_addr = list_entry(pos, struct sctp_transport, transports);
                new_addr = list_entry(pos, struct sctp_transport, transports);
                found = 0;
                found = 0;
                list_for_each(pos2, &asoc->peer.transport_addr_list) {
                list_for_each(pos2, &asoc->peer.transport_addr_list) {
                        addr = list_entry(pos2, struct sctp_transport,
                        addr = list_entry(pos2, struct sctp_transport,
                                          transports);
                                          transports);
                        if (sctp_cmp_addr_exact(&new_addr->ipaddr,
                        if (sctp_cmp_addr_exact(&new_addr->ipaddr,
                                                &addr->ipaddr)) {
                                                &addr->ipaddr)) {
                                found = 1;
                                found = 1;
                                break;
                                break;
                        }
                        }
                }
                }
                if (!found)
                if (!found)
                        break;
                        break;
        }
        }
 
 
        /* If a new address was added, ABORT the sender. */
        /* If a new address was added, ABORT the sender. */
        if (!found && new_addr) {
        if (!found && new_addr) {
                sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
                sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
        }
        }
 
 
        /* Return success if all addresses were found. */
        /* Return success if all addresses were found. */
        return found;
        return found;
}
}
 
 
/* Populate the verification/tie tags based on overlapping INIT
/* Populate the verification/tie tags based on overlapping INIT
 * scenario.
 * scenario.
 *
 *
 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
 */
 */
static void sctp_tietags_populate(struct sctp_association *new_asoc,
static void sctp_tietags_populate(struct sctp_association *new_asoc,
                                  const struct sctp_association *asoc)
                                  const struct sctp_association *asoc)
{
{
        switch (asoc->state) {
        switch (asoc->state) {
 
 
        /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
        /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
 
 
        case SCTP_STATE_COOKIE_WAIT:
        case SCTP_STATE_COOKIE_WAIT:
                new_asoc->c.my_vtag     = asoc->c.my_vtag;
                new_asoc->c.my_vtag     = asoc->c.my_vtag;
                new_asoc->c.my_ttag     = asoc->c.my_vtag;
                new_asoc->c.my_ttag     = asoc->c.my_vtag;
                new_asoc->c.peer_ttag   = 0;
                new_asoc->c.peer_ttag   = 0;
                break;
                break;
 
 
        case SCTP_STATE_COOKIE_ECHOED:
        case SCTP_STATE_COOKIE_ECHOED:
                new_asoc->c.my_vtag     = asoc->c.my_vtag;
                new_asoc->c.my_vtag     = asoc->c.my_vtag;
                new_asoc->c.my_ttag     = asoc->c.my_vtag;
                new_asoc->c.my_ttag     = asoc->c.my_vtag;
                new_asoc->c.peer_ttag   = asoc->c.peer_vtag;
                new_asoc->c.peer_ttag   = asoc->c.peer_vtag;
                break;
                break;
 
 
        /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
        /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
         * COOKIE-WAIT and SHUTDOWN-ACK-SENT
         * COOKIE-WAIT and SHUTDOWN-ACK-SENT
         */
         */
        default:
        default:
                new_asoc->c.my_ttag   = asoc->c.my_vtag;
                new_asoc->c.my_ttag   = asoc->c.my_vtag;
                new_asoc->c.peer_ttag = asoc->c.peer_vtag;
                new_asoc->c.peer_ttag = asoc->c.peer_vtag;
                break;
                break;
        };
        };
 
 
        /* Other parameters for the endpoint SHOULD be copied from the
        /* Other parameters for the endpoint SHOULD be copied from the
         * existing parameters of the association (e.g. number of
         * existing parameters of the association (e.g. number of
         * outbound streams) into the INIT ACK and cookie.
         * outbound streams) into the INIT ACK and cookie.
         */
         */
        new_asoc->rwnd                  = asoc->rwnd;
        new_asoc->rwnd                  = asoc->rwnd;
        new_asoc->c.sinit_num_ostreams  = asoc->c.sinit_num_ostreams;
        new_asoc->c.sinit_num_ostreams  = asoc->c.sinit_num_ostreams;
        new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
        new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
        new_asoc->c.initial_tsn         = asoc->c.initial_tsn;
        new_asoc->c.initial_tsn         = asoc->c.initial_tsn;
}
}
 
 
/*
/*
 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
 * handling action.
 * handling action.
 *
 *
 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
 *
 *
 * Returns value representing action to be taken.   These action values
 * Returns value representing action to be taken.   These action values
 * correspond to Action/Description values in RFC 2960, Table 2.
 * correspond to Action/Description values in RFC 2960, Table 2.
 */
 */
static char sctp_tietags_compare(struct sctp_association *new_asoc,
static char sctp_tietags_compare(struct sctp_association *new_asoc,
                                 const struct sctp_association *asoc)
                                 const struct sctp_association *asoc)
{
{
        /* In this case, the peer may have restarted.  */
        /* In this case, the peer may have restarted.  */
        if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
        if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
            (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
            (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
            (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
            (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
            (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
            (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
                return 'A';
                return 'A';
 
 
        /* Collision case B. */
        /* Collision case B. */
        if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
        if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
            ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
            ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
             (0 == asoc->c.peer_vtag))) {
             (0 == asoc->c.peer_vtag))) {
                return 'B';
                return 'B';
        }
        }
 
 
        /* Collision case D. */
        /* Collision case D. */
        if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
        if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
            (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
            (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
                return 'D';
                return 'D';
 
 
        /* Collision case C. */
        /* Collision case C. */
        if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
        if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
            (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
            (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
            (0 == new_asoc->c.my_ttag) &&
            (0 == new_asoc->c.my_ttag) &&
            (0 == new_asoc->c.peer_ttag))
            (0 == new_asoc->c.peer_ttag))
                return 'C';
                return 'C';
 
 
        /* No match to any of the special cases; discard this packet. */
        /* No match to any of the special cases; discard this packet. */
        return 'E';
        return 'E';
}
}
 
 
/* Common helper routine for both duplicate and simulataneous INIT
/* Common helper routine for both duplicate and simulataneous INIT
 * chunk handling.
 * chunk handling.
 */
 */
static sctp_disposition_t sctp_sf_do_unexpected_init(
static sctp_disposition_t sctp_sf_do_unexpected_init(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg, sctp_cmd_seq_t *commands)
        void *arg, sctp_cmd_seq_t *commands)
{
{
        sctp_disposition_t retval;
        sctp_disposition_t retval;
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *repl;
        struct sctp_chunk *repl;
        struct sctp_association *new_asoc;
        struct sctp_association *new_asoc;
        struct sctp_chunk *err_chunk;
        struct sctp_chunk *err_chunk;
        struct sctp_packet *packet;
        struct sctp_packet *packet;
        sctp_unrecognized_param_t *unk_param;
        sctp_unrecognized_param_t *unk_param;
        int len;
        int len;
 
 
        /* 6.10 Bundling
        /* 6.10 Bundling
         * An endpoint MUST NOT bundle INIT, INIT ACK or
         * An endpoint MUST NOT bundle INIT, INIT ACK or
         * SHUTDOWN COMPLETE with any other chunks.
         * SHUTDOWN COMPLETE with any other chunks.
         */
         */
        if (!chunk->singleton)
        if (!chunk->singleton)
                return SCTP_DISPOSITION_VIOLATION;
                return SCTP_DISPOSITION_VIOLATION;
 
 
        /* Grab the INIT header.  */
        /* Grab the INIT header.  */
        chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
        chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
 
 
        /* Tag the variable length parameters.  */
        /* Tag the variable length parameters.  */
        chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
        chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
 
 
        /* Verify the INIT chunk before processing it. */
        /* Verify the INIT chunk before processing it. */
        err_chunk = NULL;
        err_chunk = NULL;
        if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
        if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
                              (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
                              (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
                              &err_chunk)) {
                              &err_chunk)) {
                /* This chunk contains fatal error. It is to be discarded.
                /* This chunk contains fatal error. It is to be discarded.
                 * Send an ABORT, with causes if there is any.
                 * Send an ABORT, with causes if there is any.
                 */
                 */
                if (err_chunk) {
                if (err_chunk) {
                        packet = sctp_abort_pkt_new(ep, asoc, arg,
                        packet = sctp_abort_pkt_new(ep, asoc, arg,
                                        (__u8 *)(err_chunk->chunk_hdr) +
                                        (__u8 *)(err_chunk->chunk_hdr) +
                                        sizeof(sctp_chunkhdr_t),
                                        sizeof(sctp_chunkhdr_t),
                                        ntohs(err_chunk->chunk_hdr->length) -
                                        ntohs(err_chunk->chunk_hdr->length) -
                                        sizeof(sctp_chunkhdr_t));
                                        sizeof(sctp_chunkhdr_t));
 
 
                        if (packet) {
                        if (packet) {
                                sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
                                sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
                                                SCTP_PACKET(packet));
                                                SCTP_PACKET(packet));
                                SCTP_INC_STATS(SctpOutCtrlChunks);
                                SCTP_INC_STATS(SctpOutCtrlChunks);
                                retval = SCTP_DISPOSITION_CONSUME;
                                retval = SCTP_DISPOSITION_CONSUME;
                        } else {
                        } else {
                                retval = SCTP_DISPOSITION_NOMEM;
                                retval = SCTP_DISPOSITION_NOMEM;
                        }
                        }
                        goto cleanup;
                        goto cleanup;
                } else {
                } else {
                        return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
                        return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
                                                    commands);
                                                    commands);
                }
                }
        }
        }
 
 
        /*
        /*
         * Other parameters for the endpoint SHOULD be copied from the
         * Other parameters for the endpoint SHOULD be copied from the
         * existing parameters of the association (e.g. number of
         * existing parameters of the association (e.g. number of
         * outbound streams) into the INIT ACK and cookie.
         * outbound streams) into the INIT ACK and cookie.
         * FIXME:  We are copying parameters from the endpoint not the
         * FIXME:  We are copying parameters from the endpoint not the
         * association.
         * association.
         */
         */
        new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
        new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
        if (!new_asoc)
        if (!new_asoc)
                goto nomem;
                goto nomem;
 
 
        /* In the outbound INIT ACK the endpoint MUST copy its current
        /* In the outbound INIT ACK the endpoint MUST copy its current
         * Verification Tag and Peers Verification tag into a reserved
         * Verification Tag and Peers Verification tag into a reserved
         * place (local tie-tag and per tie-tag) within the state cookie.
         * place (local tie-tag and per tie-tag) within the state cookie.
         */
         */
        if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
        if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
                               sctp_source(chunk),
                               sctp_source(chunk),
                               (sctp_init_chunk_t *)chunk->chunk_hdr,
                               (sctp_init_chunk_t *)chunk->chunk_hdr,
                               GFP_ATOMIC)) {
                               GFP_ATOMIC)) {
                retval = SCTP_DISPOSITION_NOMEM;
                retval = SCTP_DISPOSITION_NOMEM;
                goto nomem_init;
                goto nomem_init;
        }
        }
 
 
        /* Make sure no new addresses are being added during the
        /* Make sure no new addresses are being added during the
         * restart.   Do not do this check for COOKIE-WAIT state,
         * restart.   Do not do this check for COOKIE-WAIT state,
         * since there are no peer addresses to check against.
         * since there are no peer addresses to check against.
         * Upon return an ABORT will have been sent if needed.
         * Upon return an ABORT will have been sent if needed.
         */
         */
        if (!sctp_state(asoc, COOKIE_WAIT)) {
        if (!sctp_state(asoc, COOKIE_WAIT)) {
                if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
                if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
                                                 commands)) {
                                                 commands)) {
                        retval = SCTP_DISPOSITION_CONSUME;
                        retval = SCTP_DISPOSITION_CONSUME;
                        goto cleanup_asoc;
                        goto cleanup_asoc;
                }
                }
        }
        }
 
 
        sctp_tietags_populate(new_asoc, asoc);
        sctp_tietags_populate(new_asoc, asoc);
 
 
        /* B) "Z" shall respond immediately with an INIT ACK chunk.  */
        /* B) "Z" shall respond immediately with an INIT ACK chunk.  */
 
 
        /* If there are errors need to be reported for unknown parameters,
        /* If there are errors need to be reported for unknown parameters,
         * make sure to reserve enough room in the INIT ACK for them.
         * make sure to reserve enough room in the INIT ACK for them.
         */
         */
        len = 0;
        len = 0;
        if (err_chunk) {
        if (err_chunk) {
                len = ntohs(err_chunk->chunk_hdr->length) -
                len = ntohs(err_chunk->chunk_hdr->length) -
                        sizeof(sctp_chunkhdr_t);
                        sizeof(sctp_chunkhdr_t);
        }
        }
 
 
        if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
        if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
                goto nomem;
                goto nomem;
 
 
        repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
        repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
        if (!repl)
        if (!repl)
                goto nomem;
                goto nomem;
 
 
        /* If there are errors need to be reported for unknown parameters,
        /* If there are errors need to be reported for unknown parameters,
         * include them in the outgoing INIT ACK as "Unrecognized parameter"
         * include them in the outgoing INIT ACK as "Unrecognized parameter"
         * parameter.
         * parameter.
         */
         */
        if (err_chunk) {
        if (err_chunk) {
                /* Get the "Unrecognized parameter" parameter(s) out of the
                /* Get the "Unrecognized parameter" parameter(s) out of the
                 * ERROR chunk generated by sctp_verify_init(). Since the
                 * ERROR chunk generated by sctp_verify_init(). Since the
                 * error cause code for "unknown parameter" and the
                 * error cause code for "unknown parameter" and the
                 * "Unrecognized parameter" type is the same, we can
                 * "Unrecognized parameter" type is the same, we can
                 * construct the parameters in INIT ACK by copying the
                 * construct the parameters in INIT ACK by copying the
                 * ERROR causes over.
                 * ERROR causes over.
                 */
                 */
                unk_param = (sctp_unrecognized_param_t *)
                unk_param = (sctp_unrecognized_param_t *)
                            ((__u8 *)(err_chunk->chunk_hdr) +
                            ((__u8 *)(err_chunk->chunk_hdr) +
                            sizeof(sctp_chunkhdr_t));
                            sizeof(sctp_chunkhdr_t));
                /* Replace the cause code with the "Unrecognized parameter"
                /* Replace the cause code with the "Unrecognized parameter"
                 * parameter type.
                 * parameter type.
                 */
                 */
                sctp_addto_chunk(repl, len, unk_param);
                sctp_addto_chunk(repl, len, unk_param);
        }
        }
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
 
 
        /*
        /*
         * Note: After sending out INIT ACK with the State Cookie parameter,
         * Note: After sending out INIT ACK with the State Cookie parameter,
         * "Z" MUST NOT allocate any resources for this new association.
         * "Z" MUST NOT allocate any resources for this new association.
         * Otherwise, "Z" will be vulnerable to resource attacks.
         * Otherwise, "Z" will be vulnerable to resource attacks.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
        retval = SCTP_DISPOSITION_CONSUME;
        retval = SCTP_DISPOSITION_CONSUME;
 
 
cleanup:
cleanup:
        if (err_chunk)
        if (err_chunk)
                sctp_chunk_free(err_chunk);
                sctp_chunk_free(err_chunk);
        return retval;
        return retval;
nomem:
nomem:
        retval = SCTP_DISPOSITION_NOMEM;
        retval = SCTP_DISPOSITION_NOMEM;
        goto cleanup;
        goto cleanup;
nomem_init:
nomem_init:
cleanup_asoc:
cleanup_asoc:
        sctp_association_free(new_asoc);
        sctp_association_free(new_asoc);
        goto cleanup;
        goto cleanup;
}
}
 
 
/*
/*
 * Handle simultanous INIT.
 * Handle simultanous INIT.
 * This means we started an INIT and then we got an INIT request from
 * This means we started an INIT and then we got an INIT request from
 * our peer.
 * our peer.
 *
 *
 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
 * This usually indicates an initialization collision, i.e., each
 * This usually indicates an initialization collision, i.e., each
 * endpoint is attempting, at about the same time, to establish an
 * endpoint is attempting, at about the same time, to establish an
 * association with the other endpoint.
 * association with the other endpoint.
 *
 *
 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
 * endpoint MUST respond with an INIT ACK using the same parameters it
 * endpoint MUST respond with an INIT ACK using the same parameters it
 * sent in its original INIT chunk (including its Verification Tag,
 * sent in its original INIT chunk (including its Verification Tag,
 * unchanged). These original parameters are combined with those from the
 * unchanged). These original parameters are combined with those from the
 * newly received INIT chunk. The endpoint shall also generate a State
 * newly received INIT chunk. The endpoint shall also generate a State
 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
 * INIT to calculate the State Cookie.
 * INIT to calculate the State Cookie.
 *
 *
 * After that, the endpoint MUST NOT change its state, the T1-init
 * After that, the endpoint MUST NOT change its state, the T1-init
 * timer shall be left running and the corresponding TCB MUST NOT be
 * timer shall be left running and the corresponding TCB MUST NOT be
 * destroyed. The normal procedures for handling State Cookies when
 * destroyed. The normal procedures for handling State Cookies when
 * a TCB exists will resolve the duplicate INITs to a single association.
 * a TCB exists will resolve the duplicate INITs to a single association.
 *
 *
 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
 * its Tie-Tags with the Tag information of itself and its peer (see
 * its Tie-Tags with the Tag information of itself and its peer (see
 * section 5.2.2 for a description of the Tie-Tags).
 * section 5.2.2 for a description of the Tie-Tags).
 *
 *
 * Verification Tag: Not explicit, but an INIT can not have a valid
 * Verification Tag: Not explicit, but an INIT can not have a valid
 * verification tag, so we skip the check.
 * verification tag, so we skip the check.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
                                    const struct sctp_association *asoc,
                                    const struct sctp_association *asoc,
                                    const sctp_subtype_t type,
                                    const sctp_subtype_t type,
                                    void *arg,
                                    void *arg,
                                    sctp_cmd_seq_t *commands)
                                    sctp_cmd_seq_t *commands)
{
{
        /* Call helper to do the real work for both simulataneous and
        /* Call helper to do the real work for both simulataneous and
         * duplicate INIT chunk handling.
         * duplicate INIT chunk handling.
         */
         */
        return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
        return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
}
}
 
 
/*
/*
 * Handle duplicated INIT messages.  These are usually delayed
 * Handle duplicated INIT messages.  These are usually delayed
 * restransmissions.
 * restransmissions.
 *
 *
 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
 * COOKIE-ECHOED and COOKIE-WAIT
 * COOKIE-ECHOED and COOKIE-WAIT
 *
 *
 * Unless otherwise stated, upon reception of an unexpected INIT for
 * Unless otherwise stated, upon reception of an unexpected INIT for
 * this association, the endpoint shall generate an INIT ACK with a
 * this association, the endpoint shall generate an INIT ACK with a
 * State Cookie.  In the outbound INIT ACK the endpoint MUST copy its
 * State Cookie.  In the outbound INIT ACK the endpoint MUST copy its
 * current Verification Tag and peer's Verification Tag into a reserved
 * current Verification Tag and peer's Verification Tag into a reserved
 * place within the state cookie.  We shall refer to these locations as
 * place within the state cookie.  We shall refer to these locations as
 * the Peer's-Tie-Tag and the Local-Tie-Tag.  The outbound SCTP packet
 * the Peer's-Tie-Tag and the Local-Tie-Tag.  The outbound SCTP packet
 * containing this INIT ACK MUST carry a Verification Tag value equal to
 * containing this INIT ACK MUST carry a Verification Tag value equal to
 * the Initiation Tag found in the unexpected INIT.  And the INIT ACK
 * the Initiation Tag found in the unexpected INIT.  And the INIT ACK
 * MUST contain a new Initiation Tag (randomly generated see Section
 * MUST contain a new Initiation Tag (randomly generated see Section
 * 5.3.1).  Other parameters for the endpoint SHOULD be copied from the
 * 5.3.1).  Other parameters for the endpoint SHOULD be copied from the
 * existing parameters of the association (e.g. number of outbound
 * existing parameters of the association (e.g. number of outbound
 * streams) into the INIT ACK and cookie.
 * streams) into the INIT ACK and cookie.
 *
 *
 * After sending out the INIT ACK, the endpoint shall take no further
 * After sending out the INIT ACK, the endpoint shall take no further
 * actions, i.e., the existing association, including its current state,
 * actions, i.e., the existing association, including its current state,
 * and the corresponding TCB MUST NOT be changed.
 * and the corresponding TCB MUST NOT be changed.
 *
 *
 * Note: Only when a TCB exists and the association is not in a COOKIE-
 * Note: Only when a TCB exists and the association is not in a COOKIE-
 * WAIT state are the Tie-Tags populated.  For a normal association INIT
 * WAIT state are the Tie-Tags populated.  For a normal association INIT
 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
 * set to 0 (indicating that no previous TCB existed).  The INIT ACK and
 * set to 0 (indicating that no previous TCB existed).  The INIT ACK and
 * State Cookie are populated as specified in section 5.2.1.
 * State Cookie are populated as specified in section 5.2.1.
 *
 *
 * Verification Tag: Not specified, but an INIT has no way of knowing
 * Verification Tag: Not specified, but an INIT has no way of knowing
 * what the verification tag could be, so we ignore it.
 * what the verification tag could be, so we ignore it.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        /* Call helper to do the real work for both simulataneous and
        /* Call helper to do the real work for both simulataneous and
         * duplicate INIT chunk handling.
         * duplicate INIT chunk handling.
         */
         */
        return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
        return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
}
}
 
 
 
 
 
 
/* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
/* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
 *
 *
 * Section 5.2.4
 * Section 5.2.4
 *  A)  In this case, the peer may have restarted.
 *  A)  In this case, the peer may have restarted.
 */
 */
static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        struct sctp_chunk *chunk,
                                        struct sctp_chunk *chunk,
                                        sctp_cmd_seq_t *commands,
                                        sctp_cmd_seq_t *commands,
                                        struct sctp_association *new_asoc)
                                        struct sctp_association *new_asoc)
{
{
        sctp_init_chunk_t *peer_init;
        sctp_init_chunk_t *peer_init;
        struct sctp_ulpevent *ev;
        struct sctp_ulpevent *ev;
        struct sctp_chunk *repl;
        struct sctp_chunk *repl;
 
 
        /* new_asoc is a brand-new association, so these are not yet
        /* new_asoc is a brand-new association, so these are not yet
         * side effects--it is safe to run them here.
         * side effects--it is safe to run them here.
         */
         */
        peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
        peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
 
 
        if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
        if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
                               sctp_source(chunk), peer_init,
                               sctp_source(chunk), peer_init,
                               GFP_ATOMIC))
                               GFP_ATOMIC))
                goto nomem;
                goto nomem;
 
 
        /* Make sure no new addresses are being added during the
        /* Make sure no new addresses are being added during the
         * restart.  Though this is a pretty complicated attack
         * restart.  Though this is a pretty complicated attack
         * since you'd have to get inside the cookie.
         * since you'd have to get inside the cookie.
         */
         */
        if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
        if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
                return SCTP_DISPOSITION_CONSUME;
                return SCTP_DISPOSITION_CONSUME;
        }
        }
 
 
        /* For now, fail any unsent/unacked data.  Consider the optional
        /* For now, fail any unsent/unacked data.  Consider the optional
         * choice of resending of this data.
         * choice of resending of this data.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
 
 
        /* Update the content of current association. */
        /* Update the content of current association. */
        sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
        sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
 
 
        repl = sctp_make_cookie_ack(new_asoc, chunk);
        repl = sctp_make_cookie_ack(new_asoc, chunk);
        if (!repl)
        if (!repl)
                goto nomem;
                goto nomem;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
 
 
        /* Report association restart to upper layer. */
        /* Report association restart to upper layer. */
        ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
        ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
                                             new_asoc->c.sinit_num_ostreams,
                                             new_asoc->c.sinit_num_ostreams,
                                             new_asoc->c.sinit_max_instreams,
                                             new_asoc->c.sinit_max_instreams,
                                             GFP_ATOMIC);
                                             GFP_ATOMIC);
        if (!ev)
        if (!ev)
                goto nomem_ev;
                goto nomem_ev;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem_ev:
nomem_ev:
        sctp_chunk_free(repl);
        sctp_chunk_free(repl);
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
/* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
 *
 *
 * Section 5.2.4
 * Section 5.2.4
 *   B) In this case, both sides may be attempting to start an association
 *   B) In this case, both sides may be attempting to start an association
 *      at about the same time but the peer endpoint started its INIT
 *      at about the same time but the peer endpoint started its INIT
 *      after responding to the local endpoint's INIT
 *      after responding to the local endpoint's INIT
 */
 */
/* This case represents an initialization collision.  */
/* This case represents an initialization collision.  */
static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        struct sctp_chunk *chunk,
                                        struct sctp_chunk *chunk,
                                        sctp_cmd_seq_t *commands,
                                        sctp_cmd_seq_t *commands,
                                        struct sctp_association *new_asoc)
                                        struct sctp_association *new_asoc)
{
{
        sctp_init_chunk_t *peer_init;
        sctp_init_chunk_t *peer_init;
        struct sctp_ulpevent *ev;
        struct sctp_ulpevent *ev;
        struct sctp_chunk *repl;
        struct sctp_chunk *repl;
 
 
        /* new_asoc is a brand-new association, so these are not yet
        /* new_asoc is a brand-new association, so these are not yet
         * side effects--it is safe to run them here.
         * side effects--it is safe to run them here.
         */
         */
        peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
        peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
        if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
        if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
                               sctp_source(chunk), peer_init,
                               sctp_source(chunk), peer_init,
                               GFP_ATOMIC))
                               GFP_ATOMIC))
                goto nomem;
                goto nomem;
 
 
        /* Update the content of current association.  */
        /* Update the content of current association.  */
        sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
        sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_ESTABLISHED));
                        SCTP_STATE(SCTP_STATE_ESTABLISHED));
        SCTP_INC_STATS(SctpCurrEstab);
        SCTP_INC_STATS(SctpCurrEstab);
        sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
 
 
        repl = sctp_make_cookie_ack(new_asoc, chunk);
        repl = sctp_make_cookie_ack(new_asoc, chunk);
        if (!repl)
        if (!repl)
                goto nomem;
                goto nomem;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
        sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
 
 
        /* RFC 2960 5.1 Normal Establishment of an Association
        /* RFC 2960 5.1 Normal Establishment of an Association
         *
         *
         * D) IMPLEMENTATION NOTE: An implementation may choose to
         * D) IMPLEMENTATION NOTE: An implementation may choose to
         * send the Communication Up notification to the SCTP user
         * send the Communication Up notification to the SCTP user
         * upon reception of a valid COOKIE ECHO chunk.
         * upon reception of a valid COOKIE ECHO chunk.
         */
         */
        ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, 0,
        ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, 0,
                                             new_asoc->c.sinit_num_ostreams,
                                             new_asoc->c.sinit_num_ostreams,
                                             new_asoc->c.sinit_max_instreams,
                                             new_asoc->c.sinit_max_instreams,
                                             GFP_ATOMIC);
                                             GFP_ATOMIC);
        if (!ev)
        if (!ev)
                goto nomem_ev;
                goto nomem_ev;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem_ev:
nomem_ev:
        sctp_chunk_free(repl);
        sctp_chunk_free(repl);
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
/* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
 *
 *
 * Section 5.2.4
 * Section 5.2.4
 *  C) In this case, the local endpoint's cookie has arrived late.
 *  C) In this case, the local endpoint's cookie has arrived late.
 *     Before it arrived, the local endpoint sent an INIT and received an
 *     Before it arrived, the local endpoint sent an INIT and received an
 *     INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
 *     INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
 *     but a new tag of its own.
 *     but a new tag of its own.
 */
 */
/* This case represents an initialization collision.  */
/* This case represents an initialization collision.  */
static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        struct sctp_chunk *chunk,
                                        struct sctp_chunk *chunk,
                                        sctp_cmd_seq_t *commands,
                                        sctp_cmd_seq_t *commands,
                                        struct sctp_association *new_asoc)
                                        struct sctp_association *new_asoc)
{
{
        /* The cookie should be silently discarded.
        /* The cookie should be silently discarded.
         * The endpoint SHOULD NOT change states and should leave
         * The endpoint SHOULD NOT change states and should leave
         * any timers running.
         * any timers running.
         */
         */
        return SCTP_DISPOSITION_DISCARD;
        return SCTP_DISPOSITION_DISCARD;
}
}
 
 
/* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
/* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
 *
 *
 * Section 5.2.4
 * Section 5.2.4
 *
 *
 * D) When both local and remote tags match the endpoint should always
 * D) When both local and remote tags match the endpoint should always
 *    enter the ESTABLISHED state, if it has not already done so.
 *    enter the ESTABLISHED state, if it has not already done so.
 */
 */
/* This case represents an initialization collision.  */
/* This case represents an initialization collision.  */
static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        struct sctp_chunk *chunk,
                                        struct sctp_chunk *chunk,
                                        sctp_cmd_seq_t *commands,
                                        sctp_cmd_seq_t *commands,
                                        struct sctp_association *new_asoc)
                                        struct sctp_association *new_asoc)
{
{
        struct sctp_ulpevent *ev = NULL;
        struct sctp_ulpevent *ev = NULL;
        struct sctp_chunk *repl;
        struct sctp_chunk *repl;
 
 
        /* Clarification from Implementor's Guide:
        /* Clarification from Implementor's Guide:
         * D) When both local and remote tags match the endpoint should
         * D) When both local and remote tags match the endpoint should
         * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
         * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
         * It should stop any cookie timer that may be running and send
         * It should stop any cookie timer that may be running and send
         * a COOKIE ACK.
         * a COOKIE ACK.
         */
         */
 
 
        /* Don't accidentally move back into established state. */
        /* Don't accidentally move back into established state. */
        if (asoc->state < SCTP_STATE_ESTABLISHED) {
        if (asoc->state < SCTP_STATE_ESTABLISHED) {
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                                SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
                                SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
                sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                                SCTP_STATE(SCTP_STATE_ESTABLISHED));
                                SCTP_STATE(SCTP_STATE_ESTABLISHED));
                SCTP_INC_STATS(SctpCurrEstab);
                SCTP_INC_STATS(SctpCurrEstab);
                sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
                sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
                                SCTP_NULL());
                                SCTP_NULL());
 
 
                /* RFC 2960 5.1 Normal Establishment of an Association
                /* RFC 2960 5.1 Normal Establishment of an Association
                 *
                 *
                 * D) IMPLEMENTATION NOTE: An implementation may choose
                 * D) IMPLEMENTATION NOTE: An implementation may choose
                 * to send the Communication Up notification to the
                 * to send the Communication Up notification to the
                 * SCTP user upon reception of a valid COOKIE
                 * SCTP user upon reception of a valid COOKIE
                 * ECHO chunk.
                 * ECHO chunk.
                 */
                 */
                ev = sctp_ulpevent_make_assoc_change(new_asoc, 0,
                ev = sctp_ulpevent_make_assoc_change(new_asoc, 0,
                                             SCTP_COMM_UP, 0,
                                             SCTP_COMM_UP, 0,
                                             new_asoc->c.sinit_num_ostreams,
                                             new_asoc->c.sinit_num_ostreams,
                                             new_asoc->c.sinit_max_instreams,
                                             new_asoc->c.sinit_max_instreams,
                                             GFP_ATOMIC);
                                             GFP_ATOMIC);
                if (!ev)
                if (!ev)
                        goto nomem;
                        goto nomem;
                sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
                sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
                                SCTP_ULPEVENT(ev));
                                SCTP_ULPEVENT(ev));
        }
        }
        sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
 
 
        repl = sctp_make_cookie_ack(new_asoc, chunk);
        repl = sctp_make_cookie_ack(new_asoc, chunk);
        if (!repl)
        if (!repl)
                goto nomem;
                goto nomem;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
        sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem:
nomem:
        if (ev)
        if (ev)
                sctp_ulpevent_free(ev);
                sctp_ulpevent_free(ev);
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Handle a duplicate COOKIE-ECHO.  This usually means a cookie-carrying
 * Handle a duplicate COOKIE-ECHO.  This usually means a cookie-carrying
 * chunk was retransmitted and then delayed in the network.
 * chunk was retransmitted and then delayed in the network.
 *
 *
 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
 *
 *
 * Verification Tag: None.  Do cookie validation.
 * Verification Tag: None.  Do cookie validation.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        sctp_disposition_t retval;
        sctp_disposition_t retval;
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        struct sctp_association *new_asoc;
        struct sctp_association *new_asoc;
        int error = 0;
        int error = 0;
        char action;
        char action;
        struct sctp_chunk *err_chk_p;
        struct sctp_chunk *err_chk_p;
 
 
        /* "Decode" the chunk.  We have no optional parameters so we
        /* "Decode" the chunk.  We have no optional parameters so we
         * are in good shape.
         * are in good shape.
         */
         */
        chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
        chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
        skb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
        skb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
                 sizeof(sctp_chunkhdr_t));
                 sizeof(sctp_chunkhdr_t));
 
 
        /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
        /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
         * of a duplicate COOKIE ECHO match the Verification Tags of the
         * of a duplicate COOKIE ECHO match the Verification Tags of the
         * current association, consider the State Cookie valid even if
         * current association, consider the State Cookie valid even if
         * the lifespan is exceeded.
         * the lifespan is exceeded.
         */
         */
        new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
        new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
                                      &err_chk_p);
                                      &err_chk_p);
 
 
        /* FIXME:
        /* FIXME:
         * If the re-build failed, what is the proper error path
         * If the re-build failed, what is the proper error path
         * from here?
         * from here?
         *
         *
         * [We should abort the association. --piggy]
         * [We should abort the association. --piggy]
         */
         */
        if (!new_asoc) {
        if (!new_asoc) {
                /* FIXME: Several errors are possible.  A bad cookie should
                /* FIXME: Several errors are possible.  A bad cookie should
                 * be silently discarded, but think about logging it too.
                 * be silently discarded, but think about logging it too.
                 */
                 */
                switch (error) {
                switch (error) {
                case -SCTP_IERROR_NOMEM:
                case -SCTP_IERROR_NOMEM:
                        goto nomem;
                        goto nomem;
 
 
                case -SCTP_IERROR_STALE_COOKIE:
                case -SCTP_IERROR_STALE_COOKIE:
                        sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
                        sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
                                                   err_chk_p);
                                                   err_chk_p);
                        return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                        return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                case -SCTP_IERROR_BAD_SIG:
                case -SCTP_IERROR_BAD_SIG:
                default:
                default:
                        return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                        return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                };
                };
        }
        }
 
 
        /* Compare the tie_tag in cookie with the verification tag of
        /* Compare the tie_tag in cookie with the verification tag of
         * current association.
         * current association.
         */
         */
        action = sctp_tietags_compare(new_asoc, asoc);
        action = sctp_tietags_compare(new_asoc, asoc);
 
 
        switch (action) {
        switch (action) {
        case 'A': /* Association restart. */
        case 'A': /* Association restart. */
                retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
                retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
                                              new_asoc);
                                              new_asoc);
                break;
                break;
 
 
        case 'B': /* Collision case B. */
        case 'B': /* Collision case B. */
                retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
                retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
                                              new_asoc);
                                              new_asoc);
                break;
                break;
 
 
        case 'C': /* Collision case C. */
        case 'C': /* Collision case C. */
                retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
                retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
                                              new_asoc);
                                              new_asoc);
                break;
                break;
 
 
        case 'D': /* Collision case D. */
        case 'D': /* Collision case D. */
                retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
                retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
                                              new_asoc);
                                              new_asoc);
                break;
                break;
 
 
        default: /* Discard packet for all others. */
        default: /* Discard packet for all others. */
                retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                break;
                break;
        };
        };
 
 
        /* Delete the tempory new association. */
        /* Delete the tempory new association. */
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
 
 
        return retval;
        return retval;
 
 
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Process an ABORT.  (SHUTDOWN-PENDING state)
 * Process an ABORT.  (SHUTDOWN-PENDING state)
 *
 *
 * See sctp_sf_do_9_1_abort().
 * See sctp_sf_do_9_1_abort().
 */
 */
sctp_disposition_t sctp_sf_shutdown_pending_abort(
sctp_disposition_t sctp_sf_shutdown_pending_abort(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
 
 
        if (!sctp_vtag_verify_either(chunk, asoc))
        if (!sctp_vtag_verify_either(chunk, asoc))
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
        /* Stop the T5-shutdown guard timer.  */
        /* Stop the T5-shutdown guard timer.  */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
 
 
        return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
        return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
}
}
 
 
/*
/*
 * Process an ABORT.  (SHUTDOWN-SENT state)
 * Process an ABORT.  (SHUTDOWN-SENT state)
 *
 *
 * See sctp_sf_do_9_1_abort().
 * See sctp_sf_do_9_1_abort().
 */
 */
sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
 
 
        if (!sctp_vtag_verify_either(chunk, asoc))
        if (!sctp_vtag_verify_either(chunk, asoc))
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
        /* Stop the T2-shutdown timer. */
        /* Stop the T2-shutdown timer. */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
 
 
        /* Stop the T5-shutdown guard timer.  */
        /* Stop the T5-shutdown guard timer.  */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
 
 
        return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
        return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
}
}
 
 
/*
/*
 * Process an ABORT.  (SHUTDOWN-ACK-SENT state)
 * Process an ABORT.  (SHUTDOWN-ACK-SENT state)
 *
 *
 * See sctp_sf_do_9_1_abort().
 * See sctp_sf_do_9_1_abort().
 */
 */
sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        /* The same T2 timer, so we should be able to use
        /* The same T2 timer, so we should be able to use
         * common function with the SHUTDOWN-SENT state.
         * common function with the SHUTDOWN-SENT state.
         */
         */
        return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
        return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
}
}
 
 
/*
/*
 * Handle an Error received in COOKIE_ECHOED state.
 * Handle an Error received in COOKIE_ECHOED state.
 *
 *
 * Only handle the error type of stale COOKIE Error, the other errors will
 * Only handle the error type of stale COOKIE Error, the other errors will
 * be ignored.
 * be ignored.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        sctp_errhdr_t *err;
        sctp_errhdr_t *err;
 
 
        /* Process the error here */
        /* Process the error here */
        /* FUTURE FIXME:  When PR-SCTP related and other optional
        /* FUTURE FIXME:  When PR-SCTP related and other optional
         * parms are emitted, this will have to change to handle multiple
         * parms are emitted, this will have to change to handle multiple
         * errors.
         * errors.
         */
         */
        sctp_walk_errors(err, chunk->chunk_hdr) {
        sctp_walk_errors(err, chunk->chunk_hdr) {
                if (SCTP_ERROR_STALE_COOKIE == err->cause)
                if (SCTP_ERROR_STALE_COOKIE == err->cause)
                        return sctp_sf_do_5_2_6_stale(ep, asoc, type,
                        return sctp_sf_do_5_2_6_stale(ep, asoc, type,
                                                        arg, commands);
                                                        arg, commands);
        }
        }
        return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
        return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
}
}
 
 
/*
/*
 * Handle a Stale COOKIE Error
 * Handle a Stale COOKIE Error
 *
 *
 * Section: 5.2.6 Handle Stale COOKIE Error
 * Section: 5.2.6 Handle Stale COOKIE Error
 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
 * one of the following three alternatives.
 * one of the following three alternatives.
 * ...
 * ...
 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
 *    Preservative parameter requesting an extension to the lifetime of
 *    Preservative parameter requesting an extension to the lifetime of
 *    the State Cookie. When calculating the time extension, an
 *    the State Cookie. When calculating the time extension, an
 *    implementation SHOULD use the RTT information measured based on the
 *    implementation SHOULD use the RTT information measured based on the
 *    previous COOKIE ECHO / ERROR exchange, and should add no more
 *    previous COOKIE ECHO / ERROR exchange, and should add no more
 *    than 1 second beyond the measured RTT, due to long State Cookie
 *    than 1 second beyond the measured RTT, due to long State Cookie
 *    lifetimes making the endpoint more subject to a replay attack.
 *    lifetimes making the endpoint more subject to a replay attack.
 *
 *
 * Verification Tag:  Not explicit, but safe to ignore.
 * Verification Tag:  Not explicit, but safe to ignore.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
                                          const struct sctp_association *asoc,
                                          const struct sctp_association *asoc,
                                          const sctp_subtype_t type,
                                          const sctp_subtype_t type,
                                          void *arg,
                                          void *arg,
                                          sctp_cmd_seq_t *commands)
                                          sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        time_t stale;
        time_t stale;
        sctp_cookie_preserve_param_t bht;
        sctp_cookie_preserve_param_t bht;
        sctp_errhdr_t *err;
        sctp_errhdr_t *err;
        struct list_head *pos;
        struct list_head *pos;
        struct sctp_transport *t;
        struct sctp_transport *t;
        struct sctp_chunk *reply;
        struct sctp_chunk *reply;
        struct sctp_bind_addr *bp;
        struct sctp_bind_addr *bp;
        int attempts;
        int attempts;
 
 
        attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
        attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
 
 
        if (attempts >= asoc->max_init_attempts) {
        if (attempts >= asoc->max_init_attempts) {
                sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
                sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
                                SCTP_U32(SCTP_ERROR_STALE_COOKIE));
                                SCTP_U32(SCTP_ERROR_STALE_COOKIE));
                return SCTP_DISPOSITION_DELETE_TCB;
                return SCTP_DISPOSITION_DELETE_TCB;
        }
        }
 
 
        err = (sctp_errhdr_t *)(chunk->skb->data);
        err = (sctp_errhdr_t *)(chunk->skb->data);
 
 
        /* When calculating the time extension, an implementation
        /* When calculating the time extension, an implementation
         * SHOULD use the RTT information measured based on the
         * SHOULD use the RTT information measured based on the
         * previous COOKIE ECHO / ERROR exchange, and should add no
         * previous COOKIE ECHO / ERROR exchange, and should add no
         * more than 1 second beyond the measured RTT, due to long
         * more than 1 second beyond the measured RTT, due to long
         * State Cookie lifetimes making the endpoint more subject to
         * State Cookie lifetimes making the endpoint more subject to
         * a replay attack.
         * a replay attack.
         * Measure of Staleness's unit is usec. (1/1000000 sec)
         * Measure of Staleness's unit is usec. (1/1000000 sec)
         * Suggested Cookie Life-span Increment's unit is msec.
         * Suggested Cookie Life-span Increment's unit is msec.
         * (1/1000 sec)
         * (1/1000 sec)
         * In general, if you use the suggested cookie life, the value
         * In general, if you use the suggested cookie life, the value
         * found in the field of measure of staleness should be doubled
         * found in the field of measure of staleness should be doubled
         * to give ample time to retransmit the new cookie and thus
         * to give ample time to retransmit the new cookie and thus
         * yield a higher probability of success on the reattempt.
         * yield a higher probability of success on the reattempt.
         */
         */
        stale = ntohl(*(suseconds_t *)((u8 *)err + sizeof(sctp_errhdr_t)));
        stale = ntohl(*(suseconds_t *)((u8 *)err + sizeof(sctp_errhdr_t)));
        stale = (stale * 2) / 1000;
        stale = (stale * 2) / 1000;
 
 
        bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
        bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
        bht.param_hdr.length = htons(sizeof(bht));
        bht.param_hdr.length = htons(sizeof(bht));
        bht.lifespan_increment = htonl(stale);
        bht.lifespan_increment = htonl(stale);
 
 
        /* Build that new INIT chunk.  */
        /* Build that new INIT chunk.  */
        bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
        bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
        reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
        reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
        if (!reply)
        if (!reply)
                goto nomem;
                goto nomem;
 
 
        sctp_addto_chunk(reply, sizeof(bht), &bht);
        sctp_addto_chunk(reply, sizeof(bht), &bht);
 
 
        /* Cast away the const modifier, as we want to just
        /* Cast away the const modifier, as we want to just
         * rerun it through as a sideffect.
         * rerun it through as a sideffect.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_INC,
        sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_INC,
                        SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
                        SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
 
 
        /* If we've sent any data bundled with COOKIE-ECHO we need to
        /* If we've sent any data bundled with COOKIE-ECHO we need to
         * resend.
         * resend.
         */
         */
        list_for_each(pos, &asoc->peer.transport_addr_list) {
        list_for_each(pos, &asoc->peer.transport_addr_list) {
                t = list_entry(pos, struct sctp_transport, transports);
                t = list_entry(pos, struct sctp_transport, transports);
                sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(t));
                sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(t));
        }
        }
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
                        SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Process an ABORT.
 * Process an ABORT.
 *
 *
 * Section: 9.1
 * Section: 9.1
 * After checking the Verification Tag, the receiving endpoint shall
 * After checking the Verification Tag, the receiving endpoint shall
 * remove the association from its record, and shall report the
 * remove the association from its record, and shall report the
 * termination to its upper layer.
 * termination to its upper layer.
 *
 *
 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
 * B) Rules for packet carrying ABORT:
 * B) Rules for packet carrying ABORT:
 *
 *
 *  - The endpoint shall always fill in the Verification Tag field of the
 *  - The endpoint shall always fill in the Verification Tag field of the
 *    outbound packet with the destination endpoint's tag value if it
 *    outbound packet with the destination endpoint's tag value if it
 *    is known.
 *    is known.
 *
 *
 *  - If the ABORT is sent in response to an OOTB packet, the endpoint
 *  - If the ABORT is sent in response to an OOTB packet, the endpoint
 *    MUST follow the procedure described in Section 8.4.
 *    MUST follow the procedure described in Section 8.4.
 *
 *
 *  - The receiver MUST accept the packet if the Verification Tag
 *  - The receiver MUST accept the packet if the Verification Tag
 *    matches either its own tag, OR the tag of its peer. Otherwise, the
 *    matches either its own tag, OR the tag of its peer. Otherwise, the
 *    receiver MUST silently discard the packet and take no further
 *    receiver MUST silently discard the packet and take no further
 *    action.
 *    action.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        unsigned len;
        unsigned len;
        __u16 error = SCTP_ERROR_NO_ERROR;
        __u16 error = SCTP_ERROR_NO_ERROR;
 
 
        if (!sctp_vtag_verify_either(chunk, asoc))
        if (!sctp_vtag_verify_either(chunk, asoc))
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
        /* Check that chunk header looks valid.  */
        /* Check that chunk header looks valid.  */
        len = ntohs(chunk->chunk_hdr->length);
        len = ntohs(chunk->chunk_hdr->length);
        if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
        if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
                error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
                error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
 
 
 
 
        /* ASSOC_FAILED will DELETE_TCB. */
        /* ASSOC_FAILED will DELETE_TCB. */
        sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_U32(error));
        sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_U32(error));
        SCTP_INC_STATS(SctpAborteds);
        SCTP_INC_STATS(SctpAborteds);
        SCTP_DEC_STATS(SctpCurrEstab);
        SCTP_DEC_STATS(SctpCurrEstab);
 
 
        return SCTP_DISPOSITION_ABORT;
        return SCTP_DISPOSITION_ABORT;
}
}
 
 
/*
/*
 * Process an ABORT.  (COOKIE-WAIT state)
 * Process an ABORT.  (COOKIE-WAIT state)
 *
 *
 * See sctp_sf_do_9_1_abort() above.
 * See sctp_sf_do_9_1_abort() above.
 */
 */
sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
                                     const struct sctp_association *asoc,
                                     const struct sctp_association *asoc,
                                     const sctp_subtype_t type,
                                     const sctp_subtype_t type,
                                     void *arg,
                                     void *arg,
                                     sctp_cmd_seq_t *commands)
                                     sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        unsigned len;
        unsigned len;
        __u16 error = SCTP_ERROR_NO_ERROR;
        __u16 error = SCTP_ERROR_NO_ERROR;
 
 
        if (!sctp_vtag_verify_either(chunk, asoc))
        if (!sctp_vtag_verify_either(chunk, asoc))
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_CLOSED));
                        SCTP_STATE(SCTP_STATE_CLOSED));
        SCTP_INC_STATS(SctpAborteds);
        SCTP_INC_STATS(SctpAborteds);
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
 
 
        /* Check that chunk header looks valid.  */
        /* Check that chunk header looks valid.  */
        len = ntohs(chunk->chunk_hdr->length);
        len = ntohs(chunk->chunk_hdr->length);
        if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
        if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
                error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
                error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
 
 
        /* CMD_INIT_FAILED will DELETE_TCB. */
        /* CMD_INIT_FAILED will DELETE_TCB. */
        sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, SCTP_U32(error));
        sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, SCTP_U32(error));
 
 
        return SCTP_DISPOSITION_ABORT;
        return SCTP_DISPOSITION_ABORT;
}
}
 
 
/*
/*
 * Process an ABORT.  (COOKIE-ECHOED state)
 * Process an ABORT.  (COOKIE-ECHOED state)
 *
 *
 * See sctp_sf_do_9_1_abort() above.
 * See sctp_sf_do_9_1_abort() above.
 */
 */
sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
                                               const struct sctp_association *asoc,
                                               const struct sctp_association *asoc,
                                               const sctp_subtype_t type,
                                               const sctp_subtype_t type,
                                               void *arg,
                                               void *arg,
                                               sctp_cmd_seq_t *commands)
                                               sctp_cmd_seq_t *commands)
{
{
        /* There is a single T1 timer, so we should be able to use
        /* There is a single T1 timer, so we should be able to use
         * common function with the COOKIE-WAIT state.
         * common function with the COOKIE-WAIT state.
         */
         */
        return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
        return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
}
}
 
 
/*
/*
 * sctp_sf_do_9_2_shut
 * sctp_sf_do_9_2_shut
 *
 *
 * Section: 9.2
 * Section: 9.2
 * Upon the reception of the SHUTDOWN, the peer endpoint shall
 * Upon the reception of the SHUTDOWN, the peer endpoint shall
 *  - enter the SHUTDOWN-RECEIVED state,
 *  - enter the SHUTDOWN-RECEIVED state,
 *
 *
 *  - stop accepting new data from its SCTP user
 *  - stop accepting new data from its SCTP user
 *
 *
 *  - verify, by checking the Cumulative TSN Ack field of the chunk,
 *  - verify, by checking the Cumulative TSN Ack field of the chunk,
 *    that all its outstanding DATA chunks have been received by the
 *    that all its outstanding DATA chunks have been received by the
 *    SHUTDOWN sender.
 *    SHUTDOWN sender.
 *
 *
 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
 * send a SHUTDOWN in response to a ULP request. And should discard
 * send a SHUTDOWN in response to a ULP request. And should discard
 * subsequent SHUTDOWN chunks.
 * subsequent SHUTDOWN chunks.
 *
 *
 * If there are still outstanding DATA chunks left, the SHUTDOWN
 * If there are still outstanding DATA chunks left, the SHUTDOWN
 * receiver shall continue to follow normal data transmission
 * receiver shall continue to follow normal data transmission
 * procedures defined in Section 6 until all outstanding DATA chunks
 * procedures defined in Section 6 until all outstanding DATA chunks
 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
 * new data from its SCTP user.
 * new data from its SCTP user.
 *
 *
 * Verification Tag:  8.5 Verification Tag [Normal verification]
 * Verification Tag:  8.5 Verification Tag [Normal verification]
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
                                           const struct sctp_association *asoc,
                                           const struct sctp_association *asoc,
                                           const sctp_subtype_t type,
                                           const sctp_subtype_t type,
                                           void *arg,
                                           void *arg,
                                           sctp_cmd_seq_t *commands)
                                           sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        sctp_shutdownhdr_t *sdh;
        sctp_shutdownhdr_t *sdh;
        sctp_disposition_t disposition;
        sctp_disposition_t disposition;
        struct sctp_ulpevent *ev;
        struct sctp_ulpevent *ev;
 
 
        /* Convert the elaborate header.  */
        /* Convert the elaborate header.  */
        sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
        sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
        skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
        skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
        chunk->subh.shutdown_hdr = sdh;
        chunk->subh.shutdown_hdr = sdh;
 
 
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
         * that the value in the Verification Tag field of the
         * that the value in the Verification Tag field of the
         * received SCTP packet matches its own Tag. If the received
         * received SCTP packet matches its own Tag. If the received
         * Verification Tag value does not match the receiver's own
         * Verification Tag value does not match the receiver's own
         * tag value, the receiver shall silently discard the packet...
         * tag value, the receiver shall silently discard the packet...
         */
         */
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
        /* Upon the reception of the SHUTDOWN, the peer endpoint shall
        /* Upon the reception of the SHUTDOWN, the peer endpoint shall
         *  - enter the SHUTDOWN-RECEIVED state,
         *  - enter the SHUTDOWN-RECEIVED state,
         *  - stop accepting new data from its SCTP user
         *  - stop accepting new data from its SCTP user
         *
         *
         * [This is implicit in the new state.]
         * [This is implicit in the new state.]
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
                        SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
        disposition = SCTP_DISPOSITION_CONSUME;
        disposition = SCTP_DISPOSITION_CONSUME;
 
 
        if (sctp_outq_is_empty(&asoc->outqueue)) {
        if (sctp_outq_is_empty(&asoc->outqueue)) {
                disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
                disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
                                                          arg, commands);
                                                          arg, commands);
        }
        }
 
 
        if (SCTP_DISPOSITION_NOMEM == disposition)
        if (SCTP_DISPOSITION_NOMEM == disposition)
                goto out;
                goto out;
 
 
        /*  - verify, by checking the Cumulative TSN Ack field of the
        /*  - verify, by checking the Cumulative TSN Ack field of the
         *    chunk, that all its outstanding DATA chunks have been
         *    chunk, that all its outstanding DATA chunks have been
         *    received by the SHUTDOWN sender.
         *    received by the SHUTDOWN sender.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
        sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
                        SCTP_U32(chunk->subh.shutdown_hdr->cum_tsn_ack));
                        SCTP_U32(chunk->subh.shutdown_hdr->cum_tsn_ack));
 
 
        /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
        /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
         * When a peer sends a SHUTDOWN, SCTP delivers this notification to
         * When a peer sends a SHUTDOWN, SCTP delivers this notification to
         * inform the application that it should cease sending data.
         * inform the application that it should cease sending data.
         */
         */
        ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
        ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
        if (!ev) {
        if (!ev) {
                disposition = SCTP_DISPOSITION_NOMEM;
                disposition = SCTP_DISPOSITION_NOMEM;
                goto out;
                goto out;
        }
        }
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
 
 
out:
out:
        return disposition;
        return disposition;
}
}
 
 
/* RFC 2960 9.2
/* RFC 2960 9.2
 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
 * transport addresses (either in the IP addresses or in the INIT chunk)
 * transport addresses (either in the IP addresses or in the INIT chunk)
 * that belong to this association, it should discard the INIT chunk and
 * that belong to this association, it should discard the INIT chunk and
 * retransmit the SHUTDOWN ACK chunk.
 * retransmit the SHUTDOWN ACK chunk.
 */
 */
sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
                                    const struct sctp_association *asoc,
                                    const struct sctp_association *asoc,
                                    const sctp_subtype_t type,
                                    const sctp_subtype_t type,
                                    void *arg,
                                    void *arg,
                                    sctp_cmd_seq_t *commands)
                                    sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
        struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
        struct sctp_chunk *reply;
        struct sctp_chunk *reply;
 
 
        reply = sctp_make_shutdown_ack(asoc, chunk);
        reply = sctp_make_shutdown_ack(asoc, chunk);
        if (NULL == reply)
        if (NULL == reply)
                goto nomem;
                goto nomem;
 
 
        /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
        /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
         * the T2-SHUTDOWN timer.
         * the T2-SHUTDOWN timer.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
 
 
        /* and restart the T2-shutdown timer. */
        /* and restart the T2-shutdown timer. */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * sctp_sf_do_ecn_cwr
 * sctp_sf_do_ecn_cwr
 *
 *
 * Section:  Appendix A: Explicit Congestion Notification
 * Section:  Appendix A: Explicit Congestion Notification
 *
 *
 * CWR:
 * CWR:
 *
 *
 * RFC 2481 details a specific bit for a sender to send in the header of
 * RFC 2481 details a specific bit for a sender to send in the header of
 * its next outbound TCP segment to indicate to its peer that it has
 * its next outbound TCP segment to indicate to its peer that it has
 * reduced its congestion window.  This is termed the CWR bit.  For
 * reduced its congestion window.  This is termed the CWR bit.  For
 * SCTP the same indication is made by including the CWR chunk.
 * SCTP the same indication is made by including the CWR chunk.
 * This chunk contains one data element, i.e. the TSN number that
 * This chunk contains one data element, i.e. the TSN number that
 * was sent in the ECNE chunk.  This element represents the lowest
 * was sent in the ECNE chunk.  This element represents the lowest
 * TSN number in the datagram that was originally marked with the
 * TSN number in the datagram that was originally marked with the
 * CE bit.
 * CE bit.
 *
 *
 * Verification Tag: 8.5 Verification Tag [Normal verification]
 * Verification Tag: 8.5 Verification Tag [Normal verification]
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
                                      const struct sctp_association *asoc,
                                      const struct sctp_association *asoc,
                                      const sctp_subtype_t type,
                                      const sctp_subtype_t type,
                                      void *arg,
                                      void *arg,
                                      sctp_cmd_seq_t *commands)
                                      sctp_cmd_seq_t *commands)
{
{
        sctp_cwrhdr_t *cwr;
        sctp_cwrhdr_t *cwr;
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
 
 
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
         * that the value in the Verification Tag field of the
         * that the value in the Verification Tag field of the
         * received SCTP packet matches its own Tag. If the received
         * received SCTP packet matches its own Tag. If the received
         * Verification Tag value does not match the receiver's own
         * Verification Tag value does not match the receiver's own
         * tag value, the receiver shall silently discard the packet...
         * tag value, the receiver shall silently discard the packet...
         */
         */
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
        cwr = (sctp_cwrhdr_t *) chunk->skb->data;
        cwr = (sctp_cwrhdr_t *) chunk->skb->data;
        skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
        skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
 
 
        cwr->lowest_tsn = ntohl(cwr->lowest_tsn);
        cwr->lowest_tsn = ntohl(cwr->lowest_tsn);
 
 
        /* Does this CWR ack the last sent congestion notification? */
        /* Does this CWR ack the last sent congestion notification? */
        if (TSN_lte(asoc->last_ecne_tsn, cwr->lowest_tsn)) {
        if (TSN_lte(asoc->last_ecne_tsn, cwr->lowest_tsn)) {
                /* Stop sending ECNE. */
                /* Stop sending ECNE. */
                sctp_add_cmd_sf(commands,
                sctp_add_cmd_sf(commands,
                                SCTP_CMD_ECN_CWR,
                                SCTP_CMD_ECN_CWR,
                                SCTP_U32(cwr->lowest_tsn));
                                SCTP_U32(cwr->lowest_tsn));
        }
        }
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/*
/*
 * sctp_sf_do_ecne
 * sctp_sf_do_ecne
 *
 *
 * Section:  Appendix A: Explicit Congestion Notification
 * Section:  Appendix A: Explicit Congestion Notification
 *
 *
 * ECN-Echo
 * ECN-Echo
 *
 *
 * RFC 2481 details a specific bit for a receiver to send back in its
 * RFC 2481 details a specific bit for a receiver to send back in its
 * TCP acknowledgements to notify the sender of the Congestion
 * TCP acknowledgements to notify the sender of the Congestion
 * Experienced (CE) bit having arrived from the network.  For SCTP this
 * Experienced (CE) bit having arrived from the network.  For SCTP this
 * same indication is made by including the ECNE chunk.  This chunk
 * same indication is made by including the ECNE chunk.  This chunk
 * contains one data element, i.e. the lowest TSN associated with the IP
 * contains one data element, i.e. the lowest TSN associated with the IP
 * datagram marked with the CE bit.....
 * datagram marked with the CE bit.....
 *
 *
 * Verification Tag: 8.5 Verification Tag [Normal verification]
 * Verification Tag: 8.5 Verification Tag [Normal verification]
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
                                   const struct sctp_association *asoc,
                                   const struct sctp_association *asoc,
                                   const sctp_subtype_t type,
                                   const sctp_subtype_t type,
                                   void *arg,
                                   void *arg,
                                   sctp_cmd_seq_t *commands)
                                   sctp_cmd_seq_t *commands)
{
{
        sctp_ecnehdr_t *ecne;
        sctp_ecnehdr_t *ecne;
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
 
 
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
         * that the value in the Verification Tag field of the
         * that the value in the Verification Tag field of the
         * received SCTP packet matches its own Tag. If the received
         * received SCTP packet matches its own Tag. If the received
         * Verification Tag value does not match the receiver's own
         * Verification Tag value does not match the receiver's own
         * tag value, the receiver shall silently discard the packet...
         * tag value, the receiver shall silently discard the packet...
         */
         */
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
        ecne = (sctp_ecnehdr_t *) chunk->skb->data;
        ecne = (sctp_ecnehdr_t *) chunk->skb->data;
        skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
        skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
 
 
        /* If this is a newer ECNE than the last CWR packet we sent out */
        /* If this is a newer ECNE than the last CWR packet we sent out */
        sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
        sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
                        SCTP_U32(ntohl(ecne->lowest_tsn)));
                        SCTP_U32(ntohl(ecne->lowest_tsn)));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/*
/*
 * Section: 6.2  Acknowledgement on Reception of DATA Chunks
 * Section: 6.2  Acknowledgement on Reception of DATA Chunks
 *
 *
 * The SCTP endpoint MUST always acknowledge the reception of each valid
 * The SCTP endpoint MUST always acknowledge the reception of each valid
 * DATA chunk.
 * DATA chunk.
 *
 *
 * The guidelines on delayed acknowledgement algorithm specified in
 * The guidelines on delayed acknowledgement algorithm specified in
 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
 * acknowledgement SHOULD be generated for at least every second packet
 * acknowledgement SHOULD be generated for at least every second packet
 * (not every second DATA chunk) received, and SHOULD be generated within
 * (not every second DATA chunk) received, and SHOULD be generated within
 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
 * situations it may be beneficial for an SCTP transmitter to be more
 * situations it may be beneficial for an SCTP transmitter to be more
 * conservative than the algorithms detailed in this document allow.
 * conservative than the algorithms detailed in this document allow.
 * However, an SCTP transmitter MUST NOT be more aggressive than the
 * However, an SCTP transmitter MUST NOT be more aggressive than the
 * following algorithms allow.
 * following algorithms allow.
 *
 *
 * A SCTP receiver MUST NOT generate more than one SACK for every
 * A SCTP receiver MUST NOT generate more than one SACK for every
 * incoming packet, other than to update the offered window as the
 * incoming packet, other than to update the offered window as the
 * receiving application consumes new data.
 * receiving application consumes new data.
 *
 *
 * Verification Tag:  8.5 Verification Tag [Normal verification]
 * Verification Tag:  8.5 Verification Tag [Normal verification]
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        sctp_datahdr_t *data_hdr;
        sctp_datahdr_t *data_hdr;
        struct sctp_chunk *err;
        struct sctp_chunk *err;
        size_t datalen;
        size_t datalen;
        sctp_verb_t deliver;
        sctp_verb_t deliver;
        int tmp;
        int tmp;
        __u32 tsn;
        __u32 tsn;
 
 
        /* RFC 2960 8.5 Verification Tag
        /* RFC 2960 8.5 Verification Tag
         *
         *
         * When receiving an SCTP packet, the endpoint MUST ensure
         * When receiving an SCTP packet, the endpoint MUST ensure
         * that the value in the Verification Tag field of the
         * that the value in the Verification Tag field of the
         * received SCTP packet matches its own Tag.
         * received SCTP packet matches its own Tag.
         */
         */
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag) {
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag) {
                sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
                sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
                                SCTP_NULL());
                                SCTP_NULL());
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
        }
        }
 
 
        data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
        data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
        skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
        skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
 
 
        tsn = ntohl(data_hdr->tsn);
        tsn = ntohl(data_hdr->tsn);
        SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
        SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
 
 
        /* ASSERT:  Now skb->data is really the user data.  */
        /* ASSERT:  Now skb->data is really the user data.  */
 
 
        /* Process ECN based congestion.
        /* Process ECN based congestion.
         *
         *
         * Since the chunk structure is reused for all chunks within
         * Since the chunk structure is reused for all chunks within
         * a packet, we use ecn_ce_done to track if we've already
         * a packet, we use ecn_ce_done to track if we've already
         * done CE processing for this packet.
         * done CE processing for this packet.
         *
         *
         * We need to do ECN processing even if we plan to discard the
         * We need to do ECN processing even if we plan to discard the
         * chunk later.
         * chunk later.
         */
         */
 
 
        if (!chunk->ecn_ce_done) {
        if (!chunk->ecn_ce_done) {
                struct sctp_af *af;
                struct sctp_af *af;
                chunk->ecn_ce_done = 1;
                chunk->ecn_ce_done = 1;
 
 
                af = sctp_get_af_specific(
                af = sctp_get_af_specific(
                        ipver2af(chunk->skb->nh.iph->version));
                        ipver2af(chunk->skb->nh.iph->version));
 
 
                if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
                if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
                        /* Do real work as sideffect. */
                        /* Do real work as sideffect. */
                        sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
                        sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
                                        SCTP_U32(tsn));
                                        SCTP_U32(tsn));
                }
                }
        }
        }
 
 
        tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
        tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
        if (tmp < 0) {
        if (tmp < 0) {
                /* The TSN is too high--silently discard the chunk and
                /* The TSN is too high--silently discard the chunk and
                 * count on it getting retransmitted later.
                 * count on it getting retransmitted later.
                 */
                 */
                goto discard_noforce;
                goto discard_noforce;
        } else if (tmp > 0) {
        } else if (tmp > 0) {
                /* This is a duplicate.  Record it.  */
                /* This is a duplicate.  Record it.  */
                sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
                sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
                goto discard_force;
                goto discard_force;
        }
        }
 
 
        /* This is a new TSN.  */
        /* This is a new TSN.  */
 
 
        /* Discard if there is no room in the receive window.
        /* Discard if there is no room in the receive window.
         * Actually, allow a little bit of overflow (up to a MTU).
         * Actually, allow a little bit of overflow (up to a MTU).
         */
         */
        datalen = ntohs(chunk->chunk_hdr->length);
        datalen = ntohs(chunk->chunk_hdr->length);
        datalen -= sizeof(sctp_data_chunk_t);
        datalen -= sizeof(sctp_data_chunk_t);
 
 
        deliver = SCTP_CMD_CHUNK_ULP;
        deliver = SCTP_CMD_CHUNK_ULP;
 
 
        /* Think about partial delivery. */
        /* Think about partial delivery. */
        if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
        if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
 
 
                /* Even if we don't accept this chunk there is
                /* Even if we don't accept this chunk there is
                 * memory pressure.
                 * memory pressure.
                 */
                 */
                sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
                sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
        }
        }
 
 
        /* Spill over rwnd a little bit.  Note: While allowed, this spill over
        /* Spill over rwnd a little bit.  Note: While allowed, this spill over
         * seems a bit troublesome in that frag_point varies based on
         * seems a bit troublesome in that frag_point varies based on
         * PMTU.  In cases, such as loopback, this might be a rather
         * PMTU.  In cases, such as loopback, this might be a rather
         * large spill over.
         * large spill over.
         */
         */
        if (!asoc->rwnd || asoc->rwnd_over ||
        if (!asoc->rwnd || asoc->rwnd_over ||
            (datalen > asoc->rwnd + asoc->frag_point)) {
            (datalen > asoc->rwnd + asoc->frag_point)) {
 
 
                /* If this is the next TSN, consider reneging to make
                /* If this is the next TSN, consider reneging to make
                 * room.   Note: Playing nice with a confused sender.  A
                 * room.   Note: Playing nice with a confused sender.  A
                 * malicious sender can still eat up all our buffer
                 * malicious sender can still eat up all our buffer
                 * space and in the future we may want to detect and
                 * space and in the future we may want to detect and
                 * do more drastic reneging.
                 * do more drastic reneging.
                 */
                 */
                if (sctp_tsnmap_has_gap(&asoc->peer.tsn_map) &&
                if (sctp_tsnmap_has_gap(&asoc->peer.tsn_map) &&
                    (sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1) == tsn) {
                    (sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1) == tsn) {
                        SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
                        SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
                        deliver = SCTP_CMD_RENEGE;
                        deliver = SCTP_CMD_RENEGE;
                } else {
                } else {
                        SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
                        SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
                                          "rwnd: %d\n", tsn, datalen,
                                          "rwnd: %d\n", tsn, datalen,
                                          asoc->rwnd);
                                          asoc->rwnd);
                        goto discard_force;
                        goto discard_force;
                }
                }
        }
        }
 
 
        /*
        /*
         * Section 3.3.10.9 No User Data (9)
         * Section 3.3.10.9 No User Data (9)
         *
         *
         * Cause of error
         * Cause of error
         * ---------------
         * ---------------
         * No User Data:  This error cause is returned to the originator of a
         * No User Data:  This error cause is returned to the originator of a
         * DATA chunk if a received DATA chunk has no user data.
         * DATA chunk if a received DATA chunk has no user data.
         */
         */
        if (unlikely(0 == datalen)) {
        if (unlikely(0 == datalen)) {
                err = sctp_make_abort_no_data(asoc, chunk, tsn);
                err = sctp_make_abort_no_data(asoc, chunk, tsn);
                if (err) {
                if (err) {
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                                        SCTP_CHUNK(err));
                                        SCTP_CHUNK(err));
                }
                }
                /* We are going to ABORT, so we might as well stop
                /* We are going to ABORT, so we might as well stop
                 * processing the rest of the chunks in the packet.
                 * processing the rest of the chunks in the packet.
                 */
                 */
                sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
                sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                                SCTP_U32(SCTP_ERROR_NO_DATA));
                                SCTP_U32(SCTP_ERROR_NO_DATA));
                SCTP_INC_STATS(SctpAborteds);
                SCTP_INC_STATS(SctpAborteds);
                SCTP_DEC_STATS(SctpCurrEstab);
                SCTP_DEC_STATS(SctpCurrEstab);
                return SCTP_DISPOSITION_CONSUME;
                return SCTP_DISPOSITION_CONSUME;
        }
        }
 
 
        /* If definately accepting the DATA chunk, record its TSN, otherwise
        /* If definately accepting the DATA chunk, record its TSN, otherwise
         * wait for renege processing.
         * wait for renege processing.
         */
         */
        if (SCTP_CMD_CHUNK_ULP == deliver)
        if (SCTP_CMD_CHUNK_ULP == deliver)
                sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
                sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
 
 
        /* Note: Some chunks may get overcounted (if we drop) or overcounted
        /* Note: Some chunks may get overcounted (if we drop) or overcounted
         * if we renege and the chunk arrives again.
         * if we renege and the chunk arrives again.
         */
         */
        if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
        if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
                SCTP_INC_STATS(SctpInUnorderChunks);
                SCTP_INC_STATS(SctpInUnorderChunks);
        else
        else
                SCTP_INC_STATS(SctpInOrderChunks);
                SCTP_INC_STATS(SctpInOrderChunks);
 
 
        /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
        /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
         *
         *
         * If an endpoint receive a DATA chunk with an invalid stream
         * If an endpoint receive a DATA chunk with an invalid stream
         * identifier, it shall acknowledge the reception of the DATA chunk
         * identifier, it shall acknowledge the reception of the DATA chunk
         * following the normal procedure, immediately send an ERROR chunk
         * following the normal procedure, immediately send an ERROR chunk
         * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
         * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
         * and discard the DATA chunk.
         * and discard the DATA chunk.
         */
         */
        if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
        if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
                err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
                err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
                                         &data_hdr->stream,
                                         &data_hdr->stream,
                                         sizeof(data_hdr->stream));
                                         sizeof(data_hdr->stream));
                if (err)
                if (err)
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                                        SCTP_CHUNK(err));
                                        SCTP_CHUNK(err));
                goto discard_noforce;
                goto discard_noforce;
        }
        }
 
 
        /* Send the data up to the user.  Note:  Schedule  the
        /* Send the data up to the user.  Note:  Schedule  the
         * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
         * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
         * chunk needs the updated rwnd.
         * chunk needs the updated rwnd.
         */
         */
        sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
        sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
 
 
        if (asoc->autoclose) {
        if (asoc->autoclose) {
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
                                SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
                                SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
        }
        }
 
 
        /* If this is the last chunk in a packet, we need to count it
        /* If this is the last chunk in a packet, we need to count it
         * toward sack generation.  Note that we need to SACK every
         * toward sack generation.  Note that we need to SACK every
         * OTHER packet containing data chunks, EVEN IF WE DISCARD
         * OTHER packet containing data chunks, EVEN IF WE DISCARD
         * THEM.  We elect to NOT generate SACK's if the chunk fails
         * THEM.  We elect to NOT generate SACK's if the chunk fails
         * the verification tag test.
         * the verification tag test.
         *
         *
         * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
         * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
         *
         *
         * The SCTP endpoint MUST always acknowledge the reception of
         * The SCTP endpoint MUST always acknowledge the reception of
         * each valid DATA chunk.
         * each valid DATA chunk.
         *
         *
         * The guidelines on delayed acknowledgement algorithm
         * The guidelines on delayed acknowledgement algorithm
         * specified in  Section 4.2 of [RFC2581] SHOULD be followed.
         * specified in  Section 4.2 of [RFC2581] SHOULD be followed.
         * Specifically, an acknowledgement SHOULD be generated for at
         * Specifically, an acknowledgement SHOULD be generated for at
         * least every second packet (not every second DATA chunk)
         * least every second packet (not every second DATA chunk)
         * received, and SHOULD be generated within 200 ms of the
         * received, and SHOULD be generated within 200 ms of the
         * arrival of any unacknowledged DATA chunk.  In some
         * arrival of any unacknowledged DATA chunk.  In some
         * situations it may be beneficial for an SCTP transmitter to
         * situations it may be beneficial for an SCTP transmitter to
         * be more conservative than the algorithms detailed in this
         * be more conservative than the algorithms detailed in this
         * document allow. However, an SCTP transmitter MUST NOT be
         * document allow. However, an SCTP transmitter MUST NOT be
         * more aggressive than the following algorithms allow.
         * more aggressive than the following algorithms allow.
         */
         */
        if (chunk->end_of_packet) {
        if (chunk->end_of_packet) {
                sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
                sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
 
 
                /* Start the SACK timer.  */
                /* Start the SACK timer.  */
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
                                SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
                                SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
        }
        }
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
discard_force:
discard_force:
        /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
        /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
         *
         *
         * When a packet arrives with duplicate DATA chunk(s) and with
         * When a packet arrives with duplicate DATA chunk(s) and with
         * no new DATA chunk(s), the endpoint MUST immediately send a
         * no new DATA chunk(s), the endpoint MUST immediately send a
         * SACK with no delay.  If a packet arrives with duplicate
         * SACK with no delay.  If a packet arrives with duplicate
         * DATA chunk(s) bundled with new DATA chunks, the endpoint
         * DATA chunk(s) bundled with new DATA chunks, the endpoint
         * MAY immediately send a SACK.  Normally receipt of duplicate
         * MAY immediately send a SACK.  Normally receipt of duplicate
         * DATA chunks will occur when the original SACK chunk was lost
         * DATA chunks will occur when the original SACK chunk was lost
         * and the peer's RTO has expired.  The duplicate TSN number(s)
         * and the peer's RTO has expired.  The duplicate TSN number(s)
         * SHOULD be reported in the SACK as duplicate.
         * SHOULD be reported in the SACK as duplicate.
         */
         */
        /* In our case, we split the MAY SACK advice up whether or not
        /* In our case, we split the MAY SACK advice up whether or not
         * the last chunk is a duplicate.'
         * the last chunk is a duplicate.'
         */
         */
        if (chunk->end_of_packet)
        if (chunk->end_of_packet)
                sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
                sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
        return SCTP_DISPOSITION_DISCARD;
        return SCTP_DISPOSITION_DISCARD;
 
 
discard_noforce:
discard_noforce:
        if (chunk->end_of_packet) {
        if (chunk->end_of_packet) {
                sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
                sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
 
 
                /* Start the SACK timer.  */
                /* Start the SACK timer.  */
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
                                SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
                                SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
        }
        }
        return SCTP_DISPOSITION_DISCARD;
        return SCTP_DISPOSITION_DISCARD;
}
}
 
 
/*
/*
 * sctp_sf_eat_data_fast_4_4
 * sctp_sf_eat_data_fast_4_4
 *
 *
 * Section: 4 (4)
 * Section: 4 (4)
 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
 *    DATA chunks without delay.
 *    DATA chunks without delay.
 *
 *
 * Verification Tag:  8.5 Verification Tag [Normal verification]
 * Verification Tag:  8.5 Verification Tag [Normal verification]
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
                                     const struct sctp_association *asoc,
                                     const struct sctp_association *asoc,
                                     const sctp_subtype_t type,
                                     const sctp_subtype_t type,
                                     void *arg,
                                     void *arg,
                                     sctp_cmd_seq_t *commands)
                                     sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        sctp_datahdr_t *data_hdr;
        sctp_datahdr_t *data_hdr;
        struct sctp_chunk *err;
        struct sctp_chunk *err;
        size_t datalen;
        size_t datalen;
        int tmp;
        int tmp;
        __u32 tsn;
        __u32 tsn;
 
 
        /* RFC 2960 8.5 Verification Tag
        /* RFC 2960 8.5 Verification Tag
         *
         *
         * When receiving an SCTP packet, the endpoint MUST ensure
         * When receiving an SCTP packet, the endpoint MUST ensure
         * that the value in the Verification Tag field of the
         * that the value in the Verification Tag field of the
         * received SCTP packet matches its own Tag.
         * received SCTP packet matches its own Tag.
         */
         */
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag) {
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag) {
                sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
                sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
                                SCTP_NULL());
                                SCTP_NULL());
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
        }
        }
 
 
        data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *) chunk->skb->data;
        data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *) chunk->skb->data;
        skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
        skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
 
 
        tsn = ntohl(data_hdr->tsn);
        tsn = ntohl(data_hdr->tsn);
 
 
        SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
        SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
 
 
        /* ASSERT:  Now skb->data is really the user data.  */
        /* ASSERT:  Now skb->data is really the user data.  */
 
 
        /* Process ECN based congestion.
        /* Process ECN based congestion.
         *
         *
         * Since the chunk structure is reused for all chunks within
         * Since the chunk structure is reused for all chunks within
         * a packet, we use ecn_ce_done to track if we've already
         * a packet, we use ecn_ce_done to track if we've already
         * done CE processing for this packet.
         * done CE processing for this packet.
         *
         *
         * We need to do ECN processing even if we plan to discard the
         * We need to do ECN processing even if we plan to discard the
         * chunk later.
         * chunk later.
         */
         */
        if (!chunk->ecn_ce_done) {
        if (!chunk->ecn_ce_done) {
                struct sctp_af *af;
                struct sctp_af *af;
                chunk->ecn_ce_done = 1;
                chunk->ecn_ce_done = 1;
 
 
                af = sctp_get_af_specific(
                af = sctp_get_af_specific(
                        ipver2af(chunk->skb->nh.iph->version));
                        ipver2af(chunk->skb->nh.iph->version));
 
 
                if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
                if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
                        /* Do real work as sideffect. */
                        /* Do real work as sideffect. */
                        sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
                        sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
                                        SCTP_U32(tsn));
                                        SCTP_U32(tsn));
                }
                }
        }
        }
 
 
        tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
        tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
        if (tmp < 0) {
        if (tmp < 0) {
                /* The TSN is too high--silently discard the chunk and
                /* The TSN is too high--silently discard the chunk and
                 * count on it getting retransmitted later.
                 * count on it getting retransmitted later.
                 */
                 */
                goto gen_shutdown;
                goto gen_shutdown;
        } else if (tmp > 0) {
        } else if (tmp > 0) {
                /* This is a duplicate.  Record it.  */
                /* This is a duplicate.  Record it.  */
                sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
                sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
                goto gen_shutdown;
                goto gen_shutdown;
        }
        }
 
 
        /* This is a new TSN.  */
        /* This is a new TSN.  */
 
 
        datalen = ntohs(chunk->chunk_hdr->length);
        datalen = ntohs(chunk->chunk_hdr->length);
        datalen -= sizeof(sctp_data_chunk_t);
        datalen -= sizeof(sctp_data_chunk_t);
 
 
        /*
        /*
         * Section 3.3.10.9 No User Data (9)
         * Section 3.3.10.9 No User Data (9)
         *
         *
         * Cause of error
         * Cause of error
         * ---------------
         * ---------------
         * No User Data:  This error cause is returned to the originator of a
         * No User Data:  This error cause is returned to the originator of a
         * DATA chunk if a received DATA chunk has no user data.
         * DATA chunk if a received DATA chunk has no user data.
         */
         */
        if (unlikely(0 == datalen)) {
        if (unlikely(0 == datalen)) {
                err = sctp_make_abort_no_data(asoc, chunk, tsn);
                err = sctp_make_abort_no_data(asoc, chunk, tsn);
                if (err) {
                if (err) {
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                                        SCTP_CHUNK(err));
                                        SCTP_CHUNK(err));
                }
                }
                /* We are going to ABORT, so we might as well stop
                /* We are going to ABORT, so we might as well stop
                 * processing the rest of the chunks in the packet.
                 * processing the rest of the chunks in the packet.
                 */
                 */
                sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
                sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                                SCTP_U32(SCTP_ERROR_NO_DATA));
                                SCTP_U32(SCTP_ERROR_NO_DATA));
                SCTP_INC_STATS(SctpAborteds);
                SCTP_INC_STATS(SctpAborteds);
                SCTP_DEC_STATS(SctpCurrEstab);
                SCTP_DEC_STATS(SctpCurrEstab);
                return SCTP_DISPOSITION_CONSUME;
                return SCTP_DISPOSITION_CONSUME;
        }
        }
 
 
        /* We are accepting this DATA chunk. */
        /* We are accepting this DATA chunk. */
 
 
        /* Record the fact that we have received this TSN.  */
        /* Record the fact that we have received this TSN.  */
        sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
 
 
        if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
        if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
                SCTP_INC_STATS(SctpInUnorderChunks);
                SCTP_INC_STATS(SctpInUnorderChunks);
        else
        else
                SCTP_INC_STATS(SctpInOrderChunks);
                SCTP_INC_STATS(SctpInOrderChunks);
 
 
        /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
        /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
         *
         *
         * If an endpoint receive a DATA chunk with an invalid stream
         * If an endpoint receive a DATA chunk with an invalid stream
         * identifier, it shall acknowledge the reception of the DATA chunk
         * identifier, it shall acknowledge the reception of the DATA chunk
         * following the normal procedure, immediately send an ERROR chunk
         * following the normal procedure, immediately send an ERROR chunk
         * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
         * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
         * and discard the DATA chunk.
         * and discard the DATA chunk.
         */
         */
        if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
        if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
                err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
                err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
                                         &data_hdr->stream,
                                         &data_hdr->stream,
                                         sizeof(data_hdr->stream));
                                         sizeof(data_hdr->stream));
                if (err) {
                if (err) {
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                                        SCTP_CHUNK(err));
                                        SCTP_CHUNK(err));
                }
                }
        }
        }
 
 
        /* Go a head and force a SACK, since we are shutting down. */
        /* Go a head and force a SACK, since we are shutting down. */
gen_shutdown:
gen_shutdown:
        /* Implementor's Guide.
        /* Implementor's Guide.
         *
         *
         * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
         * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
         * respond to each received packet containing one or more DATA chunk(s)
         * respond to each received packet containing one or more DATA chunk(s)
         * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
         * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
         */
         */
        if (chunk->end_of_packet) {
        if (chunk->end_of_packet) {
                /* We must delay the chunk creation since the cumulative
                /* We must delay the chunk creation since the cumulative
                 * TSN has not been updated yet.
                 * TSN has not been updated yet.
                 */
                 */
                sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
                sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
                sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
                sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
                                SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
                                SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
        }
        }
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/*
/*
 * Section: 6.2  Processing a Received SACK
 * Section: 6.2  Processing a Received SACK
 * D) Any time a SACK arrives, the endpoint performs the following:
 * D) Any time a SACK arrives, the endpoint performs the following:
 *
 *
 *     i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
 *     i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
 *     then drop the SACK.   Since Cumulative TSN Ack is monotonically
 *     then drop the SACK.   Since Cumulative TSN Ack is monotonically
 *     increasing, a SACK whose Cumulative TSN Ack is less than the
 *     increasing, a SACK whose Cumulative TSN Ack is less than the
 *     Cumulative TSN Ack Point indicates an out-of-order SACK.
 *     Cumulative TSN Ack Point indicates an out-of-order SACK.
 *
 *
 *     ii) Set rwnd equal to the newly received a_rwnd minus the number
 *     ii) Set rwnd equal to the newly received a_rwnd minus the number
 *     of bytes still outstanding after processing the Cumulative TSN Ack
 *     of bytes still outstanding after processing the Cumulative TSN Ack
 *     and the Gap Ack Blocks.
 *     and the Gap Ack Blocks.
 *
 *
 *     iii) If the SACK is missing a TSN that was previously
 *     iii) If the SACK is missing a TSN that was previously
 *     acknowledged via a Gap Ack Block (e.g., the data receiver
 *     acknowledged via a Gap Ack Block (e.g., the data receiver
 *     reneged on the data), then mark the corresponding DATA chunk
 *     reneged on the data), then mark the corresponding DATA chunk
 *     as available for retransmit:  Mark it as missing for fast
 *     as available for retransmit:  Mark it as missing for fast
 *     retransmit as described in Section 7.2.4 and if no retransmit
 *     retransmit as described in Section 7.2.4 and if no retransmit
 *     timer is running for the destination address to which the DATA
 *     timer is running for the destination address to which the DATA
 *     chunk was originally transmitted, then T3-rtx is started for
 *     chunk was originally transmitted, then T3-rtx is started for
 *     that destination address.
 *     that destination address.
 *
 *
 * Verification Tag:  8.5 Verification Tag [Normal verification]
 * Verification Tag:  8.5 Verification Tag [Normal verification]
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        sctp_sackhdr_t *sackh;
        sctp_sackhdr_t *sackh;
        __u32 ctsn;
        __u32 ctsn;
 
 
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
         * that the value in the Verification Tag field of the
         * that the value in the Verification Tag field of the
         * received SCTP packet matches its own Tag. ...
         * received SCTP packet matches its own Tag. ...
         */
         */
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
        if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
        /* Pull the SACK chunk from the data buffer */
        /* Pull the SACK chunk from the data buffer */
        sackh = sctp_sm_pull_sack(chunk);
        sackh = sctp_sm_pull_sack(chunk);
        /* Was this a bogus SACK? */
        /* Was this a bogus SACK? */
        if (!sackh)
        if (!sackh)
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
        chunk->subh.sack_hdr = sackh;
        chunk->subh.sack_hdr = sackh;
        ctsn = ntohl(sackh->cum_tsn_ack);
        ctsn = ntohl(sackh->cum_tsn_ack);
 
 
        /* i) If Cumulative TSN Ack is less than the Cumulative TSN
        /* i) If Cumulative TSN Ack is less than the Cumulative TSN
         *     Ack Point, then drop the SACK.  Since Cumulative TSN
         *     Ack Point, then drop the SACK.  Since Cumulative TSN
         *     Ack is monotonically increasing, a SACK whose
         *     Ack is monotonically increasing, a SACK whose
         *     Cumulative TSN Ack is less than the Cumulative TSN Ack
         *     Cumulative TSN Ack is less than the Cumulative TSN Ack
         *     Point indicates an out-of-order SACK.
         *     Point indicates an out-of-order SACK.
         */
         */
        if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
        if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
                SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
                SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
                SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
                SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
                return SCTP_DISPOSITION_DISCARD;
                return SCTP_DISPOSITION_DISCARD;
        }
        }
 
 
        /* Return this SACK for further processing.  */
        /* Return this SACK for further processing.  */
        sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
        sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
 
 
        /* Note: We do the rest of the work on the PROCESS_SACK
        /* Note: We do the rest of the work on the PROCESS_SACK
         * sideeffect.
         * sideeffect.
         */
         */
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/*
/*
 * Generate an ABORT in response to a packet.
 * Generate an ABORT in response to a packet.
 *
 *
 * Section: 8.4 Handle "Out of the blue" Packets
 * Section: 8.4 Handle "Out of the blue" Packets
 *
 *
 * 8) The receiver should respond to the sender of the OOTB packet
 * 8) The receiver should respond to the sender of the OOTB packet
 *    with an ABORT.  When sending the ABORT, the receiver of the
 *    with an ABORT.  When sending the ABORT, the receiver of the
 *    OOTB packet MUST fill in the Verification Tag field of the
 *    OOTB packet MUST fill in the Verification Tag field of the
 *    outbound packet with the value found in the Verification Tag
 *    outbound packet with the value found in the Verification Tag
 *    field of the OOTB packet and set the T-bit in the Chunk Flags
 *    field of the OOTB packet and set the T-bit in the Chunk Flags
 *    to indicate that no TCB was found.  After sending this ABORT,
 *    to indicate that no TCB was found.  After sending this ABORT,
 *    the receiver of the OOTB packet shall discard the OOTB packet
 *    the receiver of the OOTB packet shall discard the OOTB packet
 *    and take no further action.
 *    and take no further action.
 *
 *
 * Verification Tag:
 * Verification Tag:
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
*/
*/
sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_packet *packet = NULL;
        struct sctp_packet *packet = NULL;
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *abort;
        struct sctp_chunk *abort;
 
 
        packet = sctp_ootb_pkt_new(asoc, chunk);
        packet = sctp_ootb_pkt_new(asoc, chunk);
 
 
        if (packet) {
        if (packet) {
                /* Make an ABORT. The T bit will be set if the asoc
                /* Make an ABORT. The T bit will be set if the asoc
                 * is NULL.
                 * is NULL.
                 */
                 */
                abort = sctp_make_abort(asoc, chunk, 0);
                abort = sctp_make_abort(asoc, chunk, 0);
                if (!abort) {
                if (!abort) {
                        sctp_ootb_pkt_free(packet);
                        sctp_ootb_pkt_free(packet);
                        return SCTP_DISPOSITION_NOMEM;
                        return SCTP_DISPOSITION_NOMEM;
                }
                }
 
 
                /* Set the skb to the belonging sock for accounting.  */
                /* Set the skb to the belonging sock for accounting.  */
                abort->skb->sk = ep->base.sk;
                abort->skb->sk = ep->base.sk;
 
 
                sctp_packet_append_chunk(packet, abort);
                sctp_packet_append_chunk(packet, abort);
 
 
                sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
                sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
                                SCTP_PACKET(packet));
                                SCTP_PACKET(packet));
 
 
                SCTP_INC_STATS(SctpOutCtrlChunks);
                SCTP_INC_STATS(SctpOutCtrlChunks);
 
 
                return SCTP_DISPOSITION_CONSUME;
                return SCTP_DISPOSITION_CONSUME;
        }
        }
 
 
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Received an ERROR chunk from peer.  Generate SCTP_REMOTE_ERROR
 * Received an ERROR chunk from peer.  Generate SCTP_REMOTE_ERROR
 * event as ULP notification for each cause included in the chunk.
 * event as ULP notification for each cause included in the chunk.
 *
 *
 * API 5.3.1.3 - SCTP_REMOTE_ERROR
 * API 5.3.1.3 - SCTP_REMOTE_ERROR
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
*/
*/
sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        struct sctp_ulpevent *ev;
        struct sctp_ulpevent *ev;
 
 
        while (chunk->chunk_end > chunk->skb->data) {
        while (chunk->chunk_end > chunk->skb->data) {
                ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
                ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
                                                     GFP_ATOMIC);
                                                     GFP_ATOMIC);
                if (!ev)
                if (!ev)
                        goto nomem;
                        goto nomem;
 
 
                if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
                if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
                                  SCTP_ULPEVENT(ev))) {
                                  SCTP_ULPEVENT(ev))) {
                        sctp_ulpevent_free(ev);
                        sctp_ulpevent_free(ev);
                        goto nomem;
                        goto nomem;
                }
                }
 
 
                sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
                sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
                                SCTP_CHUNK(chunk));
                                SCTP_CHUNK(chunk));
        }
        }
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Process an inbound SHUTDOWN ACK.
 * Process an inbound SHUTDOWN ACK.
 *
 *
 * From Section 9.2:
 * From Section 9.2:
 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
 * peer, and remove all record of the association.
 * peer, and remove all record of the association.
 *
 *
 * The return value is the disposition.
 * The return value is the disposition.
 */
 */
sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *reply;
        struct sctp_chunk *reply;
        struct sctp_ulpevent *ev;
        struct sctp_ulpevent *ev;
 
 
        /* 10.2 H) SHUTDOWN COMPLETE notification
        /* 10.2 H) SHUTDOWN COMPLETE notification
         *
         *
         * When SCTP completes the shutdown procedures (section 9.2) this
         * When SCTP completes the shutdown procedures (section 9.2) this
         * notification is passed to the upper layer.
         * notification is passed to the upper layer.
         */
         */
        ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
        ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
                                             0, 0, 0, GFP_ATOMIC);
                                             0, 0, 0, GFP_ATOMIC);
        if (!ev)
        if (!ev)
                goto nomem;
                goto nomem;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
        sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
 
 
        /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
        /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
         * stop the T2-shutdown timer,
         * stop the T2-shutdown timer,
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
 
 
        /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
        /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
        reply = sctp_make_shutdown_complete(asoc, chunk);
        reply = sctp_make_shutdown_complete(asoc, chunk);
        if (!reply)
        if (!reply)
                goto nomem;
                goto nomem;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_CLOSED));
                        SCTP_STATE(SCTP_STATE_CLOSED));
        SCTP_INC_STATS(SctpShutdowns);
        SCTP_INC_STATS(SctpShutdowns);
        SCTP_DEC_STATS(SctpCurrEstab);
        SCTP_DEC_STATS(SctpCurrEstab);
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
 
 
        /* ...and remove all record of the association. */
        /* ...and remove all record of the association. */
        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
        return SCTP_DISPOSITION_DELETE_TCB;
        return SCTP_DISPOSITION_DELETE_TCB;
 
 
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * RFC 2960, 8.4 - Handle "Out of the blue" Packets
 * RFC 2960, 8.4 - Handle "Out of the blue" Packets
 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
 *    respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
 *    respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
 *    When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
 *    When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
 *    packet must fill in the Verification Tag field of the outbound
 *    packet must fill in the Verification Tag field of the outbound
 *    packet with the Verification Tag received in the SHUTDOWN ACK and
 *    packet with the Verification Tag received in the SHUTDOWN ACK and
 *    set the T-bit in the Chunk Flags to indicate that no TCB was
 *    set the T-bit in the Chunk Flags to indicate that no TCB was
 *    found. Otherwise,
 *    found. Otherwise,
 *
 *
 * 8) The receiver should respond to the sender of the OOTB packet with
 * 8) The receiver should respond to the sender of the OOTB packet with
 *    an ABORT.  When sending the ABORT, the receiver of the OOTB packet
 *    an ABORT.  When sending the ABORT, the receiver of the OOTB packet
 *    MUST fill in the Verification Tag field of the outbound packet
 *    MUST fill in the Verification Tag field of the outbound packet
 *    with the value found in the Verification Tag field of the OOTB
 *    with the value found in the Verification Tag field of the OOTB
 *    packet and set the T-bit in the Chunk Flags to indicate that no
 *    packet and set the T-bit in the Chunk Flags to indicate that no
 *    TCB was found.  After sending this ABORT, the receiver of the OOTB
 *    TCB was found.  After sending this ABORT, the receiver of the OOTB
 *    packet shall discard the OOTB packet and take no further action.
 *    packet shall discard the OOTB packet and take no further action.
 */
 */
sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
                                const struct sctp_association *asoc,
                                const struct sctp_association *asoc,
                                const sctp_subtype_t type,
                                const sctp_subtype_t type,
                                void *arg,
                                void *arg,
                                sctp_cmd_seq_t *commands)
                                sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        struct sk_buff *skb = chunk->skb;
        struct sk_buff *skb = chunk->skb;
        sctp_chunkhdr_t *ch;
        sctp_chunkhdr_t *ch;
        __u8 *ch_end;
        __u8 *ch_end;
        int ootb_shut_ack = 0;
        int ootb_shut_ack = 0;
 
 
        SCTP_INC_STATS(SctpOutOfBlues);
        SCTP_INC_STATS(SctpOutOfBlues);
 
 
        ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
        ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
        do {
        do {
                ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
                ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
 
 
                if (SCTP_CID_SHUTDOWN_ACK == ch->type)
                if (SCTP_CID_SHUTDOWN_ACK == ch->type)
                        ootb_shut_ack = 1;
                        ootb_shut_ack = 1;
 
 
                ch = (sctp_chunkhdr_t *) ch_end;
                ch = (sctp_chunkhdr_t *) ch_end;
        } while (ch_end < skb->tail);
        } while (ch_end < skb->tail);
 
 
        if (ootb_shut_ack)
        if (ootb_shut_ack)
                sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
                sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
        else
        else
                sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
                sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
 
 
        return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
        return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
}
}
 
 
/*
/*
 * Handle an "Out of the blue" SHUTDOWN ACK.
 * Handle an "Out of the blue" SHUTDOWN ACK.
 *
 *
 * Section: 8.4 5)
 * Section: 8.4 5)
 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
 *   respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
 *   respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
 *   When sending the SHUTDOWN COMPLETE, the receiver of the OOTB packet
 *   When sending the SHUTDOWN COMPLETE, the receiver of the OOTB packet
 *   must fill in the Verification Tag field of the outbound packet with
 *   must fill in the Verification Tag field of the outbound packet with
 *   the Verification Tag received in the SHUTDOWN ACK and set the
 *   the Verification Tag received in the SHUTDOWN ACK and set the
 *   T-bit in the Chunk Flags to indicate that no TCB was found.
 *   T-bit in the Chunk Flags to indicate that no TCB was found.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, type, arg, commands)
 * (endpoint, asoc, type, arg, commands)
 *
 *
 * Outputs
 * Outputs
 * (sctp_disposition_t)
 * (sctp_disposition_t)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
                                      const struct sctp_association *asoc,
                                      const struct sctp_association *asoc,
                                      const sctp_subtype_t type,
                                      const sctp_subtype_t type,
                                      void *arg,
                                      void *arg,
                                      sctp_cmd_seq_t *commands)
                                      sctp_cmd_seq_t *commands)
{
{
        struct sctp_packet *packet = NULL;
        struct sctp_packet *packet = NULL;
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *shut;
        struct sctp_chunk *shut;
 
 
        packet = sctp_ootb_pkt_new(asoc, chunk);
        packet = sctp_ootb_pkt_new(asoc, chunk);
 
 
        if (packet) {
        if (packet) {
                /* Make an SHUTDOWN_COMPLETE.
                /* Make an SHUTDOWN_COMPLETE.
                 * The T bit will be set if the asoc is NULL.
                 * The T bit will be set if the asoc is NULL.
                 */
                 */
                shut = sctp_make_shutdown_complete(asoc, chunk);
                shut = sctp_make_shutdown_complete(asoc, chunk);
                if (!shut) {
                if (!shut) {
                        sctp_ootb_pkt_free(packet);
                        sctp_ootb_pkt_free(packet);
                        return SCTP_DISPOSITION_NOMEM;
                        return SCTP_DISPOSITION_NOMEM;
                }
                }
 
 
                /* Set the skb to the belonging sock for accounting.  */
                /* Set the skb to the belonging sock for accounting.  */
                shut->skb->sk = ep->base.sk;
                shut->skb->sk = ep->base.sk;
 
 
                sctp_packet_append_chunk(packet, shut);
                sctp_packet_append_chunk(packet, shut);
 
 
                sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
                sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
                                SCTP_PACKET(packet));
                                SCTP_PACKET(packet));
 
 
                SCTP_INC_STATS(SctpOutCtrlChunks);
                SCTP_INC_STATS(SctpOutCtrlChunks);
 
 
                return SCTP_DISPOSITION_CONSUME;
                return SCTP_DISPOSITION_CONSUME;
        }
        }
 
 
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
 *
 *
 * Verification Tag:  8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
 * Verification Tag:  8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
 *   If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
 *   If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
 *   procedures in section 8.4 SHOULD be followed, in other words it
 *   procedures in section 8.4 SHOULD be followed, in other words it
 *   should be treated as an Out Of The Blue packet.
 *   should be treated as an Out Of The Blue packet.
 *   [This means that we do NOT check the Verification Tag on these
 *   [This means that we do NOT check the Verification Tag on these
 *   chunks. --piggy ]
 *   chunks. --piggy ]
 *
 *
 */
 */
sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
                                      const struct sctp_association *asoc,
                                      const struct sctp_association *asoc,
                                      const sctp_subtype_t type,
                                      const sctp_subtype_t type,
                                      void *arg,
                                      void *arg,
                                      sctp_cmd_seq_t *commands)
                                      sctp_cmd_seq_t *commands)
{
{
        /* Although we do have an association in this case, it corresponds
        /* Although we do have an association in this case, it corresponds
         * to a restarted association. So the packet is treated as an OOTB
         * to a restarted association. So the packet is treated as an OOTB
         * packet and the state function that handles OOTB SHUTDOWN_ACK is
         * packet and the state function that handles OOTB SHUTDOWN_ACK is
         * called with a NULL association.
         * called with a NULL association.
         */
         */
        return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
        return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
}
}
 
 
/* ADDIP Section 4.2 Upon reception of an ASCONF Chunk.  */
/* ADDIP Section 4.2 Upon reception of an ASCONF Chunk.  */
sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
                                     const struct sctp_association *asoc,
                                     const struct sctp_association *asoc,
                                     const sctp_subtype_t type, void *arg,
                                     const sctp_subtype_t type, void *arg,
                                     sctp_cmd_seq_t *commands)
                                     sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk       *chunk = arg;
        struct sctp_chunk       *chunk = arg;
        struct sctp_chunk       *asconf_ack = NULL;
        struct sctp_chunk       *asconf_ack = NULL;
        sctp_addiphdr_t         *hdr;
        sctp_addiphdr_t         *hdr;
        __u32                   serial;
        __u32                   serial;
 
 
        hdr = (sctp_addiphdr_t *)chunk->skb->data;
        hdr = (sctp_addiphdr_t *)chunk->skb->data;
        serial = ntohl(hdr->serial);
        serial = ntohl(hdr->serial);
 
 
        /* ADDIP 4.2 C1) Compare the value of the serial number to the value
        /* ADDIP 4.2 C1) Compare the value of the serial number to the value
         * the endpoint stored in a new association variable
         * the endpoint stored in a new association variable
         * 'Peer-Serial-Number'.
         * 'Peer-Serial-Number'.
         */
         */
        if (serial == asoc->peer.addip_serial + 1) {
        if (serial == asoc->peer.addip_serial + 1) {
                /* ADDIP 4.2 C2) If the value found in the serial number is
                /* ADDIP 4.2 C2) If the value found in the serial number is
                 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
                 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
                 * do V1-V5.
                 * do V1-V5.
                 */
                 */
                asconf_ack = sctp_process_asconf((struct sctp_association *)
                asconf_ack = sctp_process_asconf((struct sctp_association *)
                                                 asoc, chunk);
                                                 asoc, chunk);
                if (!asconf_ack)
                if (!asconf_ack)
                        return SCTP_DISPOSITION_NOMEM;
                        return SCTP_DISPOSITION_NOMEM;
        } else if (serial == asoc->peer.addip_serial) {
        } else if (serial == asoc->peer.addip_serial) {
                /* ADDIP 4.2 C3) If the value found in the serial number is
                /* ADDIP 4.2 C3) If the value found in the serial number is
                 * equal to the value stored in the 'Peer-Serial-Number'
                 * equal to the value stored in the 'Peer-Serial-Number'
                 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
                 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
                 * to save the last ASCONF-ACK for some predetermined period of                  * time and instead of re-processing the ASCONF (with the same
                 * to save the last ASCONF-ACK for some predetermined period of                  * time and instead of re-processing the ASCONF (with the same
                 * serial number) it may just re-transmit the ASCONF-ACK.
                 * serial number) it may just re-transmit the ASCONF-ACK.
                 */
                 */
                if (asoc->addip_last_asconf_ack)
                if (asoc->addip_last_asconf_ack)
                        asconf_ack = asoc->addip_last_asconf_ack;
                        asconf_ack = asoc->addip_last_asconf_ack;
                else
                else
                        return SCTP_DISPOSITION_DISCARD;
                        return SCTP_DISPOSITION_DISCARD;
        } else {
        } else {
                /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
                /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
                 * it must be either a stale packet or from an attacker.
                 * it must be either a stale packet or from an attacker.
                 */
                 */
                return SCTP_DISPOSITION_DISCARD;
                return SCTP_DISPOSITION_DISCARD;
        }
        }
 
 
        /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
        /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
         * back to the source address contained in the IP header of the ASCONF
         * back to the source address contained in the IP header of the ASCONF
         * being responded to.
         * being responded to.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/*
/*
 * ADDIP Section 4.3 General rules for address manipulation
 * ADDIP Section 4.3 General rules for address manipulation
 * When building TLV parameters for the ASCONF Chunk that will add or
 * When building TLV parameters for the ASCONF Chunk that will add or
 * delete IP addresses the D0 to D13 rules should be applied:
 * delete IP addresses the D0 to D13 rules should be applied:
 */
 */
sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
                                         const struct sctp_association *asoc,
                                         const struct sctp_association *asoc,
                                         const sctp_subtype_t type, void *arg,
                                         const sctp_subtype_t type, void *arg,
                                         sctp_cmd_seq_t *commands)
                                         sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk       *asconf_ack = arg;
        struct sctp_chunk       *asconf_ack = arg;
        struct sctp_chunk       *last_asconf = asoc->addip_last_asconf;
        struct sctp_chunk       *last_asconf = asoc->addip_last_asconf;
        struct sctp_chunk       *abort;
        struct sctp_chunk       *abort;
        sctp_addiphdr_t         *addip_hdr;
        sctp_addiphdr_t         *addip_hdr;
        __u32                   sent_serial, rcvd_serial;
        __u32                   sent_serial, rcvd_serial;
 
 
        addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
        addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
        rcvd_serial = ntohl(addip_hdr->serial);
        rcvd_serial = ntohl(addip_hdr->serial);
 
 
        if (last_asconf) {
        if (last_asconf) {
                addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
                addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
                sent_serial = ntohl(addip_hdr->serial);
                sent_serial = ntohl(addip_hdr->serial);
        } else {
        } else {
                sent_serial = asoc->addip_serial - 1;
                sent_serial = asoc->addip_serial - 1;
        }
        }
 
 
        /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
        /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
         * equal to the next serial number to be used but no ASCONF chunk is
         * equal to the next serial number to be used but no ASCONF chunk is
         * outstanding the endpoint MUST ABORT the association. Note that a
         * outstanding the endpoint MUST ABORT the association. Note that a
         * sequence number is greater than if it is no more than 2^^31-1
         * sequence number is greater than if it is no more than 2^^31-1
         * larger than the current sequence number (using serial arithmetic).
         * larger than the current sequence number (using serial arithmetic).
         */
         */
        if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
        if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
            !(asoc->addip_last_asconf)) {
            !(asoc->addip_last_asconf)) {
                abort = sctp_make_abort(asoc, asconf_ack,
                abort = sctp_make_abort(asoc, asconf_ack,
                                        sizeof(sctp_errhdr_t));
                                        sizeof(sctp_errhdr_t));
                if (abort) {
                if (abort) {
                        sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, NULL, 0);
                        sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, NULL, 0);
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                                        SCTP_CHUNK(abort));
                                        SCTP_CHUNK(abort));
                }
                }
                /* We are going to ABORT, so we might as well stop
                /* We are going to ABORT, so we might as well stop
                 * processing the rest of the chunks in the packet.
                 * processing the rest of the chunks in the packet.
                 */
                 */
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                                SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
                                SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
                sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
                sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                                SCTP_U32(SCTP_ERROR_ASCONF_ACK));
                                SCTP_U32(SCTP_ERROR_ASCONF_ACK));
                SCTP_INC_STATS(SctpAborteds);
                SCTP_INC_STATS(SctpAborteds);
                SCTP_DEC_STATS(SctpCurrEstab);
                SCTP_DEC_STATS(SctpCurrEstab);
                return SCTP_DISPOSITION_ABORT;
                return SCTP_DISPOSITION_ABORT;
        }
        }
 
 
        if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
        if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                                SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
                                SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
 
 
                if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
                if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
                                             asconf_ack))
                                             asconf_ack))
                        return SCTP_DISPOSITION_CONSUME;
                        return SCTP_DISPOSITION_CONSUME;
 
 
                abort = sctp_make_abort(asoc, asconf_ack,
                abort = sctp_make_abort(asoc, asconf_ack,
                                        sizeof(sctp_errhdr_t));
                                        sizeof(sctp_errhdr_t));
                if (abort) {
                if (abort) {
                        sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, NULL, 0);
                        sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, NULL, 0);
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                                        SCTP_CHUNK(abort));
                                        SCTP_CHUNK(abort));
                }
                }
                /* We are going to ABORT, so we might as well stop
                /* We are going to ABORT, so we might as well stop
                 * processing the rest of the chunks in the packet.
                 * processing the rest of the chunks in the packet.
                 */
                 */
                sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
                sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                                SCTP_U32(SCTP_ERROR_ASCONF_ACK));
                                SCTP_U32(SCTP_ERROR_ASCONF_ACK));
                SCTP_INC_STATS(SctpAborteds);
                SCTP_INC_STATS(SctpAborteds);
                SCTP_DEC_STATS(SctpCurrEstab);
                SCTP_DEC_STATS(SctpCurrEstab);
                return SCTP_DISPOSITION_ABORT;
                return SCTP_DISPOSITION_ABORT;
        }
        }
 
 
        return SCTP_DISPOSITION_DISCARD;
        return SCTP_DISPOSITION_DISCARD;
}
}
 
 
/*
/*
 * Process an unknown chunk.
 * Process an unknown chunk.
 *
 *
 * Section: 3.2. Also, 2.1 in the implementor's guide.
 * Section: 3.2. Also, 2.1 in the implementor's guide.
 *
 *
 * Chunk Types are encoded such that the highest-order two bits specify
 * Chunk Types are encoded such that the highest-order two bits specify
 * the action that must be taken if the processing endpoint does not
 * the action that must be taken if the processing endpoint does not
 * recognize the Chunk Type.
 * recognize the Chunk Type.
 *
 *
 * 00 - Stop processing this SCTP packet and discard it, do not process
 * 00 - Stop processing this SCTP packet and discard it, do not process
 *      any further chunks within it.
 *      any further chunks within it.
 *
 *
 * 01 - Stop processing this SCTP packet and discard it, do not process
 * 01 - Stop processing this SCTP packet and discard it, do not process
 *      any further chunks within it, and report the unrecognized
 *      any further chunks within it, and report the unrecognized
 *      chunk in an 'Unrecognized Chunk Type'.
 *      chunk in an 'Unrecognized Chunk Type'.
 *
 *
 * 10 - Skip this chunk and continue processing.
 * 10 - Skip this chunk and continue processing.
 *
 *
 * 11 - Skip this chunk and continue processing, but report in an ERROR
 * 11 - Skip this chunk and continue processing, but report in an ERROR
 *      Chunk using the 'Unrecognized Chunk Type' cause of error.
 *      Chunk using the 'Unrecognized Chunk Type' cause of error.
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
                                     const struct sctp_association *asoc,
                                     const struct sctp_association *asoc,
                                     const sctp_subtype_t type,
                                     const sctp_subtype_t type,
                                     void *arg,
                                     void *arg,
                                     sctp_cmd_seq_t *commands)
                                     sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *unk_chunk = arg;
        struct sctp_chunk *unk_chunk = arg;
        struct sctp_chunk *err_chunk;
        struct sctp_chunk *err_chunk;
        sctp_chunkhdr_t *hdr;
        sctp_chunkhdr_t *hdr;
 
 
        SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
        SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
 
 
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
        /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
         * that the value in the Verification Tag field of the
         * that the value in the Verification Tag field of the
         * received SCTP packet matches its own Tag.  If the received
         * received SCTP packet matches its own Tag.  If the received
         * Verification Tag value does not match the receiver's own
         * Verification Tag value does not match the receiver's own
         * tag value, the receiver shall silently discard the packet.
         * tag value, the receiver shall silently discard the packet.
         */
         */
        if (ntohl(unk_chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
        if (ntohl(unk_chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
        switch (type.chunk & SCTP_CID_ACTION_MASK) {
        switch (type.chunk & SCTP_CID_ACTION_MASK) {
        case SCTP_CID_ACTION_DISCARD:
        case SCTP_CID_ACTION_DISCARD:
                /* Discard the packet.  */
                /* Discard the packet.  */
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                break;
                break;
        case SCTP_CID_ACTION_DISCARD_ERR:
        case SCTP_CID_ACTION_DISCARD_ERR:
                /* Discard the packet.  */
                /* Discard the packet.  */
                sctp_sf_pdiscard(ep, asoc, type, arg, commands);
                sctp_sf_pdiscard(ep, asoc, type, arg, commands);
 
 
                /* Generate an ERROR chunk as response. */
                /* Generate an ERROR chunk as response. */
                hdr = unk_chunk->chunk_hdr;
                hdr = unk_chunk->chunk_hdr;
                err_chunk = sctp_make_op_error(asoc, unk_chunk,
                err_chunk = sctp_make_op_error(asoc, unk_chunk,
                                               SCTP_ERROR_UNKNOWN_CHUNK, hdr,
                                               SCTP_ERROR_UNKNOWN_CHUNK, hdr,
                                               WORD_ROUND(ntohs(hdr->length)));
                                               WORD_ROUND(ntohs(hdr->length)));
                if (err_chunk) {
                if (err_chunk) {
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                                        SCTP_CHUNK(err_chunk));
                                        SCTP_CHUNK(err_chunk));
                }
                }
                return SCTP_DISPOSITION_CONSUME;
                return SCTP_DISPOSITION_CONSUME;
                break;
                break;
        case SCTP_CID_ACTION_SKIP:
        case SCTP_CID_ACTION_SKIP:
                /* Skip the chunk.  */
                /* Skip the chunk.  */
                return SCTP_DISPOSITION_DISCARD;
                return SCTP_DISPOSITION_DISCARD;
                break;
                break;
        case SCTP_CID_ACTION_SKIP_ERR:
        case SCTP_CID_ACTION_SKIP_ERR:
                /* Generate an ERROR chunk as response. */
                /* Generate an ERROR chunk as response. */
                hdr = unk_chunk->chunk_hdr;
                hdr = unk_chunk->chunk_hdr;
                err_chunk = sctp_make_op_error(asoc, unk_chunk,
                err_chunk = sctp_make_op_error(asoc, unk_chunk,
                                               SCTP_ERROR_UNKNOWN_CHUNK, hdr,
                                               SCTP_ERROR_UNKNOWN_CHUNK, hdr,
                                               WORD_ROUND(ntohs(hdr->length)));
                                               WORD_ROUND(ntohs(hdr->length)));
                if (err_chunk) {
                if (err_chunk) {
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                                        SCTP_CHUNK(err_chunk));
                                        SCTP_CHUNK(err_chunk));
                }
                }
                /* Skip the chunk.  */
                /* Skip the chunk.  */
                return SCTP_DISPOSITION_CONSUME;
                return SCTP_DISPOSITION_CONSUME;
                break;
                break;
        default:
        default:
                break;
                break;
        }
        }
 
 
        return SCTP_DISPOSITION_DISCARD;
        return SCTP_DISPOSITION_DISCARD;
}
}
 
 
/*
/*
 * Discard the chunk.
 * Discard the chunk.
 *
 *
 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
 * [Too numerous to mention...]
 * [Too numerous to mention...]
 * Verification Tag: No verification needed.
 * Verification Tag: No verification needed.
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
                                         const struct sctp_association *asoc,
                                         const struct sctp_association *asoc,
                                         const sctp_subtype_t type,
                                         const sctp_subtype_t type,
                                         void *arg,
                                         void *arg,
                                         sctp_cmd_seq_t *commands)
                                         sctp_cmd_seq_t *commands)
{
{
        SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
        SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
        return SCTP_DISPOSITION_DISCARD;
        return SCTP_DISPOSITION_DISCARD;
}
}
 
 
/*
/*
 * Discard the whole packet.
 * Discard the whole packet.
 *
 *
 * Section: 8.4 2)
 * Section: 8.4 2)
 *
 *
 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
 *    silently discard the OOTB packet and take no further action.
 *    silently discard the OOTB packet and take no further action.
 *    Otherwise,
 *    Otherwise,
 *
 *
 * Verification Tag: No verification necessary
 * Verification Tag: No verification necessary
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
                                    const struct sctp_association *asoc,
                                    const struct sctp_association *asoc,
                                    const sctp_subtype_t type,
                                    const sctp_subtype_t type,
                                    void *arg,
                                    void *arg,
                                    sctp_cmd_seq_t *commands)
                                    sctp_cmd_seq_t *commands)
{
{
        sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
 
 
/*
/*
 * The other end is violating protocol.
 * The other end is violating protocol.
 *
 *
 * Section: Not specified
 * Section: Not specified
 * Verification Tag: Not specified
 * Verification Tag: Not specified
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * Outputs
 * Outputs
 * (asoc, reply_msg, msg_up, timers, counters)
 * (asoc, reply_msg, msg_up, timers, counters)
 *
 *
 * We simply tag the chunk as a violation.  The state machine will log
 * We simply tag the chunk as a violation.  The state machine will log
 * the violation and continue.
 * the violation and continue.
 */
 */
sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
                                     const struct sctp_association *asoc,
                                     const struct sctp_association *asoc,
                                     const sctp_subtype_t type,
                                     const sctp_subtype_t type,
                                     void *arg,
                                     void *arg,
                                     sctp_cmd_seq_t *commands)
                                     sctp_cmd_seq_t *commands)
{
{
        return SCTP_DISPOSITION_VIOLATION;
        return SCTP_DISPOSITION_VIOLATION;
}
}
 
 
/***************************************************************************
/***************************************************************************
 * These are the state functions for handling primitive (Section 10) events.
 * These are the state functions for handling primitive (Section 10) events.
 ***************************************************************************/
 ***************************************************************************/
/*
/*
 * sctp_sf_do_prm_asoc
 * sctp_sf_do_prm_asoc
 *
 *
 * Section: 10.1 ULP-to-SCTP
 * Section: 10.1 ULP-to-SCTP
 * B) Associate
 * B) Associate
 *
 *
 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
 * outbound stream count)
 * outbound stream count)
 * -> association id [,destination transport addr list] [,outbound stream
 * -> association id [,destination transport addr list] [,outbound stream
 * count]
 * count]
 *
 *
 * This primitive allows the upper layer to initiate an association to a
 * This primitive allows the upper layer to initiate an association to a
 * specific peer endpoint.
 * specific peer endpoint.
 *
 *
 * The peer endpoint shall be specified by one of the transport addresses
 * The peer endpoint shall be specified by one of the transport addresses
 * which defines the endpoint (see Section 1.4).  If the local SCTP
 * which defines the endpoint (see Section 1.4).  If the local SCTP
 * instance has not been initialized, the ASSOCIATE is considered an
 * instance has not been initialized, the ASSOCIATE is considered an
 * error.
 * error.
 * [This is not relevant for the kernel implementation since we do all
 * [This is not relevant for the kernel implementation since we do all
 * initialization at boot time.  It we hadn't initialized we wouldn't
 * initialization at boot time.  It we hadn't initialized we wouldn't
 * get anywhere near this code.]
 * get anywhere near this code.]
 *
 *
 * An association id, which is a local handle to the SCTP association,
 * An association id, which is a local handle to the SCTP association,
 * will be returned on successful establishment of the association. If
 * will be returned on successful establishment of the association. If
 * SCTP is not able to open an SCTP association with the peer endpoint,
 * SCTP is not able to open an SCTP association with the peer endpoint,
 * an error is returned.
 * an error is returned.
 * [In the kernel implementation, the struct sctp_association needs to
 * [In the kernel implementation, the struct sctp_association needs to
 * be created BEFORE causing this primitive to run.]
 * be created BEFORE causing this primitive to run.]
 *
 *
 * Other association parameters may be returned, including the
 * Other association parameters may be returned, including the
 * complete destination transport addresses of the peer as well as the
 * complete destination transport addresses of the peer as well as the
 * outbound stream count of the local endpoint. One of the transport
 * outbound stream count of the local endpoint. One of the transport
 * address from the returned destination addresses will be selected by
 * address from the returned destination addresses will be selected by
 * the local endpoint as default primary path for sending SCTP packets
 * the local endpoint as default primary path for sending SCTP packets
 * to this peer.  The returned "destination transport addr list" can
 * to this peer.  The returned "destination transport addr list" can
 * be used by the ULP to change the default primary path or to force
 * be used by the ULP to change the default primary path or to force
 * sending a packet to a specific transport address.  [All of this
 * sending a packet to a specific transport address.  [All of this
 * stuff happens when the INIT ACK arrives.  This is a NON-BLOCKING
 * stuff happens when the INIT ACK arrives.  This is a NON-BLOCKING
 * function.]
 * function.]
 *
 *
 * Mandatory attributes:
 * Mandatory attributes:
 *
 *
 * o local SCTP instance name - obtained from the INITIALIZE operation.
 * o local SCTP instance name - obtained from the INITIALIZE operation.
 *   [This is the argument asoc.]
 *   [This is the argument asoc.]
 * o destination transport addr - specified as one of the transport
 * o destination transport addr - specified as one of the transport
 * addresses of the peer endpoint with which the association is to be
 * addresses of the peer endpoint with which the association is to be
 * established.
 * established.
 *  [This is asoc->peer.active_path.]
 *  [This is asoc->peer.active_path.]
 * o outbound stream count - the number of outbound streams the ULP
 * o outbound stream count - the number of outbound streams the ULP
 * would like to open towards this peer endpoint.
 * would like to open towards this peer endpoint.
 * [BUG: This is not currently implemented.]
 * [BUG: This is not currently implemented.]
 * Optional attributes:
 * Optional attributes:
 *
 *
 * None.
 * None.
 *
 *
 * The return value is a disposition.
 * The return value is a disposition.
 */
 */
sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
                                       const struct sctp_association *asoc,
                                       const struct sctp_association *asoc,
                                       const sctp_subtype_t type,
                                       const sctp_subtype_t type,
                                       void *arg,
                                       void *arg,
                                       sctp_cmd_seq_t *commands)
                                       sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *repl;
        struct sctp_chunk *repl;
 
 
        /* The comment below says that we enter COOKIE-WAIT AFTER
        /* The comment below says that we enter COOKIE-WAIT AFTER
         * sending the INIT, but that doesn't actually work in our
         * sending the INIT, but that doesn't actually work in our
         * implementation...
         * implementation...
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
                        SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
 
 
        /* RFC 2960 5.1 Normal Establishment of an Association
        /* RFC 2960 5.1 Normal Establishment of an Association
         *
         *
         * A) "A" first sends an INIT chunk to "Z".  In the INIT, "A"
         * A) "A" first sends an INIT chunk to "Z".  In the INIT, "A"
         * must provide its Verification Tag (Tag_A) in the Initiate
         * must provide its Verification Tag (Tag_A) in the Initiate
         * Tag field.  Tag_A SHOULD be a random number in the range of
         * Tag field.  Tag_A SHOULD be a random number in the range of
         * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
         * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
         */
         */
 
 
        repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
        repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
        if (!repl)
        if (!repl)
                goto nomem;
                goto nomem;
 
 
        /* Cast away the const modifier, as we want to just
        /* Cast away the const modifier, as we want to just
         * rerun it through as a sideffect.
         * rerun it through as a sideffect.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
                        SCTP_ASOC((struct sctp_association *) asoc));
                        SCTP_ASOC((struct sctp_association *) asoc));
 
 
        /* After sending the INIT, "A" starts the T1-init timer and
        /* After sending the INIT, "A" starts the T1-init timer and
         * enters the COOKIE-WAIT state.
         * enters the COOKIE-WAIT state.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Process the SEND primitive.
 * Process the SEND primitive.
 *
 *
 * Section: 10.1 ULP-to-SCTP
 * Section: 10.1 ULP-to-SCTP
 * E) Send
 * E) Send
 *
 *
 * Format: SEND(association id, buffer address, byte count [,context]
 * Format: SEND(association id, buffer address, byte count [,context]
 *         [,stream id] [,life time] [,destination transport address]
 *         [,stream id] [,life time] [,destination transport address]
 *         [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
 *         [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
 * -> result
 * -> result
 *
 *
 * This is the main method to send user data via SCTP.
 * This is the main method to send user data via SCTP.
 *
 *
 * Mandatory attributes:
 * Mandatory attributes:
 *
 *
 *  o association id - local handle to the SCTP association
 *  o association id - local handle to the SCTP association
 *
 *
 *  o buffer address - the location where the user message to be
 *  o buffer address - the location where the user message to be
 *    transmitted is stored;
 *    transmitted is stored;
 *
 *
 *  o byte count - The size of the user data in number of bytes;
 *  o byte count - The size of the user data in number of bytes;
 *
 *
 * Optional attributes:
 * Optional attributes:
 *
 *
 *  o context - an optional 32 bit integer that will be carried in the
 *  o context - an optional 32 bit integer that will be carried in the
 *    sending failure notification to the ULP if the transportation of
 *    sending failure notification to the ULP if the transportation of
 *    this User Message fails.
 *    this User Message fails.
 *
 *
 *  o stream id - to indicate which stream to send the data on. If not
 *  o stream id - to indicate which stream to send the data on. If not
 *    specified, stream 0 will be used.
 *    specified, stream 0 will be used.
 *
 *
 *  o life time - specifies the life time of the user data. The user data
 *  o life time - specifies the life time of the user data. The user data
 *    will not be sent by SCTP after the life time expires. This
 *    will not be sent by SCTP after the life time expires. This
 *    parameter can be used to avoid efforts to transmit stale
 *    parameter can be used to avoid efforts to transmit stale
 *    user messages. SCTP notifies the ULP if the data cannot be
 *    user messages. SCTP notifies the ULP if the data cannot be
 *    initiated to transport (i.e. sent to the destination via SCTP's
 *    initiated to transport (i.e. sent to the destination via SCTP's
 *    send primitive) within the life time variable. However, the
 *    send primitive) within the life time variable. However, the
 *    user data will be transmitted if SCTP has attempted to transmit a
 *    user data will be transmitted if SCTP has attempted to transmit a
 *    chunk before the life time expired.
 *    chunk before the life time expired.
 *
 *
 *  o destination transport address - specified as one of the destination
 *  o destination transport address - specified as one of the destination
 *    transport addresses of the peer endpoint to which this packet
 *    transport addresses of the peer endpoint to which this packet
 *    should be sent. Whenever possible, SCTP should use this destination
 *    should be sent. Whenever possible, SCTP should use this destination
 *    transport address for sending the packets, instead of the current
 *    transport address for sending the packets, instead of the current
 *    primary path.
 *    primary path.
 *
 *
 *  o unorder flag - this flag, if present, indicates that the user
 *  o unorder flag - this flag, if present, indicates that the user
 *    would like the data delivered in an unordered fashion to the peer
 *    would like the data delivered in an unordered fashion to the peer
 *    (i.e., the U flag is set to 1 on all DATA chunks carrying this
 *    (i.e., the U flag is set to 1 on all DATA chunks carrying this
 *    message).
 *    message).
 *
 *
 *  o no-bundle flag - instructs SCTP not to bundle this user data with
 *  o no-bundle flag - instructs SCTP not to bundle this user data with
 *    other outbound DATA chunks. SCTP MAY still bundle even when
 *    other outbound DATA chunks. SCTP MAY still bundle even when
 *    this flag is present, when faced with network congestion.
 *    this flag is present, when faced with network congestion.
 *
 *
 *  o payload protocol-id - A 32 bit unsigned integer that is to be
 *  o payload protocol-id - A 32 bit unsigned integer that is to be
 *    passed to the peer indicating the type of payload protocol data
 *    passed to the peer indicating the type of payload protocol data
 *    being transmitted. This value is passed as opaque data by SCTP.
 *    being transmitted. This value is passed as opaque data by SCTP.
 *
 *
 * The return value is the disposition.
 * The return value is the disposition.
 */
 */
sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
                                       const struct sctp_association *asoc,
                                       const struct sctp_association *asoc,
                                       const sctp_subtype_t type,
                                       const sctp_subtype_t type,
                                       void *arg,
                                       void *arg,
                                       sctp_cmd_seq_t *commands)
                                       sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/*
/*
 * Process the SHUTDOWN primitive.
 * Process the SHUTDOWN primitive.
 *
 *
 * Section: 10.1:
 * Section: 10.1:
 * C) Shutdown
 * C) Shutdown
 *
 *
 * Format: SHUTDOWN(association id)
 * Format: SHUTDOWN(association id)
 * -> result
 * -> result
 *
 *
 * Gracefully closes an association. Any locally queued user data
 * Gracefully closes an association. Any locally queued user data
 * will be delivered to the peer. The association will be terminated only
 * will be delivered to the peer. The association will be terminated only
 * after the peer acknowledges all the SCTP packets sent.  A success code
 * after the peer acknowledges all the SCTP packets sent.  A success code
 * will be returned on successful termination of the association. If
 * will be returned on successful termination of the association. If
 * attempting to terminate the association results in a failure, an error
 * attempting to terminate the association results in a failure, an error
 * code shall be returned.
 * code shall be returned.
 *
 *
 * Mandatory attributes:
 * Mandatory attributes:
 *
 *
 *  o association id - local handle to the SCTP association
 *  o association id - local handle to the SCTP association
 *
 *
 * Optional attributes:
 * Optional attributes:
 *
 *
 * None.
 * None.
 *
 *
 * The return value is the disposition.
 * The return value is the disposition.
 */
 */
sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(
sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        int disposition;
        int disposition;
 
 
        /* From 9.2 Shutdown of an Association
        /* From 9.2 Shutdown of an Association
         * Upon receipt of the SHUTDOWN primitive from its upper
         * Upon receipt of the SHUTDOWN primitive from its upper
         * layer, the endpoint enters SHUTDOWN-PENDING state and
         * layer, the endpoint enters SHUTDOWN-PENDING state and
         * remains there until all outstanding data has been
         * remains there until all outstanding data has been
         * acknowledged by its peer. The endpoint accepts no new data
         * acknowledged by its peer. The endpoint accepts no new data
         * from its upper layer, but retransmits data to the far end
         * from its upper layer, but retransmits data to the far end
         * if necessary to fill gaps.
         * if necessary to fill gaps.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
                        SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
 
 
        /* sctpimpguide-05 Section 2.12.2
        /* sctpimpguide-05 Section 2.12.2
         * The sender of the SHUTDOWN MAY also start an overall guard timer
         * The sender of the SHUTDOWN MAY also start an overall guard timer
         * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
         * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
 
 
        disposition = SCTP_DISPOSITION_CONSUME;
        disposition = SCTP_DISPOSITION_CONSUME;
        if (sctp_outq_is_empty(&asoc->outqueue)) {
        if (sctp_outq_is_empty(&asoc->outqueue)) {
                disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
                disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
                                                            arg, commands);
                                                            arg, commands);
        }
        }
        return disposition;
        return disposition;
}
}
 
 
/*
/*
 * Process the ABORT primitive.
 * Process the ABORT primitive.
 *
 *
 * Section: 10.1:
 * Section: 10.1:
 * C) Abort
 * C) Abort
 *
 *
 * Format: Abort(association id [, cause code])
 * Format: Abort(association id [, cause code])
 * -> result
 * -> result
 *
 *
 * Ungracefully closes an association. Any locally queued user data
 * Ungracefully closes an association. Any locally queued user data
 * will be discarded and an ABORT chunk is sent to the peer.  A success code
 * will be discarded and an ABORT chunk is sent to the peer.  A success code
 * will be returned on successful abortion of the association. If
 * will be returned on successful abortion of the association. If
 * attempting to abort the association results in a failure, an error
 * attempting to abort the association results in a failure, an error
 * code shall be returned.
 * code shall be returned.
 *
 *
 * Mandatory attributes:
 * Mandatory attributes:
 *
 *
 *  o association id - local handle to the SCTP association
 *  o association id - local handle to the SCTP association
 *
 *
 * Optional attributes:
 * Optional attributes:
 *
 *
 *  o cause code - reason of the abort to be passed to the peer
 *  o cause code - reason of the abort to be passed to the peer
 *
 *
 * None.
 * None.
 *
 *
 * The return value is the disposition.
 * The return value is the disposition.
 */
 */
sctp_disposition_t sctp_sf_do_9_1_prm_abort(
sctp_disposition_t sctp_sf_do_9_1_prm_abort(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        /* From 9.1 Abort of an Association
        /* From 9.1 Abort of an Association
         * Upon receipt of the ABORT primitive from its upper
         * Upon receipt of the ABORT primitive from its upper
         * layer, the endpoint enters CLOSED state and
         * layer, the endpoint enters CLOSED state and
         * discard all outstanding data has been
         * discard all outstanding data has been
         * acknowledged by its peer. The endpoint accepts no new data
         * acknowledged by its peer. The endpoint accepts no new data
         * from its upper layer, but retransmits data to the far end
         * from its upper layer, but retransmits data to the far end
         * if necessary to fill gaps.
         * if necessary to fill gaps.
         */
         */
        struct msghdr *msg = arg;
        struct msghdr *msg = arg;
        struct sctp_chunk *abort;
        struct sctp_chunk *abort;
        sctp_disposition_t retval;
        sctp_disposition_t retval;
 
 
        retval = SCTP_DISPOSITION_CONSUME;
        retval = SCTP_DISPOSITION_CONSUME;
 
 
        /* Generate ABORT chunk to send the peer.  */
        /* Generate ABORT chunk to send the peer.  */
        abort = sctp_make_abort_user(asoc, NULL, msg);
        abort = sctp_make_abort_user(asoc, NULL, msg);
        if (!abort)
        if (!abort)
                retval = SCTP_DISPOSITION_NOMEM;
                retval = SCTP_DISPOSITION_NOMEM;
        else
        else
                sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
                sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
 
 
        /* Even if we can't send the ABORT due to low memory delete the
        /* Even if we can't send the ABORT due to low memory delete the
         * TCB.  This is a departure from our typical NOMEM handling.
         * TCB.  This is a departure from our typical NOMEM handling.
         */
         */
 
 
        /* Delete the established association. */
        /* Delete the established association. */
        sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
        sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                        SCTP_U32(SCTP_ERROR_USER_ABORT));
                        SCTP_U32(SCTP_ERROR_USER_ABORT));
 
 
        SCTP_INC_STATS(SctpAborteds);
        SCTP_INC_STATS(SctpAborteds);
        SCTP_DEC_STATS(SctpCurrEstab);
        SCTP_DEC_STATS(SctpCurrEstab);
 
 
        return retval;
        return retval;
}
}
 
 
/* We tried an illegal operation on an association which is closed.  */
/* We tried an illegal operation on an association which is closed.  */
sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/* We tried an illegal operation on an association which is shutting
/* We tried an illegal operation on an association which is shutting
 * down.
 * down.
 */
 */
sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep,
                                          const struct sctp_association *asoc,
                                          const struct sctp_association *asoc,
                                          const sctp_subtype_t type,
                                          const sctp_subtype_t type,
                                          void *arg,
                                          void *arg,
                                          sctp_cmd_seq_t *commands)
                                          sctp_cmd_seq_t *commands)
{
{
        sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
        sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
                        SCTP_ERROR(-ESHUTDOWN));
                        SCTP_ERROR(-ESHUTDOWN));
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/*
/*
 * sctp_cookie_wait_prm_shutdown
 * sctp_cookie_wait_prm_shutdown
 *
 *
 * Section: 4 Note: 2
 * Section: 4 Note: 2
 * Verification Tag:
 * Verification Tag:
 * Inputs
 * Inputs
 * (endpoint, asoc)
 * (endpoint, asoc)
 *
 *
 * The RFC does not explicitly address this issue, but is the route through the
 * The RFC does not explicitly address this issue, but is the route through the
 * state table when someone issues a shutdown while in COOKIE_WAIT state.
 * state table when someone issues a shutdown while in COOKIE_WAIT state.
 *
 *
 * Outputs
 * Outputs
 * (timers)
 * (timers)
 */
 */
sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_CLOSED));
                        SCTP_STATE(SCTP_STATE_CLOSED));
 
 
        SCTP_INC_STATS(SctpShutdowns);
        SCTP_INC_STATS(SctpShutdowns);
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
 
 
        return SCTP_DISPOSITION_DELETE_TCB;
        return SCTP_DISPOSITION_DELETE_TCB;
}
}
 
 
/*
/*
 * sctp_cookie_echoed_prm_shutdown
 * sctp_cookie_echoed_prm_shutdown
 *
 *
 * Section: 4 Note: 2
 * Section: 4 Note: 2
 * Verification Tag:
 * Verification Tag:
 * Inputs
 * Inputs
 * (endpoint, asoc)
 * (endpoint, asoc)
 *
 *
 * The RFC does not explcitly address this issue, but is the route through the
 * The RFC does not explcitly address this issue, but is the route through the
 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
 *
 *
 * Outputs
 * Outputs
 * (timers)
 * (timers)
 */
 */
sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg, sctp_cmd_seq_t *commands)
        void *arg, sctp_cmd_seq_t *commands)
{
{
        /* There is a single T1 timer, so we should be able to use
        /* There is a single T1 timer, so we should be able to use
         * common function with the COOKIE-WAIT state.
         * common function with the COOKIE-WAIT state.
         */
         */
        return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
        return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
}
}
 
 
/*
/*
 * sctp_sf_cookie_wait_prm_abort
 * sctp_sf_cookie_wait_prm_abort
 *
 *
 * Section: 4 Note: 2
 * Section: 4 Note: 2
 * Verification Tag:
 * Verification Tag:
 * Inputs
 * Inputs
 * (endpoint, asoc)
 * (endpoint, asoc)
 *
 *
 * The RFC does not explicitly address this issue, but is the route through the
 * The RFC does not explicitly address this issue, but is the route through the
 * state table when someone issues an abort while in COOKIE_WAIT state.
 * state table when someone issues an abort while in COOKIE_WAIT state.
 *
 *
 * Outputs
 * Outputs
 * (timers)
 * (timers)
 */
 */
sctp_disposition_t sctp_sf_cookie_wait_prm_abort(
sctp_disposition_t sctp_sf_cookie_wait_prm_abort(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        struct msghdr *msg = arg;
        struct msghdr *msg = arg;
        struct sctp_chunk *abort;
        struct sctp_chunk *abort;
        sctp_disposition_t retval;
        sctp_disposition_t retval;
 
 
        /* Stop T1-init timer */
        /* Stop T1-init timer */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
        retval = SCTP_DISPOSITION_CONSUME;
        retval = SCTP_DISPOSITION_CONSUME;
 
 
        /* Generate ABORT chunk to send the peer */
        /* Generate ABORT chunk to send the peer */
        abort = sctp_make_abort_user(asoc, NULL, msg);
        abort = sctp_make_abort_user(asoc, NULL, msg);
        if (!abort)
        if (!abort)
                retval = SCTP_DISPOSITION_NOMEM;
                retval = SCTP_DISPOSITION_NOMEM;
        else
        else
                sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
                sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_CLOSED));
                        SCTP_STATE(SCTP_STATE_CLOSED));
 
 
        SCTP_INC_STATS(SctpAborteds);
        SCTP_INC_STATS(SctpAborteds);
 
 
        /* Even if we can't send the ABORT due to low memory delete the
        /* Even if we can't send the ABORT due to low memory delete the
         * TCB.  This is a departure from our typical NOMEM handling.
         * TCB.  This is a departure from our typical NOMEM handling.
         */
         */
 
 
        /* Delete the established association. */
        /* Delete the established association. */
        sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
        sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
                        SCTP_U32(SCTP_ERROR_USER_ABORT));
                        SCTP_U32(SCTP_ERROR_USER_ABORT));
 
 
        return retval;
        return retval;
}
}
 
 
/*
/*
 * sctp_sf_cookie_echoed_prm_abort
 * sctp_sf_cookie_echoed_prm_abort
 *
 *
 * Section: 4 Note: 3
 * Section: 4 Note: 3
 * Verification Tag:
 * Verification Tag:
 * Inputs
 * Inputs
 * (endpoint, asoc)
 * (endpoint, asoc)
 *
 *
 * The RFC does not explcitly address this issue, but is the route through the
 * The RFC does not explcitly address this issue, but is the route through the
 * state table when someone issues an abort while in COOKIE_ECHOED state.
 * state table when someone issues an abort while in COOKIE_ECHOED state.
 *
 *
 * Outputs
 * Outputs
 * (timers)
 * (timers)
 */
 */
sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(
sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        /* There is a single T1 timer, so we should be able to use
        /* There is a single T1 timer, so we should be able to use
         * common function with the COOKIE-WAIT state.
         * common function with the COOKIE-WAIT state.
         */
         */
        return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
        return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
}
}
 
 
/*
/*
 * sctp_sf_shutdown_pending_prm_abort
 * sctp_sf_shutdown_pending_prm_abort
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc)
 * (endpoint, asoc)
 *
 *
 * The RFC does not explicitly address this issue, but is the route through the
 * The RFC does not explicitly address this issue, but is the route through the
 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
 *
 *
 * Outputs
 * Outputs
 * (timers)
 * (timers)
 */
 */
sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        /* Stop the T5-shutdown guard timer.  */
        /* Stop the T5-shutdown guard timer.  */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
 
 
        return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
        return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
}
}
 
 
/*
/*
 * sctp_sf_shutdown_sent_prm_abort
 * sctp_sf_shutdown_sent_prm_abort
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc)
 * (endpoint, asoc)
 *
 *
 * The RFC does not explicitly address this issue, but is the route through the
 * The RFC does not explicitly address this issue, but is the route through the
 * state table when someone issues an abort while in SHUTDOWN-SENT state.
 * state table when someone issues an abort while in SHUTDOWN-SENT state.
 *
 *
 * Outputs
 * Outputs
 * (timers)
 * (timers)
 */
 */
sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        /* Stop the T2-shutdown timer.  */
        /* Stop the T2-shutdown timer.  */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
 
 
        /* Stop the T5-shutdown guard timer.  */
        /* Stop the T5-shutdown guard timer.  */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
 
 
        return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
        return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
}
}
 
 
/*
/*
 * sctp_sf_cookie_echoed_prm_abort
 * sctp_sf_cookie_echoed_prm_abort
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc)
 * (endpoint, asoc)
 *
 *
 * The RFC does not explcitly address this issue, but is the route through the
 * The RFC does not explcitly address this issue, but is the route through the
 * state table when someone issues an abort while in COOKIE_ECHOED state.
 * state table when someone issues an abort while in COOKIE_ECHOED state.
 *
 *
 * Outputs
 * Outputs
 * (timers)
 * (timers)
 */
 */
sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        /* The same T2 timer, so we should be able to use
        /* The same T2 timer, so we should be able to use
         * common function with the SHUTDOWN-SENT state.
         * common function with the SHUTDOWN-SENT state.
         */
         */
        return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
        return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
}
}
 
 
/*
/*
 * Process the REQUESTHEARTBEAT primitive
 * Process the REQUESTHEARTBEAT primitive
 *
 *
 * 10.1 ULP-to-SCTP
 * 10.1 ULP-to-SCTP
 * J) Request Heartbeat
 * J) Request Heartbeat
 *
 *
 * Format: REQUESTHEARTBEAT(association id, destination transport address)
 * Format: REQUESTHEARTBEAT(association id, destination transport address)
 *
 *
 * -> result
 * -> result
 *
 *
 * Instructs the local endpoint to perform a HeartBeat on the specified
 * Instructs the local endpoint to perform a HeartBeat on the specified
 * destination transport address of the given association. The returned
 * destination transport address of the given association. The returned
 * result should indicate whether the transmission of the HEARTBEAT
 * result should indicate whether the transmission of the HEARTBEAT
 * chunk to the destination address is successful.
 * chunk to the destination address is successful.
 *
 *
 * Mandatory attributes:
 * Mandatory attributes:
 *
 *
 * o association id - local handle to the SCTP association
 * o association id - local handle to the SCTP association
 *
 *
 * o destination transport address - the transport address of the
 * o destination transport address - the transport address of the
 *   association on which a heartbeat should be issued.
 *   association on which a heartbeat should be issued.
 */
 */
sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
                                        const struct sctp_endpoint *ep,
                                        const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        return sctp_sf_heartbeat(ep, asoc, type, (struct sctp_transport *)arg,
        return sctp_sf_heartbeat(ep, asoc, type, (struct sctp_transport *)arg,
                                 commands);
                                 commands);
}
}
 
 
/*
/*
 * ADDIP Section 4.1 ASCONF Chunk Procedures
 * ADDIP Section 4.1 ASCONF Chunk Procedures
 * When an endpoint has an ASCONF signaled change to be sent to the
 * When an endpoint has an ASCONF signaled change to be sent to the
 * remote endpoint it should do A1 to A9
 * remote endpoint it should do A1 to A9
 */
 */
sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = arg;
        struct sctp_chunk *chunk = arg;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
        sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/*
/*
 * Ignore the primitive event
 * Ignore the primitive event
 *
 *
 * The return value is the disposition of the primitive.
 * The return value is the disposition of the primitive.
 */
 */
sctp_disposition_t sctp_sf_ignore_primitive(
sctp_disposition_t sctp_sf_ignore_primitive(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
        SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
        return SCTP_DISPOSITION_DISCARD;
        return SCTP_DISPOSITION_DISCARD;
}
}
 
 
/***************************************************************************
/***************************************************************************
 * These are the state functions for the OTHER events.
 * These are the state functions for the OTHER events.
 ***************************************************************************/
 ***************************************************************************/
 
 
/*
/*
 * Start the shutdown negotiation.
 * Start the shutdown negotiation.
 *
 *
 * From Section 9.2:
 * From Section 9.2:
 * Once all its outstanding data has been acknowledged, the endpoint
 * Once all its outstanding data has been acknowledged, the endpoint
 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
 * TSN Ack field the last sequential TSN it has received from the peer.
 * TSN Ack field the last sequential TSN it has received from the peer.
 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
 * with the updated last sequential TSN received from its peer.
 * with the updated last sequential TSN received from its peer.
 *
 *
 * The return value is the disposition.
 * The return value is the disposition.
 */
 */
sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *reply;
        struct sctp_chunk *reply;
 
 
        /* Once all its outstanding data has been acknowledged, the
        /* Once all its outstanding data has been acknowledged, the
         * endpoint shall send a SHUTDOWN chunk to its peer including
         * endpoint shall send a SHUTDOWN chunk to its peer including
         * in the Cumulative TSN Ack field the last sequential TSN it
         * in the Cumulative TSN Ack field the last sequential TSN it
         * has received from the peer.
         * has received from the peer.
         */
         */
        reply = sctp_make_shutdown(asoc, NULL);
        reply = sctp_make_shutdown(asoc, NULL);
        if (!reply)
        if (!reply)
                goto nomem;
                goto nomem;
 
 
        /* Set the transport for the SHUTDOWN chunk and the timeout for the
        /* Set the transport for the SHUTDOWN chunk and the timeout for the
         * T2-shutdown timer.
         * T2-shutdown timer.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
 
 
        /* It shall then start the T2-shutdown timer */
        /* It shall then start the T2-shutdown timer */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
 
 
        if (asoc->autoclose)
        if (asoc->autoclose)
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                                SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
                                SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
 
 
        /* and enter the SHUTDOWN-SENT state.  */
        /* and enter the SHUTDOWN-SENT state.  */
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
                        SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
 
 
        /* sctp-implguide 2.10 Issues with Heartbeating and failover
        /* sctp-implguide 2.10 Issues with Heartbeating and failover
         *
         *
         * HEARTBEAT ... is discontinued after sending either SHUTDOWN
         * HEARTBEAT ... is discontinued after sending either SHUTDOWN
         * or SHUTDOWN-ACK.
         * or SHUTDOWN-ACK.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Generate a SHUTDOWN ACK now that everything is SACK'd.
 * Generate a SHUTDOWN ACK now that everything is SACK'd.
 *
 *
 * From Section 9.2:
 * From Section 9.2:
 *
 *
 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
 * endpoint must re-send the SHUTDOWN ACK.
 * endpoint must re-send the SHUTDOWN ACK.
 *
 *
 * The return value is the disposition.
 * The return value is the disposition.
 */
 */
sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
        struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
        struct sctp_chunk *reply;
        struct sctp_chunk *reply;
 
 
        /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
        /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
         * shall send a SHUTDOWN ACK ...
         * shall send a SHUTDOWN ACK ...
         */
         */
        reply = sctp_make_shutdown_ack(asoc, chunk);
        reply = sctp_make_shutdown_ack(asoc, chunk);
        if (!reply)
        if (!reply)
                goto nomem;
                goto nomem;
 
 
        /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
        /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
         * the T2-shutdown timer.
         * the T2-shutdown timer.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
 
 
        /* and start/restart a T2-shutdown timer of its own, */
        /* and start/restart a T2-shutdown timer of its own, */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
 
 
        if (asoc->autoclose)
        if (asoc->autoclose)
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                                SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
                                SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
 
 
        /* Enter the SHUTDOWN-ACK-SENT state.  */
        /* Enter the SHUTDOWN-ACK-SENT state.  */
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
                        SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
 
 
        /* sctp-implguide 2.10 Issues with Heartbeating and failover
        /* sctp-implguide 2.10 Issues with Heartbeating and failover
         *
         *
         * HEARTBEAT ... is discontinued after sending either SHUTDOWN
         * HEARTBEAT ... is discontinued after sending either SHUTDOWN
         * or SHUTDOWN-ACK.
         * or SHUTDOWN-ACK.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
        sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * Ignore the event defined as other
 * Ignore the event defined as other
 *
 *
 * The return value is the disposition of the event.
 * The return value is the disposition of the event.
 */
 */
sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
        SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
        return SCTP_DISPOSITION_DISCARD;
        return SCTP_DISPOSITION_DISCARD;
}
}
 
 
/************************************************************
/************************************************************
 * These are the state functions for handling timeout events.
 * These are the state functions for handling timeout events.
 ************************************************************/
 ************************************************************/
 
 
/*
/*
 * RTX Timeout
 * RTX Timeout
 *
 *
 * Section: 6.3.3 Handle T3-rtx Expiration
 * Section: 6.3.3 Handle T3-rtx Expiration
 *
 *
 * Whenever the retransmission timer T3-rtx expires for a destination
 * Whenever the retransmission timer T3-rtx expires for a destination
 * address, do the following:
 * address, do the following:
 * [See below]
 * [See below]
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        struct sctp_transport *transport = arg;
        struct sctp_transport *transport = arg;
 
 
        if (asoc->overall_error_count >= asoc->max_retrans) {
        if (asoc->overall_error_count >= asoc->max_retrans) {
                /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
                /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                                SCTP_U32(SCTP_ERROR_NO_ERROR));
                                SCTP_U32(SCTP_ERROR_NO_ERROR));
                SCTP_INC_STATS(SctpAborteds);
                SCTP_INC_STATS(SctpAborteds);
                SCTP_DEC_STATS(SctpCurrEstab);
                SCTP_DEC_STATS(SctpCurrEstab);
                return SCTP_DISPOSITION_DELETE_TCB;
                return SCTP_DISPOSITION_DELETE_TCB;
        }
        }
 
 
        /* E1) For the destination address for which the timer
        /* E1) For the destination address for which the timer
         * expires, adjust its ssthresh with rules defined in Section
         * expires, adjust its ssthresh with rules defined in Section
         * 7.2.3 and set the cwnd <- MTU.
         * 7.2.3 and set the cwnd <- MTU.
         */
         */
 
 
        /* E2) For the destination address for which the timer
        /* E2) For the destination address for which the timer
         * expires, set RTO <- RTO * 2 ("back off the timer").  The
         * expires, set RTO <- RTO * 2 ("back off the timer").  The
         * maximum value discussed in rule C7 above (RTO.max) may be
         * maximum value discussed in rule C7 above (RTO.max) may be
         * used to provide an upper bound to this doubling operation.
         * used to provide an upper bound to this doubling operation.
         */
         */
 
 
        /* 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
         * which the timer expires [see Section 6.4]).  Call this
         * value K. Bundle and retransmit those K DATA chunks in a
         * value K. Bundle and retransmit those K DATA chunks in a
         * single packet to the destination endpoint.
         * single packet to the destination endpoint.
         *
         *
         * Note: Any DATA chunks that were sent to the address for
         * Note: Any DATA chunks that were sent to the address for
         * which the T3-rtx timer expired but did not fit in one MTU
         * which the T3-rtx timer expired but did not fit in one MTU
         * (rule E3 above), should be marked for retransmission and
         * (rule E3 above), should be marked for retransmission and
         * sent as soon as cwnd allows (normally when a SACK arrives).
         * sent as soon as cwnd allows (normally when a SACK arrives).
         */
         */
 
 
        /* NB: Rules E4 and F1 are implicit in R1.  */
        /* NB: Rules E4 and F1 are implicit in R1.  */
        sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
        sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
 
 
        /* Do some failure management (Section 8.2). */
        /* Do some failure management (Section 8.2). */
        sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
        sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/*
/*
 * Generate delayed SACK on timeout
 * Generate delayed SACK on timeout
 *
 *
 * Section: 6.2  Acknowledgement on Reception of DATA Chunks
 * Section: 6.2  Acknowledgement on Reception of DATA Chunks
 *
 *
 * The guidelines on delayed acknowledgement algorithm specified in
 * The guidelines on delayed acknowledgement algorithm specified in
 * Section 4.2 of [RFC2581] SHOULD be followed.  Specifically, an
 * Section 4.2 of [RFC2581] SHOULD be followed.  Specifically, an
 * acknowledgement SHOULD be generated for at least every second packet
 * acknowledgement SHOULD be generated for at least every second packet
 * (not every second DATA chunk) received, and SHOULD be generated
 * (not every second DATA chunk) received, and SHOULD be generated
 * within 200 ms of the arrival of any unacknowledged DATA chunk.  In
 * within 200 ms of the arrival of any unacknowledged DATA chunk.  In
 * some situations it may be beneficial for an SCTP transmitter to be
 * some situations it may be beneficial for an SCTP transmitter to be
 * more conservative than the algorithms detailed in this document
 * more conservative than the algorithms detailed in this document
 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
 * the following algorithms allow.
 * the following algorithms allow.
 */
 */
sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep,
                                       const struct sctp_association *asoc,
                                       const struct sctp_association *asoc,
                                       const sctp_subtype_t type,
                                       const sctp_subtype_t type,
                                       void *arg,
                                       void *arg,
                                       sctp_cmd_seq_t *commands)
                                       sctp_cmd_seq_t *commands)
{
{
        sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
        sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/*
/*
 * sctp_sf_t1_timer_expire
 * sctp_sf_t1_timer_expire
 *
 *
 * Section: 4 Note: 2
 * Section: 4 Note: 2
 * Verification Tag:
 * Verification Tag:
 * Inputs
 * Inputs
 * (endpoint, asoc)
 * (endpoint, asoc)
 *
 *
 *  RFC 2960 Section 4 Notes
 *  RFC 2960 Section 4 Notes
 *  2) If the T1-init timer expires, the endpoint MUST retransmit INIT
 *  2) If the T1-init timer expires, the endpoint MUST retransmit INIT
 *     and re-start the T1-init timer without changing state.  This MUST
 *     and re-start the T1-init timer without changing state.  This MUST
 *     be repeated up to 'Max.Init.Retransmits' times.  After that, the
 *     be repeated up to 'Max.Init.Retransmits' times.  After that, the
 *     endpoint MUST abort the initialization process and report the
 *     endpoint MUST abort the initialization process and report the
 *     error to SCTP user.
 *     error to SCTP user.
 *
 *
 *   3) If the T1-cookie timer expires, the endpoint MUST retransmit
 *   3) If the T1-cookie timer expires, the endpoint MUST retransmit
 *     COOKIE ECHO and re-start the T1-cookie timer without changing
 *     COOKIE ECHO and re-start the T1-cookie timer without changing
 *     state.  This MUST be repeated up to 'Max.Init.Retransmits' times.
 *     state.  This MUST be repeated up to 'Max.Init.Retransmits' times.
 *     After that, the endpoint MUST abort the initialization process and
 *     After that, the endpoint MUST abort the initialization process and
 *     report the error to SCTP user.
 *     report the error to SCTP user.
 *
 *
 * Outputs
 * Outputs
 * (timers, events)
 * (timers, events)
 *
 *
 */
 */
sctp_disposition_t sctp_sf_t1_timer_expire(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_t1_timer_expire(const struct sctp_endpoint *ep,
                                           const struct sctp_association *asoc,
                                           const struct sctp_association *asoc,
                                           const sctp_subtype_t type,
                                           const sctp_subtype_t type,
                                           void *arg,
                                           void *arg,
                                           sctp_cmd_seq_t *commands)
                                           sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *repl;
        struct sctp_chunk *repl;
        struct sctp_bind_addr *bp;
        struct sctp_bind_addr *bp;
        sctp_event_timeout_t timer = (sctp_event_timeout_t) arg;
        sctp_event_timeout_t timer = (sctp_event_timeout_t) arg;
        int timeout;
        int timeout;
        int attempts;
        int attempts;
 
 
        timeout = asoc->timeouts[timer];
        timeout = asoc->timeouts[timer];
        attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
        attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
        repl = NULL;
        repl = NULL;
 
 
        SCTP_DEBUG_PRINTK("Timer T1 expired.\n");
        SCTP_DEBUG_PRINTK("Timer T1 expired.\n");
 
 
        if (attempts < asoc->max_init_attempts) {
        if (attempts < asoc->max_init_attempts) {
                switch (timer) {
                switch (timer) {
                case SCTP_EVENT_TIMEOUT_T1_INIT:
                case SCTP_EVENT_TIMEOUT_T1_INIT:
                        bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
                        bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
                        repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
                        repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
                        break;
                        break;
 
 
                case SCTP_EVENT_TIMEOUT_T1_COOKIE:
                case SCTP_EVENT_TIMEOUT_T1_COOKIE:
                        repl = sctp_make_cookie_echo(asoc, NULL);
                        repl = sctp_make_cookie_echo(asoc, NULL);
                        break;
                        break;
 
 
                default:
                default:
                        BUG();
                        BUG();
                        break;
                        break;
                };
                };
 
 
                if (!repl)
                if (!repl)
                        goto nomem;
                        goto nomem;
 
 
                /* Issue a sideeffect to do the needed accounting. */
                /* Issue a sideeffect to do the needed accounting. */
                sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
                sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
                                SCTP_TO(timer));
                                SCTP_TO(timer));
                sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
                sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
        } else {
        } else {
                sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
                sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
                                SCTP_U32(SCTP_ERROR_NO_ERROR));
                                SCTP_U32(SCTP_ERROR_NO_ERROR));
                return SCTP_DISPOSITION_DELETE_TCB;
                return SCTP_DISPOSITION_DELETE_TCB;
        }
        }
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
/* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
 * with the updated last sequential TSN received from its peer.
 * with the updated last sequential TSN received from its peer.
 *
 *
 * An endpoint should limit the number of retransmissions of the
 * An endpoint should limit the number of retransmissions of the
 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
 * If this threshold is exceeded the endpoint should destroy the TCB and
 * If this threshold is exceeded the endpoint should destroy the TCB and
 * MUST report the peer endpoint unreachable to the upper layer (and
 * MUST report the peer endpoint unreachable to the upper layer (and
 * thus the association enters the CLOSED state).  The reception of any
 * thus the association enters the CLOSED state).  The reception of any
 * packet from its peer (i.e. as the peer sends all of its queued DATA
 * packet from its peer (i.e. as the peer sends all of its queued DATA
 * chunks) should clear the endpoint's retransmission count and restart
 * chunks) should clear the endpoint's retransmission count and restart
 * the T2-Shutdown timer,  giving its peer ample opportunity to transmit
 * the T2-Shutdown timer,  giving its peer ample opportunity to transmit
 * all of its queued DATA chunks that have not yet been sent.
 * all of its queued DATA chunks that have not yet been sent.
 */
 */
sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep,
                                           const struct sctp_association *asoc,
                                           const struct sctp_association *asoc,
                                           const sctp_subtype_t type,
                                           const sctp_subtype_t type,
                                           void *arg,
                                           void *arg,
                                           sctp_cmd_seq_t *commands)
                                           sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *reply = NULL;
        struct sctp_chunk *reply = NULL;
 
 
        SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
        SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
        if (asoc->overall_error_count >= asoc->max_retrans) {
        if (asoc->overall_error_count >= asoc->max_retrans) {
                /* Note:  CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
                /* Note:  CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                                SCTP_U32(SCTP_ERROR_NO_ERROR));
                                SCTP_U32(SCTP_ERROR_NO_ERROR));
                SCTP_INC_STATS(SctpAborteds);
                SCTP_INC_STATS(SctpAborteds);
                SCTP_DEC_STATS(SctpCurrEstab);
                SCTP_DEC_STATS(SctpCurrEstab);
                return SCTP_DISPOSITION_DELETE_TCB;
                return SCTP_DISPOSITION_DELETE_TCB;
        }
        }
 
 
        switch (asoc->state) {
        switch (asoc->state) {
        case SCTP_STATE_SHUTDOWN_SENT:
        case SCTP_STATE_SHUTDOWN_SENT:
                reply = sctp_make_shutdown(asoc, NULL);
                reply = sctp_make_shutdown(asoc, NULL);
                break;
                break;
 
 
        case SCTP_STATE_SHUTDOWN_ACK_SENT:
        case SCTP_STATE_SHUTDOWN_ACK_SENT:
                reply = sctp_make_shutdown_ack(asoc, NULL);
                reply = sctp_make_shutdown_ack(asoc, NULL);
                break;
                break;
 
 
        default:
        default:
                BUG();
                BUG();
                break;
                break;
        };
        };
 
 
        if (!reply)
        if (!reply)
                goto nomem;
                goto nomem;
 
 
        /* Do some failure management (Section 8.2). */
        /* Do some failure management (Section 8.2). */
        sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
        sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
                        SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
                        SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
 
 
        /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
        /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
         * the T2-shutdown timer.
         * the T2-shutdown timer.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
 
 
        /* Restart the T2-shutdown timer.  */
        /* Restart the T2-shutdown timer.  */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
 
 
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/*
/*
 * ADDIP Section 4.1 ASCONF CHunk Procedures
 * ADDIP Section 4.1 ASCONF CHunk Procedures
 * If the T4 RTO timer expires the endpoint should do B1 to B5
 * If the T4 RTO timer expires the endpoint should do B1 to B5
 */
 */
sctp_disposition_t sctp_sf_t4_timer_expire(
sctp_disposition_t sctp_sf_t4_timer_expire(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *chunk = asoc->addip_last_asconf;
        struct sctp_chunk *chunk = asoc->addip_last_asconf;
        struct sctp_transport *transport = chunk->transport;
        struct sctp_transport *transport = chunk->transport;
 
 
        /* ADDIP 4.1 B1) Increment the error counters and perform path failure
        /* ADDIP 4.1 B1) Increment the error counters and perform path failure
         * detection on the appropriate destination address as defined in
         * detection on the appropriate destination address as defined in
         * RFC2960 [5] section 8.1 and 8.2.
         * RFC2960 [5] section 8.1 and 8.2.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
        sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
 
 
        /* Reconfig T4 timer and transport. */
        /* Reconfig T4 timer and transport. */
        sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
        sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
 
 
        /* ADDIP 4.1 B2) Increment the association error counters and perform
        /* ADDIP 4.1 B2) Increment the association error counters and perform
         * endpoint failure detection on the association as defined in
         * endpoint failure detection on the association as defined in
         * RFC2960 [5] section 8.1 and 8.2.
         * RFC2960 [5] section 8.1 and 8.2.
         * association error counter is incremented in SCTP_CMD_STRIKE.
         * association error counter is incremented in SCTP_CMD_STRIKE.
         */
         */
        if (asoc->overall_error_count >= asoc->max_retrans) {
        if (asoc->overall_error_count >= asoc->max_retrans) {
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
                                SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
                                SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                                SCTP_U32(SCTP_ERROR_NO_ERROR));
                                SCTP_U32(SCTP_ERROR_NO_ERROR));
                SCTP_INC_STATS(SctpAborteds);
                SCTP_INC_STATS(SctpAborteds);
                SCTP_INC_STATS(SctpCurrEstab);
                SCTP_INC_STATS(SctpCurrEstab);
                return SCTP_DISPOSITION_ABORT;
                return SCTP_DISPOSITION_ABORT;
        }
        }
 
 
        /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
        /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
         * the ASCONF chunk was sent by doubling the RTO timer value.
         * the ASCONF chunk was sent by doubling the RTO timer value.
         * This is done in SCTP_CMD_STRIKE.
         * This is done in SCTP_CMD_STRIKE.
         */
         */
 
 
        /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
        /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
         * choose an alternate destination address (please refer to RFC2960
         * choose an alternate destination address (please refer to RFC2960
         * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
         * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
         * chunk, it MUST be the same (including its serial number) as the last
         * chunk, it MUST be the same (including its serial number) as the last
         * ASCONF sent.
         * ASCONF sent.
         */
         */
        sctp_chunk_hold(asoc->addip_last_asconf);
        sctp_chunk_hold(asoc->addip_last_asconf);
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
                        SCTP_CHUNK(asoc->addip_last_asconf));
                        SCTP_CHUNK(asoc->addip_last_asconf));
 
 
        /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
        /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
         * destination is selected, then the RTO used will be that of the new
         * destination is selected, then the RTO used will be that of the new
         * destination address.
         * destination address.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
 
 
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/* sctpimpguide-05 Section 2.12.2
/* sctpimpguide-05 Section 2.12.2
 * The sender of the SHUTDOWN MAY also start an overall guard timer
 * The sender of the SHUTDOWN MAY also start an overall guard timer
 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
 * At the expiration of this timer the sender SHOULD abort the association
 * At the expiration of this timer the sender SHOULD abort the association
 * by sending an ABORT chunk.
 * by sending an ABORT chunk.
 */
 */
sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep,
                                           const struct sctp_association *asoc,
                                           const struct sctp_association *asoc,
                                           const sctp_subtype_t type,
                                           const sctp_subtype_t type,
                                           void *arg,
                                           void *arg,
                                           sctp_cmd_seq_t *commands)
                                           sctp_cmd_seq_t *commands)
{
{
        struct sctp_chunk *reply = NULL;
        struct sctp_chunk *reply = NULL;
 
 
        SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
        SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
 
 
        reply = sctp_make_abort(asoc, NULL, 0);
        reply = sctp_make_abort(asoc, NULL, 0);
        if (!reply)
        if (!reply)
                goto nomem;
                goto nomem;
 
 
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
        sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
        sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
                        SCTP_U32(SCTP_ERROR_NO_ERROR));
                        SCTP_U32(SCTP_ERROR_NO_ERROR));
 
 
        return SCTP_DISPOSITION_DELETE_TCB;
        return SCTP_DISPOSITION_DELETE_TCB;
nomem:
nomem:
        return SCTP_DISPOSITION_NOMEM;
        return SCTP_DISPOSITION_NOMEM;
}
}
 
 
/* Handle expiration of AUTOCLOSE timer.  When the autoclose timer expires,
/* Handle expiration of AUTOCLOSE timer.  When the autoclose timer expires,
 * the association is automatically closed by starting the shutdown process.
 * the association is automatically closed by starting the shutdown process.
 * The work that needs to be done is same as when SHUTDOWN is initiated by
 * The work that needs to be done is same as when SHUTDOWN is initiated by
 * the user.  So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
 * the user.  So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
 */
 */
sctp_disposition_t sctp_sf_autoclose_timer_expire(
sctp_disposition_t sctp_sf_autoclose_timer_expire(
        const struct sctp_endpoint *ep,
        const struct sctp_endpoint *ep,
        const struct sctp_association *asoc,
        const struct sctp_association *asoc,
        const sctp_subtype_t type,
        const sctp_subtype_t type,
        void *arg,
        void *arg,
        sctp_cmd_seq_t *commands)
        sctp_cmd_seq_t *commands)
{
{
        int disposition;
        int disposition;
 
 
        /* From 9.2 Shutdown of an Association
        /* From 9.2 Shutdown of an Association
         * Upon receipt of the SHUTDOWN primitive from its upper
         * Upon receipt of the SHUTDOWN primitive from its upper
         * layer, the endpoint enters SHUTDOWN-PENDING state and
         * layer, the endpoint enters SHUTDOWN-PENDING state and
         * remains there until all outstanding data has been
         * remains there until all outstanding data has been
         * acknowledged by its peer. The endpoint accepts no new data
         * acknowledged by its peer. The endpoint accepts no new data
         * from its upper layer, but retransmits data to the far end
         * from its upper layer, but retransmits data to the far end
         * if necessary to fill gaps.
         * if necessary to fill gaps.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
        sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
                        SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
                        SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
 
 
        /* sctpimpguide-05 Section 2.12.2
        /* sctpimpguide-05 Section 2.12.2
         * The sender of the SHUTDOWN MAY also start an overall guard timer
         * The sender of the SHUTDOWN MAY also start an overall guard timer
         * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
         * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
         */
         */
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
        sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
                        SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
        disposition = SCTP_DISPOSITION_CONSUME;
        disposition = SCTP_DISPOSITION_CONSUME;
        if (sctp_outq_is_empty(&asoc->outqueue)) {
        if (sctp_outq_is_empty(&asoc->outqueue)) {
                disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
                disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
                                                            arg, commands);
                                                            arg, commands);
        }
        }
        return disposition;
        return disposition;
}
}
 
 
/*****************************************************************************
/*****************************************************************************
 * These are sa state functions which could apply to all types of events.
 * These are sa state functions which could apply to all types of events.
 ****************************************************************************/
 ****************************************************************************/
 
 
/*
/*
 * This table entry is not implemented.
 * This table entry is not implemented.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep,
                                    const struct sctp_association *asoc,
                                    const struct sctp_association *asoc,
                                    const sctp_subtype_t type,
                                    const sctp_subtype_t type,
                                    void *arg,
                                    void *arg,
                                    sctp_cmd_seq_t *commands)
                                    sctp_cmd_seq_t *commands)
{
{
        return SCTP_DISPOSITION_NOT_IMPL;
        return SCTP_DISPOSITION_NOT_IMPL;
}
}
 
 
/*
/*
 * This table entry represents a bug.
 * This table entry represents a bug.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep,
                               const struct sctp_association *asoc,
                               const struct sctp_association *asoc,
                               const sctp_subtype_t type,
                               const sctp_subtype_t type,
                               void *arg,
                               void *arg,
                               sctp_cmd_seq_t *commands)
                               sctp_cmd_seq_t *commands)
{
{
        return SCTP_DISPOSITION_BUG;
        return SCTP_DISPOSITION_BUG;
}
}
 
 
/*
/*
 * This table entry represents the firing of a timer in the wrong state.
 * This table entry represents the firing of a timer in the wrong state.
 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
 * when the association is in the wrong state.   This event should
 * when the association is in the wrong state.   This event should
 * be ignored, so as to prevent any rearming of the timer.
 * be ignored, so as to prevent any rearming of the timer.
 *
 *
 * Inputs
 * Inputs
 * (endpoint, asoc, chunk)
 * (endpoint, asoc, chunk)
 *
 *
 * The return value is the disposition of the chunk.
 * The return value is the disposition of the chunk.
 */
 */
sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep,
sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep,
                                        const struct sctp_association *asoc,
                                        const struct sctp_association *asoc,
                                        const sctp_subtype_t type,
                                        const sctp_subtype_t type,
                                        void *arg,
                                        void *arg,
                                        sctp_cmd_seq_t *commands)
                                        sctp_cmd_seq_t *commands)
{
{
        SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
        SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
        return SCTP_DISPOSITION_CONSUME;
        return SCTP_DISPOSITION_CONSUME;
}
}
 
 
/********************************************************************
/********************************************************************
 * 2nd Level Abstractions
 * 2nd Level Abstractions
 ********************************************************************/
 ********************************************************************/
 
 
/* Pull the SACK chunk based on the SACK header. */
/* Pull the SACK chunk based on the SACK header. */
struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
{
{
        struct sctp_sackhdr *sack;
        struct sctp_sackhdr *sack;
        unsigned int len;
        unsigned int len;
        __u16 num_blocks;
        __u16 num_blocks;
        __u16 num_dup_tsns;
        __u16 num_dup_tsns;
 
 
        /* Protect ourselves from reading too far into
        /* Protect ourselves from reading too far into
         * the skb from a bogus sender.
         * the skb from a bogus sender.
         */
         */
        sack = (struct sctp_sackhdr *) chunk->skb->data;
        sack = (struct sctp_sackhdr *) chunk->skb->data;
 
 
        num_blocks = ntohs(sack->num_gap_ack_blocks);
        num_blocks = ntohs(sack->num_gap_ack_blocks);
        num_dup_tsns = ntohs(sack->num_dup_tsns);
        num_dup_tsns = ntohs(sack->num_dup_tsns);
        len = sizeof(struct sctp_sackhdr);
        len = sizeof(struct sctp_sackhdr);
        len = (num_blocks + num_dup_tsns) * sizeof(__u32);
        len = (num_blocks + num_dup_tsns) * sizeof(__u32);
        if (len > chunk->skb->len)
        if (len > chunk->skb->len)
                return NULL;
                return NULL;
 
 
        skb_pull(chunk->skb, len);
        skb_pull(chunk->skb, len);
 
 
        return sack;
        return sack;
}
}
 
 
/* Create an ABORT packet to be sent as a response, with the specified
/* Create an ABORT packet to be sent as a response, with the specified
 * error causes.
 * error causes.
 */
 */
struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
                                  const struct sctp_association *asoc,
                                  const struct sctp_association *asoc,
                                  struct sctp_chunk *chunk,
                                  struct sctp_chunk *chunk,
                                  const void *payload,
                                  const void *payload,
                                  size_t paylen)
                                  size_t paylen)
{
{
        struct sctp_packet *packet;
        struct sctp_packet *packet;
        struct sctp_chunk *abort;
        struct sctp_chunk *abort;
 
 
        packet = sctp_ootb_pkt_new(asoc, chunk);
        packet = sctp_ootb_pkt_new(asoc, chunk);
 
 
        if (packet) {
        if (packet) {
                /* Make an ABORT.
                /* Make an ABORT.
                 * The T bit will be set if the asoc is NULL.
                 * The T bit will be set if the asoc is NULL.
                 */
                 */
                abort = sctp_make_abort(asoc, chunk, paylen);
                abort = sctp_make_abort(asoc, chunk, paylen);
                if (!abort) {
                if (!abort) {
                        sctp_ootb_pkt_free(packet);
                        sctp_ootb_pkt_free(packet);
                        return NULL;
                        return NULL;
                }
                }
                /* Add specified error causes, i.e., payload, to the
                /* Add specified error causes, i.e., payload, to the
                 * end of the chunk.
                 * end of the chunk.
                 */
                 */
                sctp_addto_chunk(abort, paylen, payload);
                sctp_addto_chunk(abort, paylen, payload);
 
 
                /* Set the skb to the belonging sock for accounting.  */
                /* Set the skb to the belonging sock for accounting.  */
                abort->skb->sk = ep->base.sk;
                abort->skb->sk = ep->base.sk;
 
 
                sctp_packet_append_chunk(packet, abort);
                sctp_packet_append_chunk(packet, abort);
 
 
        }
        }
 
 
        return packet;
        return packet;
}
}
 
 
/* Allocate a packet for responding in the OOTB conditions.  */
/* Allocate a packet for responding in the OOTB conditions.  */
struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
                                 const struct sctp_chunk *chunk)
                                 const struct sctp_chunk *chunk)
{
{
        struct sctp_packet *packet;
        struct sctp_packet *packet;
        struct sctp_transport *transport;
        struct sctp_transport *transport;
        __u16 sport;
        __u16 sport;
        __u16 dport;
        __u16 dport;
        __u32 vtag;
        __u32 vtag;
 
 
        /* Get the source and destination port from the inbound packet.  */
        /* Get the source and destination port from the inbound packet.  */
        sport = ntohs(chunk->sctp_hdr->dest);
        sport = ntohs(chunk->sctp_hdr->dest);
        dport = ntohs(chunk->sctp_hdr->source);
        dport = ntohs(chunk->sctp_hdr->source);
 
 
        /* The V-tag is going to be the same as the inbound packet if no
        /* The V-tag is going to be the same as the inbound packet if no
         * association exists, otherwise, use the peer's vtag.
         * association exists, otherwise, use the peer's vtag.
         */
         */
        if (asoc) {
        if (asoc) {
                vtag = asoc->peer.i.init_tag;
                vtag = asoc->peer.i.init_tag;
        } else {
        } else {
                /* Special case the INIT and stale COOKIE_ECHO as there is no
                /* Special case the INIT and stale COOKIE_ECHO as there is no
                 * vtag yet.
                 * vtag yet.
                 */
                 */
                switch(chunk->chunk_hdr->type) {
                switch(chunk->chunk_hdr->type) {
                case SCTP_CID_INIT:
                case SCTP_CID_INIT:
                {
                {
                        sctp_init_chunk_t *init;
                        sctp_init_chunk_t *init;
 
 
                        init = (sctp_init_chunk_t *)chunk->chunk_hdr;
                        init = (sctp_init_chunk_t *)chunk->chunk_hdr;
                        vtag = ntohl(init->init_hdr.init_tag);
                        vtag = ntohl(init->init_hdr.init_tag);
                        break;
                        break;
                }
                }
                default:
                default:
                        vtag = ntohl(chunk->sctp_hdr->vtag);
                        vtag = ntohl(chunk->sctp_hdr->vtag);
                        break;
                        break;
                }
                }
        }
        }
 
 
        /* Make a transport for the bucket, Eliza... */
        /* Make a transport for the bucket, Eliza... */
        transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
        transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
 
 
        if (!transport)
        if (!transport)
                goto nomem;
                goto nomem;
 
 
        /* Allocate a new packet for sending the response. */
        /* Allocate a new packet for sending the response. */
        packet = t_new(struct sctp_packet, GFP_ATOMIC);
        packet = t_new(struct sctp_packet, GFP_ATOMIC);
        if (!packet)
        if (!packet)
                goto nomem_packet;
                goto nomem_packet;
 
 
        /* Cache a route for the transport with the chunk's destination as
        /* Cache a route for the transport with the chunk's destination as
         * the source address.
         * the source address.
         */
         */
        sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
        sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
                             sctp_sk(sctp_get_ctl_sock()));
                             sctp_sk(sctp_get_ctl_sock()));
 
 
        packet = sctp_packet_init(packet, transport, sport, dport);
        packet = sctp_packet_init(packet, transport, sport, dport);
        packet = sctp_packet_config(packet, vtag, 0, NULL);
        packet = sctp_packet_config(packet, vtag, 0, NULL);
 
 
        return packet;
        return packet;
 
 
nomem_packet:
nomem_packet:
        sctp_transport_free(transport);
        sctp_transport_free(transport);
nomem:
nomem:
        return NULL;
        return NULL;
}
}
 
 
/* Free the packet allocated earlier for responding in the OOTB condition.  */
/* Free the packet allocated earlier for responding in the OOTB condition.  */
void sctp_ootb_pkt_free(struct sctp_packet *packet)
void sctp_ootb_pkt_free(struct sctp_packet *packet)
{
{
        sctp_transport_free(packet->transport);
        sctp_transport_free(packet->transport);
        sctp_packet_free(packet);
        sctp_packet_free(packet);
}
}
 
 
/* Send a stale cookie error when a invalid COOKIE ECHO chunk is found  */
/* Send a stale cookie error when a invalid COOKIE ECHO chunk is found  */
void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
                                const struct sctp_association *asoc,
                                const struct sctp_association *asoc,
                                const struct sctp_chunk *chunk,
                                const struct sctp_chunk *chunk,
                                sctp_cmd_seq_t *commands,
                                sctp_cmd_seq_t *commands,
                                struct sctp_chunk *err_chunk)
                                struct sctp_chunk *err_chunk)
{
{
        struct sctp_packet *packet;
        struct sctp_packet *packet;
 
 
        if (err_chunk) {
        if (err_chunk) {
                packet = sctp_ootb_pkt_new(asoc, chunk);
                packet = sctp_ootb_pkt_new(asoc, chunk);
                if (packet) {
                if (packet) {
                        struct sctp_signed_cookie *cookie;
                        struct sctp_signed_cookie *cookie;
 
 
                        /* Override the OOTB vtag from the cookie. */
                        /* Override the OOTB vtag from the cookie. */
                        cookie = chunk->subh.cookie_hdr;
                        cookie = chunk->subh.cookie_hdr;
                        packet->vtag = cookie->c.peer_vtag;
                        packet->vtag = cookie->c.peer_vtag;
 
 
                        /* Set the skb to the belonging sock for accounting. */
                        /* Set the skb to the belonging sock for accounting. */
                        err_chunk->skb->sk = ep->base.sk;
                        err_chunk->skb->sk = ep->base.sk;
                        sctp_packet_append_chunk(packet, err_chunk);
                        sctp_packet_append_chunk(packet, err_chunk);
                        sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
                        sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
                                        SCTP_PACKET(packet));
                                        SCTP_PACKET(packet));
                        SCTP_INC_STATS(SctpOutCtrlChunks);
                        SCTP_INC_STATS(SctpOutCtrlChunks);
                } else
                } else
                        sctp_chunk_free (err_chunk);
                        sctp_chunk_free (err_chunk);
        }
        }
}
}
 
 

powered by: WebSVN 2.1.0

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