From a5ca150e4d8d8484e76f064765e2a4b3682b0115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Thu, 8 Oct 2020 19:06:20 +0200 Subject: [PATCH] B #5095: Custom NIC attributes overrides VNET (#283) --- share/etc/oned.conf | 2 ++ src/image/Image.cc | 3 ++- src/vnm/AddressRange.cc | 9 +++++---- src/vnm/VirtualNetwork.cc | 21 +++++++++++---------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/share/etc/oned.conf b/share/etc/oned.conf index cd06b25fd9..e4ecfcfa24 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -845,6 +845,8 @@ VM_RESTRICTED_ATTR = "NIC/MAC" VM_RESTRICTED_ATTR = "NIC/VLAN_ID" VM_RESTRICTED_ATTR = "NIC/BRIDGE" VM_RESTRICTED_ATTR = "NIC/FILTER" +VM_RESTRICTED_ATTR = "NIC/FILTER_IP_SPOOFING" +VM_RESTRICTED_ATTR = "NIC/FILTER_MAC_SPOOFING" VM_RESTRICTED_ATTR = "NIC/INBOUND_AVG_BW" VM_RESTRICTED_ATTR = "NIC/INBOUND_PEAK_BW" VM_RESTRICTED_ATTR = "NIC/INBOUND_PEAK_KB" diff --git a/src/image/Image.cc b/src/image/Image.cc index 1e8e055df2..d77909cd70 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -678,9 +678,10 @@ void Image::disk_attribute(VirtualMachineDisk * disk, for (const auto& inherit : inherit_attrs) { + string current_val = disk->vector_value(inherit); get_template_attribute(inherit, inherit_val); - if (!inherit_val.empty()) + if (current_val.empty() && !inherit_val.empty()) { disk->replace(inherit, inherit_val); } diff --git a/src/vnm/AddressRange.cc b/src/vnm/AddressRange.cc index f2003ca0e5..c74569b1a8 100644 --- a/src/vnm/AddressRange.cc +++ b/src/vnm/AddressRange.cc @@ -1258,13 +1258,14 @@ void AddressRange::set_vnet(VectorAttribute *nic, const vector &inherit) nic->replace("VLAN_ID", vlanid); } - for (auto it = inherit.begin(); it != inherit.end(); it++) + for (const auto& inherited : inherit) { - string inherit_val = attr->vector_value(*it); + string current_val = nic->vector_value(inherited); + string inherit_val = attr->vector_value(inherited); - if (!inherit_val.empty()) + if (current_val.empty() && !inherit_val.empty()) { - nic->replace((*it).c_str(), inherit_val); + nic->replace(inherited, inherit_val); } } } diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index fc8ecc45bd..18d28cd1c2 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -843,16 +843,6 @@ int VirtualNetwork::nic_attribute( nic->replace("BRIDGE_TYPE", bridge_type); } - for (const auto& inherited : inherit_attrs) - { - PoolObjectSQL::get_template_attribute(inherited, inherit_val); - - if (!inherit_val.empty()) - { - nic->replace(inherited, inherit_val); - } - } - //-------------------------------------------------------------------------- // Get the lease from the Virtual Network //-------------------------------------------------------------------------- @@ -892,6 +882,17 @@ int VirtualNetwork::nic_attribute( inherit_attrs); } + for (const auto& inherited : inherit_attrs) + { + string current_val = nic->vector_value(inherited); + PoolObjectSQL::get_template_attribute(inherited, inherit_val); + + if (current_val.empty() && !inherit_val.empty()) + { + nic->replace(inherited, inherit_val); + } + } + //-------------------------------------------------------------------------- // Copy the security group IDs //--------------------------------------------------------------------------