Skip to content
Merged
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
12 changes: 9 additions & 3 deletions fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,9 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
{
sendOffloadReply(route_obj);
}
auto proto_num = rtnl_route_get_protocol(route_obj);
auto proto_str = getProtocolString(proto_num);
FieldValueTuple proto("protocol", proto_str);

switch (rtnl_route_get_type(route_obj))
{
Expand All @@ -1621,6 +1624,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
vector<FieldValueTuple> fvVector;
FieldValueTuple fv("blackhole", "true");
fvVector.push_back(fv);
fvVector.push_back(proto);
m_routeTable.set(destipprefix, fvVector);
return;
}
Expand Down Expand Up @@ -1692,11 +1696,8 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
}
}

auto proto_num = rtnl_route_get_protocol(route_obj);
auto proto_str = getProtocolString(proto_num);

vector<FieldValueTuple> fvVector;
FieldValueTuple proto("protocol", proto_str);
FieldValueTuple gw("nexthop", gw_list);
FieldValueTuple intf("ifname", intf_list);

Expand Down Expand Up @@ -1776,13 +1777,18 @@ void RouteSync::onLabelRouteMsg(int nlmsg_type, struct nl_object *obj)
return;
}

auto proto_num = rtnl_route_get_protocol(route_obj);
auto proto_str = getProtocolString(proto_num);
FieldValueTuple proto("protocol", proto_str);

switch (rtnl_route_get_type(route_obj))
{
case RTN_BLACKHOLE:
{
vector<FieldValueTuple> fvVector;
FieldValueTuple fv("blackhole", "true");
fvVector.push_back(fv);
fvVector.push_back(proto);
m_label_routeTable.set(destaddr, fvVector);
return;
}
Expand Down
41 changes: 41 additions & 0 deletions tests/mock_tests/fpmsyncd/test_routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,44 @@ TEST_F(FpmSyncdResponseTest, TestGetNextHopWt)

EXPECT_EQ(m_mockRouteSync.getNextHopWt(test_route.get()), "1,1");
}

TEST_F(FpmSyncdResponseTest, TestBlackholeRoute)
{
Table route_table(m_db.get(), APP_ROUTE_TABLE_NAME);
auto createRoute = [](const char* prefix, uint8_t prefixlen) -> rtnl_route* {
rtnl_route* route = rtnl_route_alloc();
nl_addr* dst_addr;
nl_addr_parse(prefix, AF_INET, &dst_addr);
rtnl_route_set_dst(route, dst_addr);
rtnl_route_set_type(route, RTN_BLACKHOLE);
rtnl_route_set_protocol(route, RTPROT_STATIC);
rtnl_route_set_family(route, AF_INET);
rtnl_route_set_scope(route, RT_SCOPE_UNIVERSE);
rtnl_route_set_table(route, RT_TABLE_MAIN);
nl_addr_put(dst_addr);
return route;
};

// create a route
const char* test_destipprefix = "10.1.1.0";
rtnl_route* test_route = createRoute(test_destipprefix, 24);

{

m_mockRouteSync.onRouteMsg(RTM_NEWROUTE, (nl_object*)test_route, nullptr);

// verify the blackhole route has protocol programmed
vector<FieldValueTuple> fvs;
EXPECT_TRUE(route_table.get(test_destipprefix, fvs));

bool proto_found = false;
for (const auto& fv : fvs) {
if (fvField(fv) == "protocol") {
proto_found = true;
EXPECT_EQ(fvValue(fv), "static");
}
}
EXPECT_TRUE(proto_found);
}

}
Loading