Skip to content
Merged
Changes from 2 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
46 changes: 22 additions & 24 deletions fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,32 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
{
struct rtnl_route *route_obj = (struct rtnl_route *)obj;
struct nl_addr *dip;
char ifname[MAX_ADDR_SIZE + 1] = {0};
uint32_t ipv4;
int prefix;
char destipprefix[MAX_ADDR_SIZE + 1] = {0};

dip = rtnl_route_get_dst(route_obj);
/* Supports IPv4 address only for now */
if (rtnl_route_get_family(route_obj) != AF_INET)
nl_addr2str(dip, destipprefix, MAX_ADDR_SIZE);
SWSS_LOG_DEBUG("destipprefix=%s\n", destipprefix);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we need this debug log, at minimum it needs more be descriptive, like receive new route message dest ip prefix %s

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved.

/* Supports IPv4 or IPv6 address, otherwise return immediately */
switch (rtnl_route_get_family(route_obj))
{
nl_addr2str(dip, ifname, MAX_ADDR_SIZE);
SWSS_LOG_INFO("%s: Unknown route family support: %s (object: %s)\n",
__FUNCTION__, ifname, nl_object_get_type(obj));
return;
case AF_INET:
case AF_INET6:
break;
default:
SWSS_LOG_INFO("%s: Unknown route family support: %s (object: %s)\n",
__FUNCTION__, destipprefix, nl_object_get_type(obj));
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to if (family != AF_NET and family != AF_INET) return. it's more clear then switch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved.


prefix = nl_addr_get_prefixlen(dip);
ipv4 = *(uint32_t*)nl_addr_get_binary_addr(dip);
IpPrefix destip(ipv4, prefix);

if (nlmsg_type == RTM_DELROUTE)
{
m_routeTable.del(destip.to_string());
m_routeTable.del(destipprefix);
return;
}
else if (nlmsg_type != RTM_NEWROUTE)
{
nl_addr2str(dip, ifname, MAX_ADDR_SIZE);
SWSS_LOG_INFO("%s: Unknown message-type: %d for %s\n",
__FUNCTION__, nlmsg_type, ifname);
__FUNCTION__, nlmsg_type, destipprefix);
return;
}

Expand All @@ -63,7 +61,7 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
std::vector<FieldValueTuple> fvVector;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the std:: and the std:: on line 117

FieldValueTuple fv("blackhole", "true");
fvVector.push_back(fv);
m_routeTable.set(destip.to_string(), fvVector);
m_routeTable.set(destipprefix, fvVector);
return;
}
case RTN_UNICAST:
Expand All @@ -72,9 +70,8 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
case RTN_MULTICAST:
case RTN_BROADCAST:
case RTN_LOCAL:
nl_addr2str(dip, ifname, MAX_ADDR_SIZE);
SWSS_LOG_INFO("%s: BUM routes aren't supported yet (%s)\n",
__FUNCTION__, ifname);
__FUNCTION__, destipprefix);
return;

default:
Expand All @@ -88,12 +85,12 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
struct nl_list_head *nhs = rtnl_route_get_nexthops(route_obj);
if (!nhs)
{
nl_addr2str(dip, ifname, MAX_ADDR_SIZE);
SWSS_LOG_INFO("%s: Nexthop list is empty for %s\n",
__FUNCTION__, ifname);
__FUNCTION__, destipprefix);
return;
}

char ifname[IFNAMSIZ] = {0};
for (int i = 0; i < rtnl_route_get_nnexthops(route_obj); i++)
{
struct rtnl_nexthop *nexthop = rtnl_route_nexthop_n(route_obj, i);
Expand All @@ -106,12 +103,13 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
nexthops += nh.to_string();
}

rtnl_link_i2name(m_link_cache, ifindex, ifname, MAX_ADDR_SIZE);
rtnl_link_i2name(m_link_cache, ifindex, ifname, IFNAMSIZ);
SWSS_LOG_DEBUG("ifname=%s\n", ifname);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we need this debug log, it's like dev debug log.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved.

/* Cannot get ifname. Possibly interfaces get re-created. */
if (!strlen(ifname))
{
rtnl_link_alloc_cache(m_nl_sock, AF_UNSPEC, &m_link_cache);
rtnl_link_i2name(m_link_cache, ifindex, ifname, MAX_ADDR_SIZE);
rtnl_link_i2name(m_link_cache, ifindex, ifname, IFNAMSIZ);
if (!strlen(ifname))
strcpy(ifname, "unknown");
}
Expand All @@ -129,5 +127,5 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
FieldValueTuple idx("ifname", ifnames);
fvVector.push_back(nh);
fvVector.push_back(idx);
m_routeTable.set(destip.to_string(), fvVector);
m_routeTable.set(destipprefix, fvVector);
}