Don't unset IKE_SA on bus before we released virtual IPs and attributes
[strongswan.git] / src / libcharon / sa / ike_sa.c
index 050279a..d7a9076 100644 (file)
@@ -766,7 +766,6 @@ METHOD(ike_sa_t, add_virtual_ip, void,
        else
        {
                this->other_vips->insert_last(this->other_vips, ip->clone(ip));
-               charon->bus->assign_vip(charon->bus, &this->public, ip, TRUE);
        }
 }
 
@@ -777,6 +776,10 @@ METHOD(ike_sa_t, clear_virtual_ips, void,
        linked_list_t *vips = local ? this->my_vips : this->other_vips;
        host_t *vip;
 
+       if (!local && vips->get_count(vips))
+       {
+               charon->bus->assign_vips(charon->bus, &this->public, FALSE);
+       }
        while (vips->remove_first(vips, (void**)&vip) == SUCCESS)
        {
                if (local)
@@ -784,10 +787,6 @@ METHOD(ike_sa_t, clear_virtual_ips, void,
                        hydra->kernel_interface->del_ip(hydra->kernel_interface,
                                                                                        vip, -1, TRUE);
                }
-               else
-               {
-                       charon->bus->assign_vip(charon->bus, &this->public, vip, FALSE);
-               }
                vip->destroy(vip);
        }
 }
@@ -2095,21 +2094,15 @@ METHOD(ike_sa_t, destroy, void,
                free(entry->data.ptr);
                free(entry);
        }
-       this->attributes->destroy(this->attributes);
-
-       this->child_sas->destroy_offset(this->child_sas, offsetof(child_sa_t, destroy));
-
-       /* unset SA after here to avoid usage by the listeners */
-       charon->bus->set_sa(charon->bus, NULL);
-
-       DESTROY_IF(this->keymat);
-
        while (this->my_vips->remove_last(this->my_vips, (void**)&vip) == SUCCESS)
        {
                hydra->kernel_interface->del_ip(hydra->kernel_interface, vip, -1, TRUE);
                vip->destroy(vip);
        }
-       this->my_vips->destroy(this->my_vips);
+       if (this->other_vips->get_count(this->other_vips))
+       {
+               charon->bus->assign_vips(charon->bus, &this->public, FALSE);
+       }
        while (this->other_vips->remove_last(this->other_vips,
                                                                                 (void**)&vip) == SUCCESS)
        {
@@ -2124,9 +2117,16 @@ METHOD(ike_sa_t, destroy, void,
                        hydra->attributes->release_address(hydra->attributes, pools, vip, id);
                        pools->destroy(pools);
                }
-               charon->bus->assign_vip(charon->bus, &this->public, vip, FALSE);
                vip->destroy(vip);
        }
+
+       /* unset SA after here to avoid usage by the listeners */
+       charon->bus->set_sa(charon->bus, NULL);
+
+       this->child_sas->destroy_offset(this->child_sas, offsetof(child_sa_t, destroy));
+       DESTROY_IF(this->keymat);
+       this->attributes->destroy(this->attributes);
+       this->my_vips->destroy(this->my_vips);
        this->other_vips->destroy(this->other_vips);
        this->peer_addresses->destroy_offset(this->peer_addresses,
                                                                                 offsetof(host_t, destroy));