Skip to content

Commit 2adc6a0

Browse files
Merge branch 'master' of https://github.com/divyagayathri-hcl/sonic-swss into pytest_skip
2 parents 201030f + 7106cc0 commit 2adc6a0

File tree

3 files changed

+76
-16
lines changed

3 files changed

+76
-16
lines changed

cfgmgr/macsecmgr.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,11 @@ task_process_status MACsecMgr::enableMACsec(
503503
return task_need_retry;
504504
}
505505

506-
// Create MKA Session object
507-
auto port = m_macsec_ports.emplace(
508-
std::piecewise_construct,
509-
std::make_tuple(port_name),
510-
std::make_tuple());
511-
if (!port.second)
506+
// Handle existing macsec profile
507+
auto port_itr = m_macsec_ports.find(port_name);
508+
if (port_itr != m_macsec_ports.end())
512509
{
513-
if (port.first->second.profile_name == profile_name)
510+
if (port_itr->second.profile_name == profile_name)
514511
{
515512
SWSS_LOG_NOTICE(
516513
"The MACsec profile '%s' on the port '%s' has been loaded",
@@ -523,7 +520,7 @@ task_process_status MACsecMgr::enableMACsec(
523520
SWSS_LOG_NOTICE(
524521
"The MACsec profile '%s' on the port '%s' "
525522
"will be replaced by the MACsec profile '%s'",
526-
port.first->second.profile_name.c_str(),
523+
port_itr->second.profile_name.c_str(),
527524
port_name.c_str(),
528525
profile_name.c_str());
529526
auto result = disableMACsec(port_name, port_attr);
@@ -533,6 +530,11 @@ task_process_status MACsecMgr::enableMACsec(
533530
}
534531
}
535532
}
533+
// Create MKA Session object
534+
auto port = m_macsec_ports.emplace(
535+
std::piecewise_construct,
536+
std::make_tuple(port_name),
537+
std::make_tuple());
536538
auto & session = port.first->second;
537539
session.profile_name = profile_name;
538540
ostringstream ostream;

fpmsyncd/routesync.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,9 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
16361636
{
16371637
sendOffloadReply(route_obj);
16381638
}
1639+
auto proto_num = rtnl_route_get_protocol(route_obj);
1640+
auto proto_str = getProtocolString(proto_num);
1641+
FieldValueTuple proto("protocol", proto_str);
16391642

16401643
switch (rtnl_route_get_type(route_obj))
16411644
{
@@ -1644,6 +1647,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
16441647
vector<FieldValueTuple> fvVector;
16451648
FieldValueTuple fv("blackhole", "true");
16461649
fvVector.push_back(fv);
1650+
fvVector.push_back(proto);
16471651
m_routeTable.set(destipprefix, fvVector);
16481652
return;
16491653
}
@@ -1699,9 +1703,6 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
16991703
installNextHopGroup(nhg_id);
17001704
}
17011705

1702-
auto proto_num = rtnl_route_get_protocol(route_obj);
1703-
auto proto_str = getProtocolString(proto_num);
1704-
FieldValueTuple proto("protocol", proto_str);
17051706
fvVector.push_back(proto);
17061707

17071708
}
@@ -1766,11 +1767,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
17661767
}
17671768
}
17681769

1769-
auto proto_num = rtnl_route_get_protocol(route_obj);
1770-
auto proto_str = getProtocolString(proto_num);
1771-
17721770

1773-
FieldValueTuple proto("protocol", proto_str);
17741771
FieldValueTuple gw("nexthop", gw_list);
17751772
FieldValueTuple intf("ifname", intf_list);
17761773

@@ -1983,13 +1980,18 @@ void RouteSync::onLabelRouteMsg(int nlmsg_type, struct nl_object *obj)
19831980
return;
19841981
}
19851982

1983+
auto proto_num = rtnl_route_get_protocol(route_obj);
1984+
auto proto_str = getProtocolString(proto_num);
1985+
FieldValueTuple proto("protocol", proto_str);
1986+
19861987
switch (rtnl_route_get_type(route_obj))
19871988
{
19881989
case RTN_BLACKHOLE:
19891990
{
19901991
vector<FieldValueTuple> fvVector;
19911992
FieldValueTuple fv("blackhole", "true");
19921993
fvVector.push_back(fv);
1994+
fvVector.push_back(proto);
19931995
m_label_routeTable.set(destaddr, fvVector);
19941996
return;
19951997
}
@@ -2745,4 +2747,4 @@ void RouteSync::getNextHopGroupFields(const NextHopGroup& nhg, string& nexthops,
27452747
++i;
27462748
}
27472749
}
2748-
}
2750+
}

tests/mock_tests/fpmsyncd/test_routesync.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,62 @@ TEST_F(FpmSyncdResponseTest, TestRouteMsgWithNHG)
905905
rtnl_route_put(test_route);
906906
}
907907

908+
TEST_F(FpmSyncdResponseTest, TestBlackholeRoute)
909+
{
910+
Table route_table(m_db.get(), APP_ROUTE_TABLE_NAME);
911+
Table label_route_table(m_db.get(), APP_LABEL_ROUTE_TABLE_NAME);
912+
auto createRoute = [](const char* prefix, uint8_t prefixlen) -> rtnl_route* {
913+
rtnl_route* route = rtnl_route_alloc();
914+
nl_addr* dst_addr;
915+
nl_addr_parse(prefix, AF_INET, &dst_addr);
916+
rtnl_route_set_dst(route, dst_addr);
917+
rtnl_route_set_type(route, RTN_BLACKHOLE);
918+
rtnl_route_set_protocol(route, RTPROT_STATIC);
919+
rtnl_route_set_family(route, AF_INET);
920+
rtnl_route_set_scope(route, RT_SCOPE_UNIVERSE);
921+
rtnl_route_set_table(route, RT_TABLE_UNSPEC);
922+
nl_addr_put(dst_addr);
923+
return route;
924+
};
925+
926+
// create a route
927+
const char* test_destipprefix = "10.1.1.0";
928+
rtnl_route* test_route = createRoute(test_destipprefix, 24);
929+
930+
const char* test_destipprefix2 = "20.1.1.0";
931+
rtnl_route* test_route2 = createRoute(test_destipprefix2, 24);
932+
{
933+
934+
m_mockRouteSync.onRouteMsg(RTM_NEWROUTE, (nl_object*)test_route, nullptr);
935+
936+
// verify the blackhole route has protocol programmed
937+
vector<FieldValueTuple> fvs;
938+
EXPECT_TRUE(route_table.get(test_destipprefix, fvs));
939+
940+
bool proto_found = false;
941+
for (const auto& fv : fvs) {
942+
if (fvField(fv) == "protocol") {
943+
proto_found = true;
944+
EXPECT_EQ(fvValue(fv), "static");
945+
}
946+
}
947+
EXPECT_TRUE(proto_found);
948+
949+
m_mockRouteSync.onLabelRouteMsg(RTM_NEWROUTE, (nl_object*)test_route2);
950+
951+
// verify the blackhole route has protocol programmed
952+
EXPECT_TRUE(label_route_table.get(test_destipprefix2, fvs));
953+
954+
proto_found = false;
955+
for (const auto& fv : fvs) {
956+
if (fvField(fv) == "protocol") {
957+
proto_found = true;
958+
EXPECT_EQ(fvValue(fv), "static");
959+
}
960+
}
961+
EXPECT_TRUE(proto_found);
962+
}
963+
}
908964
auto create_nl_addr(const char* addr_str)
909965
{
910966
nl_addr* addr;

0 commit comments

Comments
 (0)