Skip to content

Commit e3f2b29

Browse files
author
Tyler Li
authored
[routeorch] Handle the empty "nexthop" field for backward compatibility (#1263)
* [routeorch] Handle the empty "nexthop" field for backward compatibility
1 parent d304673 commit e3f2b29

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

orchagent/routeorch.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,36 @@ void RouteOrch::doTask(Consumer& consumer)
466466
vector<string> ipv = tokenize(ips, ',');
467467
vector<string> alsv = tokenize(aliases, ',');
468468

469+
/*
470+
* For backward compatibility, adjust ip string from old format to
471+
* new format. Meanwhile it can deal with some abnormal cases.
472+
*/
473+
474+
/* Resize the ip vector to match ifname vector
475+
* as tokenize(",", ',') will miss the last empty segment. */
476+
if (alsv.size() == 0)
477+
{
478+
SWSS_LOG_WARN("Skip the route %s, for it has an empty ifname field.", key.c_str());
479+
it = consumer.m_toSync.erase(it);
480+
continue;
481+
}
482+
else if (alsv.size() != ipv.size())
483+
{
484+
SWSS_LOG_NOTICE("Route %s: resize ipv to match alsv, %zd -> %zd.", key.c_str(), ipv.size(), alsv.size());
485+
ipv.resize(alsv.size());
486+
}
487+
488+
/* Set the empty ip(s) to zero
489+
* as IpAddress("") will construst a incorrect ip. */
490+
for (auto &ip : ipv)
491+
{
492+
if (ip.empty())
493+
{
494+
SWSS_LOG_NOTICE("Route %s: set the empty nexthop ip to zero.", key.c_str());
495+
ip = ip_prefix.isV4() ? "0.0.0.0" : "::";
496+
}
497+
}
498+
469499
for (auto alias : alsv)
470500
{
471501
if (alias == "eth0" || alias == "lo" || alias == "docker0")

0 commit comments

Comments
 (0)