Check existance on VLAN creation
This patch checks if the VLAN ID has already been used on the interface
when creating new VLANs.
Tested:
Creating VLAN with existing VLAN ID gives InvalidArgument error.
Change-Id: I73b4a932756863cec79d52f17fd462a20c99770b
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 1e63a48..610ec79 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -916,12 +916,20 @@
ObjectPath EthernetInterface::createVLAN(VlanId id)
{
std::string vlanInterfaceName = interfaceName() + "." + std::to_string(id);
+
+ if (this->vlanInterfaces.count(vlanInterfaceName))
+ {
+ log<level::ERR>("VLAN already exists", entry("VLANID=%u", id));
+ elog<InvalidArgument>(
+ Argument::ARGUMENT_NAME("VLANId"),
+ Argument::ARGUMENT_VALUE(std::to_string(id).c_str()));
+ }
+
std::string path = objPath;
path += "_" + std::to_string(id);
// Pass the parents nicEnabled property, so that the child
// VLAN interface can inherit.
-
auto vlanIntf = std::make_unique<phosphor::network::VlanInterface>(
bus, path.c_str(), EthernetInterface::DHCPConf::none,
EthernetInterfaceIntf::nicEnabled(), id, *this, manager);