From e23dda6166abb29ab60e7e7651171c5576ddbbd3 Mon Sep 17 00:00:00 2001 From: Ann Pokora Date: Thu, 3 Jun 2021 05:20:10 -0700 Subject: [PATCH] Linux netlink runtime option --- fpmsyncd/fpmsyncd.cpp | 72 +++++++++++++++++++++++++++++++++++++++--- fpmsyncd/routesync.cpp | 4 +-- 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/fpmsyncd/fpmsyncd.cpp b/fpmsyncd/fpmsyncd.cpp index 8f797e178ca..b9b214d2206 100644 --- a/fpmsyncd/fpmsyncd.cpp +++ b/fpmsyncd/fpmsyncd.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "logger.h" @@ -7,6 +8,7 @@ #include "warmRestartHelper.h" #include "fpmsyncd/fpmlink.h" #include "fpmsyncd/routesync.h" +#include "netlink.h" using namespace std; @@ -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"); @@ -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. @@ -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 link; + if (useFpmLink) + { + shared_ptr fpm = make_shared(&sync); + + cout << "Waiting for fpm-client connection..." << endl; + fpm->accept(); + cout << "Connected!" << endl; - s.addSelectable(&fpm); + link = fpm; + } + else + { + shared_ptr netlink = make_shared(); + + 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(); diff --git a/fpmsyncd/routesync.cpp b/fpmsyncd/routesync.cpp index 7fae01eb3d7..73dbcf4ae89 100644 --- a/fpmsyncd/routesync.cpp +++ b/fpmsyncd/routesync.cpp @@ -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); @@ -597,7 +598,6 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj) { onRouteMsg(nlmsg_type, obj, master_name); } - } else {