@@ -1822,7 +1822,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
1822
1822
1823
1823
/*
1824
1824
* Handle Nexthop msg
1825
- * @arg nlmsghdr Netlink message
1825
+ * @arg nlmsghdr Netlink messaged
1826
1826
*/
1827
1827
void RouteSync::onNextHopMsg (struct nlmsghdr *h, int len)
1828
1828
{
@@ -1833,7 +1833,6 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
1833
1833
string ifname;
1834
1834
struct nhmsg *nhm = NULL ;
1835
1835
struct rtattr *tb[NHA_MAX + 1 ] = {};
1836
- struct nexthop_grp grp[MAX_MULTIPATH_NUM];
1837
1836
struct in_addr ipv4 = {0 };
1838
1837
struct in6_addr ipv6 = {0 };
1839
1838
char gateway[INET6_ADDRSTRLEN] = {0 };
@@ -1861,23 +1860,38 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
1861
1860
1862
1861
if (nlmsg_type == RTM_NEWNEXTHOP)
1863
1862
{
1864
- if (tb[NHA_GROUP])
1863
+ if (tb[NHA_GROUP])
1865
1864
{
1866
1865
SWSS_LOG_INFO (" New nexthop group message!" );
1866
+
1867
1867
struct nexthop_grp *nha_grp = (struct nexthop_grp *)RTA_DATA (tb[NHA_GROUP]);
1868
1868
grp_count = (int )(RTA_PAYLOAD (tb[NHA_GROUP]) / sizeof (*nha_grp));
1869
+
1869
1870
if (grp_count > MAX_MULTIPATH_NUM)
1870
1871
{
1871
1872
SWSS_LOG_ERROR (" Nexthop group count (%d) exceeds the maximum allowed (%d). Clamping to maximum." , grp_count, MAX_MULTIPATH_NUM);
1872
1873
grp_count = MAX_MULTIPATH_NUM;
1873
1874
}
1874
- for (int i = 0 ; i < grp_count; i++) {
1875
- grp[i].id = nha_grp[i].id ;
1876
- /*
1877
- The minimum weight value is 1, but kernel store it as zero (https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/ip/iproute.c?h=v5.19.0#n1028).
1878
- Adding one to weight to write the right value to the database.
1879
- */
1880
- grp[i].weight = nha_grp[i].weight + 1 ;
1875
+
1876
+ vector<pair<uint32_t , uint8_t >> group (grp_count);
1877
+ for (int i = 0 ; i < grp_count; i++)
1878
+ {
1879
+ group[i] = std::make_pair (nha_grp[i].id , nha_grp[i].weight + 1 );
1880
+ }
1881
+
1882
+ auto it = m_nh_groups.find (id);
1883
+ if (it != m_nh_groups.end ())
1884
+ {
1885
+ NextHopGroup &nhg = it->second ;
1886
+ nhg.group = group;
1887
+ if (nhg.installed )
1888
+ {
1889
+ updateNextHopGroupDb (nhg);
1890
+ }
1891
+ }
1892
+ else
1893
+ {
1894
+ m_nh_groups.insert ({id, NextHopGroup (id, group)});
1881
1895
}
1882
1896
}
1883
1897
else
@@ -1896,13 +1910,12 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
1896
1910
}
1897
1911
else
1898
1912
{
1899
- SWSS_LOG_ERROR (
1900
- " Unexpected nexthop address family" );
1913
+ SWSS_LOG_ERROR (" Unexpected nexthop address family" );
1901
1914
return ;
1902
1915
}
1903
1916
}
1904
1917
1905
- if (tb[NHA_OIF])
1918
+ if (tb[NHA_OIF])
1906
1919
{
1907
1920
ifindex = *((int32_t *)RTA_DATA (tb[NHA_OIF]));
1908
1921
char if_name[IFNAMSIZ] = {0 };
@@ -1913,36 +1926,11 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
1913
1926
ifname = string (if_name);
1914
1927
if (ifname == " eth0" || ifname == " docker0" )
1915
1928
{
1916
- SWSS_LOG_DEBUG (" Skip routes to inteface : %s id[%d]" , ifname.c_str (), id);
1929
+ SWSS_LOG_DEBUG (" Skip routes to interface : %s id[%d]" , ifname.c_str (), id);
1917
1930
return ;
1918
1931
}
1919
1932
}
1920
- }
1921
- if (grp_count > 0 )
1922
- {
1923
- vector<pair<uint32_t , uint8_t >> group (grp_count);
1924
- for (int i = 0 ; i < grp_count; i++)
1925
- {
1926
- group[i] = std::make_pair (grp[i].id , grp[i].weight );
1927
- }
1928
1933
1929
- auto it = m_nh_groups.find (id);
1930
- if (it != m_nh_groups.end ())
1931
- {
1932
- NextHopGroup &nhg = it->second ;
1933
- nhg.group = group;
1934
- if (nhg.installed )
1935
- {
1936
- updateNextHopGroupDb (nhg);
1937
- }
1938
- }
1939
- else
1940
- {
1941
- m_nh_groups.insert ({id, NextHopGroup (id, group)});
1942
- }
1943
- }
1944
- else
1945
- {
1946
1934
SWSS_LOG_DEBUG (" Received: id[%d], if[%d/%s] address[%s]" , id, ifindex, ifname.c_str (), gateway);
1947
1935
m_nh_groups.insert ({id, NextHopGroup (id, string (gateway), ifname)});
1948
1936
}
0 commit comments