@@ -25,34 +25,27 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
2525{
2626 struct rtnl_route *route_obj = (struct rtnl_route *)obj;
2727 struct nl_addr *dip;
28- char ifname[MAX_ADDR_SIZE + 1 ] = {0 };
29- uint32_t ipv4;
30- int prefix;
28+ char destipprefix[MAX_ADDR_SIZE + 1 ] = {0 };
3129
3230 dip = rtnl_route_get_dst (route_obj);
33- /* Supports IPv4 address only for now */
34- if (rtnl_route_get_family (route_obj) != AF_INET)
31+ nl_addr2str (dip, destipprefix, MAX_ADDR_SIZE);
32+ SWSS_LOG_DEBUG (" Receive new route message dest ip prefix: %s\n " , destipprefix);
33+ /* Supports IPv4 or IPv6 address, otherwise return immediately */
34+ auto family = rtnl_route_get_family (route_obj);
35+ if (family != AF_INET && family != AF_INET6)
3536 {
36- nl_addr2str (dip, ifname, MAX_ADDR_SIZE);
37- SWSS_LOG_INFO (" %s: Unknown route family support: %s (object: %s)\n " ,
38- __FUNCTION__, ifname, nl_object_get_type (obj));
37+ SWSS_LOG_INFO (" Unknown route family support: %s (object: %s)\n " , destipprefix, nl_object_get_type (obj));
3938 return ;
4039 }
4140
42- prefix = nl_addr_get_prefixlen (dip);
43- ipv4 = *(uint32_t *)nl_addr_get_binary_addr (dip);
44- IpPrefix destip (ipv4, prefix);
45-
4641 if (nlmsg_type == RTM_DELROUTE)
4742 {
48- m_routeTable.del (destip. to_string () );
43+ m_routeTable.del (destipprefix );
4944 return ;
5045 }
5146 else if (nlmsg_type != RTM_NEWROUTE)
5247 {
53- nl_addr2str (dip, ifname, MAX_ADDR_SIZE);
54- SWSS_LOG_INFO (" %s: Unknown message-type: %d for %s\n " ,
55- __FUNCTION__, nlmsg_type, ifname);
48+ SWSS_LOG_INFO (" Unknown message-type: %d for %s\n " , nlmsg_type, destipprefix);
5649 return ;
5750 }
5851
@@ -63,7 +56,7 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
6356 std::vector<FieldValueTuple> fvVector;
6457 FieldValueTuple fv (" blackhole" , " true" );
6558 fvVector.push_back (fv);
66- m_routeTable.set (destip. to_string () , fvVector);
59+ m_routeTable.set (destipprefix , fvVector);
6760 return ;
6861 }
6962 case RTN_UNICAST:
@@ -72,9 +65,7 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
7265 case RTN_MULTICAST:
7366 case RTN_BROADCAST:
7467 case RTN_LOCAL:
75- nl_addr2str (dip, ifname, MAX_ADDR_SIZE);
76- SWSS_LOG_INFO (" %s: BUM routes aren't supported yet (%s)\n " ,
77- __FUNCTION__, ifname);
68+ SWSS_LOG_INFO (" BUM routes aren't supported yet (%s)\n " , destipprefix);
7869 return ;
7970
8071 default :
@@ -88,12 +79,11 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
8879 struct nl_list_head *nhs = rtnl_route_get_nexthops (route_obj);
8980 if (!nhs)
9081 {
91- nl_addr2str (dip, ifname, MAX_ADDR_SIZE);
92- SWSS_LOG_INFO (" %s: Nexthop list is empty for %s\n " ,
93- __FUNCTION__, ifname);
82+ SWSS_LOG_INFO (" Nexthop list is empty for %s\n " , destipprefix);
9483 return ;
9584 }
9685
86+ char ifname[IFNAMSIZ] = {0 };
9787 for (int i = 0 ; i < rtnl_route_get_nnexthops (route_obj); i++)
9888 {
9989 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)
10696 nexthops += nh.to_string ();
10797 }
10898
109- rtnl_link_i2name (m_link_cache, ifindex, ifname, MAX_ADDR_SIZE );
99+ rtnl_link_i2name (m_link_cache, ifindex, ifname, IFNAMSIZ );
110100 /* Cannot get ifname. Possibly interfaces get re-created. */
111101 if (!strlen (ifname))
112102 {
113103 rtnl_link_alloc_cache (m_nl_sock, AF_UNSPEC, &m_link_cache);
114- rtnl_link_i2name (m_link_cache, ifindex, ifname, MAX_ADDR_SIZE );
104+ rtnl_link_i2name (m_link_cache, ifindex, ifname, IFNAMSIZ );
115105 if (!strlen (ifname))
116106 strcpy (ifname, " unknown" );
117107 }
@@ -129,5 +119,5 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj)
129119 FieldValueTuple idx (" ifname" , ifnames);
130120 fvVector.push_back (nh);
131121 fvVector.push_back (idx);
132- m_routeTable.set (destip. to_string () , fvVector);
122+ m_routeTable.set (destipprefix , fvVector);
133123}
0 commit comments