[SCTP]: "list_for_each()" -> "list_for_each_entry()" where appropriate.
[pandora-kernel.git] / net / sctp / outqueue.c
index fa76f23..213c2e2 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-2003 Intel Corp.
  *
- * This file is part of the SCTP kernel reference Implementation
+ * This file is part of the SCTP kernel implementation
  *
  * These functions implement the sctp_outq class.   The outqueue handles
  * bundling and queueing of outgoing SCTP chunks.
  *
- * 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.
@@ -221,12 +221,12 @@ void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
 void sctp_outq_teardown(struct sctp_outq *q)
 {
        struct sctp_transport *transport;
-       struct list_head *lchunk, *pos, *temp;
+       struct list_head *lchunk, *temp;
        struct sctp_chunk *chunk, *tmp;
 
        /* Throw away unacknowledged chunks. */
-       list_for_each(pos, &q->asoc->peer.transport_addr_list) {
-               transport = list_entry(pos, struct sctp_transport, transports);
+       list_for_each_entry(transport, &q->asoc->peer.transport_addr_list,
+                       transports) {
                while ((lchunk = sctp_list_dequeue(&transport->transmitted)) != NULL) {
                        chunk = list_entry(lchunk, struct sctp_chunk,
                                           transmitted_list);
@@ -469,7 +469,7 @@ void sctp_retransmit_mark(struct sctp_outq *q,
 
        SCTP_DEBUG_PRINTK("%s: transport: %p, reason: %d, "
                          "cwnd: %d, ssthresh: %d, flight_size: %d, "
-                         "pba: %d\n", __FUNCTION__,
+                         "pba: %d\n", __func__,
                          transport, reason,
                          transport->cwnd, transport->ssthresh,
                          transport->flight_size,
@@ -494,6 +494,8 @@ void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
                 */
                if (transport == transport->asoc->peer.retran_path)
                        sctp_assoc_update_retran_path(transport->asoc);
+               transport->asoc->rtx_data_chunks +=
+                       transport->asoc->unack_data;
                break;
        case SCTP_RTXR_FAST_RTX:
                SCTP_INC_STATS(SCTP_MIB_FAST_RETRANSMITS);
@@ -504,6 +506,7 @@ void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
                break;
        case SCTP_RTXR_T1_RTX:
                SCTP_INC_STATS(SCTP_MIB_T1_RETRANSMITS);
+               transport->asoc->init_retries++;
                break;
        default:
                BUG();
@@ -535,7 +538,7 @@ static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
                               int rtx_timeout, int *start_timer)
 {
        struct list_head *lqueue;
-       struct list_head *lchunk, *lchunk1;
+       struct list_head *lchunk;
        struct sctp_transport *transport = pkt->transport;
        sctp_xmit_t status;
        struct sctp_chunk *chunk, *chunk1;
@@ -646,9 +649,7 @@ static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
                 * to be marked as ineligible for a subsequent fast retransmit.
                 */
                if (rtx_timeout && !lchunk) {
-                       list_for_each(lchunk1, lqueue) {
-                               chunk1 = list_entry(lchunk1, struct sctp_chunk,
-                                                   transmitted_list);
+                       list_for_each_entry(chunk1, lqueue, transmitted_list) {
                                if (chunk1->fast_retransmit > 0)
                                        chunk1->fast_retransmit = -1;
                        }
@@ -716,7 +717,29 @@ int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
                new_transport = chunk->transport;
 
                if (!new_transport) {
-                       new_transport = asoc->peer.active_path;
+                       /*
+                        * If we have a prior transport pointer, see if
+                        * the destination address of the chunk
+                        * matches the destination address of the
+                        * current transport.  If not a match, then
+                        * try to look up the transport with a given
+                        * destination address.  We do this because
+                        * after processing ASCONFs, we may have new
+                        * transports created.
+                        */
+                       if (transport &&
+                           sctp_cmp_addr_exact(&chunk->dest,
+                                               &transport->ipaddr))
+                                       new_transport = transport;
+                       else
+                               new_transport = sctp_assoc_lookup_paddr(asoc,
+                                                               &chunk->dest);
+
+                       /* if we still don't have a new transport, then
+                        * use the current active path.
+                        */
+                       if (!new_transport)
+                               new_transport = asoc->peer.active_path;
                } else if ((new_transport->state == SCTP_INACTIVE) ||
                           (new_transport->state == SCTP_UNCONFIRMED)) {
                        /* If the chunk is Heartbeat or Heartbeat Ack,
@@ -729,9 +752,12 @@ int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
                         * address of the IP datagram containing the
                         * HEARTBEAT chunk to which this ack is responding.
                         * ...
+                        *
+                        * ASCONF_ACKs also must be sent to the source.
                         */
                        if (chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT &&
-                           chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT_ACK)
+                           chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT_ACK &&
+                           chunk->chunk_hdr->type != SCTP_CID_ASCONF_ACK)
                                new_transport = asoc->peer.active_path;
                }
 
@@ -1009,7 +1035,6 @@ static void sctp_sack_update_unack_data(struct sctp_association *assoc,
 static __u32 sctp_highest_new_tsn(struct sctp_sackhdr *sack,
                                  struct sctp_association *asoc)
 {
-       struct list_head *ltransport, *lchunk;
        struct sctp_transport *transport;
        struct sctp_chunk *chunk;
        __u32 highest_new_tsn, tsn;
@@ -1017,12 +1042,9 @@ static __u32 sctp_highest_new_tsn(struct sctp_sackhdr *sack,
 
        highest_new_tsn = ntohl(sack->cum_tsn_ack);
 
-       list_for_each(ltransport, transport_list) {
-               transport = list_entry(ltransport, struct sctp_transport,
-                                      transports);
-               list_for_each(lchunk, &transport->transmitted) {
-                       chunk = list_entry(lchunk, struct sctp_chunk,
-                                          transmitted_list);
+       list_for_each_entry(transport, transport_list, transports) {
+               list_for_each_entry(chunk, &transport->transmitted,
+                               transmitted_list) {
                        tsn = ntohl(chunk->subh.data_hdr->tsn);
 
                        if (!chunk->tsn_gap_acked &&
@@ -1045,7 +1067,7 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
        struct sctp_association *asoc = q->asoc;
        struct sctp_transport *transport;
        struct sctp_chunk *tchunk = NULL;
-       struct list_head *lchunk, *transport_list, *pos, *temp;
+       struct list_head *lchunk, *transport_list, *temp;
        sctp_sack_variable_t *frags = sack->variable;
        __u32 sack_ctsn, ctsn, tsn;
        __u32 highest_tsn, highest_new_tsn;
@@ -1071,9 +1093,8 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
         */
        if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) {
                primary->cacc.changeover_active = 0;
-               list_for_each(pos, transport_list) {
-                       transport = list_entry(pos, struct sctp_transport,
-                                       transports);
+               list_for_each_entry(transport, transport_list,
+                               transports) {
                        transport->cacc.cycling_changeover = 0;
                }
        }
@@ -1088,9 +1109,7 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
         */
        if (sack->num_gap_ack_blocks &&
            primary->cacc.changeover_active) {
-               list_for_each(pos, transport_list) {
-                       transport = list_entry(pos, struct sctp_transport,
-                                       transports);
+               list_for_each_entry(transport, transport_list, transports) {
                        transport->cacc.cacc_saw_newack = 0;
                }
        }
@@ -1119,9 +1138,7 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
         *
         * This is a MASSIVE candidate for optimization.
         */
-       list_for_each(pos, transport_list) {
-               transport  = list_entry(pos, struct sctp_transport,
-                                       transports);
+       list_for_each_entry(transport, transport_list, transports) {
                sctp_check_transmitted(q, &transport->transmitted,
                                       transport, sack, highest_new_tsn);
                /*
@@ -1133,9 +1150,7 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
                        count_of_newacks ++;
        }
 
-       list_for_each(pos, transport_list) {
-               transport  = list_entry(pos, struct sctp_transport,
-                                       transports);
+       list_for_each_entry(transport, transport_list, transports) {
                sctp_mark_missing(q, &transport->transmitted, transport,
                                  highest_new_tsn, count_of_newacks);
        }
@@ -1154,8 +1169,10 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
                tchunk = list_entry(lchunk, struct sctp_chunk,
                                    transmitted_list);
                tsn = ntohl(tchunk->subh.data_hdr->tsn);
-               if (TSN_lte(tsn, ctsn))
+               if (TSN_lte(tsn, ctsn)) {
+                       list_del_init(&tchunk->transmitted_list);
                        sctp_chunk_free(tchunk);
+               }
        }
 
        /* ii) Set rwnd equal to the newly received a_rwnd minus the
@@ -1176,10 +1193,10 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
        sctp_generate_fwdtsn(q, sack_ctsn);
 
        SCTP_DEBUG_PRINTK("%s: sack Cumulative TSN Ack is 0x%x.\n",
-                         __FUNCTION__, sack_ctsn);
+                         __func__, sack_ctsn);
        SCTP_DEBUG_PRINTK("%s: Cumulative TSN Ack of association, "
                          "%p is 0x%x. Adv peer ack point: 0x%x\n",
-                         __FUNCTION__, asoc, ctsn, asoc->adv_peer_ack_point);
+                         __func__, asoc, ctsn, asoc->adv_peer_ack_point);
 
        /* See if all chunks are acked.
         * Make sure the empty queue handler will get run later.
@@ -1190,9 +1207,7 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
        if (!q->empty)
                goto finish;
 
-       list_for_each(pos, transport_list) {
-               transport  = list_entry(pos, struct sctp_transport,
-                                       transports);
+       list_for_each_entry(transport, transport_list, transports) {
                q->empty = q->empty && list_empty(&transport->transmitted);
                if (!q->empty)
                        goto finish;
@@ -1414,7 +1429,7 @@ static void sctp_check_transmitted(struct sctp_outq *q,
                        if (tchunk->tsn_gap_acked) {
                                SCTP_DEBUG_PRINTK("%s: Receiver reneged on "
                                                  "data TSN: 0x%x\n",
-                                                 __FUNCTION__,
+                                                 __func__,
                                                  tsn);
                                tchunk->tsn_gap_acked = 0;
 
@@ -1531,7 +1546,7 @@ static void sctp_check_transmitted(struct sctp_outq *q,
                            (sack_ctsn+2 == q->asoc->next_tsn)) {
                                SCTP_DEBUG_PRINTK("%s: SACK received for zero "
                                                  "window probe: %u\n",
-                                                 __FUNCTION__, sack_ctsn);
+                                                 __func__, sack_ctsn);
                                q->asoc->overall_error_count = 0;
                                transport->error_count = 0;
                        }
@@ -1566,14 +1581,12 @@ static void sctp_mark_missing(struct sctp_outq *q,
                              int count_of_newacks)
 {
        struct sctp_chunk *chunk;
-       struct list_head *pos;
        __u32 tsn;
        char do_fast_retransmit = 0;
        struct sctp_transport *primary = q->asoc->peer.primary_path;
 
-       list_for_each(pos, transmitted_queue) {
+       list_for_each_entry(chunk, transmitted_queue, transmitted_list) {
 
-               chunk = list_entry(pos, struct sctp_chunk, transmitted_list);
                tsn = ntohl(chunk->subh.data_hdr->tsn);
 
                /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all
@@ -1596,7 +1609,7 @@ static void sctp_mark_missing(struct sctp_outq *q,
 
                                SCTP_DEBUG_PRINTK(
                                        "%s: TSN 0x%x missing counter: %d\n",
-                                       __FUNCTION__, tsn,
+                                       __func__, tsn,
                                        chunk->tsn_missing_report);
                        }
                }
@@ -1619,7 +1632,7 @@ static void sctp_mark_missing(struct sctp_outq *q,
 
                SCTP_DEBUG_PRINTK("%s: transport: %p, cwnd: %d, "
                                  "ssthresh: %d, flight_size: %d, pba: %d\n",
-                                 __FUNCTION__, transport, transport->cwnd,
+                                 __func__, transport, transport->cwnd,
                                  transport->ssthresh, transport->flight_size,
                                  transport->partial_bytes_acked);
        }