]> nv-tegra.nvidia Code Review - linux-3.10.git/blobdiff - net/sctp/sm_make_chunk.c
SUNRPC: don't map EKEYEXPIRED to EACCES in call_refreshresult
[linux-3.10.git] / net / sctp / sm_make_chunk.c
index 04954e5f6846c2d16763ce1c0bcf2e6900957df7..cf579e71cff0652cd2fea2d7aae8c8343ecc66f7 100644 (file)
@@ -1,22 +1,22 @@
-/* SCTP kernel reference Implementation
+/* SCTP kernel implementation
  * (C) Copyright IBM Corp. 2001, 2004
  * Copyright (c) 1999-2000 Cisco, Inc.
  * Copyright (c) 1999-2001 Motorola, Inc.
  * Copyright (c) 2001-2002 Intel Corp.
  *
- * This file is part of the SCTP kernel reference Implementation
+ * This file is part of the SCTP kernel implementation
  *
  * These functions work with the state functions in sctp_sm_statefuns.c
  * to implement the state operations.  These functions implement the
  * steps which require modifying existing data structures.
  *
- * The SCTP reference implementation is free software;
+ * This SCTP implementation is free software;
  * you can redistribute it and/or modify it under the terms of
  * the GNU General Public License as published by
  * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
  *
- * The SCTP reference implementation is distributed in the hope that it
+ * This SCTP implementation is distributed in the hope that it
  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
  *                 ************************
  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * be incorporated into the next SCTP release.
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/ip.h>
 #include <linux/ipv6.h>
 #include <linux/net.h>
 #include <linux/inet.h>
-#include <asm/scatterlist.h>
+#include <linux/scatterlist.h>
 #include <linux/crypto.h>
+#include <linux/slab.h>
 #include <net/sock.h>
 
 #include <linux/skbuff.h>
@@ -65,8 +68,6 @@
 #include <net/sctp/sctp.h>
 #include <net/sctp/sm.h>
 
-extern kmem_cache_t *sctp_chunk_cachep;
-
 SCTP_STATIC
 struct sctp_chunk *sctp_make_chunk(const struct sctp_association *asoc,
                                   __u8 type, __u8 flags, int paylen);
@@ -79,6 +80,8 @@ static int sctp_process_param(struct sctp_association *asoc,
                              union sctp_params param,
                              const union sctp_addr *peer_addr,
                              gfp_t gfp);
+static void *sctp_addto_param(struct sctp_chunk *chunk, int len,
+                             const void *data);
 
 /* What was the inbound interface for this chunk? */
 int sctp_chunk_iif(const struct sctp_chunk *chunk)
@@ -86,7 +89,7 @@ int sctp_chunk_iif(const struct sctp_chunk *chunk)
        struct sctp_af *af;
        int iif = 0;
 
-       af = sctp_get_af_specific(ipver2af(chunk->skb->nh.iph->version));
+       af = sctp_get_af_specific(ipver2af(ip_hdr(chunk->skb)->version));
        if (af)
                iif = af->skb_iif(chunk->skb);
 
@@ -100,34 +103,53 @@ int sctp_chunk_iif(const struct sctp_chunk *chunk)
  */
 static const struct sctp_paramhdr ecap_param = {
        SCTP_PARAM_ECN_CAPABLE,
-       __constant_htons(sizeof(struct sctp_paramhdr)),
+       cpu_to_be16(sizeof(struct sctp_paramhdr)),
 };
 static const struct sctp_paramhdr prsctp_param = {
        SCTP_PARAM_FWD_TSN_SUPPORT,
-       __constant_htons(sizeof(struct sctp_paramhdr)),
+       cpu_to_be16(sizeof(struct sctp_paramhdr)),
 };
 
-/* A helper to initialize to initialize an op error inside a
+/* A helper to initialize an op error inside a
  * provided chunk, as most cause codes will be embedded inside an
  * abort chunk.
  */
 void  sctp_init_cause(struct sctp_chunk *chunk, __be16 cause_code,
-                     const void *payload, size_t paylen)
+                     size_t paylen)
 {
        sctp_errhdr_t err;
-       int padlen;
        __u16 len;
 
-        /* Cause code constants are now defined in network order.  */
+       /* Cause code constants are now defined in network order.  */
        err.cause = cause_code;
        len = sizeof(sctp_errhdr_t) + paylen;
-       padlen = len % 4;
        err.length  = htons(len);
-       len += padlen;
-       sctp_addto_chunk(chunk, sizeof(sctp_errhdr_t), &err);
-       chunk->subh.err_hdr = sctp_addto_chunk(chunk, paylen, payload);
+       chunk->subh.err_hdr = sctp_addto_chunk(chunk, sizeof(sctp_errhdr_t), &err);
 }
 
+/* A helper to initialize an op error inside a
+ * provided chunk, as most cause codes will be embedded inside an
+ * abort chunk.  Differs from sctp_init_cause in that it won't oops
+ * if there isn't enough space in the op error chunk
+ */
+static int sctp_init_cause_fixed(struct sctp_chunk *chunk, __be16 cause_code,
+                     size_t paylen)
+{
+       sctp_errhdr_t err;
+       __u16 len;
+
+       /* Cause code constants are now defined in network order.  */
+       err.cause = cause_code;
+       len = sizeof(sctp_errhdr_t) + paylen;
+       err.length  = htons(len);
+
+       if (skb_tailroom(chunk->skb) < len)
+               return -ENOSPC;
+       chunk->subh.err_hdr = sctp_addto_chunk_fixed(chunk,
+                                                    sizeof(sctp_errhdr_t),
+                                                    &err);
+       return 0;
+}
 /* 3.3.2 Initiation (INIT) (1)
  *
  * This chunk is used to initiate a SCTP association between two
@@ -176,6 +198,7 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
                             const struct sctp_bind_addr *bp,
                             gfp_t gfp, int vparam_len)
 {
+       struct net *net = sock_net(asoc->base.sk);
        sctp_inithdr_t init;
        union sctp_params addrs;
        size_t chunksize;
@@ -184,7 +207,12 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
        struct sctp_sock *sp;
        sctp_supported_addrs_param_t sat;
        __be16 types[2];
-       sctp_adaption_ind_param_t aiparam;
+       sctp_adaptation_ind_param_t aiparam;
+       sctp_supported_ext_param_t ext_param;
+       int num_ext = 0;
+       __u8 extensions[3];
+       sctp_paramhdr_t *auth_chunks = NULL,
+                       *auth_hmacs = NULL;
 
        /* RFC 2960 3.3.2 Initiation (INIT) (1)
         *
@@ -206,13 +234,57 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
        sp = sctp_sk(asoc->base.sk);
        num_types = sp->pf->supported_addrs(sp, types);
 
-       chunksize = sizeof(init) + addrs_len + SCTP_SAT_LEN(num_types);
+       chunksize = sizeof(init) + addrs_len;
+       chunksize += WORD_ROUND(SCTP_SAT_LEN(num_types));
        chunksize += sizeof(ecap_param);
-       if (sctp_prsctp_enable)
+
+       if (net->sctp.prsctp_enable)
                chunksize += sizeof(prsctp_param);
-       chunksize += sizeof(aiparam);
+
+       /* ADDIP: Section 4.2.7:
+        *  An implementation supporting this extension [ADDIP] MUST list
+        *  the ASCONF,the ASCONF-ACK, and the AUTH  chunks in its INIT and
+        *  INIT-ACK parameters.
+        */
+       if (net->sctp.addip_enable) {
+               extensions[num_ext] = SCTP_CID_ASCONF;
+               extensions[num_ext+1] = SCTP_CID_ASCONF_ACK;
+               num_ext += 2;
+       }
+
+       if (sp->adaptation_ind)
+               chunksize += sizeof(aiparam);
+
        chunksize += vparam_len;
 
+       /* Account for AUTH related parameters */
+       if (net->sctp.auth_enable) {
+               /* Add random parameter length*/
+               chunksize += sizeof(asoc->c.auth_random);
+
+               /* Add HMACS parameter length if any were defined */
+               auth_hmacs = (sctp_paramhdr_t *)asoc->c.auth_hmacs;
+               if (auth_hmacs->length)
+                       chunksize += WORD_ROUND(ntohs(auth_hmacs->length));
+               else
+                       auth_hmacs = NULL;
+
+               /* Add CHUNKS parameter length */
+               auth_chunks = (sctp_paramhdr_t *)asoc->c.auth_chunks;
+               if (auth_chunks->length)
+                       chunksize += WORD_ROUND(ntohs(auth_chunks->length));
+               else
+                       auth_chunks = NULL;
+
+               extensions[num_ext] = SCTP_CID_AUTH;
+               num_ext += 1;
+       }
+
+       /* If we have any extensions to report, account for that */
+       if (num_ext)
+               chunksize += WORD_ROUND(sizeof(sctp_supported_ext_param_t) +
+                                       num_ext);
+
        /* RFC 2960 3.3.2 Initiation (INIT) (1)
         *
         * Note 3: An INIT chunk MUST NOT contain more than one Host
@@ -247,12 +319,40 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
        sctp_addto_chunk(retval, num_types * sizeof(__u16), &types);
 
        sctp_addto_chunk(retval, sizeof(ecap_param), &ecap_param);
-       if (sctp_prsctp_enable)
+
+       /* Add the supported extensions parameter.  Be nice and add this
+        * fist before addiding the parameters for the extensions themselves
+        */
+       if (num_ext) {
+               ext_param.param_hdr.type = SCTP_PARAM_SUPPORTED_EXT;
+               ext_param.param_hdr.length =
+                           htons(sizeof(sctp_supported_ext_param_t) + num_ext);
+               sctp_addto_chunk(retval, sizeof(sctp_supported_ext_param_t),
+                               &ext_param);
+               sctp_addto_param(retval, num_ext, extensions);
+       }
+
+       if (net->sctp.prsctp_enable)
                sctp_addto_chunk(retval, sizeof(prsctp_param), &prsctp_param);
-       aiparam.param_hdr.type = SCTP_PARAM_ADAPTION_LAYER_IND;
-       aiparam.param_hdr.length = htons(sizeof(aiparam));
-       aiparam.adaption_ind = htonl(sp->adaption_ind);
-       sctp_addto_chunk(retval, sizeof(aiparam), &aiparam);
+
+       if (sp->adaptation_ind) {
+               aiparam.param_hdr.type = SCTP_PARAM_ADAPTATION_LAYER_IND;
+               aiparam.param_hdr.length = htons(sizeof(aiparam));
+               aiparam.adaptation_ind = htonl(sp->adaptation_ind);
+               sctp_addto_chunk(retval, sizeof(aiparam), &aiparam);
+       }
+
+       /* Add SCTP-AUTH chunks to the parameter list */
+       if (net->sctp.auth_enable) {
+               sctp_addto_chunk(retval, sizeof(asoc->c.auth_random),
+                                asoc->c.auth_random);
+               if (auth_hmacs)
+                       sctp_addto_chunk(retval, ntohs(auth_hmacs->length),
+                                       auth_hmacs);
+               if (auth_chunks)
+                       sctp_addto_chunk(retval, ntohs(auth_chunks->length),
+                                       auth_chunks);
+       }
 nodata:
        kfree(addrs.v);
        return retval;
@@ -265,11 +365,18 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
        sctp_inithdr_t initack;
        struct sctp_chunk *retval;
        union sctp_params addrs;
+       struct sctp_sock *sp;
        int addrs_len;
        sctp_cookie_param_t *cookie;
        int cookie_len;
        size_t chunksize;
-       sctp_adaption_ind_param_t aiparam;
+       sctp_adaptation_ind_param_t aiparam;
+       sctp_supported_ext_param_t ext_param;
+       int num_ext = 0;
+       __u8 extensions[3];
+       sctp_paramhdr_t *auth_chunks = NULL,
+                       *auth_hmacs = NULL,
+                       *auth_random = NULL;
 
        retval = NULL;
 
@@ -293,56 +400,103 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
        /* Calculate the total size of allocation, include the reserved
         * space for reporting unknown parameters if it is specified.
         */
+       sp = sctp_sk(asoc->base.sk);
        chunksize = sizeof(initack) + addrs_len + cookie_len + unkparam_len;
 
-        /* Tell peer that we'll do ECN only if peer advertised such cap.  */
+       /* Tell peer that we'll do ECN only if peer advertised such cap.  */
        if (asoc->peer.ecn_capable)
                chunksize += sizeof(ecap_param);
 
-        /* Tell peer that we'll do PR-SCTP only if peer advertised.  */
        if (asoc->peer.prsctp_capable)
                chunksize += sizeof(prsctp_param);
 
-       chunksize += sizeof(aiparam);
+       if (asoc->peer.asconf_capable) {
+               extensions[num_ext] = SCTP_CID_ASCONF;
+               extensions[num_ext+1] = SCTP_CID_ASCONF_ACK;
+               num_ext += 2;
+       }
+
+       if (sp->adaptation_ind)
+               chunksize += sizeof(aiparam);
+
+       if (asoc->peer.auth_capable) {
+               auth_random = (sctp_paramhdr_t *)asoc->c.auth_random;
+               chunksize += ntohs(auth_random->length);
+
+               auth_hmacs = (sctp_paramhdr_t *)asoc->c.auth_hmacs;
+               if (auth_hmacs->length)
+                       chunksize += WORD_ROUND(ntohs(auth_hmacs->length));
+               else
+                       auth_hmacs = NULL;
+
+               auth_chunks = (sctp_paramhdr_t *)asoc->c.auth_chunks;
+               if (auth_chunks->length)
+                       chunksize += WORD_ROUND(ntohs(auth_chunks->length));
+               else
+                       auth_chunks = NULL;
+
+               extensions[num_ext] = SCTP_CID_AUTH;
+               num_ext += 1;
+       }
+
+       if (num_ext)
+               chunksize += WORD_ROUND(sizeof(sctp_supported_ext_param_t) +
+                                       num_ext);
 
        /* Now allocate and fill out the chunk.  */
        retval = sctp_make_chunk(asoc, SCTP_CID_INIT_ACK, 0, chunksize);
        if (!retval)
                goto nomem_chunk;
 
-       /* Per the advice in RFC 2960 6.4, send this reply to
-        * the source of the INIT packet.
+       /* RFC 2960 6.4 Multi-homed SCTP Endpoints
+        *
+        * An endpoint SHOULD transmit reply chunks (e.g., SACK,
+        * HEARTBEAT ACK, * etc.) to the same destination transport
+        * address from which it received the DATA or control chunk
+        * to which it is replying.
+        *
+        * [INIT ACK back to where the INIT came from.]
         */
        retval->transport = chunk->transport;
+
        retval->subh.init_hdr =
                sctp_addto_chunk(retval, sizeof(initack), &initack);
        retval->param_hdr.v = sctp_addto_chunk(retval, addrs_len, addrs.v);
        sctp_addto_chunk(retval, cookie_len, cookie);
        if (asoc->peer.ecn_capable)
                sctp_addto_chunk(retval, sizeof(ecap_param), &ecap_param);
+       if (num_ext) {
+               ext_param.param_hdr.type = SCTP_PARAM_SUPPORTED_EXT;
+               ext_param.param_hdr.length =
+                           htons(sizeof(sctp_supported_ext_param_t) + num_ext);
+               sctp_addto_chunk(retval, sizeof(sctp_supported_ext_param_t),
+                                &ext_param);
+               sctp_addto_param(retval, num_ext, extensions);
+       }
        if (asoc->peer.prsctp_capable)
                sctp_addto_chunk(retval, sizeof(prsctp_param), &prsctp_param);
 
-       aiparam.param_hdr.type = SCTP_PARAM_ADAPTION_LAYER_IND;
-       aiparam.param_hdr.length = htons(sizeof(aiparam));
-       aiparam.adaption_ind = htonl(sctp_sk(asoc->base.sk)->adaption_ind);
-       sctp_addto_chunk(retval, sizeof(aiparam), &aiparam);
+       if (sp->adaptation_ind) {
+               aiparam.param_hdr.type = SCTP_PARAM_ADAPTATION_LAYER_IND;
+               aiparam.param_hdr.length = htons(sizeof(aiparam));
+               aiparam.adaptation_ind = htonl(sp->adaptation_ind);
+               sctp_addto_chunk(retval, sizeof(aiparam), &aiparam);
+       }
+
+       if (asoc->peer.auth_capable) {
+               sctp_addto_chunk(retval, ntohs(auth_random->length),
+                                auth_random);
+               if (auth_hmacs)
+                       sctp_addto_chunk(retval, ntohs(auth_hmacs->length),
+                                       auth_hmacs);
+               if (auth_chunks)
+                       sctp_addto_chunk(retval, ntohs(auth_chunks->length),
+                                       auth_chunks);
+       }
 
        /* We need to remove the const qualifier at this point.  */
        retval->asoc = (struct sctp_association *) asoc;
 
-       /* RFC 2960 6.4 Multi-homed SCTP Endpoints
-        *
-        * An endpoint SHOULD transmit reply chunks (e.g., SACK,
-        * HEARTBEAT ACK, * etc.) to the same destination transport
-        * address from which it received the DATA or control chunk
-        * to which it is replying.
-        *
-        * [INIT ACK back to where the INIT came from.]
-        */
-       if (chunk)
-               retval->transport = chunk->transport;
-
 nomem_chunk:
        kfree(cookie);
 nomem_cookie:
@@ -581,13 +735,17 @@ struct sctp_chunk *sctp_make_sack(const struct sctp_association *asoc)
        int len;
        __u32 ctsn;
        __u16 num_gabs, num_dup_tsns;
+       struct sctp_association *aptr = (struct sctp_association *)asoc;
        struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
+       struct sctp_gap_ack_block gabs[SCTP_MAX_GABS];
+       struct sctp_transport *trans;
 
+       memset(gabs, 0, sizeof(gabs));
        ctsn = sctp_tsnmap_get_ctsn(map);
        SCTP_DEBUG_PRINTK("sackCTSNAck sent:  0x%x.\n", ctsn);
 
        /* How much room is needed in the chunk? */
-       num_gabs = sctp_tsnmap_num_gabs(map);
+       num_gabs = sctp_tsnmap_num_gabs(map, gabs);
        num_dup_tsns = sctp_tsnmap_num_dups(map);
 
        /* Initialize the SACK header.  */
@@ -643,13 +801,28 @@ struct sctp_chunk *sctp_make_sack(const struct sctp_association *asoc)
        /* Add the gap ack block information.   */
        if (num_gabs)
                sctp_addto_chunk(retval, sizeof(__u32) * num_gabs,
-                                sctp_tsnmap_get_gabs(map));
+                                gabs);
 
        /* Add the duplicate TSN information.  */
-       if (num_dup_tsns)
+       if (num_dup_tsns) {
+               aptr->stats.idupchunks += num_dup_tsns;
                sctp_addto_chunk(retval, sizeof(__u32) * num_dup_tsns,
                                 sctp_tsnmap_get_dups(map));
-
+       }
+       /* Once we have a sack generated, check to see what our sack
+        * generation is, if its 0, reset the transports to 0, and reset
+        * the association generation to 1
+        *
+        * The idea is that zero is never used as a valid generation for the
+        * association so no transport will match after a wrap event like this,
+        * Until the next sack
+        */
+       if (++aptr->peer.sack_generation == 0) {
+               list_for_each_entry(trans, &asoc->peer.transport_addr_list,
+                                   transports)
+                       trans->sack_generation = 0;
+               aptr->peer.sack_generation = 1;
+       }
 nodata:
        return retval;
 }
@@ -728,7 +901,7 @@ struct sctp_chunk *sctp_make_shutdown_complete(
        if (retval && chunk)
                retval->transport = chunk->transport;
 
-        return retval;
+       return retval;
 }
 
 /* Create an ABORT.  Note that we set the T bit if we have no
@@ -785,8 +958,8 @@ struct sctp_chunk *sctp_make_abort_no_data(
 
        /* Put the tsn back into network byte order.  */
        payload = htonl(tsn);
-       sctp_init_cause(retval, SCTP_ERROR_NO_DATA, (const void *)&payload,
-                       sizeof(payload));
+       sctp_init_cause(retval, SCTP_ERROR_NO_DATA, sizeof(payload));
+       sctp_addto_chunk(retval, sizeof(payload), (const void *)&payload);
 
        /* RFC 2960 6.4 Multi-homed SCTP Endpoints
         *
@@ -828,7 +1001,8 @@ struct sctp_chunk *sctp_make_abort_user(const struct sctp_association *asoc,
                        goto err_copy;
        }
 
-       sctp_init_cause(retval, SCTP_ERROR_USER_ABORT, payload, paylen);
+       sctp_init_cause(retval, SCTP_ERROR_USER_ABORT, paylen);
+       sctp_addto_chunk(retval, paylen, payload);
 
        if (paylen)
                kfree(payload);
@@ -844,7 +1018,30 @@ err_chunk:
        return retval;
 }
 
-/* Make an ABORT chunk with a PROTOCOL VIOLATION cause code. */ 
+/* Append bytes to the end of a parameter.  Will panic if chunk is not big
+ * enough.
+ */
+static void *sctp_addto_param(struct sctp_chunk *chunk, int len,
+                             const void *data)
+{
+       void *target;
+       int chunklen = ntohs(chunk->chunk_hdr->length);
+
+       target = skb_put(chunk->skb, len);
+
+       if (data)
+               memcpy(target, data, len);
+       else
+               memset(target, 0, len);
+
+       /* Adjust the chunk length field.  */
+       chunk->chunk_hdr->length = htons(chunklen + len);
+       chunk->chunk_end = skb_tail_pointer(chunk->skb);
+
+       return target;
+}
+
+/* Make an ABORT chunk with a PROTOCOL VIOLATION cause code. */
 struct sctp_chunk *sctp_make_abort_violation(
        const struct sctp_association *asoc,
        const struct sctp_chunk *chunk,
@@ -855,36 +1052,88 @@ struct sctp_chunk *sctp_make_abort_violation(
        struct sctp_paramhdr phdr;
 
        retval = sctp_make_abort(asoc, chunk, sizeof(sctp_errhdr_t) + paylen
-                                       + sizeof(sctp_chunkhdr_t));
+                                       + sizeof(sctp_paramhdr_t));
        if (!retval)
                goto end;
 
-       sctp_init_cause(retval, SCTP_ERROR_PROTO_VIOLATION, payload, paylen);
+       sctp_init_cause(retval, SCTP_ERROR_PROTO_VIOLATION, paylen
+                                       + sizeof(sctp_paramhdr_t));
 
        phdr.type = htons(chunk->chunk_hdr->type);
        phdr.length = chunk->chunk_hdr->length;
-       sctp_addto_chunk(retval, sizeof(sctp_paramhdr_t), &phdr);
+       sctp_addto_chunk(retval, paylen, payload);
+       sctp_addto_param(retval, sizeof(sctp_paramhdr_t), &phdr);
 
 end:
        return retval;
 }
 
+struct sctp_chunk *sctp_make_violation_paramlen(
+       const struct sctp_association *asoc,
+       const struct sctp_chunk *chunk,
+       struct sctp_paramhdr *param)
+{
+       struct sctp_chunk *retval;
+       static const char error[] = "The following parameter had invalid length:";
+       size_t payload_len = sizeof(error) + sizeof(sctp_errhdr_t) +
+                               sizeof(sctp_paramhdr_t);
+
+       retval = sctp_make_abort(asoc, chunk, payload_len);
+       if (!retval)
+               goto nodata;
+
+       sctp_init_cause(retval, SCTP_ERROR_PROTO_VIOLATION,
+                       sizeof(error) + sizeof(sctp_paramhdr_t));
+       sctp_addto_chunk(retval, sizeof(error), error);
+       sctp_addto_param(retval, sizeof(sctp_paramhdr_t), param);
+
+nodata:
+       return retval;
+}
+
+struct sctp_chunk *sctp_make_violation_max_retrans(
+       const struct sctp_association *asoc,
+       const struct sctp_chunk *chunk)
+{
+       struct sctp_chunk *retval;
+       static const char error[] = "Association exceeded its max_retans count";
+       size_t payload_len = sizeof(error) + sizeof(sctp_errhdr_t);
+
+       retval = sctp_make_abort(asoc, chunk, payload_len);
+       if (!retval)
+               goto nodata;
+
+       sctp_init_cause(retval, SCTP_ERROR_PROTO_VIOLATION, sizeof(error));
+       sctp_addto_chunk(retval, sizeof(error), error);
+
+nodata:
+       return retval;
+}
+
 /* Make a HEARTBEAT chunk.  */
 struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
-                                 const struct sctp_transport *transport,
-                                 const void *payload, const size_t paylen)
+                                 const struct sctp_transport *transport)
 {
-       struct sctp_chunk *retval = sctp_make_chunk(asoc, SCTP_CID_HEARTBEAT,
-                                                   0, paylen);
+       struct sctp_chunk *retval;
+       sctp_sender_hb_info_t hbinfo;
+
+       retval = sctp_make_chunk(asoc, SCTP_CID_HEARTBEAT, 0, sizeof(hbinfo));
 
        if (!retval)
                goto nodata;
 
+       hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
+       hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
+       hbinfo.daddr = transport->ipaddr;
+       hbinfo.sent_at = jiffies;
+       hbinfo.hb_nonce = transport->hb_nonce;
+
        /* Cast away the 'const', as this is just telling the chunk
         * what transport it belongs to.
         */
        retval->transport = (struct sctp_transport *) transport;
-       retval->subh.hbs_hdr = sctp_addto_chunk(retval, paylen, payload);
+       retval->subh.hbs_hdr = sctp_addto_chunk(retval, sizeof(hbinfo),
+                                               &hbinfo);
 
 nodata:
        return retval;
@@ -948,24 +1197,80 @@ nodata:
        return retval;
 }
 
+/* Create an Operation Error chunk of a fixed size,
+ * specifically, max(asoc->pathmtu, SCTP_DEFAULT_MAXSEGMENT)
+ * This is a helper function to allocate an error chunk for
+ * for those invalid parameter codes in which we may not want
+ * to report all the errors, if the incoming chunk is large
+ */
+static inline struct sctp_chunk *sctp_make_op_error_fixed(
+       const struct sctp_association *asoc,
+       const struct sctp_chunk *chunk)
+{
+       size_t size = asoc ? asoc->pathmtu : 0;
+
+       if (!size)
+               size = SCTP_DEFAULT_MAXSEGMENT;
+
+       return sctp_make_op_error_space(asoc, chunk, size);
+}
+
 /* Create an Operation Error chunk.  */
 struct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc,
                                 const struct sctp_chunk *chunk,
                                 __be16 cause_code, const void *payload,
-                                size_t paylen)
+                                size_t paylen, size_t reserve_tail)
 {
        struct sctp_chunk *retval;
 
-       retval = sctp_make_op_error_space(asoc, chunk, paylen);
+       retval = sctp_make_op_error_space(asoc, chunk, paylen + reserve_tail);
        if (!retval)
                goto nodata;
 
-       sctp_init_cause(retval, cause_code, payload, paylen);
+       sctp_init_cause(retval, cause_code, paylen + reserve_tail);
+       sctp_addto_chunk(retval, paylen, payload);
+       if (reserve_tail)
+               sctp_addto_param(retval, reserve_tail, NULL);
 
 nodata:
        return retval;
 }
 
+struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc)
+{
+       struct sctp_chunk *retval;
+       struct sctp_hmac *hmac_desc;
+       struct sctp_authhdr auth_hdr;
+       __u8 *hmac;
+
+       /* Get the first hmac that the peer told us to use */
+       hmac_desc = sctp_auth_asoc_get_hmac(asoc);
+       if (unlikely(!hmac_desc))
+               return NULL;
+
+       retval = sctp_make_chunk(asoc, SCTP_CID_AUTH, 0,
+                       hmac_desc->hmac_len + sizeof(sctp_authhdr_t));
+       if (!retval)
+               return NULL;
+
+       auth_hdr.hmac_id = htons(hmac_desc->hmac_id);
+       auth_hdr.shkey_id = htons(asoc->active_key_id);
+
+       retval->subh.auth_hdr = sctp_addto_chunk(retval, sizeof(sctp_authhdr_t),
+                                               &auth_hdr);
+
+       hmac = skb_put(retval->skb, hmac_desc->hmac_len);
+       memset(hmac, 0, hmac_desc->hmac_len);
+
+       /* Adjust the chunk header to include the empty MAC */
+       retval->chunk_hdr->length =
+               htons(ntohs(retval->chunk_hdr->length) + hmac_desc->hmac_len);
+       retval->chunk_end = skb_tail_pointer(retval->skb);
+
+       return retval;
+}
+
+
 /********************************************************************
  * 2nd Level Abstractions
  ********************************************************************/
@@ -979,11 +1284,10 @@ struct sctp_chunk *sctp_chunkify(struct sk_buff *skb,
 {
        struct sctp_chunk *retval;
 
-       retval = kmem_cache_alloc(sctp_chunk_cachep, SLAB_ATOMIC);
+       retval = kmem_cache_zalloc(sctp_chunk_cachep, GFP_ATOMIC);
 
        if (!retval)
                goto nodata;
-       memset(retval, 0, sizeof(struct sctp_chunk));
 
        if (!sk) {
                SCTP_DEBUG_PRINTK("chunkifying skb %p w/o an sk\n", skb);
@@ -992,7 +1296,6 @@ struct sctp_chunk *sctp_chunkify(struct sk_buff *skb,
        INIT_LIST_HEAD(&retval->list);
        retval->skb             = skb;
        retval->asoc            = (struct sctp_association *)asoc;
-       retval->resent          = 0;
        retval->has_tsn         = 0;
        retval->has_ssn         = 0;
        retval->rtt_in_progress = 0;
@@ -1010,7 +1313,7 @@ struct sctp_chunk *sctp_chunkify(struct sk_buff *skb,
         */
        retval->tsn_missing_report = 0;
        retval->tsn_gap_acked = 0;
-       retval->fast_retransmit = 0;
+       retval->fast_retransmit = SCTP_CAN_FRTX;
 
        /* If this is a fragmented message, track all fragments
         * of the message (for SEND_FAILED).
@@ -1081,6 +1384,10 @@ struct sctp_chunk *sctp_make_chunk(const struct sctp_association *asoc,
        retval->chunk_hdr = chunk_hdr;
        retval->chunk_end = ((__u8 *)chunk_hdr) + sizeof(struct sctp_chunkhdr);
 
+       /* Determine if the chunk needs to be authenticated */
+       if (sctp_auth_send_cid(type, asoc))
+               retval->auth = 1;
+
        /* Set the skb to the belonging sock for accounting.  */
        skb->sk = sk;
 
@@ -1093,6 +1400,9 @@ nodata:
 /* Release the memory occupied by a chunk.  */
 static void sctp_chunk_destroy(struct sctp_chunk *chunk)
 {
+       BUG_ON(!list_empty(&chunk->list));
+       list_del_init(&chunk->transmitted_list);
+
        /* Free the chunk skb data and the SCTP_chunk stub itself. */
        dev_kfree_skb(chunk->skb);
 
@@ -1103,9 +1413,6 @@ static void sctp_chunk_destroy(struct sctp_chunk *chunk)
 /* Possibly, free the chunk.  */
 void sctp_chunk_free(struct sctp_chunk *chunk)
 {
-       BUG_ON(!list_empty(&chunk->list));
-       list_del_init(&chunk->transmitted_list);
-
        /* Release our reference on the message tracker. */
        if (chunk->msg)
                sctp_datamsg_put(chunk->msg);
@@ -1134,7 +1441,7 @@ void *sctp_addto_chunk(struct sctp_chunk *chunk, int len, const void *data)
        void *target;
        void *padding;
        int chunklen = ntohs(chunk->chunk_hdr->length);
-       int padlen = chunklen % 4;
+       int padlen = WORD_ROUND(chunklen) - chunklen;
 
        padding = skb_put(chunk->skb, padlen);
        target = skb_put(chunk->skb, len);
@@ -1144,11 +1451,23 @@ void *sctp_addto_chunk(struct sctp_chunk *chunk, int len, const void *data)
 
        /* Adjust the chunk length field.  */
        chunk->chunk_hdr->length = htons(chunklen + padlen + len);
-       chunk->chunk_end = chunk->skb->tail;
+       chunk->chunk_end = skb_tail_pointer(chunk->skb);
 
        return target;
 }
 
+/* Append bytes to the end of a chunk. Returns NULL if there isn't sufficient
+ * space in the chunk
+ */
+void *sctp_addto_chunk_fixed(struct sctp_chunk *chunk,
+                            int len, const void *data)
+{
+       if (skb_tailroom(chunk->skb) >= len)
+               return sctp_addto_chunk(chunk, len, data);
+       else
+               return NULL;
+}
+
 /* Append bytes from user space to the end of a chunk.  Will panic if
  * chunk is not big enough.
  * Returns a kernel err value.
@@ -1169,7 +1488,7 @@ int sctp_user_addto_chunk(struct sctp_chunk *chunk, int off, int len,
        /* Adjust the chunk length field.  */
        chunk->chunk_hdr->length =
                htons(ntohs(chunk->chunk_hdr->length) + len);
-       chunk->chunk_end = chunk->skb->tail;
+       chunk->chunk_end = skb_tail_pointer(chunk->skb);
 
 out:
        return err;
@@ -1180,25 +1499,36 @@ out:
  */
 void sctp_chunk_assign_ssn(struct sctp_chunk *chunk)
 {
+       struct sctp_datamsg *msg;
+       struct sctp_chunk *lchunk;
+       struct sctp_stream *stream;
        __u16 ssn;
        __u16 sid;
 
        if (chunk->has_ssn)
                return;
 
-       /* This is the last possible instant to assign a SSN. */
-       if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
-               ssn = 0;
-       } else {
-               sid = ntohs(chunk->subh.data_hdr->stream);
-               if (chunk->chunk_hdr->flags & SCTP_DATA_LAST_FRAG)
-                       ssn = sctp_ssn_next(&chunk->asoc->ssnmap->out, sid);
-               else
-                       ssn = sctp_ssn_peek(&chunk->asoc->ssnmap->out, sid);
-       }
+       /* All fragments will be on the same stream */
+       sid = ntohs(chunk->subh.data_hdr->stream);
+       stream = &chunk->asoc->ssnmap->out;
 
-       chunk->subh.data_hdr->ssn = htons(ssn);
-       chunk->has_ssn = 1;
+       /* Now assign the sequence number to the entire message.
+        * All fragments must have the same stream sequence number.
+        */
+       msg = chunk->msg;
+       list_for_each_entry(lchunk, &msg->chunks, frag_list) {
+               if (lchunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
+                       ssn = 0;
+               } else {
+                       if (lchunk->chunk_hdr->flags & SCTP_DATA_LAST_FRAG)
+                               ssn = sctp_ssn_next(stream, sid);
+                       else
+                               ssn = sctp_ssn_peek(stream, sid);
+               }
+
+               lchunk->subh.data_hdr->ssn = htons(ssn);
+               lchunk->has_ssn = 1;
+       }
 }
 
 /* Helper function to assign a TSN if needed.  This assumes that both
@@ -1234,7 +1564,7 @@ struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *ep,
        asoc->temp = 1;
        skb = chunk->skb;
        /* Create an entry for the source address of the packet.  */
-       af = sctp_get_af_specific(ipver2af(skb->nh.iph->version));
+       af = sctp_get_af_specific(ipver2af(ip_hdr(skb)->version));
        if (unlikely(!af))
                goto fail;
        af->from_skb(&asoc->c.peer_addr, skb, 1);
@@ -1259,14 +1589,12 @@ static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
        struct sctp_signed_cookie *cookie;
        struct scatterlist sg;
        int headersize, bodysize;
-       unsigned int keylen;
-       char *key;
 
        /* Header size is static data prior to the actual cookie, including
         * any padding.
         */
-       headersize = sizeof(sctp_paramhdr_t) + 
-                    (sizeof(struct sctp_signed_cookie) - 
+       headersize = sizeof(sctp_paramhdr_t) +
+                    (sizeof(struct sctp_signed_cookie) -
                      sizeof(struct sctp_cookie));
        bodysize = sizeof(struct sctp_cookie)
                + ntohs(init_chunk->chunk_hdr->length) + addrs_len;
@@ -1300,8 +1628,8 @@ static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
        /* Remember PR-SCTP capability. */
        cookie->c.prsctp_capable = asoc->peer.prsctp_capable;
 
-       /* Save adaption indication in the cookie. */
-       cookie->c.adaption_ind = asoc->peer.adaption_ind;
+       /* Save adaptation indication in the cookie. */
+       cookie->c.adaptation_ind = asoc->peer.adaptation_ind;
 
        /* Set an expiration time for the cookie.  */
        do_gettimeofday(&cookie->c.expiration);
@@ -1315,19 +1643,16 @@ static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
        memcpy((__u8 *)&cookie->c.peer_init[0] +
               ntohs(init_chunk->chunk_hdr->length), raw_addrs, addrs_len);
 
-       if (sctp_sk(ep->base.sk)->hmac) {
+       if (sctp_sk(ep->base.sk)->hmac) {
                struct hash_desc desc;
 
                /* Sign the message.  */
-               sg.page = virt_to_page(&cookie->c);
-               sg.offset = (unsigned long)(&cookie->c) % PAGE_SIZE;
-               sg.length = bodysize;
-               keylen = SCTP_SECRET_SIZE;
-               key = (char *)ep->secret_key[ep->current_key];
-               desc.tfm = sctp_sk(ep->base.sk)->hmac;
-               desc.flags = 0;
-
-               if (crypto_hash_setkey(desc.tfm, key, keylen) ||
+               sg_init_one(&sg, &cookie->c, bodysize);
+               desc.tfm = sctp_sk(ep->base.sk)->hmac;
+               desc.flags = 0;
+
+               if (crypto_hash_setkey(desc.tfm, ep->secret_key,
+                                      sizeof(ep->secret_key)) ||
                    crypto_hash_digest(&desc, &sg, bodysize, cookie->signature))
                        goto free_cookie;
        }
@@ -1354,8 +1679,7 @@ struct sctp_association *sctp_unpack_cookie(
        int headersize, bodysize, fixed_size;
        __u8 *digest = ep->digest;
        struct scatterlist sg;
-       unsigned int keylen, len;
-       char *key;
+       unsigned int len;
        sctp_scope_t scope;
        struct sk_buff *skb = chunk->skb;
        struct timeval tv;
@@ -1365,7 +1689,7 @@ struct sctp_association *sctp_unpack_cookie(
         * any padding.
         */
        headersize = sizeof(sctp_chunkhdr_t) +
-                    (sizeof(struct sctp_signed_cookie) - 
+                    (sizeof(struct sctp_signed_cookie) -
                      sizeof(struct sctp_cookie));
        bodysize = ntohs(chunk->chunk_hdr->length) - headersize;
        fixed_size = headersize + sizeof(struct sctp_cookie);
@@ -1390,36 +1714,21 @@ struct sctp_association *sctp_unpack_cookie(
                goto no_hmac;
 
        /* Check the signature.  */
-       keylen = SCTP_SECRET_SIZE;
-       sg.page = virt_to_page(bear_cookie);
-       sg.offset = (unsigned long)(bear_cookie) % PAGE_SIZE;
-       sg.length = bodysize;
-       key = (char *)ep->secret_key[ep->current_key];
+       sg_init_one(&sg, bear_cookie, bodysize);
        desc.tfm = sctp_sk(ep->base.sk)->hmac;
        desc.flags = 0;
 
        memset(digest, 0x00, SCTP_SIGNATURE_SIZE);
-       if (crypto_hash_setkey(desc.tfm, key, keylen) ||
+       if (crypto_hash_setkey(desc.tfm, ep->secret_key,
+                              sizeof(ep->secret_key)) ||
            crypto_hash_digest(&desc, &sg, bodysize, digest)) {
                *error = -SCTP_IERROR_NOMEM;
                goto fail;
        }
 
        if (memcmp(digest, cookie->signature, SCTP_SIGNATURE_SIZE)) {
-               /* Try the previous key. */
-               key = (char *)ep->secret_key[ep->last_key];
-               memset(digest, 0x00, SCTP_SIGNATURE_SIZE);
-               if (crypto_hash_setkey(desc.tfm, key, keylen) ||
-                   crypto_hash_digest(&desc, &sg, bodysize, digest)) {
-                       *error = -SCTP_IERROR_NOMEM;
-                       goto fail;
-               }
-
-               if (memcmp(digest, cookie->signature, SCTP_SIGNATURE_SIZE)) {
-                       /* Yikes!  Still bad signature! */
-                       *error = -SCTP_IERROR_BAD_SIG;
-                       goto fail;
-               }
+               *error = -SCTP_IERROR_BAD_SIG;
+               goto fail;
        }
 
 no_hmac:
@@ -1455,7 +1764,6 @@ no_hmac:
                do_gettimeofday(&tv);
 
        if (!asoc && tv_lt(bear_cookie->expiration, tv)) {
-               __u16 len;
                /*
                 * Section 3.3.10.3 Stale Cookie Error (3)
                 *
@@ -1473,7 +1781,8 @@ no_hmac:
                        __be32 n = htonl(usecs);
 
                        sctp_init_cause(*errp, SCTP_ERROR_STALE_COOKIE,
-                                       &n, sizeof(n));
+                                       sizeof(n));
+                       sctp_addto_chunk(*errp, sizeof(n), &n);
                        *error = -SCTP_IERROR_STALE_COOKIE;
                } else
                        *error = -SCTP_IERROR_NOMEM;
@@ -1503,8 +1812,8 @@ no_hmac:
 
        /* Also, add the destination address. */
        if (list_empty(&retval->base.bind_addr.address_list)) {
-               sctp_add_bind_addr(&retval->base.bind_addr, &chunk->dest, 1,
-                                  GFP_ATOMIC);
+               sctp_add_bind_addr(&retval->base.bind_addr, &chunk->dest,
+                               SCTP_ADDR_SRC, GFP_ATOMIC);
        }
 
        retval->next_tsn = retval->c.initial_tsn;
@@ -1512,7 +1821,7 @@ no_hmac:
        retval->addip_serial = retval->c.initial_tsn;
        retval->adv_peer_ack_point = retval->ctsn_ack_point;
        retval->peer.prsctp_capable = retval->c.prsctp_capable;
-       retval->peer.adaption_ind = retval->c.adaption_ind;
+       retval->peer.adaptation_ind = retval->c.adaptation_ind;
 
        /* The INIT stuff will be done by the side effects.  */
        return retval;
@@ -1538,7 +1847,7 @@ malformed:
 struct __sctp_missing {
        __be32 num_missing;
        __be16 type;
-}  __attribute__((packed));
+}  __packed;
 
 /*
  * Report a missing mandatory parameter.
@@ -1562,8 +1871,9 @@ static int sctp_process_missing_param(const struct sctp_association *asoc,
        if (*errp) {
                report.num_missing = htonl(1);
                report.type = paramtype;
-               sctp_init_cause(*errp, SCTP_ERROR_INV_PARAM,
-                               &report, sizeof(report));
+               sctp_init_cause(*errp, SCTP_ERROR_MISS_PARAM,
+                               sizeof(report));
+               sctp_addto_chunk(*errp, sizeof(report), &report);
        }
 
        /* Stop processing this chunk. */
@@ -1581,7 +1891,7 @@ static int sctp_process_inv_mandatory(const struct sctp_association *asoc,
                *errp = sctp_make_op_error_space(asoc, chunk, 0);
 
        if (*errp)
-               sctp_init_cause(*errp, SCTP_ERROR_INV_PARAM, NULL, 0);
+               sctp_init_cause(*errp, SCTP_ERROR_INV_PARAM, 0);
 
        /* Stop processing this chunk. */
        return 0;
@@ -1592,20 +1902,14 @@ static int sctp_process_inv_paramlength(const struct sctp_association *asoc,
                                        const struct sctp_chunk *chunk,
                                        struct sctp_chunk **errp)
 {
-       char            error[] = "The following parameter had invalid length:";
-       size_t          payload_len = WORD_ROUND(sizeof(error)) + 
-                                               sizeof(sctp_paramhdr_t);
-
+       /* This is a fatal error.  Any accumulated non-fatal errors are
+        * not reported.
+        */
+       if (*errp)
+               sctp_chunk_free(*errp);
 
        /* Create an error chunk and fill it in with our payload. */
-       if (!*errp)
-               *errp = sctp_make_op_error_space(asoc, chunk, payload_len);
-
-       if (*errp) {
-               sctp_init_cause(*errp, SCTP_ERROR_PROTO_VIOLATION, error,
-                               sizeof(error));
-               sctp_addto_chunk(*errp, sizeof(sctp_paramhdr_t), param);
-       }
+       *errp = sctp_make_violation_paramlen(asoc, chunk, param);
 
        return 0;
 }
@@ -1621,18 +1925,90 @@ static int sctp_process_hn_param(const struct sctp_association *asoc,
 {
        __u16 len = ntohs(param.p->length);
 
-       /* Make an ERROR chunk. */
-       if (!*errp)
-               *errp = sctp_make_op_error_space(asoc, chunk, len);
-
+       /* Processing of the HOST_NAME parameter will generate an
+        * ABORT.  If we've accumulated any non-fatal errors, they
+        * would be unrecognized parameters and we should not include
+        * them in the ABORT.
+        */
        if (*errp)
-               sctp_init_cause(*errp, SCTP_ERROR_DNS_FAILED,
-                               param.v, len);
+               sctp_chunk_free(*errp);
+
+       *errp = sctp_make_op_error_space(asoc, chunk, len);
+
+       if (*errp) {
+               sctp_init_cause(*errp, SCTP_ERROR_DNS_FAILED, len);
+               sctp_addto_chunk(*errp, len, param.v);
+       }
 
        /* Stop processing this chunk. */
        return 0;
 }
 
+static int sctp_verify_ext_param(struct net *net, union sctp_params param)
+{
+       __u16 num_ext = ntohs(param.p->length) - sizeof(sctp_paramhdr_t);
+       int have_auth = 0;
+       int have_asconf = 0;
+       int i;
+
+       for (i = 0; i < num_ext; i++) {
+               switch (param.ext->chunks[i]) {
+                   case SCTP_CID_AUTH:
+                           have_auth = 1;
+                           break;
+                   case SCTP_CID_ASCONF:
+                   case SCTP_CID_ASCONF_ACK:
+                           have_asconf = 1;
+                           break;
+               }
+       }
+
+       /* ADD-IP Security: The draft requires us to ABORT or ignore the
+        * INIT/INIT-ACK if ADD-IP is listed, but AUTH is not.  Do this
+        * only if ADD-IP is turned on and we are not backward-compatible
+        * mode.
+        */
+       if (net->sctp.addip_noauth)
+               return 1;
+
+       if (net->sctp.addip_enable && !have_auth && have_asconf)
+               return 0;
+
+       return 1;
+}
+
+static void sctp_process_ext_param(struct sctp_association *asoc,
+                                   union sctp_params param)
+{
+       struct net *net = sock_net(asoc->base.sk);
+       __u16 num_ext = ntohs(param.p->length) - sizeof(sctp_paramhdr_t);
+       int i;
+
+       for (i = 0; i < num_ext; i++) {
+               switch (param.ext->chunks[i]) {
+                   case SCTP_CID_FWD_TSN:
+                           if (net->sctp.prsctp_enable &&
+                               !asoc->peer.prsctp_capable)
+                                   asoc->peer.prsctp_capable = 1;
+                           break;
+                   case SCTP_CID_AUTH:
+                           /* if the peer reports AUTH, assume that he
+                            * supports AUTH.
+                            */
+                           if (net->sctp.auth_enable)
+                                   asoc->peer.auth_capable = 1;
+                           break;
+                   case SCTP_CID_ASCONF:
+                   case SCTP_CID_ASCONF_ACK:
+                           if (net->sctp.addip_enable)
+                                   asoc->peer.asconf_capable = 1;
+                           break;
+                   default:
+                           break;
+               }
+       }
+}
+
 /* RFC 3.2.1 & the Implementers Guide 2.2.
  *
  * The Parameter Types are encoded such that the
@@ -1640,74 +2016,61 @@ static int sctp_process_hn_param(const struct sctp_association *asoc,
  * taken if the processing endpoint does not recognize the
  * Parameter Type.
  *
- * 00 - Stop processing this SCTP chunk and discard it,
- *     do not process any further chunks within it.
+ * 00 - Stop processing this parameter; do not process any further
+ *     parameters within this chunk
  *
- * 01 - Stop processing this SCTP chunk and discard it,
- *     do not process any further chunks within it, and report
- *     the unrecognized parameter in an 'Unrecognized
- *     Parameter Type' (in either an ERROR or in the INIT ACK).
+ * 01 - Stop processing this parameter, do not process any further
+ *     parameters within this chunk, and report the unrecognized
+ *     parameter in an 'Unrecognized Parameter' ERROR chunk.
  *
  * 10 - Skip this parameter and continue processing.
  *
  * 11 - Skip this parameter and continue processing but
  *     report the unrecognized parameter in an
- *     'Unrecognized Parameter Type' (in either an ERROR or in
- *     the INIT ACK).
+ *     'Unrecognized Parameter' ERROR chunk.
  *
  * Return value:
- *     0 - discard the chunk
- *     1 - continue with the chunk
+ *     SCTP_IERROR_NO_ERROR - continue with the chunk
+ *     SCTP_IERROR_ERROR    - stop and report an error.
+ *     SCTP_IERROR_NOMEME   - out of memory.
  */
-static int sctp_process_unk_param(const struct sctp_association *asoc,
-                                 union sctp_params param,
-                                 struct sctp_chunk *chunk,
-                                 struct sctp_chunk **errp)
+static sctp_ierror_t sctp_process_unk_param(const struct sctp_association *asoc,
+                                           union sctp_params param,
+                                           struct sctp_chunk *chunk,
+                                           struct sctp_chunk **errp)
 {
-       int retval = 1;
+       int retval = SCTP_IERROR_NO_ERROR;
 
        switch (param.p->type & SCTP_PARAM_ACTION_MASK) {
        case SCTP_PARAM_ACTION_DISCARD:
-               retval =  0;
-               break;
-       case SCTP_PARAM_ACTION_DISCARD_ERR:
-               retval =  0;
-               /* Make an ERROR chunk, preparing enough room for
-                * returning multiple unknown parameters.
-                */
-               if (NULL == *errp)
-                       *errp = sctp_make_op_error_space(asoc, chunk,
-                                       ntohs(chunk->chunk_hdr->length));
-
-               if (*errp)
-                       sctp_init_cause(*errp, SCTP_ERROR_UNKNOWN_PARAM,
-                                       param.v,
-                                       WORD_ROUND(ntohs(param.p->length)));
-
+               retval =  SCTP_IERROR_ERROR;
                break;
        case SCTP_PARAM_ACTION_SKIP:
                break;
+       case SCTP_PARAM_ACTION_DISCARD_ERR:
+               retval =  SCTP_IERROR_ERROR;
+               /* Fall through */
        case SCTP_PARAM_ACTION_SKIP_ERR:
                /* Make an ERROR chunk, preparing enough room for
                 * returning multiple unknown parameters.
                 */
                if (NULL == *errp)
-                       *errp = sctp_make_op_error_space(asoc, chunk,
-                                       ntohs(chunk->chunk_hdr->length));
+                       *errp = sctp_make_op_error_fixed(asoc, chunk);
 
                if (*errp) {
-                       sctp_init_cause(*errp, SCTP_ERROR_UNKNOWN_PARAM,
-                                       param.v,
-                                       WORD_ROUND(ntohs(param.p->length)));
+                       if (!sctp_init_cause_fixed(*errp, SCTP_ERROR_UNKNOWN_PARAM,
+                                       WORD_ROUND(ntohs(param.p->length))))
+                               sctp_addto_chunk_fixed(*errp,
+                                               WORD_ROUND(ntohs(param.p->length)),
+                                               param.v);
                } else {
                        /* If there is no memory for generating the ERROR
                         * report as specified, an ABORT will be triggered
                         * to the peer and the association won't be
                         * established.
                         */
-                       retval = 0;
+                       retval = SCTP_IERROR_NOMEM;
                }
-
                break;
        default:
                break;
@@ -1716,18 +2079,24 @@ static int sctp_process_unk_param(const struct sctp_association *asoc,
        return retval;
 }
 
-/* Find unrecognized parameters in the chunk.
+/* Verify variable length parameters
  * Return values:
- *     0 - discard the chunk
- *     1 - continue with the chunk
+ *     SCTP_IERROR_ABORT - trigger an ABORT
+ *     SCTP_IERROR_NOMEM - out of memory (abort)
+ *     SCTP_IERROR_ERROR - stop processing, trigger an ERROR
+ *     SCTP_IERROR_NO_ERROR - continue with the chunk
  */
-static int sctp_verify_param(const struct sctp_association *asoc,
-                            union sctp_params param,
-                            sctp_cid_t cid,
-                            struct sctp_chunk *chunk,
-                            struct sctp_chunk **err_chunk)
+static sctp_ierror_t sctp_verify_param(struct net *net,
+                                       const struct sctp_association *asoc,
+                                       union sctp_params param,
+                                       sctp_cid_t cid,
+                                       struct sctp_chunk *chunk,
+                                       struct sctp_chunk **err_chunk)
 {
-       int retval = 1;
+       struct sctp_hmac_algo_param *hmacs;
+       int retval = SCTP_IERROR_NO_ERROR;
+       __u16 n_elt, id = 0;
+       int i;
 
        /* FIXME - This routine is not looking at each parameter per the
         * chunk type, i.e., unrecognized parameters should be further
@@ -1743,28 +2112,99 @@ static int sctp_verify_param(const struct sctp_association *asoc,
        case SCTP_PARAM_HEARTBEAT_INFO:
        case SCTP_PARAM_UNRECOGNIZED_PARAMETERS:
        case SCTP_PARAM_ECN_CAPABLE:
-       case SCTP_PARAM_ADAPTION_LAYER_IND:
+       case SCTP_PARAM_ADAPTATION_LAYER_IND:
+               break;
+
+       case SCTP_PARAM_SUPPORTED_EXT:
+               if (!sctp_verify_ext_param(net, param))
+                       return SCTP_IERROR_ABORT;
                break;
 
+       case SCTP_PARAM_SET_PRIMARY:
+               if (net->sctp.addip_enable)
+                       break;
+               goto fallthrough;
+
        case SCTP_PARAM_HOST_NAME_ADDRESS:
                /* Tell the peer, we won't support this param.  */
-               return sctp_process_hn_param(asoc, param, chunk, err_chunk);
+               sctp_process_hn_param(asoc, param, chunk, err_chunk);
+               retval = SCTP_IERROR_ABORT;
+               break;
+
        case SCTP_PARAM_FWD_TSN_SUPPORT:
-               if (sctp_prsctp_enable)
+               if (net->sctp.prsctp_enable)
                        break;
-               /* Fall Through */ 
+               goto fallthrough;
+
+       case SCTP_PARAM_RANDOM:
+               if (!net->sctp.auth_enable)
+                       goto fallthrough;
+
+               /* SCTP-AUTH: Secion 6.1
+                * If the random number is not 32 byte long the association
+                * MUST be aborted.  The ABORT chunk SHOULD contain the error
+                * cause 'Protocol Violation'.
+                */
+               if (SCTP_AUTH_RANDOM_LENGTH !=
+                       ntohs(param.p->length) - sizeof(sctp_paramhdr_t)) {
+                       sctp_process_inv_paramlength(asoc, param.p,
+                                                       chunk, err_chunk);
+                       retval = SCTP_IERROR_ABORT;
+               }
+               break;
+
+       case SCTP_PARAM_CHUNKS:
+               if (!net->sctp.auth_enable)
+                       goto fallthrough;
+
+               /* SCTP-AUTH: Section 3.2
+                * The CHUNKS parameter MUST be included once in the INIT or
+                *  INIT-ACK chunk if the sender wants to receive authenticated
+                *  chunks.  Its maximum length is 260 bytes.
+                */
+               if (260 < ntohs(param.p->length)) {
+                       sctp_process_inv_paramlength(asoc, param.p,
+                                                    chunk, err_chunk);
+                       retval = SCTP_IERROR_ABORT;
+               }
+               break;
+
+       case SCTP_PARAM_HMAC_ALGO:
+               if (!net->sctp.auth_enable)
+                       goto fallthrough;
+
+               hmacs = (struct sctp_hmac_algo_param *)param.p;
+               n_elt = (ntohs(param.p->length) - sizeof(sctp_paramhdr_t)) >> 1;
+
+               /* SCTP-AUTH: Section 6.1
+                * The HMAC algorithm based on SHA-1 MUST be supported and
+                * included in the HMAC-ALGO parameter.
+                */
+               for (i = 0; i < n_elt; i++) {
+                       id = ntohs(hmacs->hmac_ids[i]);
+
+                       if (id == SCTP_AUTH_HMAC_ID_SHA1)
+                               break;
+               }
+
+               if (id != SCTP_AUTH_HMAC_ID_SHA1) {
+                       sctp_process_inv_paramlength(asoc, param.p, chunk,
+                                                    err_chunk);
+                       retval = SCTP_IERROR_ABORT;
+               }
+               break;
+fallthrough:
        default:
                SCTP_DEBUG_PRINTK("Unrecognized param: %d for chunk %d.\n",
                                ntohs(param.p->type), cid);
-               return sctp_process_unk_param(asoc, param, chunk, err_chunk);
-
+               retval = sctp_process_unk_param(asoc, param, chunk, err_chunk);
                break;
        }
        return retval;
 }
 
 /* Verify the INIT packet before we process it.  */
-int sctp_verify_init(const struct sctp_association *asoc,
+int sctp_verify_init(struct net *net, const struct sctp_association *asoc,
                     sctp_cid_t cid,
                     sctp_init_chunk_t *peer_init,
                     struct sctp_chunk *chunk,
@@ -1772,13 +2212,15 @@ int sctp_verify_init(const struct sctp_association *asoc,
 {
        union sctp_params param;
        int has_cookie = 0;
+       int result;
 
        /* Verify stream values are non-zero. */
        if ((0 == peer_init->init_hdr.num_outbound_streams) ||
-           (0 == peer_init->init_hdr.num_inbound_streams)) {
+           (0 == peer_init->init_hdr.num_inbound_streams) ||
+           (0 == peer_init->init_hdr.init_tag) ||
+           (SCTP_DEFAULT_MINWINDOW > ntohl(peer_init->init_hdr.a_rwnd))) {
 
-               sctp_process_inv_mandatory(asoc, chunk, errp);
-               return 0;
+               return sctp_process_inv_mandatory(asoc, chunk, errp);
        }
 
        /* Check for missing mandatory parameters.  */
@@ -1796,29 +2238,29 @@ int sctp_verify_init(const struct sctp_association *asoc,
         * VIOLATION error.  We build the ERROR chunk here and let the normal
         * error handling code build and send the packet.
         */
-       if (param.v < (void*)chunk->chunk_end - sizeof(sctp_paramhdr_t)) {
-               sctp_process_inv_paramlength(asoc, param.p, chunk, errp);
-               return 0;
-       }
+       if (param.v != (void*)chunk->chunk_end)
+               return sctp_process_inv_paramlength(asoc, param.p, chunk, errp);
 
        /* The only missing mandatory param possible today is
         * the state cookie for an INIT-ACK chunk.
         */
-       if ((SCTP_CID_INIT_ACK == cid) && !has_cookie) {
-               sctp_process_missing_param(asoc, SCTP_PARAM_STATE_COOKIE,
-                                          chunk, errp);
-               return 0;
-       }
-
-       /* Find unrecognized parameters. */
+       if ((SCTP_CID_INIT_ACK == cid) && !has_cookie)
+               return sctp_process_missing_param(asoc, SCTP_PARAM_STATE_COOKIE,
+                                                 chunk, errp);
 
+       /* Verify all the variable length parameters */
        sctp_walk_params(param, peer_init, init_hdr.params) {
 
-               if (!sctp_verify_param(asoc, param, cid, chunk, errp)) {
-                       if (SCTP_PARAM_HOST_NAME_ADDRESS == param.p->type)
+               result = sctp_verify_param(net, asoc, param, cid, chunk, errp);
+               switch (result) {
+                   case SCTP_IERROR_ABORT:
+                   case SCTP_IERROR_NOMEM:
                                return 0;
-                       else
+                   case SCTP_IERROR_ERROR:
                                return 1;
+                   case SCTP_IERROR_NO_ERROR:
+                   default:
+                               break;
                }
 
        } /* for (loop through all parameters) */
@@ -1830,14 +2272,18 @@ int sctp_verify_init(const struct sctp_association *asoc,
  * Returns 0 on failure, else success.
  * FIXME:  This is an association method.
  */
-int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid,
+int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
                      const union sctp_addr *peer_addr,
                      sctp_init_chunk_t *peer_init, gfp_t gfp)
 {
+       struct net *net = sock_net(asoc->base.sk);
        union sctp_params param;
        struct sctp_transport *transport;
        struct list_head *pos, *temp;
+       struct sctp_af *af;
+       union sctp_addr addr;
        char *cookie;
+       int src_match = 0;
 
        /* We must include the address that the INIT packet came from.
         * This is the only address that matters for an INIT packet.
@@ -1849,17 +2295,51 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid,
         * added as the primary transport.  The source address seems to
         * be a a better choice than any of the embedded addresses.
         */
-       if (peer_addr) {
-               if(!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE))
-                       goto nomem;
-       }
+       if(!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE))
+               goto nomem;
 
-       /* Process the initialization parameters.  */
+       if (sctp_cmp_addr_exact(sctp_source(chunk), peer_addr))
+               src_match = 1;
 
+       /* Process the initialization parameters.  */
        sctp_walk_params(param, peer_init, init_hdr.params) {
+               if (!src_match && (param.p->type == SCTP_PARAM_IPV4_ADDRESS ||
+                   param.p->type == SCTP_PARAM_IPV6_ADDRESS)) {
+                       af = sctp_get_af_specific(param_type2af(param.p->type));
+                       af->from_addr_param(&addr, param.addr,
+                                           chunk->sctp_hdr->source, 0);
+                       if (sctp_cmp_addr_exact(sctp_source(chunk), &addr))
+                               src_match = 1;
+               }
 
                if (!sctp_process_param(asoc, param, peer_addr, gfp))
-                        goto clean_up;
+                       goto clean_up;
+       }
+
+       /* source address of chunk may not match any valid address */
+       if (!src_match)
+               goto clean_up;
+
+       /* AUTH: After processing the parameters, make sure that we
+        * have all the required info to potentially do authentications.
+        */
+       if (asoc->peer.auth_capable && (!asoc->peer.peer_random ||
+                                       !asoc->peer.peer_hmacs))
+               asoc->peer.auth_capable = 0;
+
+       /* In a non-backward compatible mode, if the peer claims
+        * support for ADD-IP but not AUTH,  the ADD-IP spec states
+        * that we MUST ABORT the association. Section 6.  The section
+        * also give us an option to silently ignore the packet, which
+        * is what we'll do here.
+        */
+       if (!net->sctp.addip_noauth &&
+            (asoc->peer.asconf_capable && !asoc->peer.auth_capable)) {
+               asoc->peer.addip_disabled_mask |= (SCTP_PARAM_ADD_IP |
+                                                 SCTP_PARAM_DEL_IP |
+                                                 SCTP_PARAM_SET_PRIMARY);
+               asoc->peer.asconf_capable = 0;
+               goto clean_up;
        }
 
        /* Walk list of transports, removing transports in the UNKNOWN state. */
@@ -1917,14 +2397,15 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid,
         * high (for example, implementations MAY use the size of the receiver
         * advertised window).
         */
-       list_for_each(pos, &asoc->peer.transport_addr_list) {
-               transport = list_entry(pos, struct sctp_transport, transports);
+       list_for_each_entry(transport, &asoc->peer.transport_addr_list,
+                       transports) {
                transport->ssthresh = asoc->peer.i.a_rwnd;
        }
 
        /* Set up the TSN tracking pieces.  */
-       sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_SIZE,
-                        asoc->peer.i.initial_tsn);
+       if (!sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL,
+                               asoc->peer.i.initial_tsn, gfp))
+               goto clean_up;
 
        /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
         *
@@ -1935,10 +2416,9 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid,
         */
 
        /* Allocate storage for the negotiated streams if it is not a temporary
-        * association.
+        * association.
         */
        if (!asoc->temp) {
-               int assoc_id;
                int error;
 
                asoc->ssnmap = sctp_ssnmap_new(asoc->c.sinit_max_instreams,
@@ -1946,19 +2426,9 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid,
                if (!asoc->ssnmap)
                        goto clean_up;
 
-       retry:
-               if (unlikely(!idr_pre_get(&sctp_assocs_id, gfp)))
+               error = sctp_assoc_set_id(asoc, gfp);
+               if (error)
                        goto clean_up;
-               spin_lock_bh(&sctp_assocs_id_lock);
-               error = idr_get_new_above(&sctp_assocs_id, (void *)asoc, 1,
-                                         &assoc_id);
-               spin_unlock_bh(&sctp_assocs_id_lock);
-               if (error == -EAGAIN)
-                       goto retry;
-               else if (error)
-                       goto clean_up;
-
-               asoc->assoc_id = (sctp_assoc_t) assoc_id;
        }
 
        /* ADDIP Section 4.1 ASCONF Chunk Procedures
@@ -1978,12 +2448,10 @@ clean_up:
        /* Release the transport structures. */
        list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
                transport = list_entry(pos, struct sctp_transport, transports);
-               list_del_init(pos);
-               sctp_transport_free(transport);
+               if (transport->state != SCTP_ACTIVE)
+                       sctp_assoc_rm_peer(asoc, transport);
        }
 
-       asoc->peer.transport_count = 0;
-
 nomem:
        return 0;
 }
@@ -2005,6 +2473,7 @@ static int sctp_process_param(struct sctp_association *asoc,
                              const union sctp_addr *peer_addr,
                              gfp_t gfp)
 {
+       struct net *net = sock_net(asoc->base.sk);
        union sctp_addr addr;
        int i;
        __u16 sat;
@@ -2012,6 +2481,8 @@ static int sctp_process_param(struct sctp_association *asoc,
        sctp_scope_t scope;
        time_t stale;
        struct sctp_af *af;
+       union sctp_addr_param *addr_param;
+       struct sctp_transport *t;
 
        /* We maintain all INIT parameters in network byte order all the
         * time.  This allows us to not worry about whether the parameters
@@ -2021,18 +2492,23 @@ static int sctp_process_param(struct sctp_association *asoc,
        case SCTP_PARAM_IPV6_ADDRESS:
                if (PF_INET6 != asoc->base.sk->sk_family)
                        break;
-               /* Fall through. */
+               goto do_addr_param;
+
        case SCTP_PARAM_IPV4_ADDRESS:
+               /* v4 addresses are not allowed on v6-only socket */
+               if (ipv6_only_sock(asoc->base.sk))
+                       break;
+do_addr_param:
                af = sctp_get_af_specific(param_type2af(param.p->type));
                af->from_addr_param(&addr, param.addr, htons(asoc->peer.port), 0);
                scope = sctp_scope(peer_addr);
-               if (sctp_in_scope(&addr, scope))
+               if (sctp_in_scope(net, &addr, scope))
                        if (!sctp_assoc_add_peer(asoc, &addr, gfp, SCTP_UNCONFIRMED))
                                return 0;
                break;
 
        case SCTP_PARAM_COOKIE_PRESERVATIVE:
-               if (!sctp_cookie_preserve_enable)
+               if (!net->sctp.cookie_preserve_enable)
                        break;
 
                stale = ntohl(param.life->lifespan_increment);
@@ -2055,6 +2531,14 @@ static int sctp_process_param(struct sctp_association *asoc,
                asoc->peer.ipv4_address = 0;
                asoc->peer.ipv6_address = 0;
 
+               /* Assume that peer supports the address family
+                * by which it sends a packet.
+                */
+               if (peer_addr->sa.sa_family == AF_INET6)
+                       asoc->peer.ipv6_address = 1;
+               else if (peer_addr->sa.sa_family == AF_INET)
+                       asoc->peer.ipv4_address = 1;
+
                /* Cycle through address types; avoid divide by 0. */
                sat = ntohs(param.p->length) - sizeof(sctp_paramhdr_t);
                if (sat)
@@ -2067,7 +2551,8 @@ static int sctp_process_param(struct sctp_association *asoc,
                                break;
 
                        case SCTP_PARAM_IPV6_ADDRESS:
-                               asoc->peer.ipv6_address = 1;
+                               if (PF_INET6 == asoc->base.sk->sk_family)
+                                       asoc->peer.ipv6_address = 1;
                                break;
 
                        case SCTP_PARAM_HOST_NAME_ADDRESS:
@@ -2076,7 +2561,7 @@ static int sctp_process_param(struct sctp_association *asoc,
 
                        default: /* Just ignore anything else.  */
                                break;
-                       };
+                       }
                }
                break;
 
@@ -2098,16 +2583,84 @@ static int sctp_process_param(struct sctp_association *asoc,
                asoc->peer.ecn_capable = 1;
                break;
 
-       case SCTP_PARAM_ADAPTION_LAYER_IND:
-               asoc->peer.adaption_ind = param.aind->adaption_ind;
+       case SCTP_PARAM_ADAPTATION_LAYER_IND:
+               asoc->peer.adaptation_ind = ntohl(param.aind->adaptation_ind);
+               break;
+
+       case SCTP_PARAM_SET_PRIMARY:
+               if (!net->sctp.addip_enable)
+                       goto fall_through;
+
+               addr_param = param.v + sizeof(sctp_addip_param_t);
+
+               af = sctp_get_af_specific(param_type2af(param.p->type));
+               af->from_addr_param(&addr, addr_param,
+                                   htons(asoc->peer.port), 0);
+
+               /* if the address is invalid, we can't process it.
+                * XXX: see spec for what to do.
+                */
+               if (!af->addr_valid(&addr, NULL, NULL))
+                       break;
+
+               t = sctp_assoc_lookup_paddr(asoc, &addr);
+               if (!t)
+                       break;
+
+               sctp_assoc_set_primary(asoc, t);
+               break;
+
+       case SCTP_PARAM_SUPPORTED_EXT:
+               sctp_process_ext_param(asoc, param);
                break;
 
        case SCTP_PARAM_FWD_TSN_SUPPORT:
-               if (sctp_prsctp_enable) {
+               if (net->sctp.prsctp_enable) {
                        asoc->peer.prsctp_capable = 1;
                        break;
                }
-               /* Fall Through */ 
+               /* Fall Through */
+               goto fall_through;
+
+       case SCTP_PARAM_RANDOM:
+               if (!net->sctp.auth_enable)
+                       goto fall_through;
+
+               /* Save peer's random parameter */
+               asoc->peer.peer_random = kmemdup(param.p,
+                                           ntohs(param.p->length), gfp);
+               if (!asoc->peer.peer_random) {
+                       retval = 0;
+                       break;
+               }
+               break;
+
+       case SCTP_PARAM_HMAC_ALGO:
+               if (!net->sctp.auth_enable)
+                       goto fall_through;
+
+               /* Save peer's HMAC list */
+               asoc->peer.peer_hmacs = kmemdup(param.p,
+                                           ntohs(param.p->length), gfp);
+               if (!asoc->peer.peer_hmacs) {
+                       retval = 0;
+                       break;
+               }
+
+               /* Set the default HMAC the peer requested*/
+               sctp_auth_asoc_set_default_hmac(asoc, param.hmac_algo);
+               break;
+
+       case SCTP_PARAM_CHUNKS:
+               if (!net->sctp.auth_enable)
+                       goto fall_through;
+
+               asoc->peer.peer_chunks = kmemdup(param.p,
+                                           ntohs(param.p->length), gfp);
+               if (!asoc->peer.peer_chunks)
+                       retval = 0;
+               break;
+fall_through:
        default:
                /* Any unrecognized parameters should have been caught
                 * and handled by sctp_verify_param() which should be
@@ -2117,7 +2670,7 @@ static int sctp_process_param(struct sctp_association *asoc,
                SCTP_DEBUG_PRINTK("Ignoring param: %d for association %p.\n",
                                  ntohs(param.p->type), asoc);
                break;
-       };
+       }
 
        return retval;
 }
@@ -2166,7 +2719,7 @@ __u32 sctp_generate_tsn(const struct sctp_endpoint *ep)
  *     |                     ASCONF Parameter #N                       |
  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  *
- * Address Parameter and other parameter will not be wrapped in this function 
+ * Address Parameter and other parameter will not be wrapped in this function
  */
 static struct sctp_chunk *sctp_make_asconf(struct sctp_association *asoc,
                                           union sctp_addr *addr,
@@ -2239,11 +2792,12 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
        int                     addr_param_len = 0;
        int                     totallen = 0;
        int                     i;
+       int                     del_pickup = 0;
 
        /* Get total length of all the address parameters. */
        addr_buf = addrs;
        for (i = 0; i < addrcnt; i++) {
-               addr = (union sctp_addr *)addr_buf;
+               addr = addr_buf;
                af = sctp_get_af_specific(addr->v4.sin_family);
                addr_param_len = af->to_addr_param(addr, &addr_param);
 
@@ -2251,6 +2805,13 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
                totallen += addr_param_len;
 
                addr_buf += af->sockaddr_len;
+               if (asoc->asconf_addr_del_pending && !del_pickup) {
+                       /* reuse the parameter length from the same scope one */
+                       totallen += paramlen;
+                       totallen += addr_param_len;
+                       del_pickup = 1;
+                       SCTP_DEBUG_PRINTK("mkasconf_update_ip: picked same-scope del_pending addr, totallen for all addresses is %d\n", totallen);
+               }
        }
 
        /* Create an asconf chunk with the required length. */
@@ -2261,7 +2822,7 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
        /* Add the address parameters to the asconf chunk. */
        addr_buf = addrs;
        for (i = 0; i < addrcnt; i++) {
-               addr = (union sctp_addr *)addr_buf;
+               addr = addr_buf;
                af = sctp_get_af_specific(addr->v4.sin_family);
                addr_param_len = af->to_addr_param(addr, &addr_param);
                param.param_hdr.type = flags;
@@ -2273,6 +2834,17 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
 
                addr_buf += af->sockaddr_len;
        }
+       if (flags == SCTP_PARAM_ADD_IP && del_pickup) {
+               addr = asoc->asconf_addr_del_pending;
+               af = sctp_get_af_specific(addr->v4.sin_family);
+               addr_param_len = af->to_addr_param(addr, &addr_param);
+               param.param_hdr.type = SCTP_PARAM_DEL_IP;
+               param.param_hdr.length = htons(paramlen + addr_param_len);
+               param.crr_id = i;
+
+               sctp_addto_chunk(retval, paramlen, &param);
+               sctp_addto_chunk(retval, addr_param_len, &addr_param);
+       }
        return retval;
 }
 
@@ -2288,7 +2860,7 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
  *     |                       Address Parameter                       |
  *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  *
- * Create an ASCONF chunk with Set Primary IP address parameter. 
+ * Create an ASCONF chunk with Set Primary IP address parameter.
  */
 struct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc,
                                             union sctp_addr *addr)
@@ -2337,7 +2909,7 @@ struct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc,
  *     |                 ASCONF Parameter Response#N                   |
  *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  *
- * Create an ASCONF_ACK chunk with enough space for the parameter responses. 
+ * Create an ASCONF_ACK chunk with enough space for the parameter responses.
  */
 static struct sctp_chunk *sctp_make_asconf_ack(const struct sctp_association *asoc,
                                               __u32 serial, int vparam_len)
@@ -2379,7 +2951,7 @@ static void sctp_add_asconf_response(struct sctp_chunk *chunk, __be32 crr_id,
                                 ntohs(asconf_param->param_hdr.length);
        }
 
-       /* Add Success Indication or Error Cause Indication parameter. */ 
+       /* Add Success Indication or Error Cause Indication parameter. */
        ack_param.param_hdr.type = response_type;
        ack_param.param_hdr.length = htons(sizeof(ack_param) +
                                           err_param_len +
@@ -2408,25 +2980,57 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
        struct sctp_transport *peer;
        struct sctp_af *af;
        union sctp_addr addr;
-       struct list_head *pos;
        union sctp_addr_param *addr_param;
 
-       addr_param = (union sctp_addr_param *)
-                       ((void *)asconf_param + sizeof(sctp_addip_param_t));
+       addr_param = (void *)asconf_param + sizeof(sctp_addip_param_t);
+
+       if (asconf_param->param_hdr.type != SCTP_PARAM_ADD_IP &&
+           asconf_param->param_hdr.type != SCTP_PARAM_DEL_IP &&
+           asconf_param->param_hdr.type != SCTP_PARAM_SET_PRIMARY)
+               return SCTP_ERROR_UNKNOWN_PARAM;
 
-       af = sctp_get_af_specific(param_type2af(addr_param->v4.param_hdr.type));
+       switch (addr_param->p.type) {
+       case SCTP_PARAM_IPV6_ADDRESS:
+               if (!asoc->peer.ipv6_address)
+                       return SCTP_ERROR_DNS_FAILED;
+               break;
+       case SCTP_PARAM_IPV4_ADDRESS:
+               if (!asoc->peer.ipv4_address)
+                       return SCTP_ERROR_DNS_FAILED;
+               break;
+       default:
+               return SCTP_ERROR_DNS_FAILED;
+       }
+
+       af = sctp_get_af_specific(param_type2af(addr_param->p.type));
        if (unlikely(!af))
-               return SCTP_ERROR_INV_PARAM;
+               return SCTP_ERROR_DNS_FAILED;
 
        af->from_addr_param(&addr, addr_param, htons(asoc->peer.port), 0);
+
+       /* ADDIP 4.2.1  This parameter MUST NOT contain a broadcast
+        * or multicast address.
+        * (note: wildcard is permitted and requires special handling so
+        *  make sure we check for that)
+        */
+       if (!af->is_any(&addr) && !af->addr_valid(&addr, NULL, asconf->skb))
+               return SCTP_ERROR_DNS_FAILED;
+
        switch (asconf_param->param_hdr.type) {
        case SCTP_PARAM_ADD_IP:
+               /* Section 4.2.1:
+                * If the address 0.0.0.0 or ::0 is provided, the source
+                * address of the packet MUST be added.
+                */
+               if (af->is_any(&addr))
+                       memcpy(&addr, &asconf->source, sizeof(addr));
+
                /* ADDIP 4.3 D9) If an endpoint receives an ADD IP address
-                * request and does not have the local resources to add this
-                * new address to the association, it MUST return an Error
-                * Cause TLV set to the new error code 'Operation Refused
-                * Due to Resource Shortage'.
-                */
+                * request and does not have the local resources to add this
+                * new address to the association, it MUST return an Error
+                * Cause TLV set to the new error code 'Operation Refused
+                * Due to Resource Shortage'.
+                */
 
                peer = sctp_assoc_add_peer(asoc, &addr, GFP_ATOMIC, SCTP_UNCONFIRMED);
                if (!peer)
@@ -2435,15 +3039,15 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
                /* Start the heartbeat timer. */
                if (!mod_timer(&peer->hb_timer, sctp_transport_timeout(peer)))
                        sctp_transport_hold(peer);
+               asoc->new_transport = peer;
                break;
        case SCTP_PARAM_DEL_IP:
                /* ADDIP 4.3 D7) If a request is received to delete the
-                * last remaining IP address of a peer endpoint, the receiver
-                * MUST send an Error Cause TLV with the error cause set to the
-                * new error code 'Request to Delete Last Remaining IP Address'.
-                */
-               pos = asoc->peer.transport_addr_list.next;
-               if (pos->next == &asoc->peer.transport_addr_list)
+                * last remaining IP address of a peer endpoint, the receiver
+                * MUST send an Error Cause TLV with the error cause set to the
+                * new error code 'Request to Delete Last Remaining IP Address'.
+                */
+               if (asoc->peer.transport_count == 1)
                        return SCTP_ERROR_DEL_LAST_IP;
 
                /* ADDIP 4.3 D8) If a request is received to delete an IP
@@ -2453,27 +3057,88 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
                 * an Error Cause TLV set to the new error code 'Request to
                 * Delete Source IP Address'
                 */
-               if (sctp_cmp_addr_exact(sctp_source(asconf), &addr))
+               if (sctp_cmp_addr_exact(&asconf->source, &addr))
                        return SCTP_ERROR_DEL_SRC_IP;
 
-               sctp_assoc_del_peer(asoc, &addr);
+               /* Section 4.2.2
+                * If the address 0.0.0.0 or ::0 is provided, all
+                * addresses of the peer except the source address of the
+                * packet MUST be deleted.
+                */
+               if (af->is_any(&addr)) {
+                       sctp_assoc_set_primary(asoc, asconf->transport);
+                       sctp_assoc_del_nonprimary_peers(asoc,
+                                                       asconf->transport);
+               } else
+                       sctp_assoc_del_peer(asoc, &addr);
                break;
        case SCTP_PARAM_SET_PRIMARY:
+               /* ADDIP Section 4.2.4
+                * If the address 0.0.0.0 or ::0 is provided, the receiver
+                * MAY mark the source address of the packet as its
+                * primary.
+                */
+               if (af->is_any(&addr))
+                       memcpy(&addr.v4, sctp_source(asconf), sizeof(addr));
+
                peer = sctp_assoc_lookup_paddr(asoc, &addr);
                if (!peer)
-                       return SCTP_ERROR_INV_PARAM;
+                       return SCTP_ERROR_DNS_FAILED;
 
                sctp_assoc_set_primary(asoc, peer);
                break;
-       default:
-               return SCTP_ERROR_INV_PARAM;
-               break;
        }
 
        return SCTP_ERROR_NO_ERROR;
 }
 
-/* Process an incoming ASCONF chunk with the next expected serial no. and 
+/* Verify the ASCONF packet before we process it.  */
+int sctp_verify_asconf(const struct sctp_association *asoc,
+                      struct sctp_paramhdr *param_hdr, void *chunk_end,
+                      struct sctp_paramhdr **errp) {
+       sctp_addip_param_t *asconf_param;
+       union sctp_params param;
+       int length, plen;
+
+       param.v = (sctp_paramhdr_t *) param_hdr;
+       while (param.v <= chunk_end - sizeof(sctp_paramhdr_t)) {
+               length = ntohs(param.p->length);
+               *errp = param.p;
+
+               if (param.v > chunk_end - length ||
+                   length < sizeof(sctp_paramhdr_t))
+                       return 0;
+
+               switch (param.p->type) {
+               case SCTP_PARAM_ADD_IP:
+               case SCTP_PARAM_DEL_IP:
+               case SCTP_PARAM_SET_PRIMARY:
+                       asconf_param = (sctp_addip_param_t *)param.v;
+                       plen = ntohs(asconf_param->param_hdr.length);
+                       if (plen < sizeof(sctp_addip_param_t) +
+                           sizeof(sctp_paramhdr_t))
+                               return 0;
+                       break;
+               case SCTP_PARAM_SUCCESS_REPORT:
+               case SCTP_PARAM_ADAPTATION_LAYER_IND:
+                       if (length != sizeof(sctp_addip_param_t))
+                               return 0;
+
+                       break;
+               default:
+                       break;
+               }
+
+               param.v += WORD_ROUND(length);
+       }
+
+       if (param.v != chunk_end)
+               return 0;
+
+       return 1;
+}
+
+/* Process an incoming ASCONF chunk with the next expected serial no. and
  * return an ASCONF_ACK chunk to be sent in response.
  */
 struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
@@ -2486,31 +3151,32 @@ struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
 
        __be16  err_code;
        int     length = 0;
-       int     chunk_len = asconf->skb->len;
+       int     chunk_len;
        __u32   serial;
        int     all_param_pass = 1;
 
+       chunk_len = ntohs(asconf->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
        hdr = (sctp_addiphdr_t *)asconf->skb->data;
        serial = ntohl(hdr->serial);
 
-       /* Skip the addiphdr and store a pointer to address parameter.  */ 
+       /* Skip the addiphdr and store a pointer to address parameter.  */
        length = sizeof(sctp_addiphdr_t);
        addr_param = (union sctp_addr_param *)(asconf->skb->data + length);
        chunk_len -= length;
 
        /* Skip the address parameter and store a pointer to the first
-        * asconf paramter.
-        */ 
-       length = ntohs(addr_param->v4.param_hdr.length);
-       asconf_param = (sctp_addip_param_t *)((void *)addr_param + length);
+        * asconf parameter.
+        */
+       length = ntohs(addr_param->p.length);
+       asconf_param = (void *)addr_param + length;
        chunk_len -= length;
 
-       /* create an ASCONF_ACK chunk. 
+       /* create an ASCONF_ACK chunk.
         * Based on the definitions of parameters, we know that the size of
-        * ASCONF_ACK parameters are less than or equal to the twice of ASCONF
-        * paramters.
+        * ASCONF_ACK parameters are less than or equal to the fourfold of ASCONF
+        * parameters.
         */
-       asconf_ack = sctp_make_asconf_ack(asoc, serial, chunk_len * 2);
+       asconf_ack = sctp_make_asconf_ack(asoc, serial, chunk_len * 4);
        if (!asconf_ack)
                goto done;
 
@@ -2536,91 +3202,89 @@ struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
                /* ADDIP 4.3 D11) When an endpoint receiving an ASCONF to add
                 * an IP address sends an 'Out of Resource' in its response, it
                 * MUST also fail any subsequent add or delete requests bundled
-                * in the ASCONF. 
+                * in the ASCONF.
                 */
                if (SCTP_ERROR_RSRC_LOW == err_code)
                        goto done;
 
                /* Move to the next ASCONF param. */
                length = ntohs(asconf_param->param_hdr.length);
-               asconf_param = (sctp_addip_param_t *)((void *)asconf_param +
-                                                     length);
+               asconf_param = (void *)asconf_param + length;
                chunk_len -= length;
        }
-       
+
 done:
        asoc->peer.addip_serial++;
 
        /* If we are sending a new ASCONF_ACK hold a reference to it in assoc
-        * after freeing the reference to old asconf ack if any. 
+        * after freeing the reference to old asconf ack if any.
         */
        if (asconf_ack) {
-               if (asoc->addip_last_asconf_ack)
-                       sctp_chunk_free(asoc->addip_last_asconf_ack);
-
                sctp_chunk_hold(asconf_ack);
-               asoc->addip_last_asconf_ack = asconf_ack;
+               list_add_tail(&asconf_ack->transmitted_list,
+                             &asoc->asconf_ack_list);
        }
 
        return asconf_ack;
 }
 
 /* Process a asconf parameter that is successfully acked. */
-static int sctp_asconf_param_success(struct sctp_association *asoc,
+static void sctp_asconf_param_success(struct sctp_association *asoc,
                                     sctp_addip_param_t *asconf_param)
 {
        struct sctp_af *af;
        union sctp_addr addr;
        struct sctp_bind_addr *bp = &asoc->base.bind_addr;
        union sctp_addr_param *addr_param;
-       struct list_head *pos;
        struct sctp_transport *transport;
        struct sctp_sockaddr_entry *saddr;
-       int retval = 0;
 
-       addr_param = (union sctp_addr_param *)
-                       ((void *)asconf_param + sizeof(sctp_addip_param_t));
+       addr_param = (void *)asconf_param + sizeof(sctp_addip_param_t);
 
        /* We have checked the packet before, so we do not check again. */
-       af = sctp_get_af_specific(param_type2af(addr_param->v4.param_hdr.type));
+       af = sctp_get_af_specific(param_type2af(addr_param->p.type));
        af->from_addr_param(&addr, addr_param, htons(bp->port), 0);
 
        switch (asconf_param->param_hdr.type) {
        case SCTP_PARAM_ADD_IP:
-               sctp_local_bh_disable();
-               sctp_write_lock(&asoc->base.addr_lock);
-               list_for_each(pos, &bp->address_list) {
-                       saddr = list_entry(pos, struct sctp_sockaddr_entry, list);
+               /* This is always done in BH context with a socket lock
+                * held, so the list can not change.
+                */
+               local_bh_disable();
+               list_for_each_entry(saddr, &bp->address_list, list) {
                        if (sctp_cmp_addr_exact(&saddr->a, &addr))
-                               saddr->use_as_src = 1;
+                               saddr->state = SCTP_ADDR_SRC;
+               }
+               local_bh_enable();
+               list_for_each_entry(transport, &asoc->peer.transport_addr_list,
+                               transports) {
+                       dst_release(transport->dst);
+                       transport->dst = NULL;
                }
-               sctp_write_unlock(&asoc->base.addr_lock);
-               sctp_local_bh_enable();
                break;
        case SCTP_PARAM_DEL_IP:
-               sctp_local_bh_disable();
-               sctp_write_lock(&asoc->base.addr_lock);
-               retval = sctp_del_bind_addr(bp, &addr);
-               sctp_write_unlock(&asoc->base.addr_lock);
-               sctp_local_bh_enable();
-               list_for_each(pos, &asoc->peer.transport_addr_list) {
-                       transport = list_entry(pos, struct sctp_transport,
-                                                transports);
+               local_bh_disable();
+               sctp_del_bind_addr(bp, &addr);
+               if (asoc->asconf_addr_del_pending != NULL &&
+                   sctp_cmp_addr_exact(asoc->asconf_addr_del_pending, &addr)) {
+                       kfree(asoc->asconf_addr_del_pending);
+                       asoc->asconf_addr_del_pending = NULL;
+               }
+               local_bh_enable();
+               list_for_each_entry(transport, &asoc->peer.transport_addr_list,
+                               transports) {
                        dst_release(transport->dst);
-                       sctp_transport_route(transport, NULL,
-                                            sctp_sk(asoc->base.sk));
+                       transport->dst = NULL;
                }
                break;
        default:
                break;
        }
-
-       return retval;
 }
 
 /* Get the corresponding ASCONF response error code from the ASCONF_ACK chunk
  * for the given asconf parameter.  If there is no response for this parameter,
- * return the error code based on the third argument 'no_err'. 
+ * return the error code based on the third argument 'no_err'.
  * ADDIP 4.1
  * A7) If an error response is received for a TLV parameter, all TLVs with no
  * response before the failed TLV are considered successful if not reported.
@@ -2634,7 +3298,7 @@ static __be16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack,
        sctp_addip_param_t      *asconf_ack_param;
        sctp_errhdr_t           *err_param;
        int                     length;
-       int                     asconf_ack_len = asconf_ack->skb->len;
+       int                     asconf_ack_len;
        __be16                  err_code;
 
        if (no_err)
@@ -2642,9 +3306,12 @@ static __be16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack,
        else
                err_code = SCTP_ERROR_REQ_REFUSED;
 
+       asconf_ack_len = ntohs(asconf_ack->chunk_hdr->length) -
+                            sizeof(sctp_chunkhdr_t);
+
        /* Skip the addiphdr from the asconf_ack chunk and store a pointer to
         * the first asconf_ack parameter.
-        */ 
+        */
        length = sizeof(sctp_addiphdr_t);
        asconf_ack_param = (sctp_addip_param_t *)(asconf_ack->skb->data +
                                                  length);
@@ -2657,8 +3324,7 @@ static __be16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack,
                                return SCTP_ERROR_NO_ERROR;
                        case SCTP_PARAM_ERR_CAUSE:
                                length = sizeof(sctp_addip_param_t);
-                               err_param = (sctp_errhdr_t *)
-                                          ((void *)asconf_ack_param + length);
+                               err_param = (void *)asconf_ack_param + length;
                                asconf_ack_len -= length;
                                if (asconf_ack_len > 0)
                                        return err_param->cause;
@@ -2671,8 +3337,7 @@ static __be16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack,
                }
 
                length = ntohs(asconf_ack_param->param_hdr.length);
-               asconf_ack_param = (sctp_addip_param_t *)
-                                       ((void *)asconf_ack_param + length);
+               asconf_ack_param = (void *)asconf_ack_param + length;
                asconf_ack_len -= length;
        }
 
@@ -2695,16 +3360,16 @@ int sctp_process_asconf_ack(struct sctp_association *asoc,
 
        /* Skip the chunkhdr and addiphdr from the last asconf sent and store
         * a pointer to address parameter.
-        */ 
+        */
        length = sizeof(sctp_addip_chunk_t);
        addr_param = (union sctp_addr_param *)(asconf->skb->data + length);
        asconf_len -= length;
 
        /* Skip the address parameter in the last asconf sent and store a
-        * pointer to the first asconf paramter.
-        */ 
-       length = ntohs(addr_param->v4.param_hdr.length);
-       asconf_param = (sctp_addip_param_t *)((void *)addr_param + length);
+        * pointer to the first asconf parameter.
+        */
+       length = ntohs(addr_param->p.length);
+       asconf_param = (void *)addr_param + length;
        asconf_len -= length;
 
        /* ADDIP 4.1
@@ -2729,17 +3394,17 @@ int sctp_process_asconf_ack(struct sctp_association *asoc,
 
                switch (err_code) {
                case SCTP_ERROR_NO_ERROR:
-                       retval = sctp_asconf_param_success(asoc, asconf_param);
+                       sctp_asconf_param_success(asoc, asconf_param);
                        break;
 
                case SCTP_ERROR_RSRC_LOW:
                        retval = 1;
                        break;
 
-               case SCTP_ERROR_INV_PARAM:
+               case SCTP_ERROR_UNKNOWN_PARAM:
                        /* Disable sending this type of asconf parameter in
                         * future.
-                        */     
+                        */
                        asoc->peer.addip_disabled_mask |=
                                asconf_param->param_hdr.type;
                        break;
@@ -2753,43 +3418,32 @@ int sctp_process_asconf_ack(struct sctp_association *asoc,
 
                /* Skip the processed asconf parameter and move to the next
                 * one.
-                */ 
+                */
                length = ntohs(asconf_param->param_hdr.length);
-               asconf_param = (sctp_addip_param_t *)((void *)asconf_param +
-                                                     length);
+               asconf_param = (void *)asconf_param + length;
                asconf_len -= length;
        }
 
+       if (no_err && asoc->src_out_of_asoc_ok) {
+               asoc->src_out_of_asoc_ok = 0;
+               sctp_transport_immediate_rtx(asoc->peer.primary_path);
+       }
+
        /* Free the cached last sent asconf chunk. */
+       list_del_init(&asconf->transmitted_list);
        sctp_chunk_free(asconf);
        asoc->addip_last_asconf = NULL;
 
-       /* Send the next asconf chunk from the addip chunk queue. */
-       if (!list_empty(&asoc->addip_chunk_list)) {
-               struct list_head *entry = asoc->addip_chunk_list.next;
-               asconf = list_entry(entry, struct sctp_chunk, list);
-
-               list_del_init(entry);
-
-               /* Hold the chunk until an ASCONF_ACK is received. */
-               sctp_chunk_hold(asconf);
-               if (sctp_primitive_ASCONF(asoc, asconf))
-                       sctp_chunk_free(asconf);
-               else
-                       asoc->addip_last_asconf = asconf;
-       }
-
        return retval;
 }
 
-/* Make a FWD TSN chunk. */ 
+/* Make a FWD TSN chunk. */
 struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
                                    __u32 new_cum_tsn, size_t nstreams,
                                    struct sctp_fwdtsn_skip *skiplist)
 {
        struct sctp_chunk *retval = NULL;
-       struct sctp_fwdtsn_chunk *ftsn_chunk;
-       struct sctp_fwdtsn_hdr ftsn_hdr; 
+       struct sctp_fwdtsn_hdr ftsn_hdr;
        struct sctp_fwdtsn_skip skip;
        size_t hint;
        int i;
@@ -2801,8 +3455,6 @@ struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
        if (!retval)
                return NULL;
 
-       ftsn_chunk = (struct sctp_fwdtsn_chunk *)retval->subh.fwdtsn_hdr;
-
        ftsn_hdr.new_cum_tsn = htonl(new_cum_tsn);
        retval->subh.fwdtsn_hdr =
                sctp_addto_chunk(retval, sizeof(ftsn_hdr), &ftsn_hdr);