mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-12 08:58:17 +03:00
F #5027: New address range types for IP6 no SLAAC. Basic lease
functionality
This commit is contained in:
parent
32576f61fc
commit
948d1d98c4
@ -39,18 +39,30 @@ public:
|
|||||||
|
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
// Address Range types
|
// Address Range types
|
||||||
// *************************************************************************
|
/// *************************************************************************
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of Addresses defined by this address range
|
* Type of Addresses defined by this address range
|
||||||
|
* Constants are encoded as follows:
|
||||||
|
*
|
||||||
|
* option bits address family bits
|
||||||
|
* ---+----+----+
|
||||||
|
* ...*|0000|****|
|
||||||
|
* ----+----+||||+
|
||||||
|
* |||\___ AR with Ethernet addresses
|
||||||
|
* ||\____ AR with IPv4 addresses
|
||||||
|
* |\_____ AR with IPv6 addresses (SLAAC)
|
||||||
|
* \______ AR with IPv6 addresses (static, non-SLAAC)
|
||||||
*/
|
*/
|
||||||
enum AddressType
|
enum AddressType
|
||||||
{
|
{
|
||||||
NONE = 0x00000000, /** Undefined Address Type */
|
NONE = 0x00000000, /** Undefined Address Type */
|
||||||
ETHER = 0x00000001, /** MAC address type */
|
ETHER = 0x00000001, /** MAC address type */
|
||||||
IP4 = 0x00000003, /** IP version 4 address */
|
IP4 = 0x00000003, /** MAC + IP4 address */
|
||||||
IP6 = 0x00000005, /** IP version 6 address */
|
IP6 = 0x00000005, /** MAC + IP6 address */
|
||||||
IP4_6 = 0x00000007 /** IP dual stack version 4 & 6 addresses */
|
IP6_STATIC = 0x00000009, /** MAC + IP6 (no-SLAAC) address */
|
||||||
|
IP4_6 = 0x00000007, /** MAC + IP4 + IP6 addresses */
|
||||||
|
IP4_6_STATIC = 0x0000000B, /** MAC + IP4 + IP6 (no-SLAAC) addresses */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,6 +79,31 @@ public:
|
|||||||
*/
|
*/
|
||||||
static AddressType str_to_type(string& str_type);
|
static AddressType str_to_type(string& str_type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the address range includes IPv4 addresses
|
||||||
|
*/
|
||||||
|
bool is_ipv4() const
|
||||||
|
{
|
||||||
|
return (type & 0x00000002) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the address range includes IPv6 addresses
|
||||||
|
*/
|
||||||
|
bool is_ipv6() const
|
||||||
|
{
|
||||||
|
return (type & 0x00000004) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the address range includes static IPv6 addresses (host id
|
||||||
|
* is manually defined)
|
||||||
|
*/
|
||||||
|
bool is_ipv6_static() const
|
||||||
|
{
|
||||||
|
return (type & 0x00000008) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
// Address Range initialization functions
|
// Address Range initialization functions
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
@ -421,13 +458,13 @@ protected:
|
|||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
/**
|
/**
|
||||||
* Sets the given range of addresses (by index) as used
|
* Sets the given range of addresses (by index) as used
|
||||||
* @param index the first address to set as used
|
* @param ix the first address to set as used
|
||||||
* @param sz number of addresses to set
|
* @param sz number of addresses to set
|
||||||
* @param msg describing the error if any
|
* @param mg describing the error if any
|
||||||
*
|
*
|
||||||
* @return 0 if success
|
* @return 0 if success
|
||||||
*/
|
*/
|
||||||
virtual int allocate_addr(unsigned int index, unsigned int sz, string& msg) = 0;
|
virtual int allocate_addr(unsigned int ix, unsigned int sz, string& mg) = 0;
|
||||||
/**
|
/**
|
||||||
* Gets a range of free addresses
|
* Gets a range of free addresses
|
||||||
* @param index the first address in the range
|
* @param index the first address in the range
|
||||||
@ -487,6 +524,13 @@ private:
|
|||||||
*/
|
*/
|
||||||
int ip_to_i(const string& _ip, unsigned int& i_ip) const;
|
int ip_to_i(const string& _ip, unsigned int& i_ip) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IP version 6 to binary (32 bits)
|
||||||
|
* @param ip string form 2a00:1bc0:b001:A::3
|
||||||
|
* @return 0 on success
|
||||||
|
*/
|
||||||
|
int ip6_to_i(const string& _ip, unsigned int i_ip[]) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IP version 4 to dot notation
|
* IP version 4 to dot notation
|
||||||
*
|
*
|
||||||
@ -512,6 +556,14 @@ private:
|
|||||||
int ip6_to_s(const unsigned int prefix[], const unsigned int mac[],
|
int ip6_to_s(const unsigned int prefix[], const unsigned int mac[],
|
||||||
string& ip6_s) const;
|
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;
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
/* NIC setup functions */
|
/* NIC setup functions */
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
@ -537,6 +589,13 @@ private:
|
|||||||
*/
|
*/
|
||||||
void set_ip6(unsigned int addr_index, VectorAttribute * nic) const;
|
void set_ip6(unsigned int addr_index, VectorAttribute * nic) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes IPv6 address (no-slaac) to the given NIC attribute
|
||||||
|
* @param addr_index internal index for the lease
|
||||||
|
* @param nic attribute of a VMTemplate
|
||||||
|
*/
|
||||||
|
void set_ip6_static(unsigned int addr_index, VectorAttribute * nic) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes VNET configuration attributes to the given NIC attribute. It
|
* Writes VNET configuration attributes to the given NIC attribute. It
|
||||||
* includes: BRIDGE, VLAN_ID, PHYDEV and INHERIT_VNET_ATTR in oned.conf
|
* includes: BRIDGE, VLAN_ID, PHYDEV and INHERIT_VNET_ATTR in oned.conf
|
||||||
@ -605,6 +664,39 @@ private:
|
|||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
/* Restricted Attributes functions */
|
/* Restricted Attributes functions */
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Function to parse the IPv4 attribute ("IP") for IP4 and IP4_6 ARs
|
||||||
|
* @param error_msg if any
|
||||||
|
* @return 0 on success
|
||||||
|
*/
|
||||||
|
int init_ipv4(string& error_msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to parse the IPv6 attributes ("GLOBAL_PREFIX" and "ULA_PREFIX")
|
||||||
|
* for IP6 and IP4_6 ARs
|
||||||
|
* @param error_msg if any
|
||||||
|
* @return 0 on success
|
||||||
|
*/
|
||||||
|
int init_ipv6(string& error_msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to parse the IPv6 attributes no slaac ("IP6") for IP6_STATIC
|
||||||
|
* and IP4_6_STATIC ARs
|
||||||
|
* @param error_msg if any
|
||||||
|
* @return 0 on success
|
||||||
|
*/
|
||||||
|
int init_ipv6_static(string& error_msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to parse the MAC attributes ("MAC") for all AR types
|
||||||
|
* @param error_msg if any
|
||||||
|
* @return 0 on success
|
||||||
|
*/
|
||||||
|
int init_mac(string& error_msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for restricted attributes, returns the first one found
|
||||||
|
*/
|
||||||
bool check(string& rs_attr) const;
|
bool check(string& rs_attr) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -655,6 +747,11 @@ private:
|
|||||||
*/
|
*/
|
||||||
unsigned int ula6[2];
|
unsigned int ula6[2];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binary representation of the first IPv6 address in the AR. No SLAAC ARs
|
||||||
|
*/
|
||||||
|
unsigned int ip6[4];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Security Group IDs for this Address Range
|
* Security Group IDs for this Address Range
|
||||||
*/
|
*/
|
||||||
|
@ -169,7 +169,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
vm_nics.each do |nic|
|
vm_nics.each do |nic|
|
||||||
["IP", "IP6_GLOBAL", "IP6_ULA",
|
["IP", "IP6_GLOBAL", "IP6_ULA", "IP6",
|
||||||
"VROUTER_IP", "VROUTER_IP6_GLOBAL", "VROUTER_IP6_ULA"].each do |attr|
|
"VROUTER_IP", "VROUTER_IP6_GLOBAL", "VROUTER_IP6_ULA"].each do |attr|
|
||||||
if nic.has_key?(attr)
|
if nic.has_key?(attr)
|
||||||
ips.push(nic[attr])
|
ips.push(nic[attr])
|
||||||
@ -752,7 +752,7 @@ in the frontend machine.
|
|||||||
|
|
||||||
next if nic.has_key?("CLI_DONE")
|
next if nic.has_key?("CLI_DONE")
|
||||||
|
|
||||||
["IP6_LINK", "IP6_ULA", "IP6_GLOBAL"].each do |attr|
|
["IP6_LINK", "IP6_ULA", "IP6_GLOBAL", "IP6"].each do |attr|
|
||||||
if nic.has_key?(attr)
|
if nic.has_key?(attr)
|
||||||
shown_ips << nic[attr]
|
shown_ips << nic[attr]
|
||||||
|
|
||||||
|
@ -32,11 +32,13 @@ string AddressRange::type_to_str(AddressType ob)
|
|||||||
{
|
{
|
||||||
switch (ob)
|
switch (ob)
|
||||||
{
|
{
|
||||||
case ETHER: return "ETHER"; break;
|
case ETHER: return "ETHER" ;
|
||||||
case IP4: return "IP4" ; break;
|
case IP4: return "IP4" ;
|
||||||
case IP6: return "IP6" ; break;
|
case IP6: return "IP6" ;
|
||||||
case IP4_6: return "IP4_6"; break;
|
case IP6_STATIC: return "IP6_STATIC" ;
|
||||||
default: return "";
|
case IP4_6: return "IP4_6" ;
|
||||||
|
case IP4_6_STATIC: return "IP4_6_STATIC";
|
||||||
|
default: return "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,6 +64,14 @@ AddressRange::AddressType AddressRange::str_to_type(string& str_type)
|
|||||||
{
|
{
|
||||||
return IP4_6;
|
return IP4_6;
|
||||||
}
|
}
|
||||||
|
else if (str_type == "IP4_6_STATIC")
|
||||||
|
{
|
||||||
|
return IP4_6_STATIC;
|
||||||
|
}
|
||||||
|
else if (str_type == "IP6_STATIC")
|
||||||
|
{
|
||||||
|
return IP6_STATIC;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return NONE;
|
return NONE;
|
||||||
@ -71,6 +81,116 @@ AddressRange::AddressType AddressRange::str_to_type(string& str_type)
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
int AddressRange::init_ipv4(string& error_msg)
|
||||||
|
{
|
||||||
|
if (!is_ipv4())
|
||||||
|
{
|
||||||
|
attr->remove("IP");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
string value = attr->vector_value("IP");
|
||||||
|
|
||||||
|
if (value.empty() || ip_to_i(value, ip) == -1)
|
||||||
|
{
|
||||||
|
error_msg = "Wrong or empty IP attribute";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int AddressRange::init_ipv6(string& error_msg)
|
||||||
|
{
|
||||||
|
if (!is_ipv6())
|
||||||
|
{
|
||||||
|
attr->remove("GLOBAL_PREFIX");
|
||||||
|
attr->remove("ULA_PREFIX");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
string value = attr->vector_value("GLOBAL_PREFIX");
|
||||||
|
|
||||||
|
if (prefix6_to_i(value, global6) != 0 )
|
||||||
|
{
|
||||||
|
error_msg = "Wrong format for IP6 global address prefix";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = attr->vector_value("ULA_PREFIX");
|
||||||
|
|
||||||
|
if (prefix6_to_i(value, ula6) != 0 )
|
||||||
|
{
|
||||||
|
error_msg = "Wrong format for IP6 unique local address prefix";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int AddressRange::init_ipv6_static(string& error_msg)
|
||||||
|
{
|
||||||
|
if (!is_ipv6_static())
|
||||||
|
{
|
||||||
|
attr->remove("IP6");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
string value = attr->vector_value("IP6");
|
||||||
|
|
||||||
|
if (value.empty() || ip6_to_i(value, ip6) == -1)
|
||||||
|
{
|
||||||
|
error_msg = "Wrong or empty IP6 attribute";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int AddressRange::init_mac(string& error_msg)
|
||||||
|
{
|
||||||
|
string value = attr->vector_value("MAC");
|
||||||
|
|
||||||
|
if (value.empty())
|
||||||
|
{
|
||||||
|
mac[1] = VirtualNetworkPool::mac_prefix();
|
||||||
|
|
||||||
|
if ( is_ipv4() )
|
||||||
|
{
|
||||||
|
mac[0] = ip;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
srand(time(0));
|
||||||
|
|
||||||
|
mac[0] = rand() & 0x0000FFFF;
|
||||||
|
mac[0]+= (rand()<<16) & 0xFFFF0000;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_mac(0, attr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (mac_to_i(value, mac) == -1)
|
||||||
|
{
|
||||||
|
error_msg = "Wrong format for MAC attribute";
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int AddressRange::from_attr(VectorAttribute *vattr, string& error_msg)
|
int AddressRange::from_attr(VectorAttribute *vattr, string& error_msg)
|
||||||
{
|
{
|
||||||
string value;
|
string value;
|
||||||
@ -94,78 +214,27 @@ int AddressRange::from_attr(VectorAttribute *vattr, string& error_msg)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- MAC & IPv4 start addresses ---------------------- */
|
/* ---------------------- L3 & L2 start addresses ---------------------- */
|
||||||
|
|
||||||
bool do_mac = false;
|
if ( init_ipv4(error_msg) != 0 )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
value = vattr->vector_value("MAC");
|
if ( init_ipv6(error_msg) != 0 )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (value.empty())
|
if ( init_ipv6_static(error_msg) != 0 )
|
||||||
{
|
{
|
||||||
do_mac = true;
|
return -1;
|
||||||
mac[1] = VirtualNetworkPool::mac_prefix();
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (mac_to_i(value, mac) == -1)
|
|
||||||
{
|
|
||||||
error_msg = "Wrong format for MAC attribute";
|
|
||||||
return -1;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(type)
|
if ( init_mac(error_msg) != 0 )
|
||||||
{
|
{
|
||||||
case ETHER:
|
return -1;
|
||||||
case IP6:
|
}
|
||||||
vattr->remove("IP");
|
|
||||||
|
|
||||||
if (do_mac)
|
|
||||||
{
|
|
||||||
srand(time(0));
|
|
||||||
|
|
||||||
mac[0] = rand() & 0x0000FFFF;
|
|
||||||
mac[0]+= (rand()<<16) & 0xFFFF0000;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IP4:
|
|
||||||
case IP4_6:
|
|
||||||
value = vattr->vector_value("IP");
|
|
||||||
|
|
||||||
if (value.empty() || ip_to_i(value, ip) == -1)
|
|
||||||
{
|
|
||||||
error_msg = "Wrong or empty IP attribute";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (do_mac)
|
|
||||||
{
|
|
||||||
mac[0] = ip;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------- IP6 prefixes ------------------------------ */
|
|
||||||
|
|
||||||
value = vattr->vector_value("GLOBAL_PREFIX");
|
|
||||||
|
|
||||||
if (prefix6_to_i(value, global6) != 0 )
|
|
||||||
{
|
|
||||||
error_msg = "Wrong format for IP6 global address prefix";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
value = vattr->vector_value("ULA_PREFIX");
|
|
||||||
|
|
||||||
if (prefix6_to_i(value, ula6) != 0 )
|
|
||||||
{
|
|
||||||
error_msg = "Wrong format for IP6 unique local address prefix";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------- Security Groups ---------------------------- */
|
/* ------------------------- Security Groups ---------------------------- */
|
||||||
|
|
||||||
@ -194,11 +263,6 @@ int AddressRange::from_attr(VectorAttribute *vattr, string& error_msg)
|
|||||||
|
|
||||||
vattr->remove("PARENT_NETWORK");
|
vattr->remove("PARENT_NETWORK");
|
||||||
|
|
||||||
if (do_mac) //Need to add MAC to the attribute
|
|
||||||
{
|
|
||||||
set_mac(0, attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,7 +301,14 @@ int AddressRange::update_attributes(
|
|||||||
|
|
||||||
vup->remove("IP");
|
vup->remove("IP");
|
||||||
|
|
||||||
if (type & 0x00000002)
|
if (is_ipv4())
|
||||||
|
{
|
||||||
|
vup->replace("IP", attr->vector_value("IP"));
|
||||||
|
}
|
||||||
|
|
||||||
|
vup->remove("IP6");
|
||||||
|
|
||||||
|
if (is_ipv6_static())
|
||||||
{
|
{
|
||||||
vup->replace("IP", attr->vector_value("IP"));
|
vup->replace("IP", attr->vector_value("IP"));
|
||||||
}
|
}
|
||||||
@ -266,6 +337,8 @@ int AddressRange::update_attributes(
|
|||||||
|
|
||||||
vup->remove("IP_END");
|
vup->remove("IP_END");
|
||||||
|
|
||||||
|
vup->remove("IP6_END");
|
||||||
|
|
||||||
vup->remove("IP6_ULA");
|
vup->remove("IP6_ULA");
|
||||||
|
|
||||||
vup->remove("IP6_ULA_END");
|
vup->remove("IP6_ULA_END");
|
||||||
@ -367,11 +440,16 @@ int AddressRange::from_vattr_db(VectorAttribute *vattr)
|
|||||||
|
|
||||||
rc += mac_to_i(vattr->vector_value("MAC"), mac);
|
rc += mac_to_i(vattr->vector_value("MAC"), mac);
|
||||||
|
|
||||||
if (type & 0x00000002)
|
if (is_ipv4())
|
||||||
{
|
{
|
||||||
rc += ip_to_i(vattr->vector_value("IP"), ip);
|
rc += ip_to_i(vattr->vector_value("IP"), ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_ipv6_static())
|
||||||
|
{
|
||||||
|
rc += ip6_to_i(vattr->vector_value("IP6"), ip6);
|
||||||
|
}
|
||||||
|
|
||||||
rc += prefix6_to_i(vattr->vector_value("GLOBAL_PREFIX"), global6);
|
rc += prefix6_to_i(vattr->vector_value("GLOBAL_PREFIX"), global6);
|
||||||
|
|
||||||
rc += prefix6_to_i(vattr->vector_value("ULA_PREFIX"), ula6);
|
rc += prefix6_to_i(vattr->vector_value("ULA_PREFIX"), ula6);
|
||||||
@ -426,6 +504,16 @@ void AddressRange::addr_to_xml(unsigned int index, unsigned int rsize,
|
|||||||
<< "</IP6_GLOBAL>";
|
<< "</IP6_GLOBAL>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ip6[0] != 0 || ip6[1] != 0 || ip6[2] != 0 || ip6[3] != 0 )
|
||||||
|
{
|
||||||
|
unsigned int ip_low[2];
|
||||||
|
|
||||||
|
ip_low[0] = ip6[0] + index;
|
||||||
|
ip_low[1] = ip6[1];
|
||||||
|
|
||||||
|
oss << "<IP6>" << ip6_to_s(&(ip6[2]), ip_low, ip6_s) << "</IP6>";
|
||||||
|
}
|
||||||
|
|
||||||
oss << "<SIZE>" << rsize << "</SIZE>"
|
oss << "<SIZE>" << rsize << "</SIZE>"
|
||||||
<< "</ADDRESS>";
|
<< "</ADDRESS>";
|
||||||
}
|
}
|
||||||
@ -438,7 +526,6 @@ void AddressRange::to_xml(ostringstream &oss) const
|
|||||||
const map<string,string>& ar_attrs = attr->value();
|
const map<string,string>& ar_attrs = attr->value();
|
||||||
map<string,string>::const_iterator it;
|
map<string,string>::const_iterator it;
|
||||||
|
|
||||||
string aux_st;
|
|
||||||
unsigned int mac_end[2];
|
unsigned int mac_end[2];
|
||||||
|
|
||||||
oss << "<AR>";
|
oss << "<AR>";
|
||||||
@ -460,12 +547,13 @@ void AddressRange::to_xml(ostringstream &oss) const
|
|||||||
|
|
||||||
oss << "<MAC_END>" << one_util::escape_xml(mac_to_s(mac_end))<<"</MAC_END>";
|
oss << "<MAC_END>" << one_util::escape_xml(mac_to_s(mac_end))<<"</MAC_END>";
|
||||||
|
|
||||||
aux_st = attr->vector_value("IP");
|
if (is_ipv4())
|
||||||
|
|
||||||
if (aux_st != "")
|
|
||||||
{
|
{
|
||||||
|
string aux_st;
|
||||||
unsigned int ip_i;
|
unsigned int ip_i;
|
||||||
|
|
||||||
|
aux_st = attr->vector_value("IP");
|
||||||
|
|
||||||
if (ip_to_i(aux_st, ip_i) == 0)
|
if (ip_to_i(aux_st, ip_i) == 0)
|
||||||
{
|
{
|
||||||
oss << "<IP_END>" << one_util::escape_xml(ip_to_s(ip_i + size - 1))
|
oss << "<IP_END>" << one_util::escape_xml(ip_to_s(ip_i + size - 1))
|
||||||
@ -473,7 +561,7 @@ void AddressRange::to_xml(ostringstream &oss) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type & 0x00000004)
|
if (is_ipv6())
|
||||||
{
|
{
|
||||||
string ip6_s;
|
string ip6_s;
|
||||||
|
|
||||||
@ -499,6 +587,22 @@ void AddressRange::to_xml(ostringstream &oss) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_ipv6_static())
|
||||||
|
{
|
||||||
|
string ip6_s;
|
||||||
|
|
||||||
|
ip6_to_s(&(ip6[2]), ip6, ip6_s);
|
||||||
|
oss << "<IP6>" << one_util::escape_xml(ip6_s) << "</IP6>";
|
||||||
|
|
||||||
|
unsigned int ip_low[2];
|
||||||
|
|
||||||
|
ip_low[1] = ip6[1];
|
||||||
|
ip_low[0] = ip6[0] + size - 1;
|
||||||
|
|
||||||
|
ip6_to_s(&(ip6[2]), ip_low, ip6_s);
|
||||||
|
oss << "<IP6_END>" << one_util::escape_xml(ip6_s) << "</IP6_END>";
|
||||||
|
}
|
||||||
|
|
||||||
oss << "<USED_LEASES>" << get_used_addr() << "</USED_LEASES>";
|
oss << "<USED_LEASES>" << get_used_addr() << "</USED_LEASES>";
|
||||||
oss << "</AR>";
|
oss << "</AR>";
|
||||||
}
|
}
|
||||||
@ -539,11 +643,10 @@ void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
|
|||||||
|
|
||||||
oss << "<MAC_END>" << one_util::escape_xml(mac_to_s(mac_end))<<"</MAC_END>";
|
oss << "<MAC_END>" << one_util::escape_xml(mac_to_s(mac_end))<<"</MAC_END>";
|
||||||
|
|
||||||
aux_st = attr->vector_value("IP");
|
if (is_ipv4())
|
||||||
|
|
||||||
if (aux_st != "")
|
|
||||||
{
|
{
|
||||||
unsigned int ip_i;
|
unsigned int ip_i;
|
||||||
|
string aux_st = attr->vector_value("IP");
|
||||||
|
|
||||||
rc = ip_to_i(aux_st, ip_i);
|
rc = ip_to_i(aux_st, ip_i);
|
||||||
|
|
||||||
@ -554,7 +657,7 @@ void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type & 0x00000004)
|
if (is_ipv6())
|
||||||
{
|
{
|
||||||
string ip6_s;
|
string ip6_s;
|
||||||
|
|
||||||
@ -564,7 +667,8 @@ void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
|
|||||||
oss << "<IP6_ULA>" << one_util::escape_xml(ip6_s) << "</IP6_ULA>";
|
oss << "<IP6_ULA>" << one_util::escape_xml(ip6_s) << "</IP6_ULA>";
|
||||||
|
|
||||||
ip6_to_s(ula6, mac_end, ip6_s);
|
ip6_to_s(ula6, mac_end, ip6_s);
|
||||||
oss << "<IP6_ULA_END>" << one_util::escape_xml(ip6_s) << "</IP6_ULA_END>";
|
oss << "<IP6_ULA_END>" << one_util::escape_xml(ip6_s)
|
||||||
|
<< "</IP6_ULA_END>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global6[1] != 0 || global6[0] != 0 ) /* Glocal Unicast */
|
if (global6[1] != 0 || global6[0] != 0 ) /* Glocal Unicast */
|
||||||
@ -573,10 +677,27 @@ void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
|
|||||||
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);
|
ip6_to_s(global6, mac_end, ip6_s);
|
||||||
oss << "<IP6_GLOBAL_END>" << one_util::escape_xml(ip6_s) << "</IP6_GLOBAL_END>";
|
oss << "<IP6_GLOBAL_END>" << one_util::escape_xml(ip6_s)
|
||||||
|
<< "</IP6_GLOBAL_END>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_ipv6_static())
|
||||||
|
{
|
||||||
|
string ip6_s;
|
||||||
|
|
||||||
|
ip6_to_s(&(ip6[2]), ip6, ip6_s);
|
||||||
|
oss << "<IP6>" << one_util::escape_xml(ip6_s) << "</IP6>";
|
||||||
|
|
||||||
|
unsigned int ip_low[2];
|
||||||
|
|
||||||
|
ip_low[1] = ip6[1];
|
||||||
|
ip_low[0] = ip6[0] + size - 1;
|
||||||
|
|
||||||
|
ip6_to_s(&(ip6[2]), ip_low, ip6_s);
|
||||||
|
oss << "<IP6_END>" << one_util::escape_xml(ip6_s) << "</IP6_END>";
|
||||||
|
}
|
||||||
|
|
||||||
oss << "<USED_LEASES>" << get_used_addr() << "</USED_LEASES>";
|
oss << "<USED_LEASES>" << get_used_addr() << "</USED_LEASES>";
|
||||||
|
|
||||||
if (allocated.empty())
|
if (allocated.empty())
|
||||||
@ -636,16 +757,21 @@ void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
|
|||||||
|
|
||||||
set_mac(it->first, &lease);
|
set_mac(it->first, &lease);
|
||||||
|
|
||||||
if (type & 0x00000002 )
|
if (is_ipv4())
|
||||||
{
|
{
|
||||||
set_ip(it->first, &lease);
|
set_ip(it->first, &lease);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type & 0x00000004)
|
if (is_ipv6())
|
||||||
{
|
{
|
||||||
set_ip6(it->first, &lease);
|
set_ip6(it->first, &lease);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_ipv6_static())
|
||||||
|
{
|
||||||
|
set_ip6_static(it->first, &lease);
|
||||||
|
}
|
||||||
|
|
||||||
lease.to_xml(oss);
|
lease.to_xml(oss);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -810,6 +936,34 @@ string AddressRange::ip_to_s(unsigned int i_ip) const
|
|||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int AddressRange::ip6_to_i(const string& _ip, unsigned int i_ip[]) const
|
||||||
|
{
|
||||||
|
struct in6_addr s6;
|
||||||
|
|
||||||
|
if (_ip.empty())
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rc = inet_pton(AF_INET6, _ip.c_str(), &s6);
|
||||||
|
|
||||||
|
if ( rc != 1 )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
i_ip[3] = ntohl(s6.s6_addr32[0]);
|
||||||
|
i_ip[2] = ntohl(s6.s6_addr32[1]);
|
||||||
|
i_ip[1] = ntohl(s6.s6_addr32[2]);
|
||||||
|
i_ip[0] = ntohl(s6.s6_addr32[3]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int AddressRange::prefix6_to_i(const string& prefix, unsigned int ip[]) const
|
int AddressRange::prefix6_to_i(const string& prefix, unsigned int ip[]) const
|
||||||
{
|
{
|
||||||
struct in6_addr s6;
|
struct in6_addr s6;
|
||||||
@ -983,6 +1137,24 @@ 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];
|
||||||
|
string ip6_s;
|
||||||
|
|
||||||
|
low_ip[0] = ip6[0] + addr_index;
|
||||||
|
low_ip[1] = ip6[1];
|
||||||
|
|
||||||
|
if ( ip6_to_s(&(ip6[2]), low_ip, ip6_s) == 0 )
|
||||||
|
{
|
||||||
|
nic->replace("IP6", ip6_s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void AddressRange::set_vnet(VectorAttribute *nic, const vector<string> &inherit) const
|
void AddressRange::set_vnet(VectorAttribute *nic, const vector<string> &inherit) const
|
||||||
{
|
{
|
||||||
nic->replace("AR_ID", id);
|
nic->replace("AR_ID", id);
|
||||||
@ -1127,16 +1299,21 @@ void AddressRange::allocate_by_index(unsigned int index,
|
|||||||
{
|
{
|
||||||
set_mac(index, nic);
|
set_mac(index, nic);
|
||||||
|
|
||||||
if (type & 0x00000002 )
|
if (is_ipv4())
|
||||||
{
|
{
|
||||||
set_ip(index, nic);
|
set_ip(index, nic);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type & 0x00000004)
|
if (is_ipv6())
|
||||||
{
|
{
|
||||||
set_ip6(index, nic);
|
set_ip6(index, nic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_ipv6_static())
|
||||||
|
{
|
||||||
|
set_ip6_static(index, nic);
|
||||||
|
}
|
||||||
|
|
||||||
set_vnet(nic, inherit);
|
set_vnet(nic, inherit);
|
||||||
|
|
||||||
set_allocated_addr(ot, obid, index);
|
set_allocated_addr(ot, obid, index);
|
||||||
@ -1263,7 +1440,7 @@ int AddressRange::free_addr_by_ip(PoolObjectSQL::ObjectType ot, int obid,
|
|||||||
{
|
{
|
||||||
string error_msg;
|
string error_msg;
|
||||||
|
|
||||||
if (!(type & 0x00000002))//Not of type IP4 or IP4_6
|
if (!is_ipv4())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user