diff --git a/sys/net/network_layer/ng_ipv6/netif/ng_ipv6_netif.c b/sys/net/network_layer/ng_ipv6/netif/ng_ipv6_netif.c index 044b32d960c0..b6647e2f8c06 100644 --- a/sys/net/network_layer/ng_ipv6/netif/ng_ipv6_netif.c +++ b/sys/net/network_layer/ng_ipv6/netif/ng_ipv6_netif.c @@ -468,6 +468,8 @@ static bool _create_candidate_set(ng_ipv6_netif_t *iface, { bool res = false; + DEBUG("gathering candidates\n"); + /* currently this implementation supports only addresses as source address * candidates assigned to this interface. Thus we assume all addresses to be * on interface @p iface */ @@ -476,6 +478,9 @@ static bool _create_candidate_set(ng_ipv6_netif_t *iface, for (int i = 0; i < NG_IPV6_NETIF_ADDR_NUMOF; i++) { ng_ipv6_netif_addr_t *iter = &(iface->addrs[i]); + DEBUG("Checking address: %s\n", + ng_ipv6_addr_to_str(addr_str, &(iter->addr), sizeof(addr_str))); + /* "In any case, multicast addresses and the unspecified address MUST NOT * be included in a candidate set." */ @@ -496,6 +501,7 @@ static bool _create_candidate_set(ng_ipv6_netif_t *iface, */ /* put all other addresses into the candidate set */ + DEBUG("add to candidate set\n"); bf_set(candidate_set, i); res = true; } @@ -524,19 +530,24 @@ static ng_ipv6_addr_t *_source_address_selection(ng_ipv6_netif_t *iface, BITFIELD(tiebreaker_tmp_set, candidate_set_len); memset(tiebreaker_tmp_set, 0, candidate_set_len); uint8_t tiebreaker_count = 0; + DEBUG("finding a the best match within the source address candidates\n"); for (int i = 0; i < NG_IPV6_NETIF_ADDR_NUMOF; i++) { ng_ipv6_netif_addr_t *iter = &(iface->addrs[i]); + DEBUG("Checking address: %s\n", + ng_ipv6_addr_to_str(addr_str, &(iter->addr), sizeof(addr_str))); /* entries configured to unspecified address or those which are not * part of the candidate set can be ignored */ if (ng_ipv6_addr_is_unspecified(&(iter->addr)) || !(bf_isset(candidate_set, i))) { + DEBUG("Unspecified or not part of the candidate set - skipping\n"); continue; } /* Rule 1: if we have an address configured that equals the destination * use this one as source */ if (ng_ipv6_addr_equal(&(iter->addr), dest)) { + DEBUG("Ease one - rule 1\n"); return &(iter->addr); } @@ -559,12 +570,14 @@ static ng_ipv6_addr_t *_source_address_selection(ng_ipv6_netif_t *iface, /* both global unicast */ (ng_ipv6_addr_is_global_unicast(dest) && ng_ipv6_addr_is_global_unicast(&(iter->addr)))) { + DEBUG("winner for rule 2 found\n"); bf_set(rule2_tmp_set, i); rule2_hit++; } /* Rule 3: Avoid deprecated addresses. */ if (iter->preferred > 0) { + DEBUG("winner for rule 3 found\n"); bf_set(rule3_tmp_set, i); rule3_hit++; } @@ -608,6 +621,7 @@ static ng_ipv6_addr_t *_source_address_selection(ng_ipv6_netif_t *iface, } /* check if we can use rule 3 as a tiebreaker for candidates winning in rule 2 */ else if ((rule2_hit > 1) && (rule3_hit > 1)) { + DEBUG("Looking for a tiebreaker\n"); for (int i = 0; i < candidate_set_len; i++) { if (bf_isset(rule2_tmp_set, i) && bf_isset(rule3_tmp_set, i)) { bf_set(tiebreaker_tmp_set, i); @@ -615,6 +629,7 @@ static ng_ipv6_addr_t *_source_address_selection(ng_ipv6_netif_t *iface, } } if (tiebreaker_count == 1) { + DEBUG("Found a match\n"); int tmp = bf_get_first_set(tiebreaker_tmp_set, candidate_set_len); return &(iface->addrs[tmp].addr); }