Skip to content

Commit

Permalink
Merge branch 'master' into Fix_Loopback_VRF_assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
ram25794 authored Jan 10, 2025
2 parents ad22bcf + 6f30ddd commit 5b1d481
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 101 deletions.
23 changes: 19 additions & 4 deletions orchagent/macsecorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extern sai_switch_api_t *sai_switch_api;
constexpr bool DEFAULT_ENABLE_ENCRYPT = true;
constexpr bool DEFAULT_SCI_IN_SECTAG = false;
constexpr sai_macsec_cipher_suite_t DEFAULT_CIPHER_SUITE = SAI_MACSEC_CIPHER_SUITE_GCM_AES_128;
bool saiAclFieldSciMatchSupported = true;

static const std::vector<std::string> macsec_sa_attrs =
{
Expand Down Expand Up @@ -637,6 +638,17 @@ MACsecOrch::MACsecOrch(
MACSEC_STAT_POLLING_INTERVAL_MS, true)
{
SWSS_LOG_ENTER();
sai_attr_capability_t capability;
if (sai_query_attribute_capability(gSwitchId, SAI_OBJECT_TYPE_ACL_TABLE,
SAI_ACL_TABLE_ATTR_FIELD_MACSEC_SCI,
&capability) == SAI_STATUS_SUCCESS)
{
if (capability.create_implemented == false)
{
SWSS_LOG_DEBUG("SAI_ACL_TABLE_ATTR_FIELD_MACSEC_SCI is not supported");
saiAclFieldSciMatchSupported = false;
}
}
}

MACsecOrch::~MACsecOrch()
Expand Down Expand Up @@ -2570,9 +2582,12 @@ bool MACsecOrch::createMACsecACLTable(
attr.value.booldata = true;
attrs.push_back(attr);

attr.id = SAI_ACL_TABLE_ATTR_FIELD_MACSEC_SCI;
attr.value.booldata = sci_in_sectag;
attrs.push_back(attr);
if (saiAclFieldSciMatchSupported == true)
{
attr.id = SAI_ACL_TABLE_ATTR_FIELD_MACSEC_SCI;
attr.value.booldata = sci_in_sectag;
attrs.push_back(attr);
}

sai_status_t status = sai_acl_api->create_acl_table(
&table_id,
Expand Down Expand Up @@ -2738,7 +2753,7 @@ bool MACsecOrch::createMACsecACLDataEntry(
attr.value.aclaction.parameter.s32 = SAI_PACKET_ACTION_DROP;
attr.value.aclaction.enable = true;
attrs.push_back(attr);
if (sci_in_sectag)
if ((saiAclFieldSciMatchSupported == true) && sci_in_sectag)
{
attr.id = SAI_ACL_ENTRY_ATTR_FIELD_MACSEC_SCI;
attr.value.aclfield.enable = true;
Expand Down
63 changes: 2 additions & 61 deletions portsyncd/linksync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ using namespace swss;
#define VLAN_DRV_NAME "bridge"
#define TEAM_DRV_NAME "team"

const string MGMT_PREFIX = "eth";
const string INTFS_PREFIX = "Ethernet";
const string LAG_PREFIX = "PortChannel";

Expand All @@ -38,57 +37,11 @@ extern string g_switchType;
LinkSync::LinkSync(DBConnector *appl_db, DBConnector *state_db) :
m_portTableProducer(appl_db, APP_PORT_TABLE_NAME),
m_portTable(appl_db, APP_PORT_TABLE_NAME),
m_statePortTable(state_db, STATE_PORT_TABLE_NAME),
m_stateMgmtPortTable(state_db, STATE_MGMT_PORT_TABLE_NAME)
m_statePortTable(state_db, STATE_PORT_TABLE_NAME)
{
std::shared_ptr<struct if_nameindex> if_ni(if_nameindex(), if_freenameindex);
struct if_nameindex *idx_p;

for (idx_p = if_ni.get();
idx_p != NULL && idx_p->if_index != 0 && idx_p->if_name != NULL;
idx_p++)
{
string key = idx_p->if_name;

/* Explicitly store management ports oper status into the state database.
* This piece of information is used by SNMP. */
if (!key.compare(0, MGMT_PREFIX.length(), MGMT_PREFIX))
{
ostringstream cmd;
string res;
cmd << "cat /sys/class/net/" << shellquote(key) << "/operstate";
try
{
EXEC_WITH_ERROR_THROW(cmd.str(), res);
}
catch (...)
{
SWSS_LOG_WARN("Failed to get %s oper status", key.c_str());
continue;
}

/* Remove the trailing newline */
if (res.length() >= 1 && res.at(res.length() - 1) == '\n')
{
res.erase(res.length() - 1);
/* The value of operstate will be either up or down */
if (res != "up" && res != "down")
{
SWSS_LOG_WARN("Unknown %s oper status %s",
key.c_str(), res.c_str());
}
FieldValueTuple fv("oper_status", res);
vector<FieldValueTuple> fvs;
fvs.push_back(fv);

m_stateMgmtPortTable.set(key, fvs);
SWSS_LOG_INFO("Store %s oper status %s to state DB",
key.c_str(), res.c_str());
}
continue;
}
}

if (!WarmStart::isWarmStart())
{
/* See the comments for g_portSet in portsyncd.cpp */
Expand Down Expand Up @@ -168,8 +121,7 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
string key = rtnl_link_get_name(link);

if (key.compare(0, INTFS_PREFIX.length(), INTFS_PREFIX) &&
key.compare(0, LAG_PREFIX.length(), LAG_PREFIX) &&
key.compare(0, MGMT_PREFIX.length(), MGMT_PREFIX))
key.compare(0, LAG_PREFIX.length(), LAG_PREFIX))
{
return;
}
Expand Down Expand Up @@ -197,17 +149,6 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
nlmsg_type, key.c_str(), admin, oper, addrStr, ifindex, master);
}

if (!key.compare(0, MGMT_PREFIX.length(), MGMT_PREFIX))
{
FieldValueTuple fv("oper_status", oper ? "up" : "down");
vector<FieldValueTuple> fvs;
fvs.push_back(fv);
m_stateMgmtPortTable.set(key, fvs);
SWSS_LOG_INFO("Store %s oper status %s to state DB",
key.c_str(), oper ? "up" : "down");
return;
}

/* teamd instances are dealt in teamsyncd */
if (type && !strcmp(type, TEAM_DRV_NAME))
{
Expand Down
2 changes: 1 addition & 1 deletion portsyncd/linksync.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LinkSync : public NetMsg

private:
ProducerStateTable m_portTableProducer;
Table m_portTable, m_statePortTable, m_stateMgmtPortTable;
Table m_portTable, m_statePortTable;

std::map<unsigned int, std::string> m_ifindexNameMap;
std::map<unsigned int, std::string> m_ifindexOldNameMap;
Expand Down
35 changes: 0 additions & 35 deletions tests/mock_tests/portsyncd/portsyncd_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,6 @@ namespace portsyncd_ut

namespace portsyncd_ut
{
TEST_F(PortSyncdTest, test_linkSyncInit)
{
if_ni_mock = populateNetDev();
mockCmdStdcout = "up\n";
swss::LinkSync sync(m_app_db.get(), m_state_db.get());
std::vector<std::string> keys;
sync.m_stateMgmtPortTable.getKeys(keys);
ASSERT_EQ(keys.size(), 1);
ASSERT_EQ(keys.back(), "eth0");
ASSERT_EQ(mockCallArgs.back(), "cat /sys/class/net/\"eth0\"/operstate");
}

TEST_F(PortSyncdTest, test_cacheOldIfaces)
{
if_ni_mock = populateNetDevAdvanced();
Expand Down Expand Up @@ -295,29 +283,6 @@ namespace portsyncd_ut
ASSERT_EQ(sync.m_statePortTable.get("Ethernet0", ovalues), false);
}

TEST_F(PortSyncdTest, test_onMsgMgmtIface){
swss::LinkSync sync(m_app_db.get(), m_state_db.get());

/* Generate a netlink notification about the eth0 netdev iface */
std::vector<unsigned int> flags = {IFF_UP};
struct nl_object* msg = draft_nlmsg("eth0",
flags,
"",
"00:50:56:28:0e:4a",
16222,
9100,
0);
sync.onMsg(RTM_NEWLINK, msg);

/* Verify if the update has been written to State DB */
std::string oper_status;
ASSERT_EQ(sync.m_stateMgmtPortTable.hget("eth0", "oper_status", oper_status), true);
ASSERT_EQ(oper_status, "down");

/* Free Nl_object */
free_nlobj(msg);
}

TEST_F(PortSyncdTest, test_onMsgIgnoreOldNetDev){
if_ni_mock = populateNetDevAdvanced();
swss::LinkSync sync(m_app_db.get(), m_state_db.get());
Expand Down

0 comments on commit 5b1d481

Please sign in to comment.