fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / net / sctp / associola.c
index 9d05e13..5db95ca 100644 (file)
@@ -61,7 +61,7 @@
 #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);
 
 
 /* 1st Level Abstractions. */
@@ -269,9 +269,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
 
        /* 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);
@@ -300,6 +298,7 @@ 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;
 
        return asoc;
 
@@ -346,11 +345,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.
@@ -441,7 +447,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->state != SCTP_INACTIVE)
+       if ((transport->state == SCTP_ACTIVE) ||
+           (transport->state == SCTP_UNKNOWN))
                asoc->peer.active_path = transport;
 
        /*
@@ -480,7 +487,7 @@ void sctp_assoc_rm_peer(struct sctp_association *asoc,
                                 " port: %d\n",
                                 asoc,
                                 (&peer->ipaddr),
-                                peer->ipaddr.v4.sin_port);
+                                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.
@@ -529,14 +536,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:%s\n",
+                                " port: %d state:%d\n",
                                 asoc,
                                 addr,
-                                addr->v4.sin_port,
-                                peer_state == SCTP_UNKNOWN?"UNKNOWN":"ACTIVE");
+                                port,
+                                peer_state);
 
        /* Set the port if it has not been set yet.  */
        if (0 == asoc->peer.port)
@@ -545,9 +552,12 @@ 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_state == SCTP_ACTIVE &&
-                   peer->state == SCTP_UNKNOWN)
-                    peer->state = SCTP_ACTIVE;
+               if (peer->state == SCTP_UNKNOWN) {
+                       if (peer_state == SCTP_ACTIVE)
+                               peer->state = SCTP_ACTIVE;
+                       if (peer_state == SCTP_UNCONFIRMED)
+                               peer->state = SCTP_UNCONFIRMED;
+               }
                return peer;
        }
 
@@ -698,6 +708,7 @@ void sctp_assoc_control_transport(struct sctp_association *asoc,
        struct sctp_transport *first;
        struct sctp_transport *second;
        struct sctp_ulpevent *event;
+       struct sockaddr_storage addr;
        struct list_head *pos;
        int spc_state = 0;
 
@@ -720,8 +731,9 @@ void sctp_assoc_control_transport(struct sctp_association *asoc,
        /* 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);
@@ -739,7 +751,8 @@ void sctp_assoc_control_transport(struct sctp_association *asoc,
        list_for_each(pos, &asoc->peer.transport_addr_list) {
                t = list_entry(pos, struct sctp_transport, transports);
 
-               if (t->state == SCTP_INACTIVE)
+               if ((t->state == SCTP_INACTIVE) ||
+                   (t->state == SCTP_UNCONFIRMED))
                        continue;
                if (!first || t->last_time_heard > first->last_time_heard) {
                        second = first;
@@ -759,7 +772,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->state != SCTP_INACTIVE &&
+       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;
@@ -855,7 +869,7 @@ struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *asoc,
        struct list_head *entry, *pos;
        struct sctp_transport *transport;
        struct sctp_chunk *chunk;
-       __u32 key = htonl(tsn);
+       __be32 key = htonl(tsn);
 
        match = NULL;
 
@@ -913,8 +927,8 @@ struct sctp_transport *sctp_assoc_is_match(struct sctp_association *asoc,
 
        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;
@@ -931,8 +945,11 @@ out:
 }
 
 /* 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;
@@ -1054,7 +1071,7 @@ void sctp_assoc_update(struct sctp_association *asoc,
                                           transports);
                        if (!sctp_assoc_lookup_paddr(asoc, &trans->ipaddr))
                                sctp_assoc_add_peer(asoc, &trans->ipaddr,
-                                                   GFP_ATOMIC, SCTP_ACTIVE);
+                                                   GFP_ATOMIC, trans->state);
                }
 
                asoc->ctsn_ack_point = asoc->next_tsn - 1;
@@ -1094,7 +1111,8 @@ void sctp_assoc_update_retran_path(struct sctp_association *asoc)
 
                /* Try to find an active transport. */
 
-               if (t->state != SCTP_INACTIVE) {
+               if ((t->state == SCTP_ACTIVE) ||
+                   (t->state == SCTP_UNKNOWN)) {
                        break;
                } else {
                        /* Keep track of the next transport in case
@@ -1121,7 +1139,7 @@ void sctp_assoc_update_retran_path(struct sctp_association *asoc)
                                 " port: %d\n",
                                 asoc,
                                 (&t->ipaddr),
-                                t->ipaddr.v4.sin_port);
+                                ntohs(t->ipaddr.v4.sin_port));
 }
 
 /* Choose the transport for sending a INIT packet.  */
@@ -1146,7 +1164,7 @@ struct sctp_transport *sctp_assoc_choose_init_transport(
                                 " port: %d\n",
                                 asoc,
                                 (&t->ipaddr),
-                                t->ipaddr.v4.sin_port);
+                                ntohs(t->ipaddr.v4.sin_port));
 
        return t;
 }