diff --git a/fpmsyncd/routesync.cpp b/fpmsyncd/routesync.cpp index afe68bc76b6..88014b87014 100644 --- a/fpmsyncd/routesync.cpp +++ b/fpmsyncd/routesync.cpp @@ -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); + /* 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; } - 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; } @@ -63,7 +56,7 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj) std::vector fvVector; FieldValueTuple fv("blackhole", "true"); fvVector.push_back(fv); - m_routeTable.set(destip.to_string(), fvVector); + m_routeTable.set(destipprefix, fvVector); return; } case RTN_UNICAST: @@ -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: @@ -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); @@ -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"); } @@ -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); }