예제 #1
0
파일: fib.c 프로젝트: robby14/RIOT
int fib_get_destination_set(uint8_t *prefix, size_t prefix_size,
                            fib_destination_set_entry_t *dst_set, size_t* dst_set_size)
{
    mutex_lock(&mtx_access);
    int ret = -EHOSTUNREACH;
    size_t found_entries = 0;

    for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
        if ((fib_table[i].global != NULL) &&
            (universal_address_compare_prefix(fib_table[i].global, prefix, prefix_size<<3) >= 0)) {
            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);
            universal_address_get_address(fib_table[i].global,
                                          dst_set[found_entries].dest,
                                          &dst_set[found_entries].dest_size);
            }
            found_entries++;
        }
    }

    if( found_entries > *dst_set_size ) {
        ret = -ENOBUFS;
    } else if( found_entries > 0 ) {
        ret = 0;
    }

    *dst_set_size = found_entries;

    mutex_unlock(&mtx_access);

    return ret;
}
예제 #2
0
파일: fib.c 프로젝트: robby14/RIOT
static void fib_print_address(universal_address_container_t *entry)
{
    uint8_t address[UNIVERSAL_ADDRESS_SIZE];
    size_t addr_size = UNIVERSAL_ADDRESS_SIZE;
    uint8_t *ret = universal_address_get_address(entry, address, &addr_size);

    if (ret == address) {
#ifdef MODULE_IPV6_ADDR
        if (addr_size == sizeof(ipv6_addr_t)) {
            printf("%-" NG_FIB_ADDR_PRINT_LENS "s",
                    ipv6_addr_to_str(addr_str, (ipv6_addr_t *) address, sizeof(addr_str)));
            return;
        }
#endif
        for (size_t i = 0; i < UNIVERSAL_ADDRESS_SIZE; ++i) {
            if (i <= addr_size) {
                printf("%02x", address[i]);
            }
            else {
                printf("  ");
            }
        }
#ifdef MODULE_IPV6_ADDR
        /* print trailing whitespaces */
        for (size_t i = 0; i < NG_FIB_ADDR_PRINT_LEN - (UNIVERSAL_ADDRESS_SIZE * 2); ++i) {
            printf(" ");
        }
#endif
    }
}
예제 #3
0
파일: fib.c 프로젝트: daniel-k/RIOT
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,
                     uint32_t dst_flags)
{
    mutex_lock(&mtx_access);
    DEBUG("[fib_get_next_hop]\n");
    size_t count = 1;
    fib_entry_t *entry[count];

    if ((iface_id == NULL)
        || (next_hop_size == NULL)
        || (next_hop_flags == NULL)) {
            mutex_unlock(&mtx_access);
            return -EINVAL;
        }

    if ((dst == NULL) || (next_hop == NULL)) {
        mutex_unlock(&mtx_access);
        return -EFAULT;
    }

    int ret = fib_find_entry(table, dst, dst_size, &(entry[0]), &count);
    if (!(ret == 0 || ret == 1)) {
        /* notify all responsible RPs for unknown  next-hop for the destination address */
        if (fib_signal_rp(dst, dst_size, dst_flags) == 0) {
            count = 1;
            /* now lets see if the RRPs have found a valid next-hop */
            ret = fib_find_entry(table, dst, dst_size, &(entry[0]), &count);
        }
    }

    if (ret == 0 || ret == 1) {

        uint8_t *address_ret = universal_address_get_address(entry[0]->next_hop,
                               next_hop, next_hop_size);

        if (address_ret == NULL) {
            mutex_unlock(&mtx_access);
            return -ENOBUFS;
        }
    }
    else {
        mutex_unlock(&mtx_access);
        return -EHOSTUNREACH;
    }

    *iface_id = entry[0]->iface_id;
    *next_hop_flags = entry[0]->next_hop_flags;
    mutex_unlock(&mtx_access);
    return 0;
}
예제 #4
0
파일: fib.c 프로젝트: JiapengLi/RIOT
static void fib_print_adress(universal_address_container_t *entry)
{
    uint8_t address[UNIVERSAL_ADDRESS_SIZE];
    size_t addr_size = UNIVERSAL_ADDRESS_SIZE;
    uint8_t *ret = universal_address_get_address(entry, address, &addr_size);

    if (ret == address) {
        for (size_t i = 0; i < UNIVERSAL_ADDRESS_SIZE; ++i) {
            if (i <= addr_size) {
                printf("%02x", address[i]);
            }
            else {
                printf("  ");
            }
        }
    }
}
예제 #5
0
파일: fib.c 프로젝트: JiapengLi/RIOT
int fib_get_next_hop(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, uint32_t dst_flags)
{
    mutex_lock(&mtx_access);
    DEBUG("[fib_get_next_hop]");
    size_t count = 1;
    fib_entry_t *entry[count];

    int ret = fib_find_entry(dst, dst_size, &(entry[0]), &count);

    if (!(ret == 0 || ret == 1)) {
        /* notify all RRPs for route discovery if available */
        if (fib_signal_rrp(dst, dst_size, dst_flags) == 0) {
            count = 1;
            /* now lets see if the RRPs have found a valid next-hop */
            ret = fib_find_entry(dst, dst_size, &(entry[0]), &count);
        }
    }

    if (ret == 0 || ret == 1) {

        uint8_t *address_ret = universal_address_get_address(entry[0]->next_hop,
                               next_hop, next_hop_size);

        if (address_ret == NULL) {
            mutex_unlock(&mtx_access);
            return -ENOBUFS;
        }
    }
    else {
        mutex_unlock(&mtx_access);
        return -EHOSTUNREACH;
    }

    *iface_id = entry[0]->iface_id;
    *next_hop_flags = entry[0]->next_hop_flags;
    mutex_unlock(&mtx_access);
    return 0;
}