Merge pull request #4519 from OlegHahm/fib_remove_superfluous_things

FIB: remove superfluous things
This commit is contained in:
Oleg Hahm 2016-01-27 16:12:08 +01:00
commit dae4253618

View File

@ -669,9 +669,9 @@ int fib_sr_create(fib_table_t *table, fib_sr_t **fib_sr, kernel_pid_t sr_iface_i
* @brief Internal function: * @brief Internal function:
* checks the lifetime and removes the entry in case it expired * checks the lifetime and removes the entry in case it expired
*/ */
static int fib_sr_check_lifetime(fib_sr_t *fib_sr, uint64_t *now) static int fib_sr_check_lifetime(fib_sr_t *fib_sr)
{ {
uint64_t tm = fib_sr->sr_lifetime - *now; uint64_t tm = fib_sr->sr_lifetime - xtimer_now64();
/* check if the lifetime expired */ /* check if the lifetime expired */
if ((int64_t)tm < 0) { if ((int64_t)tm < 0) {
/* remove this sr if its lifetime expired */ /* remove this sr if its lifetime expired */
@ -731,8 +731,6 @@ static int fib_is_sr_in_table(fib_table_t *table, fib_sr_t *fib_sr)
int fib_sr_read_head(fib_table_t *table, fib_sr_t *fib_sr, kernel_pid_t *iface_id, int fib_sr_read_head(fib_table_t *table, fib_sr_t *fib_sr, kernel_pid_t *iface_id,
uint32_t *sr_flags, uint32_t *sr_lifetime) uint32_t *sr_flags, uint32_t *sr_lifetime)
{ {
uint64_t now = xtimer_now64();
mutex_lock(&(table->mtx_access)); mutex_lock(&(table->mtx_access));
if ((fib_sr == NULL) || (iface_id == NULL) || (sr_flags == NULL) if ((fib_sr == NULL) || (iface_id == NULL) || (sr_flags == NULL)
|| (sr_lifetime == NULL) || (fib_is_sr_in_table(table, fib_sr) == -ENOENT) ) { || (sr_lifetime == NULL) || (fib_is_sr_in_table(table, fib_sr) == -ENOENT) ) {
@ -740,14 +738,14 @@ int fib_sr_read_head(fib_table_t *table, fib_sr_t *fib_sr, kernel_pid_t *iface_i
return -EFAULT; return -EFAULT;
} }
if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) { if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -ENOENT; return -ENOENT;
} }
*iface_id = fib_sr->sr_iface_id; *iface_id = fib_sr->sr_iface_id;
*sr_flags = fib_sr->sr_flags; *sr_flags = fib_sr->sr_flags;
*sr_lifetime = fib_sr->sr_lifetime - now; *sr_lifetime = fib_sr->sr_lifetime - xtimer_now64();
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return 0; return 0;
@ -756,8 +754,6 @@ int fib_sr_read_head(fib_table_t *table, fib_sr_t *fib_sr, kernel_pid_t *iface_i
int fib_sr_read_destination(fib_table_t *table, fib_sr_t *fib_sr, int fib_sr_read_destination(fib_table_t *table, fib_sr_t *fib_sr,
uint8_t *dst, size_t *dst_size) uint8_t *dst, size_t *dst_size)
{ {
uint64_t now = xtimer_now64();
mutex_lock(&(table->mtx_access)); mutex_lock(&(table->mtx_access));
if ((fib_sr == NULL) || (dst == NULL) || (dst_size == NULL) if ((fib_sr == NULL) || (dst == NULL) || (dst_size == NULL)
|| (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) { || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
@ -765,7 +761,7 @@ int fib_sr_read_destination(fib_table_t *table, fib_sr_t *fib_sr,
return -EFAULT; return -EFAULT;
} }
if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) { if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -ENOENT; return -ENOENT;
} }
@ -787,15 +783,13 @@ int fib_sr_read_destination(fib_table_t *table, fib_sr_t *fib_sr,
int fib_sr_set(fib_table_t *table, fib_sr_t *fib_sr, kernel_pid_t *sr_iface_id, int fib_sr_set(fib_table_t *table, fib_sr_t *fib_sr, kernel_pid_t *sr_iface_id,
uint32_t *sr_flags, uint32_t *sr_lifetime) uint32_t *sr_flags, uint32_t *sr_lifetime)
{ {
uint64_t now = xtimer_now64();
mutex_lock(&(table->mtx_access)); mutex_lock(&(table->mtx_access));
if ((fib_sr == NULL) || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) { if ((fib_sr == NULL) || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -EFAULT; return -EFAULT;
} }
if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) { if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -ENOENT; return -ENOENT;
} }
@ -842,8 +836,6 @@ int fib_sr_delete(fib_table_t *table, fib_sr_t *fib_sr)
int fib_sr_next(fib_table_t *table, fib_sr_t *fib_sr, fib_sr_entry_t **sr_path_entry) int fib_sr_next(fib_table_t *table, fib_sr_t *fib_sr, fib_sr_entry_t **sr_path_entry)
{ {
uint64_t now = xtimer_now64();
mutex_lock(&(table->mtx_access)); mutex_lock(&(table->mtx_access));
if ((fib_sr == NULL) || (sr_path_entry == NULL) if ((fib_sr == NULL) || (sr_path_entry == NULL)
|| (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) { || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
@ -856,7 +848,7 @@ int fib_sr_next(fib_table_t *table, fib_sr_t *fib_sr, fib_sr_entry_t **sr_path_e
return -EFAULT; return -EFAULT;
} }
if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) { if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -ENOENT; return -ENOENT;
} }
@ -883,8 +875,6 @@ int fib_sr_next(fib_table_t *table, fib_sr_t *fib_sr, fib_sr_entry_t **sr_path_e
int fib_sr_search(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, size_t addr_size, int fib_sr_search(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, size_t addr_size,
fib_sr_entry_t **sr_path_entry) fib_sr_entry_t **sr_path_entry)
{ {
uint64_t now = xtimer_now64();
mutex_lock(&(table->mtx_access)); mutex_lock(&(table->mtx_access));
if ((fib_sr == NULL) || (addr == NULL) || (sr_path_entry == NULL) if ((fib_sr == NULL) || (addr == NULL) || (sr_path_entry == NULL)
|| (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) { || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
@ -892,7 +882,7 @@ int fib_sr_search(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, size_t ad
return -EFAULT; return -EFAULT;
} }
if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) { if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -ENOENT; return -ENOENT;
} }
@ -918,8 +908,6 @@ int fib_sr_search(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, size_t ad
int fib_sr_entry_append(fib_table_t *table, fib_sr_t *fib_sr, int fib_sr_entry_append(fib_table_t *table, fib_sr_t *fib_sr,
uint8_t *addr, size_t addr_size) uint8_t *addr, size_t addr_size)
{ {
uint64_t now = xtimer_now64();
mutex_lock(&(table->mtx_access)); mutex_lock(&(table->mtx_access));
if ((fib_sr == NULL) || (addr == NULL) if ((fib_sr == NULL) || (addr == NULL)
|| (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) { || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
@ -927,7 +915,7 @@ int fib_sr_entry_append(fib_table_t *table, fib_sr_t *fib_sr,
return -EFAULT; return -EFAULT;
} }
if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) { if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -ENOENT; return -ENOENT;
} }
@ -965,8 +953,6 @@ int fib_sr_entry_add(fib_table_t *table, fib_sr_t *fib_sr,
fib_sr_entry_t *sr_path_entry, uint8_t *addr, size_t addr_size, fib_sr_entry_t *sr_path_entry, uint8_t *addr, size_t addr_size,
bool keep_remaining_route) bool keep_remaining_route)
{ {
uint64_t now = xtimer_now64();
mutex_lock(&(table->mtx_access)); mutex_lock(&(table->mtx_access));
if ((fib_sr == NULL) || (sr_path_entry == NULL) || (addr == NULL) if ((fib_sr == NULL) || (sr_path_entry == NULL) || (addr == NULL)
|| (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) { || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
@ -974,7 +960,7 @@ int fib_sr_entry_add(fib_table_t *table, fib_sr_t *fib_sr,
return -EFAULT; return -EFAULT;
} }
if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) { if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -ENOENT; return -ENOENT;
} }
@ -1023,15 +1009,13 @@ int fib_sr_entry_add(fib_table_t *table, fib_sr_t *fib_sr,
int fib_sr_entry_delete(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, size_t addr_size, int fib_sr_entry_delete(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, size_t addr_size,
bool keep_remaining_route) bool keep_remaining_route)
{ {
uint64_t now = xtimer_now64();
mutex_lock(&(table->mtx_access)); mutex_lock(&(table->mtx_access));
if ((fib_sr == NULL) || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) { if ((fib_sr == NULL) || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -EFAULT; return -EFAULT;
} }
if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) { if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -ENOENT; return -ENOENT;
} }
@ -1075,8 +1059,6 @@ int fib_sr_entry_overwrite(fib_table_t *table, fib_sr_t *fib_sr,
uint8_t *addr_old, size_t addr_old_size, uint8_t *addr_old, size_t addr_old_size,
uint8_t *addr_new, size_t addr_new_size) uint8_t *addr_new, size_t addr_new_size)
{ {
uint64_t now = xtimer_now64();
mutex_lock(&(table->mtx_access)); mutex_lock(&(table->mtx_access));
if ((fib_sr == NULL) || (addr_old == NULL) || (addr_new == NULL) if ((fib_sr == NULL) || (addr_old == NULL) || (addr_new == NULL)
|| (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) { || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
@ -1084,7 +1066,7 @@ int fib_sr_entry_overwrite(fib_table_t *table, fib_sr_t *fib_sr,
return -EFAULT; return -EFAULT;
} }
if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) { if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -ENOENT; return -ENOENT;
} }
@ -1127,15 +1109,13 @@ int fib_sr_entry_overwrite(fib_table_t *table, fib_sr_t *fib_sr,
int fib_sr_entry_get_address(fib_table_t *table, fib_sr_t *fib_sr, fib_sr_entry_t *sr_entry, int fib_sr_entry_get_address(fib_table_t *table, fib_sr_t *fib_sr, fib_sr_entry_t *sr_entry,
uint8_t *addr, size_t *addr_size) uint8_t *addr, size_t *addr_size)
{ {
uint64_t now = xtimer_now64();
mutex_lock(&(table->mtx_access)); mutex_lock(&(table->mtx_access));
if ((fib_sr == NULL) || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) { if ((fib_sr == NULL) || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -EFAULT; return -EFAULT;
} }
if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) { if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
mutex_unlock(&(table->mtx_access)); mutex_unlock(&(table->mtx_access));
return -ENOENT; return -ENOENT;
} }
@ -1274,8 +1254,6 @@ int fib_sr_get_route(fib_table_t *table, uint8_t *dst, size_t dst_size, kernel_p
uint8_t *addr_list, size_t *addr_list_elements, size_t *element_size, uint8_t *addr_list, size_t *addr_list_elements, size_t *element_size,
bool reverse, fib_sr_t **fib_sr) bool reverse, fib_sr_t **fib_sr)
{ {
uint64_t now = xtimer_now64();
mutex_lock(&(table->mtx_access)); mutex_lock(&(table->mtx_access));
if ((dst == NULL) || (sr_iface_id == NULL) || (sr_flags == NULL) if ((dst == NULL) || (sr_iface_id == NULL) || (sr_flags == NULL)
@ -1292,7 +1270,7 @@ int fib_sr_get_route(fib_table_t *table, uint8_t *dst, size_t dst_size, kernel_p
/* Case 1 - check if we know a direct route */ /* Case 1 - check if we know a direct route */
for (size_t i = 0; i < table->size; ++i) { for (size_t i = 0; i < table->size; ++i) {
if (fib_sr_check_lifetime(&table->data.source_routes->headers[i], &now) == -ENOENT) { if (fib_sr_check_lifetime(&table->data.source_routes->headers[i]) == -ENOENT) {
/* expired, so skip this sr and remember its position */ /* expired, so skip this sr and remember its position */
if (check_free_entry == -1) { if (check_free_entry == -1) {
/* we want to fill up the source routes from the beginning */ /* we want to fill up the source routes from the beginning */