Skip to content

Commit

Permalink
ipv6: source address selection debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegHahm committed Aug 7, 2015
1 parent ce8874c commit 604e5dc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sys/net/network_layer/ng_ipv6/netif/ng_ipv6_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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."
*/
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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++;
}
Expand Down Expand Up @@ -608,13 +621,15 @@ 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);
tiebreaker_count++;
}
}
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);
}
Expand Down

0 comments on commit 604e5dc

Please sign in to comment.