]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/sctp/associola.c
autofs4: fix sparse warning in waitq.c:autofs4_expire_indirect()
[linux-2.6-omap-h63xx.git] / net / sctp / associola.c
index 03158e3665da0b34786843104d4ab5f4b5fa4736..b4cd2b71953fdf66ae75bcc5c80d9e3e7d5558fb 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.
@@ -61,6 +61,7 @@
 
 /* Forward declarations for internal functions. */
 static void sctp_assoc_bh_rcv(struct work_struct *work);
+static void sctp_assoc_free_asconf_acks(struct sctp_association *asoc);
 
 
 /* 1st Level Abstractions. */
@@ -167,11 +168,9 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
                sp->autoclose * HZ;
 
        /* Initilizes the timers */
-       for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i) {
-               init_timer(&asoc->timers[i]);
-               asoc->timers[i].function = sctp_timer_events[i];
-               asoc->timers[i].data = (unsigned long) asoc;
-       }
+       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
@@ -244,6 +243,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
        asoc->addip_serial = asoc->c.initial_tsn;
 
        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);
@@ -262,10 +262,14 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
         */
        asoc->peer.sack_needed = 1;
 
-       /* 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);
@@ -429,8 +433,7 @@ void sctp_association_free(struct sctp_association *asoc)
        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)
@@ -715,12 +718,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;
        }
@@ -728,6 +730,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.
@@ -742,7 +761,6 @@ void sctp_assoc_control_transport(struct sctp_association *asoc,
        struct sctp_transport *second;
        struct sctp_ulpevent *event;
        struct sockaddr_storage addr;
-       struct list_head *pos;
        int spc_state = 0;
 
        /* Record the transition on the transport.  */
@@ -794,8 +812,8 @@ 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->state == SCTP_INACTIVE) ||
                    (t->state == SCTP_UNCONFIRMED))
@@ -912,7 +930,6 @@ 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;
        __be32 key = htonl(tsn);
@@ -936,8 +953,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;
@@ -946,14 +963,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;
@@ -1134,9 +1150,8 @@ void sctp_assoc_update(struct sctp_association *asoc,
 
        } 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, trans->state);
@@ -1286,15 +1301,14 @@ 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);
+       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;
@@ -1310,7 +1324,7 @@ void sctp_assoc_sync_pmtu(struct sctp_association *asoc)
        }
 
        SCTP_DEBUG_PRINTK("%s: asoc:%p, pmtu:%d, frag_point:%d\n",
-                         __FUNCTION__, asoc, asoc->pathmtu, asoc->frag_point);
+                         __func__, asoc, asoc->pathmtu, asoc->frag_point);
 }
 
 /* Should we send a SACK to update our peer? */
@@ -1350,7 +1364,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
@@ -1361,7 +1375,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)
@@ -1390,7 +1404,7 @@ 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);
 }
 
@@ -1466,3 +1480,56 @@ retry:
        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;
+}