Skip to content

Commit

Permalink
Linux netlink runtime option
Browse files Browse the repository at this point in the history
  • Loading branch information
qbdwlr committed Jun 3, 2021
1 parent 73ffd5f commit e23dda6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 7 deletions.
72 changes: 67 additions & 5 deletions fpmsyncd/fpmsyncd.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <getopt.h>
#include <iostream>
#include <inttypes.h>
#include "logger.h"
Expand All @@ -7,6 +8,7 @@
#include "warmRestartHelper.h"
#include "fpmsyncd/fpmlink.h"
#include "fpmsyncd/routesync.h"
#include "netlink.h"


using namespace std;
Expand Down Expand Up @@ -44,6 +46,13 @@ static bool eoiuFlagsSet(Table &bgpStateTable)
return true;
}

static void usage()
{
cout << "Usage: fpmsyncd [ -l ( fpm | net) ]" << endl;
cout << " fpm = FpmLink (default)" << endl;
cout << " net = NetLink" << endl;
}

int main(int argc, char **argv)
{
swss::Logger::linkToDbNative("fpmsyncd");
Expand All @@ -57,11 +66,45 @@ int main(int argc, char **argv)
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWROUTE, &sync);
NetDispatcher::getInstance().registerMessageHandler(RTM_DELROUTE, &sync);

bool useFpmLink = true;
int opt;
while ((opt = getopt(argc, argv, "l:h")) != -1 )
{
switch (opt)
{
case 'l':
{
string linkmode(optarg);
if (linkmode == "net")
{
useFpmLink = false;
}
else if (linkmode == "fpm")
{
useFpmLink = true;
}
else
{
usage();
return EXIT_FAILURE;
}
break;
}

case 'h':
usage();
return 1;

default: /* '?' */
usage();
return EXIT_FAILURE;
}
}

while (true)
{
try
{
FpmLink fpm(&sync);
Select s;
SelectableTimer warmStartTimer(timespec{0, 0});
// Before eoiu flags detected, check them periodically. It also stop upon detection of reconciliation done.
Expand All @@ -75,11 +118,30 @@ int main(int argc, char **argv)
*/
pipeline.flush();

cout << "Waiting for fpm-client connection..." << endl;
fpm.accept();
cout << "Connected!" << endl;
shared_ptr<Selectable> link;
if (useFpmLink)
{
shared_ptr<FpmLink> fpm = make_shared<FpmLink>(&sync);

cout << "Waiting for fpm-client connection..." << endl;
fpm->accept();
cout << "Connected!" << endl;

s.addSelectable(&fpm);
link = fpm;
}
else
{
shared_ptr<NetLink> netlink = make_shared<NetLink>();

netlink->registerGroup(RTNLGRP_IPV4_ROUTE);
netlink->registerGroup(RTNLGRP_IPV6_ROUTE);
netlink->registerGroup(RTNLGRP_MPLS_ROUTE);
cout << "NetLink listening for route messages..." << endl;
netlink->dumpRequest(RTM_GETROUTE);

link = netlink;
}
s.addSelectable(link.get());

/* If warm-restart feature is enabled, execute 'restoration' logic */
bool warmStartEnabled = sync.m_warmStartHelper.checkAndStart();
Expand Down
4 changes: 2 additions & 2 deletions fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,8 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
char master_name[IFNAMSIZ] = {0};

/* if the table_id is not set in the route obj then route is for default vrf. */
if (master_index)
if (master_index &&
(master_index != RT_TABLE_MAIN) && (master_index != RT_TABLE_DEFAULT))
{
/* Get the name of the master device */
getIfName(master_index, master_name, IFNAMSIZ);
Expand All @@ -597,7 +598,6 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
{
onRouteMsg(nlmsg_type, obj, master_name);
}

}
else
{
Expand Down

0 comments on commit e23dda6

Please sign in to comment.