Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nl_l3: fix nh_stub::operator<() strict weak ordering #430

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

KanjiMonster
Copy link
Contributor

@KanjiMonster KanjiMonster commented Apr 29, 2024

According to [1], std::set requires a Compare function that has strict weak ordering [2], but the current implementation violates the second requirement:

  • If comp(a, b) == true then comp(b, a) == false.

E.g. given the nh_stubs a = <169.254.0.1,62> and b = <172.16.111.1,4>:

  • comp(a, b) == true, as 172.16.111.1 isn't < 169.254.0.1, but 4 < 62
  • comp(b, a) == true, as 169.254.0.1 < 172.16.111.1.

This breaks e.g. lookups in sets, causing element not being deleted or being found.

Fix this by comparing the ifindex only if the addresses are equal, not only if the other one's is larger.

[1] https://en.cppreference.com/w/cpp/container/set
[2] https://en.cppreference.com/w/cpp/named_req/Compare

Fixes: 0fdba0d ("nl_l3: only route l3 neighs if we have a route for them")

@KanjiMonster KanjiMonster requested a review from rubensfig April 29, 2024 07:16
According to [1], std::set requires a Compare function that has strict
weak ordering [2], but the current implementation violates the second
requirement:

* If comp(a, b) == true then comp(b, a) == false.

E.g. given the nh_stubs a = <169.254.0.1,62> and b = <172.16.111.1,4>:

* comp(a, b) is true, as 172.16.111.1 isn't < 169.254.0.1, but 4 < 62
* comp(b, a) is true, as 169.254.0.1 < 172.16.111.1.

This breaks e.g. lookups in sets, causing element not being deleted or
being found.

Fix this by comparing the ifindex only if the addresses are equal, not
only if the other one's is larger.

[1] https://en.cppreference.com/w/cpp/container/set
[2] https://en.cppreference.com/w/cpp/named_req/Compare

Fixes: 0fdba0d ("nl_l3: only route l3 neighs if we have a route for them")
Signed-off-by: Jonas Gorski <[email protected]>
@KanjiMonster KanjiMonster force-pushed the jogo_fix_nhstub_compare branch from 6230c8a to 8a24381 Compare April 29, 2024 07:21
Copy link
Contributor

@rubensfig rubensfig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rubensfig rubensfig merged commit b51cad3 into main Apr 30, 2024
5 checks passed
@rubensfig rubensfig deleted the jogo_fix_nhstub_compare branch April 30, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants