Skip to content

Commit a748926

Browse files
committed
update nhg
Signed-off-by: Kanji Nakano <[email protected]>
1 parent 1be7d53 commit a748926

File tree

1 file changed

+27
-38
lines changed

1 file changed

+27
-38
lines changed

fpmsyncd/routesync.cpp

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
18221822

18231823
/*
18241824
* Handle Nexthop msg
1825-
* @arg nlmsghdr Netlink message
1825+
* @arg nlmsghdr Netlink messaged
18261826
*/
18271827
void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
18281828
{
@@ -1861,23 +1861,38 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
18611861

18621862
if (nlmsg_type == RTM_NEWNEXTHOP)
18631863
{
1864-
if(tb[NHA_GROUP])
1864+
if (tb[NHA_GROUP])
18651865
{
18661866
SWSS_LOG_INFO("New nexthop group message!");
1867+
18671868
struct nexthop_grp *nha_grp = (struct nexthop_grp *)RTA_DATA(tb[NHA_GROUP]);
18681869
grp_count = (int)(RTA_PAYLOAD(tb[NHA_GROUP]) / sizeof(*nha_grp));
1870+
18691871
if (grp_count > MAX_MULTIPATH_NUM)
18701872
{
18711873
SWSS_LOG_ERROR("Nexthop group count (%d) exceeds the maximum allowed (%d). Clamping to maximum.", grp_count, MAX_MULTIPATH_NUM);
18721874
grp_count = MAX_MULTIPATH_NUM;
18731875
}
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;
1876+
1877+
vector<pair<uint32_t, uint8_t>> group(grp_count);
1878+
for (int i = 0; i < grp_count; i++)
1879+
{
1880+
group[i] = std::make_pair(nha_grp[i].id, nha_grp[i].weight + 1);
1881+
}
1882+
1883+
auto it = m_nh_groups.find(id);
1884+
if (it != m_nh_groups.end())
1885+
{
1886+
NextHopGroup &nhg = it->second;
1887+
nhg.group = group;
1888+
if (nhg.installed)
1889+
{
1890+
updateNextHopGroupDb(nhg);
1891+
}
1892+
}
1893+
else
1894+
{
1895+
m_nh_groups.insert({id, NextHopGroup(id, group)});
18811896
}
18821897
}
18831898
else
@@ -1896,13 +1911,12 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
18961911
}
18971912
else
18981913
{
1899-
SWSS_LOG_ERROR(
1900-
"Unexpected nexthop address family");
1914+
SWSS_LOG_ERROR("Unexpected nexthop address family");
19011915
return;
19021916
}
19031917
}
19041918

1905-
if(tb[NHA_OIF])
1919+
if (tb[NHA_OIF])
19061920
{
19071921
ifindex = *((int32_t *)RTA_DATA(tb[NHA_OIF]));
19081922
char if_name[IFNAMSIZ] = {0};
@@ -1913,36 +1927,11 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
19131927
ifname = string(if_name);
19141928
if (ifname == "eth0" || ifname == "docker0")
19151929
{
1916-
SWSS_LOG_DEBUG("Skip routes to inteface: %s id[%d]", ifname.c_str(), id);
1930+
SWSS_LOG_DEBUG("Skip routes to interface: %s id[%d]", ifname.c_str(), id);
19171931
return;
19181932
}
19191933
}
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-
}
19281934

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-
{
19461935
SWSS_LOG_DEBUG("Received: id[%d], if[%d/%s] address[%s]", id, ifindex, ifname.c_str(), gateway);
19471936
m_nh_groups.insert({id, NextHopGroup(id, string(gateway), ifname)});
19481937
}

0 commit comments

Comments
 (0)