Skip to content

Commit

Permalink
update nhg
Browse files Browse the repository at this point in the history
Signed-off-by: Kanji Nakano <[email protected]>
  • Loading branch information
nakano-omw committed Feb 7, 2025
1 parent 1be7d53 commit a748926
Showing 1 changed file with 27 additions and 38 deletions.
65 changes: 27 additions & 38 deletions fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)

/*
* Handle Nexthop msg
* @arg nlmsghdr Netlink message
* @arg nlmsghdr Netlink messaged
*/
void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
{
Expand Down Expand Up @@ -1861,23 +1861,38 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)

if (nlmsg_type == RTM_NEWNEXTHOP)
{
if(tb[NHA_GROUP])
if (tb[NHA_GROUP])
{
SWSS_LOG_INFO("New nexthop group message!");

struct nexthop_grp *nha_grp = (struct nexthop_grp *)RTA_DATA(tb[NHA_GROUP]);
grp_count = (int)(RTA_PAYLOAD(tb[NHA_GROUP]) / sizeof(*nha_grp));

if (grp_count > MAX_MULTIPATH_NUM)
{
SWSS_LOG_ERROR("Nexthop group count (%d) exceeds the maximum allowed (%d). Clamping to maximum.", grp_count, MAX_MULTIPATH_NUM);
grp_count = MAX_MULTIPATH_NUM;
}
for (int i = 0; i < grp_count; i++) {
grp[i].id = nha_grp[i].id;
/*
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).
Adding one to weight to write the right value to the database.
*/
grp[i].weight = nha_grp[i].weight + 1;

vector<pair<uint32_t, uint8_t>> group(grp_count);
for (int i = 0; i < grp_count; i++)
{
group[i] = std::make_pair(nha_grp[i].id, nha_grp[i].weight + 1);
}

auto it = m_nh_groups.find(id);
if (it != m_nh_groups.end())
{
NextHopGroup &nhg = it->second;
nhg.group = group;
if (nhg.installed)
{
updateNextHopGroupDb(nhg);
}
}
else
{
m_nh_groups.insert({id, NextHopGroup(id, group)});
}
}
else
Expand All @@ -1896,13 +1911,12 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
}
else
{
SWSS_LOG_ERROR(
"Unexpected nexthop address family");
SWSS_LOG_ERROR("Unexpected nexthop address family");
return;
}
}

if(tb[NHA_OIF])
if (tb[NHA_OIF])
{
ifindex = *((int32_t *)RTA_DATA(tb[NHA_OIF]));
char if_name[IFNAMSIZ] = {0};
Expand All @@ -1913,36 +1927,11 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
ifname = string(if_name);
if (ifname == "eth0" || ifname == "docker0")
{
SWSS_LOG_DEBUG("Skip routes to inteface: %s id[%d]", ifname.c_str(), id);
SWSS_LOG_DEBUG("Skip routes to interface: %s id[%d]", ifname.c_str(), id);
return;
}
}
}
if (grp_count > 0)
{
vector<pair<uint32_t, uint8_t>> group(grp_count);
for (int i = 0; i < grp_count; i++)
{
group[i] = std::make_pair(grp[i].id, grp[i].weight);
}

auto it = m_nh_groups.find(id);
if (it != m_nh_groups.end())
{
NextHopGroup &nhg = it->second;
nhg.group = group;
if (nhg.installed)
{
updateNextHopGroupDb(nhg);
}
}
else
{
m_nh_groups.insert({id, NextHopGroup(id, group)});
}
}
else
{
SWSS_LOG_DEBUG("Received: id[%d], if[%d/%s] address[%s]", id, ifindex, ifname.c_str(), gateway);
m_nh_groups.insert({id, NextHopGroup(id, string(gateway), ifname)});
}
Expand Down

0 comments on commit a748926

Please sign in to comment.