1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

F #3064: Do not expose internal attribute in AddressRange class

This commit is contained in:
Ruben S. Montero 2019-09-17 17:19:04 +02:00
parent ed7c16813e
commit c78e2f2006
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
6 changed files with 97 additions and 62 deletions

View File

@ -391,12 +391,9 @@ public:
}
/*
* Get address range vector attribute representation
* Decrypts the address range attributes
*/
VectorAttribute * get_attr()
{
return attr;
}
void decrypt();
/*
* add_ar from AddressRangePool needs to access the internal representation

View File

@ -22,6 +22,8 @@
#include "Attribute.h"
#include "Template.h"
class AddressRange;
/**
* The IPAMRequest class represents a request for the IPAM driver. The request
* is in the form
@ -39,6 +41,11 @@ public:
IPAMRequest(VectorAttribute * _ar_vattr, const std::string& _address_xml);
IPAMRequest(AddressRange * _ar) : IPAMRequest(_ar,
"<ADDRESS><MAC/><IP/><IP6_GLOBAL/><IP6_ULA/><IP6/><SIZE/></ADDRESS>"){};
IPAMRequest(AddressRange * _ar, const std::string& _address_xml);
virtual ~IPAMRequest(){};
/* ---------------------------------------------------------------------- */

View File

@ -18,11 +18,14 @@
#include "VirtualNetworkTemplate.h"
#include "Nebula.h"
#include "AddressRange.h"
using namespace std;
IPAMRequest::IPAMRequest(VectorAttribute * _ar_vattr,
const std::string& _address_xml)
IPAMRequest::IPAMRequest(VectorAttribute * _ar_vattr, const std::string& _axml)
{
std::ostringstream oss;
string one_key;
Nebula::instance().get_configuration_attribute("ONE_KEY", one_key);
@ -32,9 +35,20 @@ IPAMRequest::IPAMRequest(VectorAttribute * _ar_vattr,
_ar_vattr->decrypt(one_key, ea.second);
}
_ar_vattr->to_xml(oss);
ar_xml = oss.str();
address_xml = _axml;
}
IPAMRequest::IPAMRequest(AddressRange * _ar, const std::string& _address_xml)
{
std::ostringstream oss;
_ar_vattr->to_xml(oss);
_ar->decrypt();
_ar->to_xml(oss);
ar_xml = oss.str();
address_xml = _address_xml;

View File

@ -19,6 +19,7 @@
#include "VirtualNetworkPool.h"
#include "NebulaLog.h"
#include "NebulaUtil.h"
#include "Nebula.h"
#include <arpa/inet.h>
#include <algorithm>
@ -221,25 +222,25 @@ int AddressRange::from_attr(VectorAttribute *vattr, string& error_msg)
/* ---------------------- L3 & L2 start addresses ---------------------- */
if ( init_ipv4(error_msg) != 0 )
{
return -1;
}
if ( init_ipv4(error_msg) != 0 )
{
return -1;
}
if ( init_ipv6(error_msg) != 0 )
{
return -1;
}
if ( init_ipv6(error_msg) != 0 )
{
return -1;
}
if ( init_ipv6_static(error_msg) != 0 )
{
return -1;
}
if ( init_ipv6_static(error_msg) != 0 )
{
return -1;
}
if ( init_mac(error_msg) != 0 )
{
return -1;
}
if ( init_mac(error_msg) != 0 )
{
return -1;
}
/* ------------------------- Security Groups ---------------------------- */
@ -523,17 +524,17 @@ void AddressRange::addr_to_xml(unsigned int index, unsigned int rsize,
<< "</IP6_GLOBAL>";
}
if ( ip6[0] != 0 || ip6[1] != 0 || ip6[2] != 0 || ip6[3] != 0 )
{
unsigned int ip_low[4];
if ( ip6[0] != 0 || ip6[1] != 0 || ip6[2] != 0 || ip6[3] != 0 )
{
unsigned int ip_low[4];
ip_low[3] = ip6[3];
ip_low[2] = ip6[2];
ip_low[1] = ip6[1];
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(ip_low, ip6_s) << "</IP6>";
}
}
oss << "<SIZE>" << rsize << "</SIZE>"
<< "</ADDRESS>";
@ -570,10 +571,10 @@ void AddressRange::to_xml(ostringstream &oss) const
if (is_ipv4())
{
string aux_st;
string aux_st;
unsigned int ip_i;
aux_st = attr->vector_value("IP");
aux_st = attr->vector_value("IP");
if (ip_to_i(aux_st, ip_i) == 0)
{
@ -608,19 +609,19 @@ void AddressRange::to_xml(ostringstream &oss) const
}
}
if (is_ipv6_static())
{
if (is_ipv6_static())
{
string ip6_s;
unsigned int ip_low[4];
unsigned int ip_low[4];
ip_low[3] = ip6[3];
ip_low[2] = ip6[2];
ip_low[1] = ip6[1];
ip_low[0] = ip6[0] + size - 1;
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(ip_low, ip6_s);
oss << "<IP6_END>" << one_util::escape_xml(ip6_s) << "</IP6_END>";
}
ip6_to_s(ip_low, ip6_s);
oss << "<IP6_END>" << one_util::escape_xml(ip6_s) << "</IP6_END>";
}
oss << "<USED_LEASES>" << get_used_addr() << "</USED_LEASES>";
oss << "</AR>";
@ -665,7 +666,7 @@ void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
if (is_ipv4())
{
unsigned int ip_i;
string aux_st = attr->vector_value("IP");
string aux_st = attr->vector_value("IP");
rc = ip_to_i(aux_st, ip_i);
@ -687,7 +688,7 @@ void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
ip6_to_s(ula6, mac_end, ip6_s);
oss << "<IP6_ULA_END>" << one_util::escape_xml(ip6_s)
<< "</IP6_ULA_END>";
<< "</IP6_ULA_END>";
}
if (global6[1] != 0 || global6[0] != 0 ) /* Glocal Unicast */
@ -698,23 +699,23 @@ void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
ip6_to_s(global6, mac_end, ip6_s);
oss << "<IP6_GLOBAL_END>" << one_util::escape_xml(ip6_s)
<< "</IP6_GLOBAL_END>";
<< "</IP6_GLOBAL_END>";
}
}
if (is_ipv6_static())
{
if (is_ipv6_static())
{
string ip6_s;
unsigned int ip_low[4];
unsigned int ip_low[4];
ip_low[3] = ip6[3];
ip_low[2] = ip6[2];
ip_low[1] = ip6[1];
ip_low[0] = ip6[0] + size - 1;
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(ip_low, ip6_s);
oss << "<IP6_END>" << one_util::escape_xml(ip6_s) << "</IP6_END>";
}
ip6_to_s(ip_low, ip6_s);
oss << "<IP6_END>" << one_util::escape_xml(ip6_s) << "</IP6_END>";
}
oss << "<USED_LEASES>" << get_used_addr() << "</USED_LEASES>";
@ -2051,3 +2052,19 @@ void AddressRange::remove_all_except_restricted(VectorAttribute* va)
}
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void AddressRange::decrypt()
{
string one_key;
Nebula::instance().get_configuration_attribute("ONE_KEY", one_key);
for ( auto ea : VirtualNetworkTemplate::encrypted )
{
attr->decrypt(one_key, ea.second);
}
}

View File

@ -67,7 +67,7 @@ int AddressRangeIPAM::allocate_addr(unsigned int index, unsigned int rsize,
address_xml = oss.str();
IPAMRequest ir(get_attr(), address_xml);
IPAMRequest ir(this, address_xml);
ipamm->trigger(IPMAction::ALLOCATE_ADDRESS, &ir);
@ -101,7 +101,7 @@ int AddressRangeIPAM::get_addr(unsigned int& index, unsigned int rsize,
address_xml = oss.str();
IPAMRequest ir(get_attr(), address_xml);
IPAMRequest ir(this, address_xml);
ipamm->trigger(IPMAction::GET_ADDRESS, &ir);
@ -158,7 +158,7 @@ int AddressRangeIPAM::free_addr(unsigned int index, std::string& error_msg)
address_xml = oss.str();
IPAMRequest ir(get_attr(), address_xml);
IPAMRequest ir(this, address_xml);
ipamm->trigger(IPMAction::FREE_ADDRESS, &ir);

View File

@ -208,14 +208,14 @@ int AddressRangePool::rm_ar(unsigned int ar_id, string& error_msg)
return -1;
}
AddressRange * ar_ptr = it->second;
AddressRange * ar_ptr = it->second;
VectorAttribute * the_ar = ar_ptr->attr;
if(ar_ptr->is_ipam())
{
IPAMManager * ipamm = Nebula::instance().get_ipamm();
IPAMRequest ir(ar_ptr->get_attr());
IPAMRequest ir(ar_ptr);
ipamm->trigger(IPMAction::UNREGISTER_ADDRESS_RANGE, &ir);