mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-11 05:17:41 +03:00
F #5027: Operations (hold, release, reserve...) for IP6 no-slaac ARs
This commit is contained in:
parent
948d1d98c4
commit
ba40cffd61
@ -188,7 +188,7 @@ public:
|
||||
VectorAttribute * nic, const vector<string> &inherit);
|
||||
|
||||
/**
|
||||
* Returns the specific address by mac if is not allocated. The NIC attr
|
||||
* Returns the specific address by mac/ip if is not allocated. The NIC attr
|
||||
* is filled with the configuration parameters from the address range.
|
||||
* @param mac the mac address
|
||||
* @param ot the type of the object allocating the address
|
||||
@ -200,48 +200,36 @@ public:
|
||||
int allocate_by_mac(const string& mac, PoolObjectSQL::ObjectType ot,
|
||||
int obid, VectorAttribute * nic, const vector<string> &inherit);
|
||||
|
||||
/**
|
||||
* Returns the specific address by ip if is not allocated. The NIC attr
|
||||
* is filled with the configuration parameters from the address range.
|
||||
* @param ot the type of the object allocating the address
|
||||
* @param obid the id of the object
|
||||
* @param nic the VM NIC attribute
|
||||
* @param inherit attributes to be added to the NIC attribute
|
||||
* @return 0 if success
|
||||
*/
|
||||
int allocate_by_ip(const string& ip, PoolObjectSQL::ObjectType ot,
|
||||
int obid, VectorAttribute * nic, const vector<string> &inherit);
|
||||
|
||||
/**
|
||||
* Sets the given ip on hold, the address is associated to a VM of id -1.
|
||||
* @param ip the ip to hold
|
||||
*/
|
||||
int hold_by_ip(const string& ip);
|
||||
int allocate_by_ip6(const string& ip6, PoolObjectSQL::ObjectType ot,
|
||||
int obid, VectorAttribute * nic, const vector<string> &inherit);
|
||||
|
||||
/**
|
||||
* Sets the given mac on hold, the address is associated to a VM of id -1.
|
||||
* @param mac the mac to hold
|
||||
* Sets the given ip/mac on hold, the address is associated to a VM of
|
||||
* id -1.
|
||||
* @param ip/mac the ip to hold
|
||||
*/
|
||||
int hold_by_mac(const string& mac);
|
||||
|
||||
int hold_by_ip(const string& ip);
|
||||
|
||||
int hold_by_ip6(const string& ip);
|
||||
|
||||
/**
|
||||
* Frees a previous allocated address, referenced by its MAC address
|
||||
* Frees a previous allocated address, referenced by its MAC/IP address
|
||||
* @param ot the object type of the owner of the address
|
||||
* @param obid the id of the owner of the address
|
||||
* @param mac the MAC address in string form
|
||||
* @param mac/ip the MAC/IP address in string form
|
||||
* @return 0 if the address was freed
|
||||
*/
|
||||
int free_addr(PoolObjectSQL::ObjectType ot, int obid, const string& mac);
|
||||
|
||||
/**
|
||||
* Frees a previous allocated address, referenced by its IP address
|
||||
* @param ot the object type of the owner of the address
|
||||
* @param obid the id of the owner of the address
|
||||
* @param ip the IP address in string form
|
||||
* @return 0 if the address was freed
|
||||
*/
|
||||
int free_addr_by_ip(PoolObjectSQL::ObjectType ot, int id, const string& ip);
|
||||
|
||||
int free_addr_by_ip6(PoolObjectSQL::ObjectType ot, int id,const string& ip);
|
||||
|
||||
/**
|
||||
* Frees all previous allocated address to the given object
|
||||
* @param ot the object type of the owner of the address
|
||||
@ -287,23 +275,18 @@ public:
|
||||
* @param vid the id of the VNET making the reservation
|
||||
* @param size number of addresses to reserve
|
||||
* @param rar a new address range to place the reservation
|
||||
* @param ip the firs ip in the Reservation
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr_by_ip(int vid, unsigned int rsize, const string& ip,
|
||||
AddressRange *rar);
|
||||
|
||||
/**
|
||||
* Reserve a given number of addresses from this address range
|
||||
* @param vid the id of the VNET making the reservation
|
||||
* @param size number of addresses to reserve
|
||||
* @param rar a new address range to place the reservation
|
||||
* @param mac the firs mac in the Reservation
|
||||
* @param ip/mac the firs ip in the Reservation
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr_by_mac(int vid, unsigned int rsize, const string& mac,
|
||||
AddressRange *rar);
|
||||
|
||||
int reserve_addr_by_ip(int vid, unsigned int rsize, const string& ip,
|
||||
AddressRange *rar);
|
||||
|
||||
int reserve_addr_by_ip6(int vid, unsigned int rsize, const string& ip,
|
||||
AddressRange *rar);
|
||||
|
||||
// *************************************************************************
|
||||
// Helpers
|
||||
// *************************************************************************
|
||||
@ -417,6 +400,7 @@ protected:
|
||||
* <MAC>
|
||||
* <IP6_ULA>
|
||||
* <IP6_GLOBAL>
|
||||
* <IP6>
|
||||
* <SIZE>
|
||||
*
|
||||
* @param index for the address
|
||||
@ -453,6 +437,20 @@ protected:
|
||||
*/
|
||||
bool is_valid_ip(unsigned int& index, const string& ip_s, bool check_free);
|
||||
|
||||
/**
|
||||
* Check if the given IP is valid for this address range by verifying:
|
||||
* - AR is of type IP6_STATIC or IP4_6_STATIC
|
||||
* - Correct : notation
|
||||
* - Part of the AR
|
||||
*
|
||||
* @param index of the IP in the AR
|
||||
* @param ip6_s string representation of the IP in : notation
|
||||
* @param check_free apart from previous checks
|
||||
*
|
||||
* @return true if the IP is valid
|
||||
*/
|
||||
bool is_valid_ip6(unsigned int& index, const string& ip_s, bool check_free);
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Implementation specific address management interface */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -556,13 +554,7 @@ private:
|
||||
int ip6_to_s(const unsigned int prefix[], const unsigned int mac[],
|
||||
string& ip6_s) const;
|
||||
|
||||
/**
|
||||
* IP version 6 to colon notation
|
||||
*
|
||||
* @param i_ip Numeric (128 bits) IP
|
||||
* @return string in colon notation
|
||||
*/
|
||||
string ip6_to_s(const unsigned int i_ip6[]) const;
|
||||
int ip6_to_s(const unsigned int ip6_i[], string& ip6_s) const;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* NIC setup functions */
|
||||
|
@ -117,8 +117,8 @@ public:
|
||||
VectorAttribute * nic, const vector<string> &inherit);
|
||||
|
||||
/**
|
||||
* Allocates an address in a suitable address range from the pool by mac
|
||||
* @param mac the specific MAC address requested
|
||||
* Allocates an address in a suitable address range from the pool by mac/ip
|
||||
* @param mac/ip the specific MAC/IP address requested
|
||||
* @param ot the type of the object requesting the address (VM or NET)
|
||||
* @param obid the id of the object requesting the address
|
||||
* @param nic the NIC attribute to be filled with lease attributes
|
||||
@ -128,86 +128,64 @@ public:
|
||||
int allocate_by_mac(const string &mac, PoolObjectSQL::ObjectType ot, int obid,
|
||||
VectorAttribute * nic, const vector<string> &inherit);
|
||||
|
||||
/**
|
||||
* Allocates an address in a suitable address range from the pool by mac
|
||||
* @param ip the specific IP address requested
|
||||
* @param ot the type of the object requesting the address (VM or NET)
|
||||
* @param obid the id of the object requesting the address
|
||||
* @param nic the NIC attribute to be filled with lease attributes
|
||||
* @param inherit attributes to be added to the NIC
|
||||
* @return 0 if success
|
||||
*/
|
||||
int allocate_by_ip(const string &ip, PoolObjectSQL::ObjectType ot, int obid,
|
||||
VectorAttribute * nic, const vector<string> &inherit);
|
||||
|
||||
int allocate_by_ip6(const string &ip, PoolObjectSQL::ObjectType ot, int obid,
|
||||
VectorAttribute * nic, const vector<string> &inherit);
|
||||
|
||||
/**
|
||||
* Holds an address from the specified address range.
|
||||
* @param arid of the address range
|
||||
* @param ip the ip to hold
|
||||
* @return 0 on success
|
||||
*/
|
||||
int hold_by_ip(unsigned int arid, const string& ip);
|
||||
|
||||
/**
|
||||
* Holds an address from the first address range containing the MAC
|
||||
* @param mac the mac to hold
|
||||
* @return 0 on success
|
||||
*/
|
||||
int hold_by_ip(const string& ip);
|
||||
|
||||
/**
|
||||
* Holds an address from the specified address range.
|
||||
* @param arid of the address range
|
||||
* @param mac the mac to hold
|
||||
* @param mac/ip the mac/ip to hold
|
||||
* @return 0 on success
|
||||
*/
|
||||
int hold_by_mac(unsigned int arid, const string& mac);
|
||||
|
||||
int hold_by_ip(unsigned int arid, const string& ip);
|
||||
|
||||
int hold_by_ip6(unsigned int arid, const string& ip);
|
||||
|
||||
/**
|
||||
* Holds an address from the first address range containing the MAC
|
||||
* @param mac the mac to hold
|
||||
* @param mac/ip the mac/ip to hold
|
||||
* @return 0 on success
|
||||
*/
|
||||
int hold_by_mac(const string& mac);
|
||||
|
||||
int hold_by_ip(const string& ip);
|
||||
|
||||
int hold_by_ip6(const string& ip);
|
||||
|
||||
/**
|
||||
* Frees the given address by MAC on the given address range
|
||||
* Frees the given address by MAC/IP on the given address range
|
||||
* @param arid the ID of the address range
|
||||
* @param ot the type of the object requesting the address (VM or NET)
|
||||
* @param obid the id of the object requesting the address
|
||||
* @param mac the specific MAC address requested
|
||||
* @param mac/ip the specific MAC/IP address requested
|
||||
*/
|
||||
void free_addr(unsigned int arid, PoolObjectSQL::ObjectType ot, int obid,
|
||||
const string& mac);
|
||||
|
||||
/**
|
||||
* Frees the given address by IP on the given address range
|
||||
* @param arid the ID of the address range
|
||||
* @param ot the type of the object requesting the address (VM or NET)
|
||||
* @param obid the id of the object requesting the address
|
||||
* @param ip the specific IP address requested
|
||||
*/
|
||||
void free_addr_by_ip(unsigned int arid, PoolObjectSQL::ObjectType ot,
|
||||
int obid, const string& ip);
|
||||
|
||||
void free_addr_by_ip6(unsigned int arid, PoolObjectSQL::ObjectType ot,
|
||||
int obid, const string& ip);
|
||||
|
||||
/**
|
||||
* Frees the given address by MAC from all address ranges containing
|
||||
* the MAC
|
||||
* Frees the given address by MAC/IP from all address ranges containing
|
||||
* the MAC/IP
|
||||
* @param ot the type of the object requesting the address (VM or NET)
|
||||
* @param obid the id of the object requesting the address
|
||||
* @param mac the specific MAC address requested
|
||||
* @param mac/ip the specific MAC/IP address requested
|
||||
*/
|
||||
void free_addr(PoolObjectSQL::ObjectType ot, int obid, const string& mac);
|
||||
|
||||
/**
|
||||
* Frees the given address by IP from all address ranges containing
|
||||
* the IP
|
||||
* @param ot the type of the object requesting the address (VM or NET)
|
||||
* @param obid the id of the object requesting the address
|
||||
* @param ip the specific IP address requested
|
||||
*/
|
||||
void free_addr_by_ip(PoolObjectSQL::ObjectType ot, int id, const string& ip);
|
||||
|
||||
void free_addr_by_ip6(PoolObjectSQL::ObjectType ot, int id,const string& ip);
|
||||
|
||||
/**
|
||||
* Frees all the addressed owned by the given object
|
||||
* @param ot the type of the object requesting the address (VM or NET)
|
||||
@ -265,29 +243,24 @@ public:
|
||||
AddressRange *rar);
|
||||
|
||||
/**
|
||||
* Reserve a number of addresses from an address range from a given ip
|
||||
* Reserve a number of addresses from an address range from a given ip/mac
|
||||
* @param vid the id of the VNET making the reservation
|
||||
* @param rsize number of addresses to reserve
|
||||
* @param ar_id the address range to reserve the addresses from
|
||||
* @param ip the first IP in the reservation
|
||||
* @param rar a new address range to place the reservation
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr_by_ip(int vid, unsigned int rsize, unsigned int ar_id,
|
||||
const string& ip, AddressRange *rar);
|
||||
|
||||
/**
|
||||
* Reserve a number of addresses from an address range from a given ip
|
||||
* @param vid the id of the VNET making the reservation
|
||||
* @param rsize number of addresses to reserve
|
||||
* @param ar_id the address range to reserve the addresses from
|
||||
* @param mac the first IP in the reservation
|
||||
* @param mac/ip the first MAC/IP in the reservation
|
||||
* @param rar a new address range to place the reservation
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr_by_mac(int vid, unsigned int rsize, unsigned int ar_id,
|
||||
const string& mac, AddressRange *rar);
|
||||
|
||||
int reserve_addr_by_ip(int vid, unsigned int rsize, unsigned int ar_id,
|
||||
const string& ip, AddressRange *rar);
|
||||
|
||||
int reserve_addr_by_ip6(int vid, unsigned int rsize, unsigned int ar_id,
|
||||
const string& ip, AddressRange *rar);
|
||||
|
||||
|
||||
// *************************************************************************
|
||||
// Helpers & Formatting
|
||||
// *************************************************************************
|
||||
|
@ -217,50 +217,6 @@ public:
|
||||
// Address allocation funtions
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Gets a new address lease for a specific VM
|
||||
* @param ot the type of the object requesting the address
|
||||
* @param oid the id of the object requesting the address
|
||||
* @param nic the VM NIC attribute to be filled with the lease info.
|
||||
* @param inherit attributes from the address range to include in the NIC
|
||||
* @return 0 if success
|
||||
*/
|
||||
int allocate_addr(PoolObjectSQL::ObjectType ot, int oid,
|
||||
VectorAttribute * nic, const vector<string>& inherit)
|
||||
{
|
||||
return ar_pool.allocate_addr(ot, oid, nic, inherit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new address lease for a specific VM by MAC
|
||||
* @param ot the type of the object requesting the address
|
||||
* @param oid the id of the object requesting the address
|
||||
* @param mac the MAC address requested
|
||||
* @param nic the VM NIC attribute to be filled with the lease info.
|
||||
* @param inherit attributes from the address range to include in the NIC
|
||||
* @return 0 if success
|
||||
*/
|
||||
int allocate_by_mac(PoolObjectSQL::ObjectType ot, int oid, const string& mac,
|
||||
VectorAttribute * nic, const vector<string>& inherit)
|
||||
{
|
||||
return ar_pool.allocate_by_mac(mac, ot, oid, nic, inherit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new address lease for a specific VM by IP
|
||||
* @param ot the type of the object requesting the address
|
||||
* @param oid the id of the object requesting the address
|
||||
* @param ip the IP address requested
|
||||
* @param nic the VM NIC attribute to be filled with the lease info.
|
||||
* @param inherit attributes from the address range to include in the NIC
|
||||
* @return 0 if success
|
||||
*/
|
||||
int allocate_by_ip(PoolObjectSQL::ObjectType ot, int oid, const string& ip,
|
||||
VectorAttribute * nic, const vector<string>& inherit)
|
||||
{
|
||||
return ar_pool.allocate_by_ip(ip, ot, oid, nic, inherit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release previously given address lease
|
||||
* @param arid of the address range where the address was leased from
|
||||
@ -392,20 +348,7 @@ public:
|
||||
* @param rid the reservation VNET ID to store the reserved AR
|
||||
* @param rsize number of addresses to reserve
|
||||
* @param ar_id id of the address range to obtain the addresses
|
||||
* @param ip the first ip in the reservations
|
||||
* @param rar the address range to place the reservation
|
||||
* @param err error message
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr_by_ip(int rid, unsigned int rsize, unsigned int ar_id,
|
||||
const string& ip, AddressRange *rar, string& error_str);
|
||||
|
||||
/**
|
||||
* Reserve an address range for this network and add it to the given vnet
|
||||
* @param rid the reservation VNET ID to store the reserved AR
|
||||
* @param rsize number of addresses to reserve
|
||||
* @param ar_id id of the address range to obtain the addresses
|
||||
* @param mac the first mac in the reservations
|
||||
* @param ip/mac the first ip/mac in the reservations
|
||||
* @param rar the address range to place the reservation
|
||||
* @param err error message
|
||||
* @return 0 on success
|
||||
@ -413,6 +356,12 @@ public:
|
||||
int reserve_addr_by_mac(int rid, unsigned int rsize, unsigned int ar_id,
|
||||
const string& mac, AddressRange *rar, string& error_str);
|
||||
|
||||
int reserve_addr_by_ip(int rid, unsigned int rsize, unsigned int ar_id,
|
||||
const string& ip, AddressRange *rar, string& error_str);
|
||||
|
||||
int reserve_addr_by_ip6(int rid, unsigned int rsize, unsigned int ar_id,
|
||||
const string& ip6, AddressRange *rar, string& error_str);
|
||||
|
||||
/**
|
||||
* Returns true if this VNET is a reservation
|
||||
* @return true if this VNET is a reservation
|
||||
@ -581,6 +530,51 @@ private:
|
||||
*/
|
||||
ObjectCollection vrouters;
|
||||
|
||||
// *************************************************************************
|
||||
// Address allocation funtions
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Gets a new address lease for a specific VM
|
||||
* @param ot the type of the object requesting the address
|
||||
* @param oid the id of the object requesting the address
|
||||
* @param nic the VM NIC attribute to be filled with the lease info.
|
||||
* @param inherit attributes from the address range to include in the NIC
|
||||
* @return 0 if success
|
||||
*/
|
||||
int allocate_addr(PoolObjectSQL::ObjectType ot, int oid,
|
||||
VectorAttribute * nic, const vector<string>& inherit)
|
||||
{
|
||||
return ar_pool.allocate_addr(ot, oid, nic, inherit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new address lease for a specific VM by MAC/IP
|
||||
* @param ot the type of the object requesting the address
|
||||
* @param oid the id of the object requesting the address
|
||||
* @param mac/ip the MAC/IP address requested
|
||||
* @param nic the VM NIC attribute to be filled with the lease info.
|
||||
* @param inherit attributes from the address range to include in the NIC
|
||||
* @return 0 if success
|
||||
*/
|
||||
int allocate_by_mac(PoolObjectSQL::ObjectType ot, int oid, const string& mac,
|
||||
VectorAttribute * nic, const vector<string>& inherit)
|
||||
{
|
||||
return ar_pool.allocate_by_mac(mac, ot, oid, nic, inherit);
|
||||
}
|
||||
|
||||
int allocate_by_ip(PoolObjectSQL::ObjectType ot, int oid, const string& ip,
|
||||
VectorAttribute * nic, const vector<string>& inherit)
|
||||
{
|
||||
return ar_pool.allocate_by_ip(ip, ot, oid, nic, inherit);
|
||||
}
|
||||
|
||||
int allocate_by_ip6(PoolObjectSQL::ObjectType ot, int oid, const string& ip,
|
||||
VectorAttribute * nic, const vector<string>& inherit)
|
||||
{
|
||||
return ar_pool.allocate_by_ip6(ip, ot, oid, nic, inherit);
|
||||
}
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
// *************************************************************************
|
||||
|
@ -236,24 +236,19 @@ public:
|
||||
* @param rid the reservation VNET ID to store the reserved AR
|
||||
* @param rsize number of addresses to reserve
|
||||
* @param ar_id AR to make the reservation from
|
||||
* @param ip the first ip in the reservations
|
||||
* @param ip/mac the first ip/mac in the reservations
|
||||
* @param err error message
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr_by_ip(int pid, int rid, unsigned int rsize,
|
||||
unsigned int ar_id, const string& ip, string& err);
|
||||
/**
|
||||
* Reserve an address range
|
||||
* @param pid the parent VNET ID to get the leases from
|
||||
* @param rid the reservation VNET ID to store the reserved AR
|
||||
* @param rsize number of addresses to reserve
|
||||
* @param ar_id AR to make the reservation from
|
||||
* @param mac the first mac in the reservations
|
||||
* @param err error message
|
||||
* @return 0 on success
|
||||
*/
|
||||
|
||||
int reserve_addr_by_ip6(int pid, int rid, unsigned int rsize,
|
||||
unsigned int ar_id, const string& ip, string& err);
|
||||
|
||||
int reserve_addr_by_mac(int pid, int rid, unsigned int rsize,
|
||||
unsigned int ar_id, const string& mac, string& err);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Holds the system-wide MAC prefix
|
||||
|
@ -274,6 +274,10 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
puts format % ["IP6_ULA", ar["IP6_ULA"], ar["IP6_ULA_END"]]
|
||||
end
|
||||
|
||||
if !ar["IP6"].nil?
|
||||
puts format % ["IP6", ar["IP6"], ar["IP6_END"]]
|
||||
end
|
||||
|
||||
puts
|
||||
end
|
||||
|
||||
@ -325,8 +329,8 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
d["IP"]||"-"
|
||||
end
|
||||
|
||||
column :IP6_GLOBAL, "", :donottruncate, :size=>26 do |d|
|
||||
d["IP6_GLOBAL"]||"-"
|
||||
column :IP6, "", :donottruncate, :size=>26 do |d|
|
||||
d["IP6"]||d["IP6_GLOBAL"]||"-"
|
||||
end
|
||||
end.show(leases, {})
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
|
||||
require 'opennebula/pool_element'
|
||||
require 'ipaddr'
|
||||
|
||||
module OpenNebula
|
||||
class VirtualNetwork < PoolElement
|
||||
@ -184,11 +185,9 @@ module OpenNebula
|
||||
def hold(ip, ar_id=-1)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
if ip.include?':'
|
||||
addr_name = "MAC"
|
||||
else
|
||||
addr_name = "IP"
|
||||
end
|
||||
addr_name = address_type(ip)
|
||||
|
||||
return addr_name if OpenNebula.is_error?(addr_name)
|
||||
|
||||
lease_template = "LEASES = [ #{addr_name} = #{ip}"
|
||||
lease_template << ", AR_ID = #{ar_id}" if ar_id != -1
|
||||
@ -207,11 +206,9 @@ module OpenNebula
|
||||
def release(ip, ar_id=-1)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
if ip.include?':'
|
||||
addr_name = "MAC"
|
||||
else
|
||||
addr_name = "IP"
|
||||
end
|
||||
addr_name = address_type(ip)
|
||||
|
||||
return addr_name if OpenNebula.is_error?(addr_name)
|
||||
|
||||
lease_template = "LEASES = [ #{addr_name} = #{ip}"
|
||||
lease_template << ", AR_ID = #{ar_id}" if ar_id != -1
|
||||
@ -243,11 +240,9 @@ module OpenNebula
|
||||
rtmpl << "NETWORK_ID = #{vnet}\n" if !vnet.nil?
|
||||
|
||||
if !addr.nil?
|
||||
if addr.include?':'
|
||||
addr_name = "MAC"
|
||||
else
|
||||
addr_name = "IP"
|
||||
end
|
||||
addr_name = address_type(addr)
|
||||
|
||||
return addr_name if OpenNebula.is_error?(addr_name)
|
||||
|
||||
rtmpl << "#{addr_name} = #{addr}\n"
|
||||
end
|
||||
@ -342,5 +337,27 @@ module OpenNebula
|
||||
chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
|
||||
end
|
||||
|
||||
# Returns the OpenNebula name of the address to use it in LEASE
|
||||
# attributes. MAC, IP or IP6 is returned for MAC addresses in colon
|
||||
# notation, ipv4 and ipv6 respectively
|
||||
def address_type(addr)
|
||||
begin
|
||||
ipaddr = IPAddr.new addr
|
||||
|
||||
if ipaddr.ipv4?
|
||||
return "IP"
|
||||
elsif ipaddr.ipv6?
|
||||
return "IP6"
|
||||
else
|
||||
return Error.new('Unknown IP type')
|
||||
end
|
||||
rescue
|
||||
if /^(\h{2}:){5}\h{2}$/ =~ addr
|
||||
return "MAC"
|
||||
else
|
||||
return Error.new('Unknown address type')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -301,13 +301,15 @@ void VirtualNetworkReserve::request_execute(
|
||||
return;
|
||||
}
|
||||
|
||||
string ip, mac;
|
||||
string ip, mac, ip6;
|
||||
|
||||
tmpl.get("IP", ip);
|
||||
|
||||
tmpl.get("IP6", ip6);
|
||||
|
||||
tmpl.get("MAC", mac);
|
||||
|
||||
if (!with_ar_id && (!ip.empty()||!mac.empty()))
|
||||
if (!with_ar_id && (!ip.empty() || !mac.empty() || !ip6.empty()))
|
||||
{
|
||||
att.resp_msg = "AR_ID must be specified for IP/MAC based reservations";
|
||||
failure_response(ACTION, att);
|
||||
@ -421,11 +423,18 @@ void VirtualNetworkReserve::request_execute(
|
||||
{
|
||||
if (!ip.empty())
|
||||
{
|
||||
rc = vnpool->reserve_addr_by_ip(id, rid, size, ar_id, ip, att.resp_msg);
|
||||
rc = vnpool->reserve_addr_by_ip(id, rid, size, ar_id, ip,
|
||||
att.resp_msg);
|
||||
}
|
||||
if (!ip6.empty())
|
||||
{
|
||||
rc = vnpool->reserve_addr_by_ip6(id, rid, size, ar_id, ip6,
|
||||
att.resp_msg);
|
||||
}
|
||||
else if (!mac.empty())
|
||||
{
|
||||
rc = vnpool->reserve_addr_by_mac(id, rid, size, ar_id, mac, att.resp_msg);
|
||||
rc = vnpool->reserve_addr_by_mac(id, rid, size, ar_id, mac,
|
||||
att.resp_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -310,7 +310,7 @@ int AddressRange::update_attributes(
|
||||
|
||||
if (is_ipv6_static())
|
||||
{
|
||||
vup->replace("IP", attr->vector_value("IP"));
|
||||
vup->replace("IP6", attr->vector_value("IP6"));
|
||||
}
|
||||
|
||||
/* ----------------- Remove internal attributes ----------------- */
|
||||
@ -506,12 +506,14 @@ void AddressRange::addr_to_xml(unsigned int index, unsigned int rsize,
|
||||
|
||||
if ( ip6[0] != 0 || ip6[1] != 0 || ip6[2] != 0 || ip6[3] != 0 )
|
||||
{
|
||||
unsigned int ip_low[2];
|
||||
unsigned int ip_low[4];
|
||||
|
||||
ip_low[0] = ip6[0] + index;
|
||||
ip_low[3] = ip6[3];
|
||||
ip_low[2] = ip6[2];
|
||||
ip_low[1] = ip6[1];
|
||||
ip_low[0] = ip6[0] + index;
|
||||
|
||||
oss << "<IP6>" << ip6_to_s(&(ip6[2]), ip_low, ip6_s) << "</IP6>";
|
||||
oss << "<IP6>" << ip6_to_s(ip_low, ip6_s) << "</IP6>";
|
||||
}
|
||||
|
||||
oss << "<SIZE>" << rsize << "</SIZE>"
|
||||
@ -590,16 +592,14 @@ void AddressRange::to_xml(ostringstream &oss) const
|
||||
if (is_ipv6_static())
|
||||
{
|
||||
string ip6_s;
|
||||
unsigned int ip_low[4];
|
||||
|
||||
ip6_to_s(&(ip6[2]), ip6, ip6_s);
|
||||
oss << "<IP6>" << one_util::escape_xml(ip6_s) << "</IP6>";
|
||||
|
||||
unsigned int ip_low[2];
|
||||
|
||||
ip_low[3] = ip6[3];
|
||||
ip_low[2] = ip6[2];
|
||||
ip_low[1] = ip6[1];
|
||||
ip_low[0] = ip6[0] + size - 1;
|
||||
|
||||
ip6_to_s(&(ip6[2]), ip_low, ip6_s);
|
||||
ip6_to_s(ip_low, ip6_s);
|
||||
oss << "<IP6_END>" << one_util::escape_xml(ip6_s) << "</IP6_END>";
|
||||
}
|
||||
|
||||
@ -674,7 +674,8 @@ void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
|
||||
if (global6[1] != 0 || global6[0] != 0 ) /* Glocal Unicast */
|
||||
{
|
||||
ip6_to_s(global6, mac, ip6_s);
|
||||
oss << "<IP6_GLOBAL>" << one_util::escape_xml(ip6_s) << "</IP6_GLOBAL>";
|
||||
oss << "<IP6_GLOBAL>" << one_util::escape_xml(ip6_s)
|
||||
<< "</IP6_GLOBAL>";
|
||||
|
||||
ip6_to_s(global6, mac_end, ip6_s);
|
||||
oss << "<IP6_GLOBAL_END>" << one_util::escape_xml(ip6_s)
|
||||
@ -685,16 +686,14 @@ void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
|
||||
if (is_ipv6_static())
|
||||
{
|
||||
string ip6_s;
|
||||
unsigned int ip_low[4];
|
||||
|
||||
ip6_to_s(&(ip6[2]), ip6, ip6_s);
|
||||
oss << "<IP6>" << one_util::escape_xml(ip6_s) << "</IP6>";
|
||||
|
||||
unsigned int ip_low[2];
|
||||
|
||||
ip_low[3] = ip6[3];
|
||||
ip_low[2] = ip6[2];
|
||||
ip_low[1] = ip6[1];
|
||||
ip_low[0] = ip6[0] + size - 1;
|
||||
|
||||
ip6_to_s(&(ip6[2]), ip_low, ip6_s);
|
||||
ip6_to_s(ip_low, ip6_s);
|
||||
oss << "<IP6_END>" << one_util::escape_xml(ip6_s) << "</IP6_END>";
|
||||
}
|
||||
|
||||
@ -958,7 +957,6 @@ int AddressRange::ip6_to_i(const string& _ip, unsigned int i_ip[]) const
|
||||
i_ip[0] = ntohl(s6.s6_addr32[3]);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -990,7 +988,8 @@ int AddressRange::prefix6_to_i(const string& prefix, unsigned int ip[]) const
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::ip6_to_s(const unsigned int prefix[], const unsigned int mac[], string& ip6_s) const
|
||||
int AddressRange::ip6_to_s(const unsigned int prefix[],
|
||||
const unsigned int mac[], string& ip6_s) const
|
||||
{
|
||||
unsigned int eui64[2];
|
||||
unsigned int mlow = mac[0];
|
||||
@ -1016,6 +1015,28 @@ int AddressRange::ip6_to_s(const unsigned int prefix[], const unsigned int mac[]
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::ip6_to_s(const unsigned int ip6_i[], string& ip6_s) const
|
||||
{
|
||||
struct in6_addr ip6;
|
||||
char dst[INET6_ADDRSTRLEN];
|
||||
|
||||
ip6.s6_addr32[3] = htonl(ip6_i[0]);
|
||||
ip6.s6_addr32[2] = htonl(ip6_i[1]);
|
||||
ip6.s6_addr32[1] = htonl(ip6_i[2]);
|
||||
ip6.s6_addr32[0] = htonl(ip6_i[3]);
|
||||
|
||||
if ( inet_ntop(AF_INET6, &ip6, dst, INET6_ADDRSTRLEN) != 0 )
|
||||
{
|
||||
ip6_s = dst;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -1050,7 +1071,7 @@ bool AddressRange::is_valid_mac(unsigned int& index, const string& mac_s,
|
||||
bool AddressRange::is_valid_ip(unsigned int& index, const string& ip_s,
|
||||
bool check_free)
|
||||
{
|
||||
if (!(type & 0x00000002))//Not of type IP4 or IP4_6
|
||||
if (!is_ipv4())//Not of type IP4 or IP4_6
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -1080,6 +1101,41 @@ bool AddressRange::is_valid_ip(unsigned int& index, const string& ip_s,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool AddressRange::is_valid_ip6(unsigned int& index, const string& ip_s,
|
||||
bool check_free)
|
||||
{
|
||||
if (!is_ipv6_static())//Not of type IP6_STATIC or IP4_6_STATIC
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int ip_i[4];
|
||||
|
||||
if (ip6_to_i(ip_s, ip_i) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//3 most significant 32bit blocks must be equal
|
||||
if ( ip_i[3] != ip6[3] || ip_i[2] != ip6[2] || ip_i[1] != ip6[1]
|
||||
|| ip_i[0] < ip6[0] )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
index = ip_i[0] - ip6[0];
|
||||
|
||||
if ((check_free && allocated.count(index) != 0) || (index >= size))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void AddressRange::set_mac(unsigned int addr_index, VectorAttribute * nic) const
|
||||
{
|
||||
unsigned int new_mac[2];
|
||||
@ -1140,13 +1196,15 @@ void AddressRange::set_ip6(unsigned int addr_index, VectorAttribute * nic) const
|
||||
void AddressRange::set_ip6_static(unsigned int addr_index,
|
||||
VectorAttribute * nic) const
|
||||
{
|
||||
unsigned int low_ip[2];
|
||||
unsigned int ip_low[4];
|
||||
string ip6_s;
|
||||
|
||||
low_ip[0] = ip6[0] + addr_index;
|
||||
low_ip[1] = ip6[1];
|
||||
ip_low[3] = ip6[3];
|
||||
ip_low[2] = ip6[2];
|
||||
ip_low[1] = ip6[1];
|
||||
ip_low[0] = ip6[0] + addr_index;
|
||||
|
||||
if ( ip6_to_s(&(ip6[2]), low_ip, ip6_s) == 0 )
|
||||
if ( ip6_to_s(ip_low, ip6_s) == 0 )
|
||||
{
|
||||
nic->replace("IP6", ip6_s);
|
||||
}
|
||||
@ -1408,6 +1466,35 @@ int AddressRange::allocate_by_ip(
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::allocate_by_ip6(
|
||||
const string& ip6_s,
|
||||
PoolObjectSQL::ObjectType ot,
|
||||
int obid,
|
||||
VectorAttribute* nic,
|
||||
const vector<string>& inherit)
|
||||
{
|
||||
string error_msg;
|
||||
unsigned int index;
|
||||
|
||||
if (!is_valid_ip6(index, ip6_s, true))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (allocate_addr(index, 1, error_msg) != 0)
|
||||
{
|
||||
NebulaLog::log("IPM", Log::ERROR, error_msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
allocate_by_index(index, ot, obid, nic, inherit);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::free_addr(PoolObjectSQL::ObjectType ot, int obid,
|
||||
const string& mac_s)
|
||||
{
|
||||
@ -1470,6 +1557,45 @@ int AddressRange::free_addr_by_ip(PoolObjectSQL::ObjectType ot, int obid,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::free_addr_by_ip6(PoolObjectSQL::ObjectType ot, int obid,
|
||||
const string& ip_s)
|
||||
{
|
||||
string error_msg;
|
||||
|
||||
if (!is_ipv6())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned int ip_i[4];
|
||||
|
||||
if (ip6_to_i(ip_s, ip_i) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned int index = ip_i[0] - ip6[0];
|
||||
|
||||
if (index < 0 || index >= size || ip6[3] != ip_i[3] || ip6[2] != ip_i[2]
|
||||
|| ip6[1] != ip_i[1])
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (free_addr(index, error_msg) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return free_allocated_addr(ot, obid, index);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::free_addr_by_owner(PoolObjectSQL::ObjectType ot, int obid)
|
||||
{
|
||||
map<unsigned int, long long>::iterator it = allocated.begin();
|
||||
@ -1559,9 +1685,10 @@ const char * AddressRange::SG_RULE_ATTRIBUTES[] = {
|
||||
"TYPE",
|
||||
"SIZE",
|
||||
"MAC",
|
||||
"IP"};
|
||||
"IP",
|
||||
"IP6"};
|
||||
|
||||
const int AddressRange::NUM_SG_RULE_ATTRIBUTES = 5;
|
||||
const int AddressRange::NUM_SG_RULE_ATTRIBUTES = 6;
|
||||
|
||||
void AddressRange::process_security_rule(VectorAttribute * rule)
|
||||
{
|
||||
@ -1595,6 +1722,30 @@ void AddressRange::process_security_rule(VectorAttribute * rule)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::hold_by_ip6(const string& ip_s)
|
||||
{
|
||||
string error_msg;
|
||||
unsigned int index;
|
||||
|
||||
if (!is_valid_ip6(index, ip_s, true))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (allocate_addr(index, 1, error_msg) != 0)
|
||||
{
|
||||
NebulaLog::log("IPM", Log::ERROR, error_msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
set_allocated_addr(PoolObjectSQL::VM, -1, index);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::hold_by_ip(const string& ip_s)
|
||||
{
|
||||
string error_msg;
|
||||
@ -1669,11 +1820,16 @@ int AddressRange::reserve_addr(int vid, unsigned int rsize, AddressRange *rar)
|
||||
|
||||
set_mac(first_index, new_ar);
|
||||
|
||||
if (type & 0x00000002 )
|
||||
if ( is_ipv4() )
|
||||
{
|
||||
set_ip(first_index, new_ar);
|
||||
}
|
||||
|
||||
if ( is_ipv6_static() )
|
||||
{
|
||||
set_ip6_static(first_index, new_ar);
|
||||
}
|
||||
|
||||
new_ar->replace("SIZE",rsize);
|
||||
|
||||
new_ar->remove("IPAM_MAD");
|
||||
@ -1721,11 +1877,16 @@ int AddressRange::reserve_addr_by_index(int vid, unsigned int rsize,
|
||||
|
||||
set_mac(sindex, new_ar);
|
||||
|
||||
if (type & 0x00000002 )
|
||||
if ( is_ipv4() )
|
||||
{
|
||||
set_ip(sindex, new_ar);
|
||||
}
|
||||
|
||||
if ( is_ipv6_static() )
|
||||
{
|
||||
set_ip6_static(sindex, new_ar);
|
||||
}
|
||||
|
||||
new_ar->replace("SIZE",rsize);
|
||||
|
||||
new_ar->remove("IPAM_MAD");
|
||||
@ -1740,6 +1901,22 @@ int AddressRange::reserve_addr_by_index(int vid, unsigned int rsize,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::reserve_addr_by_ip6(int vid, unsigned int rsize,
|
||||
const string& ip_s, AddressRange *rar)
|
||||
{
|
||||
unsigned int sindex;
|
||||
|
||||
if (!is_valid_ip6(sindex, ip_s, false))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return reserve_addr_by_index(vid, rsize, sindex, rar);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::reserve_addr_by_ip(int vid, unsigned int rsize,
|
||||
const string& ip_s, AddressRange *rar)
|
||||
{
|
||||
|
@ -320,6 +320,27 @@ int AddressRangePool::allocate_by_ip(const string &ip,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRangePool::allocate_by_ip6(const string &ip,
|
||||
PoolObjectSQL::ObjectType ot, int obid, VectorAttribute * nic,
|
||||
const vector<string> &inherit)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
|
||||
for (it=ar_pool.begin(); it!=ar_pool.end(); it++)
|
||||
{
|
||||
if (it->second->allocate_by_ip6(ip, ot, obid, nic, inherit) == 0)
|
||||
{
|
||||
used_addr++;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void AddressRangePool::free_addr(unsigned int arid, PoolObjectSQL::ObjectType ot,
|
||||
int obid, const string& mac)
|
||||
{
|
||||
@ -358,6 +379,25 @@ void AddressRangePool::free_addr_by_ip(unsigned int arid,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void AddressRangePool::free_addr_by_ip6(unsigned int arid,
|
||||
PoolObjectSQL::ObjectType ot, int obid, const string& ip)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
|
||||
it = ar_pool.find(arid);
|
||||
|
||||
if (it!=ar_pool.end())
|
||||
{
|
||||
if ( it->second->free_addr_by_ip6(ot, obid, ip) == 0 )
|
||||
{
|
||||
used_addr--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void AddressRangePool::free_addr(PoolObjectSQL::ObjectType ot, int obid,
|
||||
const string& mac_s)
|
||||
{
|
||||
@ -392,6 +432,23 @@ void AddressRangePool::free_addr_by_ip(PoolObjectSQL::ObjectType ot, int obid,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void AddressRangePool::free_addr_by_ip6(PoolObjectSQL::ObjectType ot, int obid,
|
||||
const string& ip_s)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
|
||||
for (it=ar_pool.begin(); it!=ar_pool.end(); it++)
|
||||
{
|
||||
if (it->second->free_addr_by_ip6(ot, obid, ip_s) == 0)
|
||||
{
|
||||
used_addr--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRangePool::free_addr_by_owner(PoolObjectSQL::ObjectType ot, int oid)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
@ -509,6 +566,7 @@ unsigned int AddressRangePool::get_size() const
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -556,6 +614,50 @@ int AddressRangePool::hold_by_ip(const string& ip_s)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRangePool::hold_by_ip6(unsigned int ar_id, const string& ip_s)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::const_iterator it;
|
||||
|
||||
it = ar_pool.find(ar_id);
|
||||
|
||||
if (it == ar_pool.end())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rc = it->second->hold_by_ip6(ip_s);
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
used_addr++;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRangePool::hold_by_ip6(const string& ip_s)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
int rc = -1;
|
||||
|
||||
for (it=ar_pool.begin(); it!=ar_pool.end(); it++)
|
||||
{
|
||||
if (it->second->hold_by_ip6(ip_s) == 0) //At least one AR hold the IP
|
||||
{
|
||||
used_addr++;
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRangePool::hold_by_mac(unsigned int ar_id, const string& mac_s)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
@ -694,6 +796,30 @@ int AddressRangePool::reserve_addr_by_mac(int vid, unsigned int rsize,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRangePool::reserve_addr_by_ip6(int vid, unsigned int rsize,
|
||||
unsigned int ar_id, const string& ip, AddressRange *rar)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
|
||||
it = ar_pool.find(ar_id);
|
||||
|
||||
if (it == ar_pool.end())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (it->second->reserve_addr_by_ip6(vid, rsize, ip, rar) == 0)
|
||||
{
|
||||
used_addr += rsize;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void AddressRangePool::process_security_rule(
|
||||
VectorAttribute * rule,
|
||||
vector<VectorAttribute*> &new_rules)
|
||||
|
@ -652,15 +652,30 @@ int VirtualNetwork::nic_attribute(
|
||||
//--------------------------------------------------------------------------
|
||||
int rc;
|
||||
|
||||
string ip6 = nic->vector_value("IP6");
|
||||
string ip = nic->vector_value("IP");
|
||||
string mac = nic->vector_value("MAC");
|
||||
|
||||
if (!ip.empty())
|
||||
int ip_ne = ip.empty() ? 0 : 1;
|
||||
int ip6_ne = ip6.empty() ? 0 : 1;
|
||||
int mac_ne = mac.empty() ? 0 : 1;
|
||||
|
||||
if ( ip_ne + ip6_ne + mac_ne > 1 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ip_ne == 1)
|
||||
{
|
||||
rc = allocate_by_ip(PoolObjectSQL::VM, vid, ip, nic->vector_attribute(),
|
||||
inherit_attrs);
|
||||
}
|
||||
else if (!mac.empty())
|
||||
else if (ip6_ne == 1)
|
||||
{
|
||||
rc = allocate_by_ip6(PoolObjectSQL::VM, vid, ip6, nic->vector_attribute(),
|
||||
inherit_attrs);
|
||||
}
|
||||
else if (mac_ne == 1)
|
||||
{
|
||||
rc = allocate_by_mac(PoolObjectSQL::VM, vid,mac,nic->vector_attribute(),
|
||||
inherit_attrs);
|
||||
@ -718,15 +733,30 @@ int VirtualNetwork::vrouter_nic_attribute(
|
||||
|
||||
if (floating)
|
||||
{
|
||||
string ip6 = nic->vector_value("IP6");
|
||||
string ip = nic->vector_value("IP");
|
||||
string mac = nic->vector_value("MAC");
|
||||
|
||||
if (!ip.empty())
|
||||
int ip_ne = ip.empty() ? 0 : 1;
|
||||
int ip6_ne = ip6.empty() ? 0 : 1;
|
||||
int mac_ne = mac.empty() ? 0 : 1;
|
||||
|
||||
if ( ip_ne + ip6_ne + mac_ne > 1 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ip_ne == 1)
|
||||
{
|
||||
rc = allocate_by_ip(PoolObjectSQL::VROUTER, vrid, ip,
|
||||
nic->vector_attribute(), inherit_attrs);
|
||||
}
|
||||
else if (!mac.empty())
|
||||
else if (ip6_ne == 1)
|
||||
{
|
||||
rc = allocate_by_ip6(PoolObjectSQL::VROUTER, vrid, ip6,
|
||||
nic->vector_attribute(), inherit_attrs);
|
||||
}
|
||||
else if (mac_ne == 1)
|
||||
{
|
||||
rc = allocate_by_mac(PoolObjectSQL::VROUTER, vrid, mac,
|
||||
nic->vector_attribute(), inherit_attrs);
|
||||
@ -846,35 +876,55 @@ int VirtualNetwork::hold_leases(VirtualNetworkTemplate * leases_template,
|
||||
unsigned int ar_id;
|
||||
|
||||
string ip = lease->vector_value("IP");
|
||||
string ip6 = lease->vector_value("IP6");
|
||||
string mac = lease->vector_value("MAC");
|
||||
|
||||
if (ip.empty() && mac.empty())
|
||||
int ip_ne = ip.empty() ? 0 : 1;
|
||||
int ip6_ne = ip6.empty() ? 0 : 1;
|
||||
int mac_ne = mac.empty() ? 0 : 1;
|
||||
|
||||
int attr_ne = ip_ne + ip6_ne + mac_ne;
|
||||
|
||||
if ( attr_ne == 0 )
|
||||
{
|
||||
error_msg = "Missing MAC or IP.";
|
||||
error_msg = "Missing MAC, IP or IP6.";
|
||||
return -1;
|
||||
}
|
||||
else if ( attr_ne > 1 )
|
||||
{
|
||||
error_msg = "Only one attribute MAC, IP or IP6 can be set.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (lease->vector_value("AR_ID", ar_id) != 0) //No AR_ID hold all addresses
|
||||
{
|
||||
if (!mac.empty())
|
||||
if (mac_ne == 1)
|
||||
{
|
||||
rc = ar_pool.hold_by_mac(mac);
|
||||
}
|
||||
else if (!ip.empty())
|
||||
else if (ip_ne == 1)
|
||||
{
|
||||
rc = ar_pool.hold_by_ip(ip);
|
||||
}
|
||||
else if (ip6_ne == 1)
|
||||
{
|
||||
rc = ar_pool.hold_by_ip6(ip6);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mac.empty())
|
||||
if (mac_ne == 1)
|
||||
{
|
||||
rc = ar_pool.hold_by_mac(ar_id, mac);
|
||||
}
|
||||
else if (!ip.empty())
|
||||
else if (ip_ne == 1)
|
||||
{
|
||||
rc = ar_pool.hold_by_ip(ar_id, ip);
|
||||
}
|
||||
else if (ip6_ne == 1)
|
||||
{
|
||||
rc = ar_pool.hold_by_ip6(ar_id, ip6);
|
||||
}
|
||||
}
|
||||
|
||||
if (rc!=0)
|
||||
@ -902,35 +952,55 @@ int VirtualNetwork::free_leases(VirtualNetworkTemplate * leases_template,
|
||||
unsigned int ar_id;
|
||||
|
||||
string ip = lease->vector_value("IP");
|
||||
string ip6 = lease->vector_value("IP6");
|
||||
string mac = lease->vector_value("MAC");
|
||||
|
||||
if (ip.empty() && mac.empty())
|
||||
int ip_ne = ip.empty() ? 0 : 1;
|
||||
int ip6_ne = ip6.empty() ? 0 : 1;
|
||||
int mac_ne = mac.empty() ? 0 : 1;
|
||||
|
||||
int attr_ne = ip_ne + ip6_ne + mac_ne;
|
||||
|
||||
if ( attr_ne == 0 )
|
||||
{
|
||||
error_msg = "Missing MAC or IP.";
|
||||
error_msg = "Missing MAC, IP or IP6.";
|
||||
return -1;
|
||||
}
|
||||
else if ( attr_ne > 1 )
|
||||
{
|
||||
error_msg = "Only one attribute MAC, IP or IP6 can be set.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (lease->vector_value("AR_ID", ar_id) != 0) //No AR_ID free all addresses
|
||||
{
|
||||
if (!mac.empty())
|
||||
if ( mac_ne == 1 )
|
||||
{
|
||||
ar_pool.free_addr(PoolObjectSQL::VM, -1, mac);
|
||||
}
|
||||
else if (!ip.empty())
|
||||
else if ( ip_ne == 1 )
|
||||
{
|
||||
ar_pool.free_addr_by_ip(PoolObjectSQL::VM, -1, ip);
|
||||
}
|
||||
else if ( ip6_ne == 1 )
|
||||
{
|
||||
ar_pool.free_addr_by_ip6(PoolObjectSQL::VM, -1, ip6);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mac.empty())
|
||||
if ( mac_ne == 1 )
|
||||
{
|
||||
ar_pool.free_addr(ar_id, PoolObjectSQL::VM, -1, mac);
|
||||
}
|
||||
else if (!ip.empty())
|
||||
else if ( ip_ne == 1 )
|
||||
{
|
||||
ar_pool.free_addr_by_ip(ar_id, PoolObjectSQL::VM, -1, ip);
|
||||
}
|
||||
else if ( ip6_ne == 1 )
|
||||
{
|
||||
ar_pool.free_addr_by_ip6(ar_id, PoolObjectSQL::VM, -1, ip6);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -1030,6 +1100,27 @@ int VirtualNetwork::reserve_addr_by_ip(int rid, unsigned int rsize,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetwork::reserve_addr_by_ip6(int rid, unsigned int rsize,
|
||||
unsigned int ar_id, const string& ip, AddressRange *rar, string& error_str)
|
||||
{
|
||||
if (ar_pool.reserve_addr_by_ip6(rid, rsize, ar_id, ip, rar)!=0)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Not enough free addresses in address range " << ar_id
|
||||
<< ", or it does not exist";
|
||||
|
||||
error_str = oss.str();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetwork::reserve_addr_by_mac(int rid, unsigned int rsize,
|
||||
unsigned int ar_id, const string& mac, AddressRange *rar, string& error_str)
|
||||
{
|
||||
|
@ -586,8 +586,48 @@ int VirtualNetworkPool::reserve_addr(int pid, int rid, unsigned int rsize, unsig
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetworkPool::reserve_addr_by_ip(int pid, int rid, unsigned int rsize, unsigned int ar_id,
|
||||
const string& ip, string& err)
|
||||
int VirtualNetworkPool::reserve_addr_by_ip6(int pid, int rid, unsigned int rsize,
|
||||
unsigned int ar_id, const string& ip, string& err)
|
||||
{
|
||||
AddressRange * rar = allocate_ar(rid, err);
|
||||
|
||||
if ( rar == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
VirtualNetwork * pvn = get(pid, true);
|
||||
|
||||
if ( pvn == 0 )
|
||||
{
|
||||
delete rar;
|
||||
|
||||
ostringstream oss;
|
||||
oss << "Virtual network " << pid << " does not exist";
|
||||
|
||||
err = oss.str();
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rc = pvn->reserve_addr_by_ip6(rid, rsize, ar_id, ip, rar, err);
|
||||
|
||||
update(pvn);
|
||||
|
||||
pvn->unlock();
|
||||
|
||||
if ( rc != 0)
|
||||
{
|
||||
delete rar;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return add_ar(rid, rar, err);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetworkPool::reserve_addr_by_ip(int pid, int rid, unsigned int rsize,
|
||||
unsigned int ar_id, const string& ip, string& err)
|
||||
{
|
||||
AddressRange * rar = allocate_ar(rid, err);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user