예제 #1
0
ipv6_addr_t *gnrc_ipv6_netif_find_best_src_addr(kernel_pid_t pid, const ipv6_addr_t *dst)
{
    gnrc_ipv6_netif_t *iface = gnrc_ipv6_netif_get(pid);
    ipv6_addr_t *best_src = NULL;
    mutex_lock(&(iface->mutex));
    BITFIELD(candidate_set, GNRC_IPV6_NETIF_ADDR_NUMOF);
    memset(candidate_set, 0, sizeof(candidate_set));

    int first_candidate = _create_candidate_set(iface, dst, candidate_set);
    if (first_candidate >= 0) {
        best_src = _source_address_selection(iface, dst, candidate_set);
        if (best_src == NULL) {
            best_src = &(iface->addrs[first_candidate].addr);
        }
    }
    mutex_unlock(&(iface->mutex));

    return best_src;
}
예제 #2
0
ipv6_addr_t *gnrc_netif_ipv6_addr_best_src(gnrc_netif_t *netif,
                                           const ipv6_addr_t *dst,
                                           bool ll_only)
{
    ipv6_addr_t *best_src = NULL;

    BITFIELD(candidate_set, GNRC_NETIF_IPV6_ADDRS_NUMOF);

    assert((netif != NULL) && (dst != NULL));
    memset(candidate_set, 0, sizeof(candidate_set));
    gnrc_netif_acquire(netif);
    int first_candidate = _create_candidate_set(netif, dst, ll_only,
                                                candidate_set);
    if (first_candidate >= 0) {
        best_src = _src_addr_selection(netif, dst, candidate_set);
        if (best_src == NULL) {
            best_src = &(netif->ipv6.addrs[first_candidate]);
        }
    }
    gnrc_netif_release(netif);
    return best_src;
}