nl_l3: fix nh_stub::operator<() strict weak ordering #430
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
According to [1], std::set requires a Compare function that has strict weak ordering [2], but the current implementation violates the second requirement:
comp(a, b) == true
thencomp(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 < 62comp(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")