Skip to content

Commit

Permalink
sixlowpan: fixed infinite loop
Browse files Browse the repository at this point in the history
When prefix entry is resued, it may form a looped list, results in infinite loop
in gnrc_ndp_internal_send_rtr_adv.
This patch avoids looped lists.
  • Loading branch information
Yonezawa-T2 committed Dec 9, 2015
1 parent b0e9c40 commit 18c0720
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ static gnrc_sixlowpan_nd_router_abr_t *_get_abr(ipv6_addr_t *addr)
return abr;
}

static gnrc_sixlowpan_nd_router_prf_t *_get_free_prefix(ipv6_addr_t *prefix, size_t prefix_len)
static gnrc_sixlowpan_nd_router_prf_t *_get_free_prefix(gnrc_ipv6_netif_t *ipv6_iface, ipv6_addr_t *prefix, size_t prefix_len)
{
gnrc_sixlowpan_nd_router_prf_t *prf = NULL;

for (int i = 0; i < GNRC_SIXLOWPAN_ND_ROUTER_ABR_PRF_NUMOF; i++) {
if ((ipv6_addr_match_prefix(&_prefixes[i].prefix->addr, prefix) >= prefix_len) &&
(_prefixes[i].prefix->prefix_len == prefix_len)) {
(_prefixes[i].prefix->prefix_len == prefix_len) &&
(_prefixes[i].iface == ipv6_iface)) {
return &_prefixes[i];
}

Expand Down Expand Up @@ -78,14 +79,13 @@ static void _add_prefix(kernel_pid_t iface, gnrc_sixlowpan_nd_router_abr_t *abr,

prefix = gnrc_ipv6_netif_match_prefix(iface, &pi_opt->prefix);

prf_ent = _get_free_prefix(&pi_opt->prefix, pi_opt->prefix_len);
prf_ent = _get_free_prefix(ipv6_iface, &pi_opt->prefix, pi_opt->prefix_len);

if (prf_ent != NULL) {
if (prf_ent != NULL && prf_ent->iface == NULL) {
prf_ent->iface = ipv6_iface;
prf_ent->prefix = container_of(prefix, gnrc_ipv6_netif_addr_t, addr);
LL_PREPEND(abr->prfs, prf_ent);
}

LL_PREPEND(abr->prfs, prf_ent);
}

static void _add_ctx(gnrc_sixlowpan_nd_router_abr_t *abr, sixlowpan_nd_opt_6ctx_t *ctx_opt)
Expand Down Expand Up @@ -312,14 +312,16 @@ int gnrc_sixlowpan_nd_router_abr_add_prf(gnrc_sixlowpan_nd_router_abr_t* abr,
if ((abr < _abrs) || (abr > (_abrs + GNRC_SIXLOWPAN_ND_ROUTER_ABR_NUMOF))) {
return -ENOENT;
}
prf_ent = _get_free_prefix(&prefix->addr, prefix->prefix_len);
prf_ent = _get_free_prefix(iface, &prefix->addr, prefix->prefix_len);
if (prf_ent == NULL) {
return -ENOMEM;
}
prf_ent->iface = iface;
prf_ent->prefix = prefix;
LL_PREPEND(abr->prfs, prf_ent);
abr->version++; /* TODO: store somewhere stable */
if (prf_ent->iface == NULL) {
prf_ent->iface = iface;
prf_ent->prefix = prefix;
LL_PREPEND(abr->prfs, prf_ent);
abr->version++; /* TODO: store somewhere stable */
}
return 0;
}

Expand Down

0 comments on commit 18c0720

Please sign in to comment.