1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

bug #1178: Ownership of the VM is checked now before releasing the IP/MAC lease

This commit is contained in:
Ruben S. Montero 2012-03-31 22:20:27 +02:00
parent 9c4d753219
commit aec7af2c75
4 changed files with 52 additions and 3 deletions

View File

@ -299,8 +299,21 @@ protected:
*/
bool check(const string& ip);
/**
* Check if the passed ip corresponds with a given lease
* @param ip of the lease to be checked
* @return true if the ip was already assigned
*/
bool check(unsigned int ip);
/**
* Check if a VM is the owner of the ip
* @param ip of the lease to be checked
* @param vid the ID of the VM
* @return true if the ip was already assigned
*/
bool is_owner(const string& ip, int vid);
/**
* Reads the leases from the DB, and updates the lease hash table
* @param db pointer to the database.

View File

@ -136,7 +136,7 @@ public:
};
/**
* Release previously given lease
* Release previously given lease
* @param _ip IP identifying the lease
* @return 0 if success
*/
@ -145,6 +145,17 @@ public:
return leases->release(ip);
};
/**
* Check if a VM is the owner of the ip
* @param ip of the lease to be checked
* @param vid the ID of the VM
* @return true if the ip was already assigned
*/
bool is_owner (const string& ip, int vid)
{
return leases->is_owner(ip, vid);
};
/**
* Gets size of the network (used + free)
* @return number of hosts that can be fitted in this network

View File

@ -1084,8 +1084,11 @@ void VirtualMachine::release_network_leases()
continue;
}
vn->release_lease(ip);
vnpool->update(vn);
if (vn->is_owner(ip,oid))
{
vn->release_lease(ip);
vnpool->update(vn);
}
vn->unlock();
}

View File

@ -415,6 +415,28 @@ bool Leases::check(unsigned int ip)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool Leases::is_owner(const string& ip, int vid)
{
unsigned int _ip;
map<unsigned int,Lease *>::iterator it;
Leases::Lease::ip_to_number(ip,_ip);
it = leases.find(_ip);
if (it!=leases.end())
{
return (it->second->vid == vid);
}
else
{
return false;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Leases::hold_leases(vector<const Attribute*>& vector_leases,
string& error_msg)
{