Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate interface name length in cfgmgr #3217

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cfgmgr/intfmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "tokenize.h"
#include "ipprefix.h"
#include "intfmgr.h"
#include "interface.h"
#include "exec.h"
#include "shellcmd.h"
#include "macaddress.h"
Expand Down Expand Up @@ -739,7 +740,6 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
subIntf subIf(alias);
// alias holds the complete sub interface name
// while parentAlias holds the parent port name
/*Check if subinterface is valid and sub interface name length is < 15(IFNAMSIZ)*/
if (!subIf.isValid())
{
SWSS_LOG_ERROR("Invalid subnitf: %s", alias.c_str());
Expand Down Expand Up @@ -839,6 +839,10 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
{
if (m_loopbackIntfList.find(alias) == m_loopbackIntfList.end())
{
if (!isInterfaceNameLenOk(alias))
{
return false;
}
addLoopbackIntf(alias);
m_loopbackIntfList.insert(alias);
SWSS_LOG_INFO("Added %s loopback interface", alias.c_str());
Expand Down Expand Up @@ -893,6 +897,11 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,

if (!parentAlias.empty())
{
if (!isInterfaceNameLenOk(alias))
{
return false;
}

subIntf subIf(alias);
if (m_subIntfList.find(alias) == m_subIntfList.end())
{
Expand Down
7 changes: 7 additions & 0 deletions cfgmgr/teammgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "logger.h"
#include "shellcmd.h"
#include "tokenize.h"
#include "interface.h"
#include "warm_restart.h"
#include "portmgr.h"
#include <swss/redisutility.h>
Expand Down Expand Up @@ -258,6 +259,12 @@ void TeamMgr::doLagTask(Consumer &consumer)
string learn_mode;
string tpid;

if (!isInterfaceNameLenOk(alias))
{
it++;
continue;
}

for (auto i : kfvFieldsValues(t))
{
// min_links and fallback attributes cannot be changed
Expand Down
20 changes: 15 additions & 5 deletions cfgmgr/vlanmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "vlanmgr.h"
#include "exec.h"
#include "tokenize.h"
#include "interface.h"
#include "shellcmd.h"
#include "warm_restart.h"
#include <swss/redisutility.h>
Expand Down Expand Up @@ -282,10 +283,9 @@ void VlanMgr::doVlanTask(Consumer &consumer)

string key = kfvKey(t);

/* Ensure the key starts with "Vlan" otherwise ignore */
if (strncmp(key.c_str(), VLAN_PREFIX, 4))
/* Ensure the key starts with "Vlan" and name length doesn't exceed limit otherwise ignore */
if (!isVlanIfaceNameValid(key) || !isInterfaceNameLenOk(key))
{
SWSS_LOG_ERROR("Invalid key format. No 'Vlan' prefix: %s", key.c_str());
it = consumer.m_toSync.erase(it);
continue;
}
Expand Down Expand Up @@ -484,6 +484,17 @@ bool VlanMgr::isVlanStateOk(const string &alias)
return false;
}

bool VlanMgr::isVlanIfaceNameValid(const string &alias)
{
/* Ensure the vlan interface name starts with "Vlan" */
if (strncmp(alias.c_str(), VLAN_PREFIX, 4))
{
SWSS_LOG_ERROR("Invalid key format. No 'Vlan' prefix: %s", alias.c_str());
return false;
}
return true;
}

bool VlanMgr::isVlanMemberStateOk(const string &vlanMemberKey)
{
vector<FieldValueTuple> temp;
Expand Down Expand Up @@ -554,9 +565,8 @@ void VlanMgr::doVlanMemberTask(Consumer &consumer)
string key = kfvKey(t);

/* Ensure the key starts with "Vlan" otherwise ignore */
if (strncmp(key.c_str(), VLAN_PREFIX, 4))
if (!isVlanIfaceNameValid(key))
{
SWSS_LOG_ERROR("Invalid key format. No 'Vlan' prefix: %s", key.c_str());
it = consumer.m_toSync.erase(it);
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion cfgmgr/vlanmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class VlanMgr : public Orch
std::set<std::string> m_vlanReplay;
std::set<std::string> m_vlanMemberReplay;
bool replayDone;

void doTask(Consumer &consumer);
void doVlanTask(Consumer &consumer);
void doVlanMemberTask(Consumer &consumer);
Expand All @@ -43,6 +43,7 @@ class VlanMgr : public Orch
bool isVlanStateOk(const std::string &alias);
bool isVlanMacOk();
bool isVlanMemberStateOk(const std::string &vlanMemberKey);
bool isVlanIfaceNameValid(const std::string &alias);
};

}
Expand Down
16 changes: 11 additions & 5 deletions cfgmgr/vrfmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "dbconnector.h"
#include "producerstatetable.h"
#include "tokenize.h"
#include "interface.h"
#include "ipprefix.h"
#include "vrfmgr.h"
#include "exec.h"
Expand Down Expand Up @@ -72,7 +73,7 @@ VrfMgr::VrfMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, con
{
// No deletion of mgmt table from kernel
if (vrfName.compare("mgmt") == 0)
{
{
SWSS_LOG_NOTICE("Skipping remove vrf device %s", vrfName.c_str());
rowType = LINK_ROW;
break;
Expand Down Expand Up @@ -172,10 +173,10 @@ bool VrfMgr::setLink(const string& vrfName)
{
return true;
}

if (vrfName == MGMT_VRF)
{
// Mgmt VRF is initialised as part of hostcfgd,
// Mgmt VRF is initialised as part of hostcfgd,
// just return the reserved table_id for mgmt VRF from here.
uint32_t table_id = MGMT_VRF_TABLE_ID;
m_vrfTableMap.emplace(vrfName, table_id);
Expand Down Expand Up @@ -229,7 +230,7 @@ void VrfMgr::doTask(Consumer &consumer)
if (consumer.getTableName() == CFG_MGMT_VRF_CONFIG_TABLE_NAME)
{
SWSS_LOG_DEBUG("Event for mgmt VRF op %s", op.c_str());
if (op == SET_COMMAND)
if (op == SET_COMMAND)
{
bool in_band_mgmt_enabled = false;
bool mgmt_vrf_enabled = false;
Expand All @@ -252,7 +253,7 @@ void VrfMgr::doTask(Consumer &consumer)
SWSS_LOG_DEBUG("Event for mgmt VRF table in_band_mgmt_enabled is set val:%s", fvValue(i).c_str());
}
}
// If mgmt VRF is not enabled or in-band-mgmt is not enabled delete the in-band-mgmt
// If mgmt VRF is not enabled or in-band-mgmt is not enabled delete the in-band-mgmt
// related VRF table map information
if ((op == SET_COMMAND) && ((mgmt_vrf_enabled == false) || (in_band_mgmt_enabled == false)))
{
Expand Down Expand Up @@ -282,6 +283,11 @@ void VrfMgr::doTask(Consumer &consumer)
{
SWSS_LOG_ERROR("Failed to create vrf netdev %s", vrfName.c_str());
}
if (!isInterfaceNameLenOk(vrfName))
{
it = consumer.m_toSync.erase(it);
continue;
}

bool status = true;
vector<FieldValueTuple> fvVector;
Expand Down
Loading
Loading