Skip to content

Commit 1534ffd

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

File tree

1 file changed

+27
-39
lines changed

1 file changed

+27
-39
lines changed

fpmsyncd/routesync.cpp

+27-39
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
{
@@ -1833,7 +1833,6 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
18331833
string ifname;
18341834
struct nhmsg *nhm = NULL;
18351835
struct rtattr *tb[NHA_MAX + 1] = {};
1836-
struct nexthop_grp grp[MAX_MULTIPATH_NUM];
18371836
struct in_addr ipv4 = {0};
18381837
struct in6_addr ipv6 = {0};
18391838
char gateway[INET6_ADDRSTRLEN] = {0};
@@ -1861,23 +1860,38 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
18611860

18621861
if (nlmsg_type == RTM_NEWNEXTHOP)
18631862
{
1864-
if(tb[NHA_GROUP])
1863+
if (tb[NHA_GROUP])
18651864
{
18661865
SWSS_LOG_INFO("New nexthop group message!");
1866+
18671867
struct nexthop_grp *nha_grp = (struct nexthop_grp *)RTA_DATA(tb[NHA_GROUP]);
18681868
grp_count = (int)(RTA_PAYLOAD(tb[NHA_GROUP]) / sizeof(*nha_grp));
1869+
18691870
if (grp_count > MAX_MULTIPATH_NUM)
18701871
{
18711872
SWSS_LOG_ERROR("Nexthop group count (%d) exceeds the maximum allowed (%d). Clamping to maximum.", grp_count, MAX_MULTIPATH_NUM);
18721873
grp_count = MAX_MULTIPATH_NUM;
18731874
}
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)});
18811895
}
18821896
}
18831897
else
@@ -1896,13 +1910,12 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
18961910
}
18971911
else
18981912
{
1899-
SWSS_LOG_ERROR(
1900-
"Unexpected nexthop address family");
1913+
SWSS_LOG_ERROR("Unexpected nexthop address family");
19011914
return;
19021915
}
19031916
}
19041917

1905-
if(tb[NHA_OIF])
1918+
if (tb[NHA_OIF])
19061919
{
19071920
ifindex = *((int32_t *)RTA_DATA(tb[NHA_OIF]));
19081921
char if_name[IFNAMSIZ] = {0};
@@ -1913,36 +1926,11 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
19131926
ifname = string(if_name);
19141927
if (ifname == "eth0" || ifname == "docker0")
19151928
{
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);
19171930
return;
19181931
}
19191932
}
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-
}
19281933

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

0 commit comments

Comments
 (0)