Skip to content
Merged
Changes from all 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
42 changes: 16 additions & 26 deletions fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,27 @@ 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("Receive new route message dest ip prefix: %s\n", destipprefix);
Copy link
Contributor

Choose a reason for hiding this comment

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

adding nlmsg_type here to log more information

/* Supports IPv4 or IPv6 address, otherwise return immediately */
auto family = rtnl_route_get_family(route_obj);
if (family != AF_INET && family != AF_INET6)
{
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));
SWSS_LOG_INFO("Unknown route family support: %s (object: %s)\n", destipprefix, nl_object_get_type(obj));
return;
}
Copy link
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
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);
SWSS_LOG_INFO("Unknown message-type: %d for %s\n", nlmsg_type, destipprefix);
return;
}

Expand All @@ -63,7 +56,7 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
std::vector<FieldValueTuple> fvVector;
Copy link
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 +65,7 @@ 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);
SWSS_LOG_INFO("BUM routes aren't supported yet (%s)\n", destipprefix);
return;

default:
Expand All @@ -88,12 +79,11 @@ 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);
SWSS_LOG_INFO("Nexthop list is empty for %s\n", 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 +96,12 @@ 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);
/* 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 +119,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);
}