Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6.git] / net / sctp / associola.c
index 663843d..525864b 100644 (file)
@@ -1,21 +1,21 @@
-/* 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 Intel Corp.
  * Copyright (c) 2001 La Monte H.P. Yarroll
  *
- * This file is part of the SCTP kernel reference Implementation
+ * This file is part of the SCTP kernel implementation
  *
  * This module provides the abstraction for an SCTP association.
  *
- * 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.
@@ -52,7 +52,6 @@
 #include <linux/fcntl.h>
 #include <linux/poll.h>
 #include <linux/init.h>
-#include <linux/sched.h>
 
 #include <linux/slab.h>
 #include <linux/in.h>
@@ -61,7 +60,8 @@
 #include <net/sctp/sm.h>
 
 /* Forward declarations for internal functions. */
-static void sctp_assoc_bh_rcv(struct sctp_association *asoc);
+static void sctp_assoc_bh_rcv(struct work_struct *work);
+static void sctp_assoc_free_asconf_acks(struct sctp_association *asoc);
 
 
 /* 1st Level Abstractions. */
@@ -71,10 +71,12 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
                                          const struct sctp_endpoint *ep,
                                          const struct sock *sk,
                                          sctp_scope_t scope,
-                                         int gfp)
+                                         gfp_t gfp)
 {
        struct sctp_sock *sp;
        int i;
+       sctp_paramhdr_t *p;
+       int err;
 
        /* Retrieve the SCTP per socket area.  */
        sp = sctp_sk((struct sock *)sk);
@@ -100,7 +102,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
 
        /* Initialize the bind addr area.  */
        sctp_bind_addr_init(&asoc->base.bind_addr, ep->base.bind_addr.port);
-       rwlock_init(&asoc->base.addr_lock);
 
        asoc->state = SCTP_STATE_CLOSED;
 
@@ -110,7 +111,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
        asoc->cookie_life.tv_sec = sp->assocparams.sasoc_cookie_life / 1000;
        asoc->cookie_life.tv_usec = (sp->assocparams.sasoc_cookie_life % 1000)
                                        * 1000;
-       asoc->pmtu = 0;
        asoc->frag_point = 0;
 
        /* Set the association max_retrans and RTO values from the
@@ -123,18 +123,55 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
 
        asoc->overall_error_count = 0;
 
+       /* Initialize the association's heartbeat interval based on the
+        * sock configured value.
+        */
+       asoc->hbinterval = msecs_to_jiffies(sp->hbinterval);
+
+       /* Initialize path max retrans value. */
+       asoc->pathmaxrxt = sp->pathmaxrxt;
+
+       /* Initialize default path MTU. */
+       asoc->pathmtu = sp->pathmtu;
+
+       /* Set association default SACK delay */
+       asoc->sackdelay = msecs_to_jiffies(sp->sackdelay);
+       asoc->sackfreq = sp->sackfreq;
+
+       /* Set the association default flags controlling
+        * Heartbeat, SACK delay, and Path MTU Discovery.
+        */
+       asoc->param_flags = sp->param_flags;
+
        /* Initialize the maximum mumber of new data packets that can be sent
         * in a burst.
         */
-       asoc->max_burst = sctp_max_burst;
+       asoc->max_burst = sp->max_burst;
+
+       /* initialize association timers */
+       asoc->timeouts[SCTP_EVENT_TIMEOUT_NONE] = 0;
+       asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] = asoc->rto_initial;
+       asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] = asoc->rto_initial;
+       asoc->timeouts[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] = asoc->rto_initial;
+       asoc->timeouts[SCTP_EVENT_TIMEOUT_T3_RTX] = 0;
+       asoc->timeouts[SCTP_EVENT_TIMEOUT_T4_RTO] = 0;
+
+       /* sctpimpguide Section 2.12.2
+        * If the 'T5-shutdown-guard' timer is used, it SHOULD be set to the
+        * recommended value of 5 times 'RTO.Max'.
+        */
+       asoc->timeouts[SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD]
+               = 5 * asoc->rto_max;
 
-       /* Copy things from the endpoint.  */
-       for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i) {
-               asoc->timeouts[i] = ep->timeouts[i];
-               init_timer(&asoc->timers[i]);
-               asoc->timers[i].function = sctp_timer_events[i];
-               asoc->timers[i].data = (unsigned long) asoc;
-       }
+       asoc->timeouts[SCTP_EVENT_TIMEOUT_HEARTBEAT] = 0;
+       asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] = asoc->sackdelay;
+       asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE] =
+               sp->autoclose * HZ;
+
+       /* Initilizes the timers */
+       for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i)
+               setup_timer(&asoc->timers[i], sctp_timer_events[i],
+                               (unsigned long)asoc);
 
        /* Pull default initialization values from the sock options.
         * Note: This assumes that the values have already been
@@ -157,10 +194,10 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
         * RFC 6 - A SCTP receiver MUST be able to receive a minimum of
         * 1500 bytes in one SCTP packet.
         */
-       if (sk->sk_rcvbuf < SCTP_DEFAULT_MINWINDOW)
+       if ((sk->sk_rcvbuf/2) < SCTP_DEFAULT_MINWINDOW)
                asoc->rwnd = SCTP_DEFAULT_MINWINDOW;
        else
-               asoc->rwnd = sk->sk_rcvbuf;
+               asoc->rwnd = sk->sk_rcvbuf/2;
 
        asoc->a_rwnd = asoc->rwnd;
 
@@ -172,6 +209,9 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
        /* Set the sndbuf size for transmit.  */
        asoc->sndbuf_used = 0;
 
+       /* Initialize the receive memory counter */
+       atomic_set(&asoc->rmem_alloc, 0);
+
        init_waitqueue_head(&asoc->wait);
 
        asoc->c.my_vtag = sctp_generate_tag(ep);
@@ -191,10 +231,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
        asoc->last_cwr_tsn = asoc->ctsn_ack_point;
        asoc->unack_data = 0;
 
-       SCTP_DEBUG_PRINTK("myctsnap for %s INIT as 0x%x.\n",
-                         asoc->ep->debug_name,
-                         asoc->ctsn_ack_point);
-
        /* ADDIP Section 4.1 Asconf Chunk Procedures
         *
         * When an endpoint has an ASCONF signaled change to be sent to the
@@ -207,10 +243,12 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
         */
        asoc->addip_serial = asoc->c.initial_tsn;
 
-       skb_queue_head_init(&asoc->addip_chunks);
+       INIT_LIST_HEAD(&asoc->addip_chunk_list);
+       INIT_LIST_HEAD(&asoc->asconf_ack_list);
 
        /* Make an empty list of remote transport addresses.  */
        INIT_LIST_HEAD(&asoc->peer.transport_addr_list);
+       asoc->peer.transport_count = 0;
 
        /* RFC 2960 5.1 Normal Establishment of an Association
         *
@@ -224,17 +262,20 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
         * already received one packet.]
         */
        asoc->peer.sack_needed = 1;
+       asoc->peer.sack_cnt = 0;
 
-       /* Assume that the peer recongizes ASCONF until reported otherwise
-        * via an ERROR chunk.
+       /* Assume that the peer will tell us if he recognizes ASCONF
+        * as part of INIT exchange.
+        * The sctp_addip_noauth option is there for backward compatibilty
+        * and will revert old behavior.
         */
-       asoc->peer.asconf_capable = 1;
+       asoc->peer.asconf_capable = 0;
+       if (sctp_addip_noauth)
+               asoc->peer.asconf_capable = 1;
 
        /* Create an input queue.  */
        sctp_inq_init(&asoc->base.inqueue);
-       sctp_inq_set_th_handler(&asoc->base.inqueue,
-                                   (void (*)(void *))sctp_assoc_bh_rcv,
-                                   asoc);
+       sctp_inq_set_th_handler(&asoc->base.inqueue, sctp_assoc_bh_rcv);
 
        /* Create an output queue.  */
        sctp_outq_init(asoc, &asoc->outqueue);
@@ -242,8 +283,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
        if (!sctp_ulpq_init(&asoc->ulpq, asoc))
                goto fail_init;
 
-       /* Set up the tsn tracking. */
-       sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_SIZE, 0);
+       memset(&asoc->peer.tsn_map, 0, sizeof(struct sctp_tsnmap));
 
        asoc->need_ecne = 0;
 
@@ -253,7 +293,8 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
         * told otherwise.
         */
        asoc->peer.ipv4_address = 1;
-       asoc->peer.ipv6_address = 1;
+       if (asoc->base.sk->sk_family == PF_INET6)
+               asoc->peer.ipv6_address = 1;
        INIT_LIST_HEAD(&asoc->asocs);
 
        asoc->autoclose = sp->autoclose;
@@ -263,6 +304,31 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
        asoc->default_flags = sp->default_flags;
        asoc->default_context = sp->default_context;
        asoc->default_timetolive = sp->default_timetolive;
+       asoc->default_rcv_context = sp->default_rcv_context;
+
+       /* AUTH related initializations */
+       INIT_LIST_HEAD(&asoc->endpoint_shared_keys);
+       err = sctp_auth_asoc_copy_shkeys(ep, asoc, gfp);
+       if (err)
+               goto fail_init;
+
+       asoc->active_key_id = ep->active_key_id;
+       asoc->asoc_shared_key = NULL;
+
+       asoc->default_hmac_id = 0;
+       /* Save the hmacs and chunks list into this association */
+       if (ep->auth_hmacs_list)
+               memcpy(asoc->c.auth_hmacs, ep->auth_hmacs_list,
+                       ntohs(ep->auth_hmacs_list->param_hdr.length));
+       if (ep->auth_chunk_list)
+               memcpy(asoc->c.auth_chunks, ep->auth_chunk_list,
+                       ntohs(ep->auth_chunk_list->param_hdr.length));
+
+       /* Get the AUTH random number for this association */
+       p = (sctp_paramhdr_t *)asoc->c.auth_random;
+       p->type = SCTP_PARAM_RANDOM;
+       p->length = htons(sizeof(sctp_paramhdr_t) + SCTP_AUTH_RANDOM_LENGTH);
+       get_random_bytes(p+1, SCTP_AUTH_RANDOM_LENGTH);
 
        return asoc;
 
@@ -275,7 +341,8 @@ fail_init:
 /* Allocate and initialize a new association */
 struct sctp_association *sctp_association_new(const struct sctp_endpoint *ep,
                                         const struct sock *sk,
-                                        sctp_scope_t scope, int gfp)
+                                        sctp_scope_t scope,
+                                        gfp_t gfp)
 {
        struct sctp_association *asoc;
 
@@ -288,6 +355,7 @@ struct sctp_association *sctp_association_new(const struct sctp_endpoint *ep,
 
        asoc->base.malloced = 1;
        SCTP_DBG_OBJCNT_INC(assoc);
+       SCTP_DEBUG_PRINTK("Created asoc %p\n", asoc);
 
        return asoc;
 
@@ -307,11 +375,18 @@ void sctp_association_free(struct sctp_association *asoc)
        struct list_head *pos, *temp;
        int i;
 
-       list_del(&asoc->asocs);
+       /* Only real associations count against the endpoint, so
+        * don't bother for if this is a temporary association.
+        */
+       if (!asoc->temp) {
+               list_del(&asoc->asocs);
 
-       /* Decrement the backlog value for a TCP-style listening socket. */
-       if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))
-               sk->sk_ack_backlog--;
+               /* Decrement the backlog value for a TCP-style listening
+                * socket.
+                */
+               if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))
+                       sk->sk_ack_backlog--;
+       }
 
        /* Mark as dead, so other users can know this structure is
         * going away.
@@ -327,6 +402,8 @@ void sctp_association_free(struct sctp_association *asoc)
        /* Dispose of any pending chunks on the inqueue. */
        sctp_inq_free(&asoc->base.inqueue);
 
+       sctp_tsnmap_free(&asoc->peer.tsn_map);
+
        /* Free ssnmap storage. */
        sctp_ssnmap_free(asoc->ssnmap);
 
@@ -345,9 +422,10 @@ void sctp_association_free(struct sctp_association *asoc)
        }
 
        /* Free peer's cached cookie. */
-       if (asoc->peer.cookie) {
-               kfree(asoc->peer.cookie);
-       }
+       kfree(asoc->peer.cookie);
+       kfree(asoc->peer.peer_random);
+       kfree(asoc->peer.peer_chunks);
+       kfree(asoc->peer.peer_hmacs);
 
        /* Release the transport structures. */
        list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
@@ -356,14 +434,21 @@ void sctp_association_free(struct sctp_association *asoc)
                sctp_transport_free(transport);
        }
 
+       asoc->peer.transport_count = 0;
+
        /* Free any cached ASCONF_ACK chunk. */
-       if (asoc->addip_last_asconf_ack)
-               sctp_chunk_free(asoc->addip_last_asconf_ack);
+       sctp_assoc_free_asconf_acks(asoc);
 
        /* Free any cached ASCONF chunk. */
        if (asoc->addip_last_asconf)
                sctp_chunk_free(asoc->addip_last_asconf);
 
+       /* AUTH - Free the endpoint shared keys */
+       sctp_auth_destroy_keys(&asoc->endpoint_shared_keys);
+
+       /* AUTH - Free the association shared key */
+       sctp_auth_key_put(asoc->asoc_shared_key);
+
        sctp_association_put(asoc);
 }
 
@@ -381,6 +466,8 @@ static void sctp_association_destroy(struct sctp_association *asoc)
                spin_unlock_bh(&sctp_assocs_id_lock);
        }
 
+       WARN_ON(atomic_read(&asoc->rmem_alloc));
+
        if (asoc->base.malloced) {
                kfree(asoc);
                SCTP_DBG_OBJCNT_DEC(assoc);
@@ -391,6 +478,15 @@ static void sctp_association_destroy(struct sctp_association *asoc)
 void sctp_assoc_set_primary(struct sctp_association *asoc,
                            struct sctp_transport *transport)
 {
+       int changeover = 0;
+
+       /* it's a changeover only if we already have a primary path
+        * that we are changing
+        */
+       if (asoc->peer.primary_path != NULL &&
+           asoc->peer.primary_path != transport)
+               changeover = 1 ;
+
        asoc->peer.primary_path = transport;
 
        /* Set a default msg_name for events. */
@@ -400,7 +496,8 @@ void sctp_assoc_set_primary(struct sctp_association *asoc,
        /* If the primary path is changing, assume that the
         * user wants to use this new path.
         */
-       if (transport->active)
+       if ((transport->state == SCTP_ACTIVE) ||
+           (transport->state == SCTP_UNKNOWN))
                asoc->peer.active_path = transport;
 
        /*
@@ -415,12 +512,12 @@ void sctp_assoc_set_primary(struct sctp_association *asoc,
         * double switch to the same destination address.
         */
        if (transport->cacc.changeover_active)
-               transport->cacc.cycling_changeover = 1;
+               transport->cacc.cycling_changeover = changeover;
 
        /* 2) The sender MUST set CHANGEOVER_ACTIVE to indicate that
         * a changeover has occurred.
         */
-       transport->cacc.changeover_active = 1;
+       transport->cacc.changeover_active = changeover;
 
        /* 3) The sender MUST store the next TSN to be sent in
         * next_tsn_at_change.
@@ -428,10 +525,73 @@ void sctp_assoc_set_primary(struct sctp_association *asoc,
        transport->cacc.next_tsn_at_change = asoc->next_tsn;
 }
 
+/* Remove a transport from an association.  */
+void sctp_assoc_rm_peer(struct sctp_association *asoc,
+                       struct sctp_transport *peer)
+{
+       struct list_head        *pos;
+       struct sctp_transport   *transport;
+
+       SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_rm_peer:association %p addr: ",
+                                " port: %d\n",
+                                asoc,
+                                (&peer->ipaddr),
+                                ntohs(peer->ipaddr.v4.sin_port));
+
+       /* If we are to remove the current retran_path, update it
+        * to the next peer before removing this peer from the list.
+        */
+       if (asoc->peer.retran_path == peer)
+               sctp_assoc_update_retran_path(asoc);
+
+       /* Remove this peer from the list. */
+       list_del(&peer->transports);
+
+       /* Get the first transport of asoc. */
+       pos = asoc->peer.transport_addr_list.next;
+       transport = list_entry(pos, struct sctp_transport, transports);
+
+       /* Update any entries that match the peer to be deleted. */
+       if (asoc->peer.primary_path == peer)
+               sctp_assoc_set_primary(asoc, transport);
+       if (asoc->peer.active_path == peer)
+               asoc->peer.active_path = transport;
+       if (asoc->peer.last_data_from == peer)
+               asoc->peer.last_data_from = transport;
+
+       /* If we remove the transport an INIT was last sent to, set it to
+        * NULL. Combined with the update of the retran path above, this
+        * will cause the next INIT to be sent to the next available
+        * transport, maintaining the cycle.
+        */
+       if (asoc->init_last_sent_to == peer)
+               asoc->init_last_sent_to = NULL;
+
+       /* If we remove the transport an SHUTDOWN was last sent to, set it
+        * to NULL. Combined with the update of the retran path above, this
+        * will cause the next SHUTDOWN to be sent to the next available
+        * transport, maintaining the cycle.
+        */
+       if (asoc->shutdown_last_sent_to == peer)
+               asoc->shutdown_last_sent_to = NULL;
+
+       /* If we remove the transport an ASCONF was last sent to, set it to
+        * NULL.
+        */
+       if (asoc->addip_last_asconf &&
+           asoc->addip_last_asconf->transport == peer)
+               asoc->addip_last_asconf->transport = NULL;
+
+       asoc->peer.transport_count--;
+
+       sctp_transport_free(peer);
+}
+
 /* Add a transport address to an association.  */
 struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
                                           const union sctp_addr *addr,
-                                          int gfp)
+                                          const gfp_t gfp,
+                                          const int peer_state)
 {
        struct sctp_transport *peer;
        struct sctp_sock *sp;
@@ -440,7 +600,14 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
        sp = sctp_sk(asoc->base.sk);
 
        /* AF_INET and AF_INET6 share common port field. */
-       port = addr->v4.sin_port;
+       port = ntohs(addr->v4.sin_port);
+
+       SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_add_peer:association %p addr: ",
+                                " port: %d state:%d\n",
+                                asoc,
+                                addr,
+                                port,
+                                peer_state);
 
        /* Set the port if it has not been set yet.  */
        if (0 == asoc->peer.port)
@@ -448,8 +615,16 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
 
        /* Check to see if this is a duplicate. */
        peer = sctp_assoc_lookup_paddr(asoc, addr);
-       if (peer)
+       if (peer) {
+               /* An UNKNOWN state is only set on transports added by
+                * user in sctp_connectx() call.  Such transports should be
+                * considered CONFIRMED per RFC 4960, Section 5.4.
+                */
+               if (peer->state == SCTP_UNKNOWN) {
+                       peer->state = SCTP_ACTIVE;
+               }
                return peer;
+       }
 
        peer = sctp_transport_new(addr, gfp);
        if (!peer)
@@ -457,23 +632,48 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
 
        sctp_transport_set_owner(peer, asoc);
 
+       /* Initialize the peer's heartbeat interval based on the
+        * association configured value.
+        */
+       peer->hbinterval = asoc->hbinterval;
+
+       /* Set the path max_retrans.  */
+       peer->pathmaxrxt = asoc->pathmaxrxt;
+
+       /* Initialize the peer's SACK delay timeout based on the
+        * association configured value.
+        */
+       peer->sackdelay = asoc->sackdelay;
+       peer->sackfreq = asoc->sackfreq;
+
+       /* Enable/disable heartbeat, SACK delay, and path MTU discovery
+        * based on association setting.
+        */
+       peer->param_flags = asoc->param_flags;
+
        /* Initialize the pmtu of the transport. */
-       sctp_transport_pmtu(peer);
+       if (peer->param_flags & SPP_PMTUD_ENABLE)
+               sctp_transport_pmtu(peer);
+       else if (asoc->pathmtu)
+               peer->pathmtu = asoc->pathmtu;
+       else
+               peer->pathmtu = SCTP_DEFAULT_MAXSEGMENT;
 
        /* If this is the first transport addr on this association,
         * initialize the association PMTU to the peer's PMTU.
         * If not and the current association PMTU is higher than the new
         * peer's PMTU, reset the association PMTU to the new peer's PMTU.
         */
-       if (asoc->pmtu)
-               asoc->pmtu = min_t(int, peer->pmtu, asoc->pmtu);
+       if (asoc->pathmtu)
+               asoc->pathmtu = min_t(int, peer->pathmtu, asoc->pathmtu);
        else
-               asoc->pmtu = peer->pmtu;
+               asoc->pathmtu = peer->pathmtu;
 
        SCTP_DEBUG_PRINTK("sctp_assoc_add_peer:association %p PMTU set to "
-                         "%d\n", asoc, asoc->pmtu);
+                         "%d\n", asoc, asoc->pathmtu);
+       peer->pmtu_pending = 0;
 
-       asoc->frag_point = sctp_frag_point(sp, asoc->pmtu);
+       asoc->frag_point = sctp_frag_point(sp, asoc->pathmtu);
 
        /* The asoc->peer.port might not be meaningful yet, but
         * initialize the packet structure anyway.
@@ -491,7 +691,7 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
         *   (for example, implementations MAY use the size of the
         *   receiver advertised window).
         */
-       peer->cwnd = min(4*asoc->pmtu, max_t(__u32, 2*asoc->pmtu, 4380));
+       peer->cwnd = min(4*asoc->pathmtu, max_t(__u32, 2*asoc->pathmtu, 4380));
 
        /* At this point, we may not have the receiver's advertised window,
         * so initialize ssthresh to the default value and it will be set
@@ -502,22 +702,15 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
        peer->partial_bytes_acked = 0;
        peer->flight_size = 0;
 
-       /* By default, enable heartbeat for peer address. */
-       peer->hb_allowed = 1;
-
-       /* Initialize the peer's heartbeat interval based on the
-        * sock configured value.
-        */
-       peer->hb_interval = msecs_to_jiffies(sp->paddrparam.spp_hbinterval);
-
-       /* Set the path max_retrans.  */
-       peer->max_retrans = sp->paddrparam.spp_pathmaxrxt;
-
        /* Set the transport's RTO.initial value */
        peer->rto = asoc->rto_initial;
 
+       /* Set the peer's active state. */
+       peer->state = peer_state;
+
        /* Attach the remote transport to our asoc.  */
        list_add_tail(&peer->transports, &asoc->peer.transport_addr_list);
+       asoc->peer.transport_count++;
 
        /* If we do not yet have a primary path, set one.  */
        if (!asoc->peer.primary_path) {
@@ -525,8 +718,9 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
                asoc->peer.retran_path = peer;
        }
 
-       if (asoc->peer.active_path == asoc->peer.retran_path)
+       if (asoc->peer.active_path == asoc->peer.retran_path) {
                asoc->peer.retran_path = peer;
+       }
 
        return peer;
 }
@@ -537,37 +731,16 @@ void sctp_assoc_del_peer(struct sctp_association *asoc,
 {
        struct list_head        *pos;
        struct list_head        *temp;
-       struct sctp_transport   *peer = NULL;
        struct sctp_transport   *transport;
 
        list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
                transport = list_entry(pos, struct sctp_transport, transports);
                if (sctp_cmp_addr_exact(addr, &transport->ipaddr)) {
-                       peer = transport;
-                       list_del(pos);
+                       /* Do book keeping for removing the peer and free it. */
+                       sctp_assoc_rm_peer(asoc, transport);
                        break;
                }
        }
-
-       /* The address we want delete is not in the association. */
-       if (!peer)
-               return;
-
-       /* Get the first transport of asoc. */ 
-       pos = asoc->peer.transport_addr_list.next;
-       transport = list_entry(pos, struct sctp_transport, transports);
-
-       /* Update any entries that match the peer to be deleted. */  
-       if (asoc->peer.primary_path == peer)
-               sctp_assoc_set_primary(asoc, transport);
-       if (asoc->peer.active_path == peer)
-               asoc->peer.active_path = transport;
-       if (asoc->peer.retran_path == peer)
-               asoc->peer.retran_path = transport;
-       if (asoc->peer.last_data_from == peer)
-               asoc->peer.last_data_from = transport;
-
-       sctp_transport_free(peer);
 }
 
 /* Lookup a transport by address. */
@@ -576,12 +749,11 @@ struct sctp_transport *sctp_assoc_lookup_paddr(
                                        const union sctp_addr *address)
 {
        struct sctp_transport *t;
-       struct list_head *pos;
 
        /* Cycle through all transports searching for a peer address. */
 
-       list_for_each(pos, &asoc->peer.transport_addr_list) {
-               t = list_entry(pos, struct sctp_transport, transports);
+       list_for_each_entry(t, &asoc->peer.transport_addr_list,
+                       transports) {
                if (sctp_cmp_addr_exact(address, &t->ipaddr))
                        return t;
        }
@@ -589,6 +761,23 @@ struct sctp_transport *sctp_assoc_lookup_paddr(
        return NULL;
 }
 
+/* Remove all transports except a give one */
+void sctp_assoc_del_nonprimary_peers(struct sctp_association *asoc,
+                                    struct sctp_transport *primary)
+{
+       struct sctp_transport   *temp;
+       struct sctp_transport   *t;
+
+       list_for_each_entry_safe(t, temp, &asoc->peer.transport_addr_list,
+                                transports) {
+               /* if the current transport is not the primary one, delete it */
+               if (t != primary)
+                       sctp_assoc_rm_peer(asoc, t);
+       }
+
+       return;
+}
+
 /* Engage in transport control operations.
  * Mark the transport up or down and send a notification to the user.
  * Select and update the new active and retran paths.
@@ -602,30 +791,44 @@ void sctp_assoc_control_transport(struct sctp_association *asoc,
        struct sctp_transport *first;
        struct sctp_transport *second;
        struct sctp_ulpevent *event;
-       struct list_head *pos;
+       struct sockaddr_storage addr;
        int spc_state = 0;
 
        /* Record the transition on the transport.  */
        switch (command) {
        case SCTP_TRANSPORT_UP:
-               transport->active = SCTP_ACTIVE;
-               spc_state = SCTP_ADDR_AVAILABLE;
+               /* If we are moving from UNCONFIRMED state due
+                * to heartbeat success, report the SCTP_ADDR_CONFIRMED
+                * state to the user, otherwise report SCTP_ADDR_AVAILABLE.
+                */
+               if (SCTP_UNCONFIRMED == transport->state &&
+                   SCTP_HEARTBEAT_SUCCESS == error)
+                       spc_state = SCTP_ADDR_CONFIRMED;
+               else
+                       spc_state = SCTP_ADDR_AVAILABLE;
+               transport->state = SCTP_ACTIVE;
                break;
 
        case SCTP_TRANSPORT_DOWN:
-               transport->active = SCTP_INACTIVE;
+               /* if the transort was never confirmed, do not transition it
+                * to inactive state.
+                */
+               if (transport->state != SCTP_UNCONFIRMED)
+                       transport->state = SCTP_INACTIVE;
+
                spc_state = SCTP_ADDR_UNREACHABLE;
                break;
 
        default:
                return;
-       };
+       }
 
        /* Generate and send a SCTP_PEER_ADDR_CHANGE notification to the
         * user.
         */
-       event = sctp_ulpevent_make_peer_addr_change(asoc,
-                               (struct sockaddr_storage *) &transport->ipaddr,
+       memset(&addr, 0, sizeof(struct sockaddr_storage));
+       memcpy(&addr, &transport->ipaddr, transport->af_specific->sockaddr_len);
+       event = sctp_ulpevent_make_peer_addr_change(asoc, &addr,
                                0, spc_state, error, GFP_ATOMIC);
        if (event)
                sctp_ulpq_tail_event(&asoc->ulpq, event);
@@ -640,10 +843,11 @@ void sctp_assoc_control_transport(struct sctp_association *asoc,
         */
        first = NULL; second = NULL;
 
-       list_for_each(pos, &asoc->peer.transport_addr_list) {
-               t = list_entry(pos, struct sctp_transport, transports);
+       list_for_each_entry(t, &asoc->peer.transport_addr_list,
+                       transports) {
 
-               if (!t->active)
+               if ((t->state == SCTP_INACTIVE) ||
+                   (t->state == SCTP_UNCONFIRMED))
                        continue;
                if (!first || t->last_time_heard > first->last_time_heard) {
                        second = first;
@@ -663,7 +867,8 @@ void sctp_assoc_control_transport(struct sctp_association *asoc,
         * [If the primary is active but not most recent, bump the most
         * recently used transport.]
         */
-       if (asoc->peer.primary_path->active &&
+       if (((asoc->peer.primary_path->state == SCTP_ACTIVE) ||
+            (asoc->peer.primary_path->state == SCTP_UNKNOWN)) &&
            first != asoc->peer.primary_path) {
                second = first;
                first = asoc->peer.primary_path;
@@ -756,10 +961,9 @@ struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *asoc,
 {
        struct sctp_transport *active;
        struct sctp_transport *match;
-       struct list_head *entry, *pos;
        struct sctp_transport *transport;
        struct sctp_chunk *chunk;
-       __u32 key = htonl(tsn);
+       __be32 key = htonl(tsn);
 
        match = NULL;
 
@@ -780,8 +984,8 @@ struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *asoc,
 
        active = asoc->peer.active_path;
 
-       list_for_each(entry, &active->transmitted) {
-               chunk = list_entry(entry, struct sctp_chunk, transmitted_list);
+       list_for_each_entry(chunk, &active->transmitted,
+                       transmitted_list) {
 
                if (key == chunk->subh.data_hdr->tsn) {
                        match = active;
@@ -790,14 +994,13 @@ struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *asoc,
        }
 
        /* If not found, go search all the other transports. */
-       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) {
 
                if (transport == active)
                        break;
-               list_for_each(entry, &transport->transmitted) {
-                       chunk = list_entry(entry, struct sctp_chunk,
-                                          transmitted_list);
+               list_for_each_entry(chunk, &transport->transmitted,
+                               transmitted_list) {
                        if (key == chunk->subh.data_hdr->tsn) {
                                match = transport;
                                goto out;
@@ -815,10 +1018,8 @@ struct sctp_transport *sctp_assoc_is_match(struct sctp_association *asoc,
 {
        struct sctp_transport *transport;
 
-       sctp_read_lock(&asoc->base.addr_lock);
-
-       if ((asoc->base.bind_addr.port == laddr->v4.sin_port) &&
-           (asoc->peer.port == paddr->v4.sin_port)) {
+       if ((htons(asoc->base.bind_addr.port) == laddr->v4.sin_port) &&
+           (htons(asoc->peer.port) == paddr->v4.sin_port)) {
                transport = sctp_assoc_lookup_paddr(asoc, paddr);
                if (!transport)
                        goto out;
@@ -830,13 +1031,15 @@ struct sctp_transport *sctp_assoc_is_match(struct sctp_association *asoc,
        transport = NULL;
 
 out:
-       sctp_read_unlock(&asoc->base.addr_lock);
        return transport;
 }
 
 /* Do delayed input processing.  This is scheduled by sctp_rcv(). */
-static void sctp_assoc_bh_rcv(struct sctp_association *asoc)
+static void sctp_assoc_bh_rcv(struct work_struct *work)
 {
+       struct sctp_association *asoc =
+               container_of(work, struct sctp_association,
+                            base.inqueue.immediate);
        struct sctp_endpoint *ep;
        struct sctp_chunk *chunk;
        struct sock *sk;
@@ -855,6 +1058,16 @@ static void sctp_assoc_bh_rcv(struct sctp_association *asoc)
                state = asoc->state;
                subtype = SCTP_ST_CHUNK(chunk->chunk_hdr->type);
 
+               /* SCTP-AUTH, Section 6.3:
+                *    The receiver has a list of chunk types which it expects
+                *    to be received only after an AUTH-chunk.  This list has
+                *    been sent to the peer during the association setup.  It
+                *    MUST silently discard these chunks if they are not placed
+                *    after an AUTH chunk in the packet.
+                */
+               if (sctp_auth_recv_cid(subtype.chunk, asoc) && !chunk->auth)
+                       continue;
+
                /* Remember where the last DATA chunk came from so we
                 * know where to send the SACK.
                 */
@@ -926,14 +1139,17 @@ void sctp_assoc_update(struct sctp_association *asoc,
        asoc->peer.rwnd = new->peer.rwnd;
        asoc->peer.sack_needed = new->peer.sack_needed;
        asoc->peer.i = new->peer.i;
-       sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_SIZE,
-                        asoc->peer.i.initial_tsn);
+       sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL,
+                        asoc->peer.i.initial_tsn, GFP_ATOMIC);
 
        /* Remove any peer addresses not present in the new association. */
        list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
                trans = list_entry(pos, struct sctp_transport, transports);
                if (!sctp_assoc_lookup_paddr(new, &trans->ipaddr))
                        sctp_assoc_del_peer(asoc, &trans->ipaddr);
+
+               if (asoc->state >= SCTP_STATE_ESTABLISHED)
+                       sctp_transport_reset(trans);
        }
 
        /* If the case is A (association restart), use
@@ -951,14 +1167,25 @@ void sctp_assoc_update(struct sctp_association *asoc,
                 */
                sctp_ssnmap_clear(asoc->ssnmap);
 
+               /* Flush the ULP reassembly and ordered queue.
+                * Any data there will now be stale and will
+                * cause problems.
+                */
+               sctp_ulpq_flush(&asoc->ulpq);
+
+               /* reset the overall association error count so
+                * that the restarted association doesn't get torn
+                * down on the next retransmission timer.
+                */
+               asoc->overall_error_count = 0;
+
        } else {
                /* Add any peer addresses from the new association. */
-               list_for_each(pos, &new->peer.transport_addr_list) {
-                       trans = list_entry(pos, struct sctp_transport,
-                                          transports);
+               list_for_each_entry(trans, &new->peer.transport_addr_list,
+                               transports) {
                        if (!sctp_assoc_lookup_paddr(asoc, &trans->ipaddr))
                                sctp_assoc_add_peer(asoc, &trans->ipaddr,
-                                                   GFP_ATOMIC);
+                                                   GFP_ATOMIC, trans->state);
                }
 
                asoc->ctsn_ack_point = asoc->next_tsn - 1;
@@ -968,7 +1195,32 @@ void sctp_assoc_update(struct sctp_association *asoc,
                        asoc->ssnmap = new->ssnmap;
                        new->ssnmap = NULL;
                }
+
+               if (!asoc->assoc_id) {
+                       /* get a new association id since we don't have one
+                        * yet.
+                        */
+                       sctp_assoc_set_id(asoc, GFP_ATOMIC);
+               }
        }
+
+       /* SCTP-AUTH: Save the peer parameters from the new assocaitions
+        * and also move the association shared keys over
+        */
+       kfree(asoc->peer.peer_random);
+       asoc->peer.peer_random = new->peer.peer_random;
+       new->peer.peer_random = NULL;
+
+       kfree(asoc->peer.peer_chunks);
+       asoc->peer.peer_chunks = new->peer.peer_chunks;
+       new->peer.peer_chunks = NULL;
+
+       kfree(asoc->peer.peer_hmacs);
+       asoc->peer.peer_hmacs = new->peer.peer_hmacs;
+       new->peer.peer_hmacs = NULL;
+
+       sctp_auth_key_put(asoc->asoc_shared_key);
+       sctp_auth_asoc_init_active_key(asoc, GFP_ATOMIC);
 }
 
 /* Update the retran path for sending a retransmitted packet.
@@ -982,6 +1234,9 @@ void sctp_assoc_update_retran_path(struct sctp_association *asoc)
        struct list_head *head = &asoc->peer.transport_addr_list;
        struct list_head *pos;
 
+       if (asoc->peer.transport_count == 1)
+               return;
+
        /* Find the next transport in a round-robin fashion. */
        t = asoc->peer.retran_path;
        pos = &t->transports;
@@ -996,9 +1251,19 @@ void sctp_assoc_update_retran_path(struct sctp_association *asoc)
 
                t = list_entry(pos, struct sctp_transport, transports);
 
+               /* We have exhausted the list, but didn't find any
+                * other active transports.  If so, use the next
+                * transport.
+                */
+               if (t == asoc->peer.retran_path) {
+                       t = next;
+                       break;
+               }
+
                /* Try to find an active transport. */
 
-               if (t->active) {
+               if ((t->state == SCTP_ACTIVE) ||
+                   (t->state == SCTP_UNKNOWN)) {
                        break;
                } else {
                        /* Keep track of the next transport in case
@@ -1007,36 +1272,33 @@ void sctp_assoc_update_retran_path(struct sctp_association *asoc)
                        if (!next)
                                next = t;
                }
-
-               /* We have exhausted the list, but didn't find any
-                * other active transports.  If so, use the next
-                * transport.
-                */
-               if (t == asoc->peer.retran_path) {
-                       t = next;
-                       break;
-               }
        }
 
        asoc->peer.retran_path = t;
+
+       SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_update_retran_path:association"
+                                " %p addr: ",
+                                " port: %d\n",
+                                asoc,
+                                (&t->ipaddr),
+                                ntohs(t->ipaddr.v4.sin_port));
 }
 
-/* Choose the transport for sending a SHUTDOWN packet.  */
-struct sctp_transport *sctp_assoc_choose_shutdown_transport(
-       struct sctp_association *asoc)
+/* Choose the transport for sending retransmit packet.  */
+struct sctp_transport *sctp_assoc_choose_alter_transport(
+       struct sctp_association *asoc, struct sctp_transport *last_sent_to)
 {
-       /* If this is the first time SHUTDOWN is sent, use the active path,
-        * else use the retran path. If the last SHUTDOWN was sent over the
+       /* If this is the first time packet is sent, use the active path,
+        * else use the retran path. If the last packet was sent over the
         * retran path, update the retran path and use it.
         */
-       if (!asoc->shutdown_last_sent_to)
+       if (!last_sent_to)
                return asoc->peer.active_path;
        else {
-               if (asoc->shutdown_last_sent_to == asoc->peer.retran_path)
+               if (last_sent_to == asoc->peer.retran_path)
                        sctp_assoc_update_retran_path(asoc);
                return asoc->peer.retran_path;
        }
-
 }
 
 /* Update the association's pmtu and frag_point by going through all the
@@ -1045,27 +1307,30 @@ struct sctp_transport *sctp_assoc_choose_shutdown_transport(
 void sctp_assoc_sync_pmtu(struct sctp_association *asoc)
 {
        struct sctp_transport *t;
-       struct list_head *pos;
        __u32 pmtu = 0;
 
        if (!asoc)
                return;
 
        /* Get the lowest pmtu of all the transports. */
-       list_for_each(pos, &asoc->peer.transport_addr_list) {
-               t = list_entry(pos, struct sctp_transport, transports);
-               if (!pmtu || (t->pmtu < pmtu))
-                       pmtu = t->pmtu;
+       list_for_each_entry(t, &asoc->peer.transport_addr_list,
+                               transports) {
+               if (t->pmtu_pending && t->dst) {
+                       sctp_transport_update_pmtu(t, dst_mtu(t->dst));
+                       t->pmtu_pending = 0;
+               }
+               if (!pmtu || (t->pathmtu < pmtu))
+                       pmtu = t->pathmtu;
        }
 
        if (pmtu) {
                struct sctp_sock *sp = sctp_sk(asoc->base.sk);
-               asoc->pmtu = pmtu;
+               asoc->pathmtu = pmtu;
                asoc->frag_point = sctp_frag_point(sp, pmtu);
        }
 
        SCTP_DEBUG_PRINTK("%s: asoc:%p, pmtu:%d, frag_point:%d\n",
-                         __FUNCTION__, asoc, asoc->pmtu, asoc->frag_point);
+                         __func__, asoc, asoc->pathmtu, asoc->frag_point);
 }
 
 /* Should we send a SACK to update our peer? */
@@ -1078,7 +1343,7 @@ static inline int sctp_peer_needs_update(struct sctp_association *asoc)
        case SCTP_STATE_SHUTDOWN_SENT:
                if ((asoc->rwnd > asoc->a_rwnd) &&
                    ((asoc->rwnd - asoc->a_rwnd) >=
-                    min_t(__u32, (asoc->base.sk->sk_rcvbuf >> 1), asoc->pmtu)))
+                    min_t(__u32, (asoc->base.sk->sk_rcvbuf >> 1), asoc->pathmtu)))
                        return 1;
                break;
        default:
@@ -1105,7 +1370,7 @@ void sctp_assoc_rwnd_increase(struct sctp_association *asoc, unsigned len)
        }
 
        SCTP_DEBUG_PRINTK("%s: asoc %p rwnd increased by %d to (%u, %u) "
-                         "- %u\n", __FUNCTION__, asoc, len, asoc->rwnd,
+                         "- %u\n", __func__, asoc, len, asoc->rwnd,
                          asoc->rwnd_over, asoc->a_rwnd);
 
        /* Send a window update SACK if the rwnd has increased by at least the
@@ -1116,7 +1381,7 @@ void sctp_assoc_rwnd_increase(struct sctp_association *asoc, unsigned len)
        if (sctp_peer_needs_update(asoc)) {
                asoc->a_rwnd = asoc->rwnd;
                SCTP_DEBUG_PRINTK("%s: Sending window update SACK- asoc: %p "
-                                 "rwnd: %u a_rwnd: %u\n", __FUNCTION__,
+                                 "rwnd: %u a_rwnd: %u\n", __func__,
                                  asoc, asoc->rwnd, asoc->a_rwnd);
                sack = sctp_make_sack(asoc);
                if (!sack)
@@ -1145,14 +1410,15 @@ void sctp_assoc_rwnd_decrease(struct sctp_association *asoc, unsigned len)
                asoc->rwnd = 0;
        }
        SCTP_DEBUG_PRINTK("%s: asoc %p rwnd decreased by %d to (%u, %u)\n",
-                         __FUNCTION__, asoc, len, asoc->rwnd,
+                         __func__, asoc, len, asoc->rwnd,
                          asoc->rwnd_over);
 }
 
 /* Build the bind address list for the association based on info from the
  * local endpoint and the remote peer.
  */
-int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc, int gfp)
+int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc,
+                                    gfp_t gfp)
 {
        sctp_scope_t scope;
        int flags;
@@ -1174,7 +1440,8 @@ int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc, int gfp)
 
 /* Build the association's bind address list from the cookie.  */
 int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *asoc,
-                                        struct sctp_cookie *cookie, int gfp)
+                                        struct sctp_cookie *cookie,
+                                        gfp_t gfp)
 {
        int var_size2 = ntohs(cookie->peer_init->chunk_hdr.length);
        int var_size3 = cookie->raw_addr_list_len;
@@ -1184,22 +1451,95 @@ int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *asoc,
                                      asoc->ep->base.bind_addr.port, gfp);
 }
 
-/* Lookup laddr in the bind address list of an association. */ 
-int sctp_assoc_lookup_laddr(struct sctp_association *asoc, 
+/* Lookup laddr in the bind address list of an association. */
+int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
                            const union sctp_addr *laddr)
 {
-       int found;
+       int found = 0;
 
-       sctp_read_lock(&asoc->base.addr_lock);
        if ((asoc->base.bind_addr.port == ntohs(laddr->v4.sin_port)) &&
            sctp_bind_addr_match(&asoc->base.bind_addr, laddr,
-                                sctp_sk(asoc->base.sk))) {
+                                sctp_sk(asoc->base.sk)))
                found = 1;
-               goto out;
-       }
 
-       found = 0;
-out:
-       sctp_read_unlock(&asoc->base.addr_lock);
        return found;
 }
+
+/* Set an association id for a given association */
+int sctp_assoc_set_id(struct sctp_association *asoc, gfp_t gfp)
+{
+       int assoc_id;
+       int error = 0;
+
+       /* If the id is already assigned, keep it. */
+       if (asoc->assoc_id)
+               return error;
+retry:
+       if (unlikely(!idr_pre_get(&sctp_assocs_id, gfp)))
+               return -ENOMEM;
+
+       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)
+               return error;
+
+       asoc->assoc_id = (sctp_assoc_t) assoc_id;
+       return error;
+}
+
+/* Free asconf_ack cache */
+static void sctp_assoc_free_asconf_acks(struct sctp_association *asoc)
+{
+       struct sctp_chunk *ack;
+       struct sctp_chunk *tmp;
+
+       list_for_each_entry_safe(ack, tmp, &asoc->asconf_ack_list,
+                               transmitted_list) {
+               list_del_init(&ack->transmitted_list);
+               sctp_chunk_free(ack);
+       }
+}
+
+/* Clean up the ASCONF_ACK queue */
+void sctp_assoc_clean_asconf_ack_cache(const struct sctp_association *asoc)
+{
+       struct sctp_chunk *ack;
+       struct sctp_chunk *tmp;
+
+       /* We can remove all the entries from the queue upto
+        * the "Peer-Sequence-Number".
+        */
+       list_for_each_entry_safe(ack, tmp, &asoc->asconf_ack_list,
+                               transmitted_list) {
+               if (ack->subh.addip_hdr->serial ==
+                               htonl(asoc->peer.addip_serial))
+                       break;
+
+               list_del_init(&ack->transmitted_list);
+               sctp_chunk_free(ack);
+       }
+}
+
+/* Find the ASCONF_ACK whose serial number matches ASCONF */
+struct sctp_chunk *sctp_assoc_lookup_asconf_ack(
+                                       const struct sctp_association *asoc,
+                                       __be32 serial)
+{
+       struct sctp_chunk *ack;
+
+       /* Walk through the list of cached ASCONF-ACKs and find the
+        * ack chunk whose serial number matches that of the request.
+        */
+       list_for_each_entry(ack, &asoc->asconf_ack_list, transmitted_list) {
+               if (ack->subh.addip_hdr->serial == serial) {
+                       sctp_chunk_hold(ack);
+                       return ack;
+               }
+       }
+
+       return NULL;
+}