Skip to content

Commit

Permalink
Fixing fpmsyncd to handle scaled nexthops (sonic-net#3361)
Browse files Browse the repository at this point in the history
What I did
Fixing fpmsyncd to handle scaled nexthops(e.g. 256 nexthops). In this scenario the max message len is increased to accommodate zebra message size. In addition initialized nlmsg_set_default_size to allow netlink to process the increased message size as well without which libnl would crash.

Why I did it
To support increased nexthops.
  • Loading branch information
dgsudharsan authored Dec 10, 2024
1 parent a4197a7 commit 90612d2
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fpmsyncd/fpm/fpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
/*
* Largest message that can be sent to or received from the FPM.
*/
#define FPM_MAX_MSG_LEN 4096
#define FPM_MAX_MSG_LEN 16384

/*
* Header that precedes each fpm message to/from the FPM.
Expand Down
1 change: 1 addition & 0 deletions fpmsyncd/fpmsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ int main(int argc, char **argv)
NetDispatcher::getInstance().registerMessageHandler(RTM_DELLINK, &sync);

rtnl_route_read_protocol_names(DefaultRtProtoPath);
nlmsg_set_default_size(FPM_MAX_MSG_LEN);

std::string suppressionEnabledStr;
deviceMetadataTable.hget("localhost", "suppress-fib-pending", suppressionEnabledStr);
Expand Down
13 changes: 12 additions & 1 deletion fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2235,12 +2235,23 @@ bool RouteSync::sendOffloadReply(struct nlmsghdr* hdr)
bool RouteSync::sendOffloadReply(struct rtnl_route* route_obj)
{
SWSS_LOG_ENTER();
int ret = 0;

nl_msg* msg{};
rtnl_route_build_add_request(route_obj, NLM_F_CREATE, &msg);
ret = rtnl_route_build_add_request(route_obj, NLM_F_CREATE, &msg);

if (ret !=0)
{
SWSS_LOG_ERROR("Route build add returned %d", ret);
return false;
}
auto nlMsg = makeUniqueWithDestructor(msg, nlmsg_free);

if (nlMsg.get() == NULL)
{
SWSS_LOG_ERROR("Error in allocation for sending offload reply");
return false;
}
return sendOffloadReply(nlmsg_hdr(nlMsg.get()));
}

Expand Down
33 changes: 33 additions & 0 deletions tests/mock_tests/fake_netlink.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include <swss/linkcache.h>
#include <swss/logger.h>
#include <netlink/route/route.h>

static rtnl_link* g_fakeLink = [](){
auto fakeLink = rtnl_link_alloc();
rtnl_link_set_ifindex(fakeLink, 42);
return fakeLink;
}();

extern int rt_build_ret;
extern bool nlmsg_alloc_ret;
extern "C"
{

Expand All @@ -15,4 +18,34 @@ struct rtnl_link* rtnl_link_get_by_name(struct nl_cache *cache, const char *name
return g_fakeLink;
}

static int build_route_msg(struct rtnl_route *tmpl, int cmd, int flags,
struct nl_msg **result)
{
struct nl_msg *msg;
int err;
if (!(msg = nlmsg_alloc_simple(cmd, flags)))
return -NLE_NOMEM;
if ((err = rtnl_route_build_msg(msg, tmpl)) < 0) {
nlmsg_free(msg);
return err;
}
*result = msg;
return 0;
}

int rtnl_route_build_add_request(struct rtnl_route *tmpl, int flags,
struct nl_msg **result)
{
if (rt_build_ret != 0)
{
return rt_build_ret;
}
else if (!nlmsg_alloc_ret)
{
*result = NULL;
return 0;
}
return build_route_msg(tmpl, RTM_NEWROUTE, NLM_F_CREATE | flags,
result);
}
}
17 changes: 17 additions & 0 deletions tests/mock_tests/fpmsyncd/test_routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ using namespace swss;

using ::testing::_;

int rt_build_ret = 0;
bool nlmsg_alloc_ret = true;
class MockRouteSync : public RouteSync
{
public:
Expand Down Expand Up @@ -232,3 +234,18 @@ TEST_F(FpmSyncdResponseTest, testEvpn)
ASSERT_EQ(value.get(), "0xc8");

}

TEST_F(FpmSyncdResponseTest, testSendOffloadReply)
{

rt_build_ret = 1;
rtnl_route* routeObject{};


ASSERT_EQ(m_routeSync.sendOffloadReply(routeObject), false);
rt_build_ret = 0;
nlmsg_alloc_ret = false;
ASSERT_EQ(m_routeSync.sendOffloadReply(routeObject), false);
nlmsg_alloc_ret = true;

}

0 comments on commit 90612d2

Please sign in to comment.