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

fib: use return constants for universal_address_compare() #5222

Conversation

BytesGalore
Copy link
Member

change: Use the introduced return values in 38d5fc2 for universal_address_compare() across the fib.

fix: notifying routing protocols used the outdated former return value (was previously 1 for successful compare) to consider if the registered prefix of a routing protocol matches the given address.
If the protocol registered the unspecified address as prefix no notification took place since the return value is UNIVERSAL_ADDRESS_IS_ALL_ZERO_ADDRESS (2) now.

@BytesGalore BytesGalore added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: network Area: Networking Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation labels Apr 1, 2016
@@ -132,7 +132,8 @@ static int fib_find_entry(fib_table_t *table, uint8_t *dst, size_t dst_size,

int ret_comp = universal_address_compare(table->data.entries[i].global, dst, &match_size);
/* If we found an exact match */
if ((ret_comp == 0) || (is_all_zeros_addr && (match_size == 0) && (ret_comp == 2))) {
if ((ret_comp == UNIVERSAL_ADDRESS_EQUAL)
|| (is_all_zeros_addr && (match_size == 0) && (ret_comp == UNIVERSAL_ADDRESS_IS_ALL_ZERO_ADDRESS))) {
Copy link
Member

Choose a reason for hiding this comment

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

I am wondering: is it even necessary to check for is_all_zeros_addr && (match_size == 0) if ret_comp == UNIVERSAL_ADDRESS_IS_ALL_ZERO_ADDRESS?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes it is :),
is_all_zeros_addr says that dst is all 0, e.g. a default route prefix.
(ret_comp == UNIVERSAL_ADDRESS_IS_ALL_ZERO_ADDRESS) says table->data.entries[i].global is all 0, e.g. also a default route entry.
In such case, where both are all 0 and match_size == 0 the compared entries are equal, i.e. an exact match.

Copy link
Member

Choose a reason for hiding this comment

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

hmm, and why do we need to check the match_size if is_all_zeros_addr points to the default route and if ret_comp is UNIVERSAL_ADDRESS_IS_ALL_ZERO_ADDRESS?

is there a case where match_size would not be 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, and why do we need to check the match_size

we don't :) its just a relic from the former approach

@BytesGalore
Copy link
Member Author

@cgundogan I added a companion commit removing the obsolete check, thx for pointing me

@@ -547,7 +548,7 @@ int fib_get_destination_set(fib_table_t *table, uint8_t *prefix,

for (size_t i = 0; i < table->size; ++i) {
if ((table->data.entries[i].global != NULL) &&
(universal_address_compare_prefix(table->data.entries[i].global, prefix, prefix_size<<3) >= 0)) {
(universal_address_compare_prefix(table->data.entries[i].global, prefix, prefix_size<<3) > -ENOENT)) {
Copy link
Member

Choose a reason for hiding this comment

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

why > -ENOENT instead of != -ENOENT ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess I just want to clearly state that in this case any positive return means a successful match.
But since we only have -ENOENT as error return value you're right and != would be sufficient.

Copy link
Member

Choose a reason for hiding this comment

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

If we want to state that a positive return means match, >=0could also work? But the current solution seems a bit... un-concise. sorry for the nitpicking ^^

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, then I change it to >= UNIVERSAL_ADDRESS_EQUAL

Copy link
Member

Choose a reason for hiding this comment

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

cool :)

@BytesGalore BytesGalore added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Apr 1, 2016
@BytesGalore
Copy link
Member Author

done.

@Lotterleben
Copy link
Member

Cool! Then I don't have any more complaints.. Could you sqash please?

@BytesGalore BytesGalore force-pushed the fib_use_universal_address_return_values branch from a0abe44 to 5ca7bf4 Compare April 2, 2016 08:02
@Lotterleben Lotterleben added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels Apr 2, 2016
@Lotterleben
Copy link
Member

Let's see what travis says :) (ACK if he's happy)

@BytesGalore BytesGalore force-pushed the fib_use_universal_address_return_values branch from 5ca7bf4 to 8589e8f Compare April 2, 2016 21:15
@BytesGalore
Copy link
Member Author

nice, thx for the review :)

@Lotterleben Lotterleben merged commit 5f6cc67 into RIOT-OS:master Apr 3, 2016
@OlegHahm OlegHahm added this to the Release 2016.04 milestone Apr 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants