Skip to content

Commit

Permalink
zebra: Fix NHLFE entry memory leaks
Browse files Browse the repository at this point in the history
Before adding an NHLFE entry, zebra calls nhlfe_nexthop_active_ipv4()/nhlfe_nexthop_active_ipv6() to check if there is a corresponding directly connected route for the next hop prefix of the NHLFE. If such a route exists, it directly overwrites the output interface of the NHLFE's next hop with the output interface of the directly connected route. If the output interface of the directly connected route is different from the output interface of the NHLFE's next hop, deleting the NHLFE entry later will fail because nhlfe_nhop_match() cannot find the same next hop address and output interface, leading to an NHLFE entry leak.
If the outbound interface of the directly connected route differs from the outbound interface of the NHLFE's next hop, we should retain the outbound interface without activating the next hop, rather than directly overwriting it.

Taking ISIS as an example, establishing neighbors in ISIS only requires the existence of the neighbor's IP address and does not need the neighbor's IP address to be in the same subnet as the local IP address. When zebra creates an adjacency label entry, it uses the neighbor's IP address as the next hop. If the neighbor's IP address is not in the same subnet as the local IP address and there is a local directly connected route with the neighbor's IP address prefix, it will result in an issue where the corresponding adjacency label entry in zebra cannot be deleted.


Signed-off-by: zhou-run <zhou.run@h3c.com>
  • Loading branch information
zhou-run authored Sep 13, 2024
1 parent 916c90f commit 6a3914f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions zebra/zebra_mpls.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,20 +663,16 @@ static int nhlfe_nexthop_active_ipv4(struct zebra_nhlfe *nhlfe,

route_unlock_node(rn);

/* Locate a valid connected route. */
/* Locate a valid route. */
RNODE_FOREACH_RE (rn, match) {
if (CHECK_FLAG(match->status, ROUTE_ENTRY_REMOVED)
|| !CHECK_FLAG(match->flags, ZEBRA_FLAG_SELECTED))
continue;

for (match_nh = match->nhe->nhg.nexthop; match_nh;
match_nh = match_nh->next) {
if ((match->type == ZEBRA_ROUTE_CONNECT ||
match->type == ZEBRA_ROUTE_LOCAL) ||
nexthop->ifindex == match_nh->ifindex) {
nexthop->ifindex = match_nh->ifindex;
if (nexthop->ifindex == match_nh->ifindex)
return 1;
}
}
}

Expand Down Expand Up @@ -713,19 +709,19 @@ static int nhlfe_nexthop_active_ipv6(struct zebra_nhlfe *nhlfe,

route_unlock_node(rn);

/* Locate a valid connected route. */
/* Locate a valid route. */
RNODE_FOREACH_RE (rn, match) {
if (((match->type == ZEBRA_ROUTE_CONNECT ||
match->type == ZEBRA_ROUTE_LOCAL)) &&
!CHECK_FLAG(match->status, ROUTE_ENTRY_REMOVED) &&
if (!CHECK_FLAG(match->status, ROUTE_ENTRY_REMOVED) &&
CHECK_FLAG(match->flags, ZEBRA_FLAG_SELECTED))
break;
}

if (!match || !match->nhe->nhg.nexthop)
return 0;

nexthop->ifindex = match->nhe->nhg.nexthop->ifindex;
if (nexthop->ifindex != match->nhe->nhg.nexthop->ifindex)
return 0;

return 1;
}

Expand Down

0 comments on commit 6a3914f

Please sign in to comment.