Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes several bugs on GNRC network stack #4447

Merged
merged 4 commits into from
Jan 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sys/include/net/gnrc/ipv6/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ ipv6_addr_t *gnrc_ipv6_netif_find_addr(kernel_pid_t pid, const ipv6_addr_t *addr
*
* @param[in] prefix The prefix you want to search for.
*
* @pre @p out must not be NULL.
*
* @return The PID to the interface the address is registered to.
* @return KERNEL_PID_UNDEF, if no matching address can not be found on any
* interface.
Expand Down
7 changes: 7 additions & 0 deletions sys/net/gnrc/network_layer/ipv6/nc/gnrc_ipv6_nc.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ void gnrc_ipv6_nc_remove(kernel_pid_t iface, const ipv6_addr_t *ipv6_addr)
#endif
#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER
xtimer_remove(&entry->type_timeout);

gnrc_ipv6_netif_t *if_entry = gnrc_ipv6_netif_get(iface);

if ((if_entry != NULL) && (if_entry->rtr_adv_msg.content.ptr == (char *) entry)) {
/* cancel timer set by gnrc_ndp_rtr_sol_handle */
xtimer_remove(&if_entry->rtr_adv_timer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if this timer was set by a router solicitation of another neighbor. I think the better solution would be to check if the neighbor cache entry is still set in the handler function of this timer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If another neighbor set the timer, if_entry->rtr_adv_msg.content.ptr will be updated, so that the timer is not cancelled here.

}
#endif
#if defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER)
xtimer_remove(&entry->rtr_adv_timer);
Expand Down
5 changes: 1 addition & 4 deletions sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,7 @@ kernel_pid_t gnrc_ipv6_netif_find_by_prefix(ipv6_addr_t **out, const ipv6_addr_t
match = _find_by_prefix_unsafe(&tmp_res, ipv6_ifs + i, prefix, NULL);

if (match > best_match) {
if (out != NULL) {
*out = tmp_res;
}

*out = tmp_res;
res = ipv6_ifs[i].pid;
best_match = match;
}
Expand Down
7 changes: 4 additions & 3 deletions sys/net/gnrc/network_layer/sixlowpan/nd/gnrc_sixlowpan_nd.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,11 @@ kernel_pid_t gnrc_sixlowpan_nd_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_
if (nc_entry != NULL) {
gnrc_ipv6_netif_t *ipv6_if = gnrc_ipv6_netif_get(nc_entry->iface);
/* and interface is not 6LoWPAN */
if (!(ipv6_if->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) ||
if (!((ipv6_if == NULL) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer an assert(). You would not be in this function if the interface wasn't available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function may be called with the nc_entry->iface is 0, resulting in a null pointer dereference. See commit message for detail.
Yonezawa-T2@b0e9c40

There would be a better comprehensive solution for coordinating NDPs for conventional IPv6 and 6LoWPAN, but it would require a large restructuring, so that ad hoc workaround here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

(ipv6_if->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN)) ||
/* or entry is registered */
(gnrc_ipv6_nc_get_type(nc_entry) == GNRC_IPV6_NC_TYPE_REGISTERED)) {
next_hop = dst;
(gnrc_ipv6_nc_get_type(nc_entry) == GNRC_IPV6_NC_TYPE_REGISTERED)) {
next_hop = dst;
}
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ bool _parse_options(int msg_type, gnrc_rpl_instance_t *inst, gnrc_rpl_opt_t *opt
case (GNRC_RPL_OPT_TARGET):
DEBUG("RPL: RPL TARGET DAO option parsed\n");
*included_opts |= ((uint32_t) 1) << GNRC_RPL_OPT_TARGET;
if_id = gnrc_ipv6_netif_find_by_prefix(NULL, &dodag->dodag_id);
ipv6_addr_t *prefix = NULL;
if_id = gnrc_ipv6_netif_find_by_prefix(&prefix, &dodag->dodag_id);
if (if_id == KERNEL_PID_UNDEF) {
DEBUG("RPL: no interface found for the configured DODAG id\n");
return false;
Expand Down
19 changes: 19 additions & 0 deletions sys/net/network_layer/fib/fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ static int fib_find_entry(fib_table_t *table, uint8_t *dst, size_t dst_size,
int ret = -EHOSTUNREACH;
bool is_all_zeros_addr = true;

#if ENABLE_DEBUG
DEBUG("[fib_find_entry] dst =");
for (size_t i = 0; i < dst_size; i++) {
DEBUG(" %02x", dst[i]);
}
DEBUG("\n");
#endif

for (size_t i = 0; i < dst_size; ++i) {
if (dst[i] != 0) {
is_all_zeros_addr = false;
Expand Down Expand Up @@ -125,6 +133,7 @@ static int fib_find_entry(fib_table_t *table, uint8_t *dst, size_t dst_size,
int ret_comp = universal_address_compare(table->data.entries[i].global, dst, &match_size);
/* If we found an exact match */
if (ret_comp == 0 || (is_all_zeros_addr && match_size == 0)) {
DEBUG("[fib_find_entry] found an exact match");
entry_arr[0] = &(table->data.entries[i]);
*entry_arr_size = 1;
/* we will not find a better one so we return */
Expand All @@ -148,6 +157,16 @@ static int fib_find_entry(fib_table_t *table, uint8_t *dst, size_t dst_size,
}
}

#if ENABLE_DEBUG
if (count > 0) {
DEBUG("[fib_find_entry] found prefix on interface %d:", entry_arr[0]->iface_id);
for (size_t i = 0; i < entry_arr[0]->global->address_size; i++) {
DEBUG(" %02x", entry_arr[0]->global->address[i]);
}
DEBUG("\n");
}
#endif

*entry_arr_size = count;
return ret;
}
Expand Down