Browse Source

Merge pull request #5019 from cgundogan/pr/fib/flush

fib: flush entries
pr/gpio
Oleg Hahm 7 years ago
parent
commit
1787cb6ed2
  1. 11
      sys/include/net/fib.h
  2. 15
      sys/net/network_layer/fib/fib.c
  3. 27
      sys/shell/commands/sc_fib.c

11
sys/include/net/fib.h

@ -160,6 +160,17 @@ int fib_update_entry(fib_table_t *table, uint8_t *dst, size_t dst_size,
*/
void fib_remove_entry(fib_table_t *table, uint8_t *dst, size_t dst_size);
/**
* @brief removes all entries from the corresponding FIB table and interface combination
*
* @note if interface is KERNEL_PID_UNDEF, then all entries regardless of the interface
* will be removed.
*
* @param[in] table the fib table to flush
* @param[in] interface entries associated with this interface will be removed
*/
void fib_flush(fib_table_t *table, kernel_pid_t interface);
/**
* @brief provides a next hop for a given destination
*

15
sys/net/network_layer/fib/fib.c

@ -451,6 +451,21 @@ void fib_remove_entry(fib_table_t *table, uint8_t *dst, size_t dst_size)
mutex_unlock(&(table->mtx_access));
}
void fib_flush(fib_table_t *table, kernel_pid_t interface)
{
mutex_lock(&(table->mtx_access));
DEBUG("[fib_flush]\n");
for (size_t i = 0; i < table->size; ++i) {
if ((interface == KERNEL_PID_UNDEF) ||
(interface == table->data.entries[i].iface_id)) {
fib_remove(&table->data.entries[i]);
}
}
mutex_unlock(&(table->mtx_access));
}
int fib_get_next_hop(fib_table_t *table, kernel_pid_t *iface_id,
uint8_t *next_hop, size_t *next_hop_size,
uint32_t *next_hop_flags, uint8_t *dst, size_t dst_size,

27
sys/shell/commands/sc_fib.c

@ -49,6 +49,11 @@ static unsigned char tmp_ipv6_nxt[IN6ADDRSZ]; /**< buffer for ipv6 address conve
static void _fib_usage(int info)
{
switch (info) {
case 0: {
puts("\nsee <fibroute [add|del]> for more information\n"
"<fibroute flush [interface]> removes all entries [associated with interface]\n");
break;
}
case 1: {
puts("\nbrief: adds a new entry to the FIB.\nusage: "
INFO1_TXT "\n" INFO3_TXT);
@ -131,21 +136,37 @@ int _fib_route_handler(int argc, char **argv)
else if ((strcmp("del", argv[1]) == 0)) {
_fib_usage(3);
}
else if ((strcmp("flush", argv[1]) == 0)) {
fib_flush(&gnrc_ipv6_fib_table, KERNEL_PID_UNDEF);
puts("successfully flushed all entries");
}
else {
puts("\nunrecognized parameter1.\nPlease enter fibroute [add|del] for more information.");
_fib_usage(0);
}
return 1;
}
if (argc > 2 && !((strcmp("add", argv[1]) == 0) || (strcmp("del", argv[1]) == 0))) {
if (argc > 2 && !((strcmp("add", argv[1]) == 0) ||
(strcmp("del", argv[1]) == 0) ||
(strcmp("flush", argv[1]) == 0))) {
puts("\nunrecognized parameter2.\nPlease enter fibroute [add|del] for more information.");
return 1;
}
/* e.g. fibroute del <destination> */
if (argc == 3) {
if (inet_pton(AF_INET6, argv[2], tmp_ipv6_dst)) {
if ((strcmp("flush", argv[1]) == 0)) {
kernel_pid_t iface = atoi(argv[2]);
if (gnrc_netif_exist(iface)) {
fib_flush(&gnrc_ipv6_fib_table, iface);
printf("successfully flushed all entries for interface %" PRIu16"\n", iface);
}
else {
printf("interface %" PRIu16" does not exist\n", iface);
}
}
else if (inet_pton(AF_INET6, argv[2], tmp_ipv6_dst)) {
fib_remove_entry(&gnrc_ipv6_fib_table, tmp_ipv6_dst, IN6ADDRSZ);
}
else if (inet_pton(AF_INET, argv[2], tmp_ipv4_dst)) {

Loading…
Cancel
Save