Replaced ike_sa_t.create_additional_address_iterator with enumerator.
authorTobias Brunner <tobias@strongswan.org>
Thu, 19 May 2011 16:05:53 +0000 (18:05 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 6 Jul 2011 07:43:45 +0000 (09:43 +0200)
src/libcharon/plugins/ha/ha_ike.c
src/libcharon/sa/ike_sa.c
src/libcharon/sa/ike_sa.h
src/libcharon/sa/tasks/ike_mobike.c

index 1efba4e..44df6c1 100644 (file)
@@ -143,7 +143,7 @@ METHOD(listener_t, ike_updown, bool,
 
        if (up)
        {
-               iterator_t *iterator;
+               enumerator_t *enumerator;
                peer_cfg_t *peer_cfg;
                u_int32_t extension, condition;
                host_t *addr;
@@ -180,12 +180,12 @@ METHOD(listener_t, ike_updown, bool,
                m->add_attribute(m, HA_CONDITIONS, condition);
                m->add_attribute(m, HA_EXTENSIONS, extension);
                m->add_attribute(m, HA_CONFIG_NAME, peer_cfg->get_name(peer_cfg));
-               iterator = ike_sa->create_additional_address_iterator(ike_sa);
-               while (iterator->iterate(iterator, (void**)&addr))
+               enumerator = ike_sa->create_additional_address_enumerator(ike_sa);
+               while (enumerator->enumerate(enumerator, (void**)&addr))
                {
                        m->add_attribute(m, HA_ADDITIONAL_ADDR, addr);
                }
-               iterator->destroy(iterator);
+               enumerator->destroy(enumerator);
        }
        else
        {
index f4ce35d..ba26369 100644 (file)
@@ -774,11 +774,25 @@ METHOD(ike_sa_t, add_additional_address, void,
        this->additional_addresses->insert_last(this->additional_addresses, host);
 }
 
-METHOD(ike_sa_t, create_additional_address_iterator, iterator_t*,
+METHOD(ike_sa_t, create_additional_address_enumerator, enumerator_t*,
        private_ike_sa_t *this)
 {
-       return this->additional_addresses->create_iterator(
-                                                                                       this->additional_addresses, TRUE);
+       return this->additional_addresses->create_enumerator(
+                                                                                               this->additional_addresses);
+}
+
+METHOD(ike_sa_t, remove_additional_addresses, void,
+       private_ike_sa_t *this)
+{
+       enumerator_t *enumerator = create_additional_address_enumerator(this);
+       host_t *host;
+       while (enumerator->enumerate(enumerator, (void**)&host))
+       {
+               this->additional_addresses->remove_at(this->additional_addresses,
+                                                                                         enumerator);
+               host->destroy(host);
+       }
+       enumerator->destroy(enumerator);
 }
 
 METHOD(ike_sa_t, has_mapping_changed, bool,
@@ -2114,8 +2128,9 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
                        .has_condition = _has_condition,
                        .set_pending_updates = _set_pending_updates,
                        .get_pending_updates = _get_pending_updates,
-                       .create_additional_address_iterator = _create_additional_address_iterator,
+                       .create_additional_address_enumerator = _create_additional_address_enumerator,
                        .add_additional_address = _add_additional_address,
+                       .remove_additional_addresses = _remove_additional_addresses,
                        .has_mapping_changed = _has_mapping_changed,
                        .retransmit = _retransmit,
                        .delete = _delete_,
index 1b2ccd7..5e3c34a 100644 (file)
@@ -472,11 +472,16 @@ struct ike_sa_t {
        void (*add_additional_address)(ike_sa_t *this, host_t *host);
 
        /**
-        * Create an iterator over all additional addresses of the peer.
+        * Create an enumerator over all additional addresses of the peer.
         *
-        * @return                              iterator over addresses
+        * @return                              enumerator over addresses
         */
-       iterator_t* (*create_additional_address_iterator)(ike_sa_t *this);
+       enumerator_t* (*create_additional_address_enumerator)(ike_sa_t *this);
+
+       /**
+        * Remove all additional addresses of the peer.
+        */
+       void (*remove_additional_addresses)(ike_sa_t *this);
 
        /**
         * Check if mappings have changed on a NAT for our source address.
index eec68c6..da8834c 100644 (file)
@@ -79,24 +79,6 @@ struct private_ike_mobike_t {
 };
 
 /**
- * flush the IKE_SAs list of additional addresses
- */
-static void flush_additional_addresses(private_ike_mobike_t *this)
-{
-       iterator_t *iterator;
-       host_t *host;
-
-       iterator = this->ike_sa->create_additional_address_iterator(this->ike_sa);
-       while (iterator->iterate(iterator, (void**)&host))
-       {
-               iterator->remove(iterator);
-               host->destroy(host);
-       }
-       iterator->destroy(iterator);
-}
-
-
-/**
  * read notifys from message and evaluate them
  */
 static void process_payloads(private_ike_mobike_t *this, message_t *message)
@@ -152,7 +134,7 @@ static void process_payloads(private_ike_mobike_t *this, message_t *message)
                        {
                                if (first)
                                {       /* an ADDITIONAL_*_ADDRESS means replace, so flush once */
-                                       flush_additional_addresses(this);
+                                       this->ike_sa->remove_additional_addresses(this->ike_sa);
                                        first = FALSE;
                                }
                                data = notify->get_notification_data(notify);
@@ -169,7 +151,7 @@ static void process_payloads(private_ike_mobike_t *this, message_t *message)
                        }
                        case NO_ADDITIONAL_ADDRESSES:
                        {
-                               flush_additional_addresses(this);
+                               this->ike_sa->remove_additional_addresses(this->ike_sa);
                                this->addresses_updated = TRUE;
                                break;
                        }
@@ -296,7 +278,7 @@ METHOD(ike_mobike_t, transmit, void,
           private_ike_mobike_t *this, packet_t *packet)
 {
        host_t *me, *other, *me_old, *other_old;
-       iterator_t *iterator;
+       enumerator_t *enumerator;
        ike_cfg_t *ike_cfg;
        packet_t *copy;
 
@@ -320,8 +302,8 @@ METHOD(ike_mobike_t, transmit, void,
                charon->sender->send(charon->sender, copy);
        }
 
-       iterator = this->ike_sa->create_additional_address_iterator(this->ike_sa);
-       while (iterator->iterate(iterator, (void**)&other))
+       enumerator = this->ike_sa->create_additional_address_enumerator(this->ike_sa);
+       while (enumerator->enumerate(enumerator, (void**)&other))
        {
                me = hydra->kernel_interface->get_source_addr(
                                                                                hydra->kernel_interface, other, NULL);
@@ -343,7 +325,7 @@ METHOD(ike_mobike_t, transmit, void,
                        charon->sender->send(charon->sender, copy);
                }
        }
-       iterator->destroy(iterator);
+       enumerator->destroy(enumerator);
 }
 
 METHOD(task_t, build_i, status_t,