From aec7af2c75960c917e381571ca630eec779653bd Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 31 Mar 2012 22:20:27 +0200 Subject: [PATCH] bug #1178: Ownership of the VM is checked now before releasing the IP/MAC lease --- include/Leases.h | 13 +++++++++++++ include/VirtualNetwork.h | 13 ++++++++++++- src/vm/VirtualMachine.cc | 7 +++++-- src/vnm/Leases.cc | 22 ++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/include/Leases.h b/include/Leases.h index 24bf919346..d6adc8040e 100644 --- a/include/Leases.h +++ b/include/Leases.h @@ -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. diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index 069a7449a6..a70063059c 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -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 diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index d60d8dcee3..f25160dcf0 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -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(); } diff --git a/src/vnm/Leases.cc b/src/vnm/Leases.cc index 5d462a69f5..b46d08ee2d 100644 --- a/src/vnm/Leases.cc +++ b/src/vnm/Leases.cc @@ -415,6 +415,28 @@ bool Leases::check(unsigned int ip) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +bool Leases::is_owner(const string& ip, int vid) +{ + unsigned int _ip; + map::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& vector_leases, string& error_msg) {