Skip to content

Commit

Permalink
route: use the new helper function for comparing nexthops
Browse files Browse the repository at this point in the history
When a route is created while the interface has no link, we get a
notification with the route and the nexthop having the flag LINKDOWN.

If the interface later gets a link, we do not get a route notification
about it, so the route and nexthop stay at LINKDOWN in the libnl cache.

If the route then gets removed again, the to be removed route will not
have the LINKDOWN flag anymore, which then can break comparison of the
nexthop(s).

So use the new nexthop identical helper to avoid this scenario.

Signed-off-by: Jonas Gorski <[email protected]>
  • Loading branch information
KanjiMonster committed May 14, 2024
1 parent 8cf29d7 commit 861fb80
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lib/route/route_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ static uint64_t route_compare(struct nl_object *_a, struct nl_object *_b,
found = 0;
nl_list_for_each_entry(nh_b, &b->rt_nexthops,
rtnh_list) {
if (!rtnl_route_nh_compare(nh_a, nh_b, ~0, 0)) {
if (rtnl_route_nh_identical(nh_a, nh_b)) {
found = 1;
break;
}
Expand All @@ -464,7 +464,7 @@ static uint64_t route_compare(struct nl_object *_a, struct nl_object *_b,
found = 0;
nl_list_for_each_entry(nh_a, &a->rt_nexthops,
rtnh_list) {
if (!rtnl_route_nh_compare(nh_a, nh_b, ~0, 0)) {
if (rtnl_route_nh_identical(nh_a, nh_b)) {
found = 1;
break;
}
Expand Down Expand Up @@ -538,7 +538,7 @@ static int route_update(struct nl_object *old_obj, struct nl_object *new_obj)
* Do not add the nexthop to old route if it was already added before
*/
nl_list_for_each_entry(old_nh, &old_route->rt_nexthops, rtnh_list) {
if (!rtnl_route_nh_compare(old_nh, new_nh, ~0, 0)) {
if (rtnl_route_nh_identical(old_nh, new_nh)) {
return 0;
}
}
Expand Down Expand Up @@ -574,15 +574,7 @@ static int route_update(struct nl_object *old_obj, struct nl_object *new_obj)
*/
nl_list_for_each_entry(old_nh, &old_route->rt_nexthops,
rtnh_list) {
/*
* Since the new route has only one nexthop, it's not
* an ECMP route and the nexthop won't have a weight.
* Similarily, the nexthop might have been marked as
* DEAD in its flags if it was deleted.
* Therefore ignore NH_ATTR_FLAGS (= 0x1) and
* NH_ATTR_WEIGHT (= 0x2) while comparing nexthops.
*/
if (!rtnl_route_nh_compare(old_nh, new_nh, ~0x3, 0)) {
if (rtnl_route_nh_identical(old_nh, new_nh)) {

rtnl_route_remove_nexthop(old_route, old_nh);

Expand Down

0 comments on commit 861fb80

Please sign in to comment.