[SCTP]: sctp_assoc_del_peer() switched to net-endian.
[linux-2.6.git] / net / sctp / associola.c
index 12b0f58..ab3141f 100644 (file)
@@ -110,7 +110,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,14 +122,52 @@ 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);
+
+       /* 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;
 
-       /* Copy things from the endpoint.  */
+       /* 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;
+
+       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) {
-               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;
@@ -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);
@@ -306,11 +346,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.
@@ -344,9 +391,7 @@ 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);
 
        /* Release the transport structures. */
        list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
@@ -382,6 +427,8 @@ static void sctp_association_destroy(struct sctp_association *asoc)
                spin_unlock_bh(&sctp_assocs_id_lock);
        }
 
+       BUG_TRAP(!atomic_read(&asoc->rmem_alloc));
+
        if (asoc->base.malloced) {
                kfree(asoc);
                SCTP_DBG_OBJCNT_DEC(assoc);
@@ -401,7 +448,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;
 
        /*
@@ -439,8 +487,8 @@ void sctp_assoc_rm_peer(struct sctp_association *asoc,
        SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_rm_peer:association %p addr: ",
                                 " port: %d\n",
                                 asoc,
-                                (&peer->ipaddr),
-                                peer->ipaddr.v4.sin_port);
+                                (&peer->ipaddr_h),
+                                peer->ipaddr_h.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.
@@ -492,11 +540,11 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
        port = 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");
+                                peer_state);
 
        /* Set the port if it has not been set yet.  */
        if (0 == asoc->peer.port)
@@ -505,9 +553,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;
        }
 
@@ -517,23 +568,46 @@ 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;
+
+       /* 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);
 
-       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.
@@ -551,7 +625,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
@@ -562,17 +636,6 @@ 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;
 
@@ -621,12 +684,14 @@ struct sctp_transport *sctp_assoc_lookup_paddr(
 {
        struct sctp_transport *t;
        struct list_head *pos;
+       union sctp_addr tmp;
 
+       flip_to_n(&tmp, address);
        /* 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);
-               if (sctp_cmp_addr_exact(address, &t->ipaddr))
+               if (sctp_cmp_addr_exact(&tmp, &t->ipaddr))
                        return t;
        }
 
@@ -646,6 +711,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;
 
@@ -668,8 +734,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));
+       flip_to_n((union sctp_addr *)&addr, &transport->ipaddr_h);
+       event = sctp_ulpevent_make_peer_addr_change(asoc, &addr,
                                0, spc_state, error, GFP_ATOMIC);
        if (event)
                sctp_ulpq_tail_event(&asoc->ulpq, event);
@@ -687,7 +754,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;
@@ -707,7 +775,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;
@@ -803,7 +872,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;
 
@@ -858,6 +927,8 @@ struct sctp_transport *sctp_assoc_is_match(struct sctp_association *asoc,
                                           const union sctp_addr *paddr)
 {
        struct sctp_transport *transport;
+       union sctp_addr tmp;
+       flip_to_n(&tmp, laddr);
 
        sctp_read_lock(&asoc->base.addr_lock);
 
@@ -867,7 +938,7 @@ struct sctp_transport *sctp_assoc_is_match(struct sctp_association *asoc,
                if (!transport)
                        goto out;
 
-               if (sctp_bind_addr_match(&asoc->base.bind_addr, laddr,
+               if (sctp_bind_addr_match(&asoc->base.bind_addr, &tmp,
                                         sctp_sk(asoc->base.sk)))
                        goto out;
        }
@@ -976,7 +1047,7 @@ void sctp_assoc_update(struct sctp_association *asoc,
        /* 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))
+               if (!sctp_assoc_lookup_paddr(new, &trans->ipaddr_h))
                        sctp_assoc_del_peer(asoc, &trans->ipaddr);
        }
 
@@ -1000,9 +1071,9 @@ void sctp_assoc_update(struct sctp_association *asoc,
                list_for_each(pos, &new->peer.transport_addr_list) {
                        trans = list_entry(pos, struct sctp_transport,
                                           transports);
-                       if (!sctp_assoc_lookup_paddr(asoc, &trans->ipaddr))
-                               sctp_assoc_add_peer(asoc, &trans->ipaddr,
-                                                   GFP_ATOMIC, SCTP_ACTIVE);
+                       if (!sctp_assoc_lookup_paddr(asoc, &trans->ipaddr_h))
+                               sctp_assoc_add_peer(asoc, &trans->ipaddr_h,
+                                                   GFP_ATOMIC, trans->state);
                }
 
                asoc->ctsn_ack_point = asoc->next_tsn - 1;
@@ -1042,7 +1113,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
@@ -1068,8 +1140,8 @@ void sctp_assoc_update_retran_path(struct sctp_association *asoc)
                                 " %p addr: ",
                                 " port: %d\n",
                                 asoc,
-                                (&t->ipaddr),
-                                t->ipaddr.v4.sin_port);
+                                (&t->ipaddr_h),
+                                t->ipaddr_h.v4.sin_port);
 }
 
 /* Choose the transport for sending a INIT packet.  */
@@ -1093,8 +1165,8 @@ struct sctp_transport *sctp_assoc_choose_init_transport(
                                 " %p addr: ",
                                 " port: %d\n",
                                 asoc,
-                                (&t->ipaddr),
-                                t->ipaddr.v4.sin_port);
+                                (&t->ipaddr_h),
+                                t->ipaddr_h.v4.sin_port);
 
        return t;
 }
@@ -1132,18 +1204,18 @@ void sctp_assoc_sync_pmtu(struct sctp_association *asoc)
        /* 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;
+               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);
+                         __FUNCTION__, asoc, asoc->pathmtu, asoc->frag_point);
 }
 
 /* Should we send a SACK to update our peer? */
@@ -1156,7 +1228,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:
@@ -1239,7 +1311,7 @@ int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc,
        /* Use scoping rules to determine the subset of addresses from
         * the endpoint.
         */
-       scope = sctp_scope(&asoc->peer.active_path->ipaddr);
+       scope = sctp_scope(&asoc->peer.active_path->ipaddr_h);
        flags = (PF_INET6 == asoc->base.sk->sk_family) ? SCTP_ADDR6_ALLOWED : 0;
        if (asoc->peer.ipv4_address)
                flags |= SCTP_ADDR4_PEERSUPP;