Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #5222 from BytesGalore/fib_use_universal_address_r…
…eturn_values

fib: use return constants for `universal_address_compare()`
  • Loading branch information
Lotterleben committed Apr 3, 2016
2 parents ceab9bd + 8589e8f commit 5f6cc67
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions sys/net/network_layer/fib/fib.c
Expand Up @@ -132,15 +132,16 @@ 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 && (ret_comp == UNIVERSAL_ADDRESS_IS_ALL_ZERO_ADDRESS))) {
entry_arr[0] = &(table->data.entries[i]);
*entry_arr_size = 1;
/* we will not find a better one so we return */
return 1;
}
else {
/* we try to find the most fitting prefix */
if (ret_comp == 1) {
if (ret_comp == UNIVERSAL_ADDRESS_MATCHING_PREFIX) {
if (table->data.entries[i].global_flags & FIB_FLAG_NET_PREFIX_MASK) {
/* we shift the most upper flag byte back to get the number of prefix bits */
size_t global_prefix_len = (table->data.entries[i].global_flags
Expand All @@ -157,7 +158,7 @@ static int fib_find_entry(fib_table_t *table, uint8_t *dst, size_t dst_size,
}
}
}
else if (ret_comp == 2) {
else if (ret_comp == UNIVERSAL_ADDRESS_IS_ALL_ZERO_ADDRESS) {
/* we found the default gateway entry, e.g. ::/0 for IPv6
* and we keep it only if there is no better one
*/
Expand Down Expand Up @@ -350,7 +351,7 @@ static int fib_signal_rp(fib_table_t *table, uint16_t type, uint8_t *dat,
if (type != FIB_MSG_RP_SIGNAL_SOURCE_ROUTE_CREATED) {
size_t dat_size_in_bits = dat_size<<3;
if (universal_address_compare(table->prefix_rp[i], dat,
&dat_size_in_bits) == 1) {
&dat_size_in_bits) != -ENOENT) {
/* the receiver, i.e. the RP, MUST copy the content value.
* using the provided pointer after replying this message
* will lead to errors
Expand All @@ -365,7 +366,7 @@ static int fib_signal_rp(fib_table_t *table, uint16_t type, uint8_t *dat,
size_t dat_size_in_bits = temp_sr->sr_dest->address->address_size << 3;
if (universal_address_compare(table->prefix_rp[i],
temp_sr->sr_dest->address->address,
&dat_size_in_bits) == 1) {
&dat_size_in_bits) != -ENOENT) {
/* the receiver, i.e. the RP, MUST copy the content value.
* using the provided pointer after replying this message
* will lead to errors
Expand Down Expand Up @@ -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) >= UNIVERSAL_ADDRESS_EQUAL)) {
if( (dst_set != NULL) && (found_entries < *dst_set_size) ) {
/* set the size to full byte usage */
dst_set[found_entries].dest_size = sizeof(dst_set[found_entries].dest);
Expand Down Expand Up @@ -921,7 +922,7 @@ int fib_sr_search(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, size_t ad
fib_sr_entry_t *elt;
LL_FOREACH(fib_sr->sr_path, elt) {
size_t addr_size_match = addr_size << 3;
if (universal_address_compare(elt->address, addr, &addr_size_match) == 0) {
if (universal_address_compare(elt->address, addr, &addr_size_match) == UNIVERSAL_ADDRESS_EQUAL) {

/* temporary workaround to calm compiler */
(void)sr_path_entry;
Expand Down Expand Up @@ -954,7 +955,7 @@ int fib_sr_entry_append(fib_table_t *table, fib_sr_t *fib_sr,
fib_sr_entry_t *elt;
LL_FOREACH(fib_sr->sr_path, elt) {
size_t addr_size_match = addr_size << 3;
if (universal_address_compare(elt->address, addr, &addr_size_match) == 0) {
if (universal_address_compare(elt->address, addr, &addr_size_match) == UNIVERSAL_ADDRESS_EQUAL) {
mutex_unlock(&(table->mtx_access));
return -EINVAL;
}
Expand Down Expand Up @@ -1000,7 +1001,7 @@ int fib_sr_entry_add(fib_table_t *table, fib_sr_t *fib_sr,
fib_sr_entry_t *elt;
LL_FOREACH(fib_sr->sr_path, elt) {
size_t addr_size_match = addr_size << 3;
if (universal_address_compare(elt->address, addr, &addr_size_match) == 0) {
if (universal_address_compare(elt->address, addr, &addr_size_match) == UNIVERSAL_ADDRESS_EQUAL) {
mutex_unlock(&(table->mtx_access));
return -EINVAL;
}
Expand Down Expand Up @@ -1056,7 +1057,7 @@ int fib_sr_entry_delete(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, siz
LL_FOREACH(fib_sr->sr_path, elt) {
size_t addr_size_match = addr_size << 3;

if (universal_address_compare(elt->address, addr, &addr_size_match) == 0) {
if (universal_address_compare(elt->address, addr, &addr_size_match) == UNIVERSAL_ADDRESS_EQUAL) {
universal_address_rem(elt->address);
if (keep_remaining_route) {
tmp->next = elt->next;
Expand Down Expand Up @@ -1107,11 +1108,11 @@ int fib_sr_entry_overwrite(fib_table_t *table, fib_sr_t *fib_sr,
LL_FOREACH(fib_sr->sr_path, elt) {
size_t addr_old_size_match = addr_old_size << 3;
size_t addr_new_size_match = addr_old_size << 3;
if (universal_address_compare(elt->address, addr_old, &addr_old_size_match) == 0) {
if (universal_address_compare(elt->address, addr_old, &addr_old_size_match) == UNIVERSAL_ADDRESS_EQUAL) {
elt_repl = elt;
}

if (universal_address_compare(elt->address, addr_new, &addr_new_size_match) == 0) {
if (universal_address_compare(elt->address, addr_new, &addr_new_size_match) == UNIVERSAL_ADDRESS_EQUAL) {
mutex_unlock(&(table->mtx_access));
return -EINVAL;
}
Expand Down Expand Up @@ -1191,7 +1192,7 @@ fib_sr_t* hit = NULL;
fib_sr_entry_t *elt;
LL_FOREACH(table->data.source_routes->headers[i].sr_path, elt) {
size_t addr_size_match = dst_size << 3;
if (universal_address_compare(elt->address, dst, &addr_size_match) == 0) {
if (universal_address_compare(elt->address, dst, &addr_size_match) == UNIVERSAL_ADDRESS_EQUAL) {
/* we create a new sr */
if (check_free_entry == -1) {
/* we have no room to create a new sr
Expand Down Expand Up @@ -1320,7 +1321,7 @@ int fib_sr_get_route(fib_table_t *table, uint8_t *dst, size_t dst_size, kernel_p

size_t addr_size_match = dst_size << 3;
if (universal_address_compare(table->data.source_routes->headers[i].sr_dest->address,
dst, &addr_size_match) == 0) {
dst, &addr_size_match) == UNIVERSAL_ADDRESS_EQUAL) {
if (*sr_flags == table->data.source_routes->headers[i].sr_flags) {
/* found a perfect matching sr, no need to search further */
hit = &table->data.source_routes->headers[i];
Expand Down Expand Up @@ -1624,7 +1625,7 @@ int fib_devel_get_lifetime(fib_table_t *table, uint64_t *lifetime, uint8_t *dst,
/* first hit wins here */
for (size_t i = 0; i < table->size; ++i) {
if (universal_address_compare(table->data.source_routes->headers[i].sr_dest->address,
dst, &addr_size_match) == 0) {
dst, &addr_size_match) == UNIVERSAL_ADDRESS_EQUAL) {
*lifetime = table->data.source_routes->headers[i].sr_lifetime;
return 0;
}
Expand Down

0 comments on commit 5f6cc67

Please sign in to comment.