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

gnrc_netif: fix timeout in gnrc_netif_ipv6_wait_for_global_address() #21137

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
1 change: 1 addition & 0 deletions sys/include/net/gnrc/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ static inline msg_bus_t* gnrc_netif_get_bus(gnrc_netif_t *netif,
* May be NULL, then this checks for a global address
* on *any* interface.
* @param timeout_ms Time to wait for an address to become available, in ms.
* Use `UINT32_MAX` to wait indefinitely.
*
* @return true if a global address is configured
*/
Expand Down
25 changes: 22 additions & 3 deletions sys/net/gnrc/netif/gnrc_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,14 @@
}
}

static void _unset_arg(void *arg)
{
ztimer_t *timer = arg;
if (timer) {
timer->arg = NULL;
}
}

bool gnrc_netif_ipv6_wait_for_global_address(gnrc_netif_t *netif,
uint32_t timeout_ms)
{
Expand All @@ -1396,6 +1404,7 @@

if (netif != NULL) {
if (_has_global_addr(netif)) {
DEBUG("gnrc_netif: %u already has a global address\n", netif->pid);
return true;
}

Expand All @@ -1406,6 +1415,7 @@
(netif = gnrc_netif_iter(netif));
count++) {
if (_has_global_addr(netif)) {
DEBUG("gnrc_netif: %u already has a global address\n", netif->pid);
has_global = true;
}

Expand All @@ -1415,15 +1425,22 @@

/* wait for global address */
msg_t m;
ztimer_now_t t_stop = ztimer_now(ZTIMER_MSEC) + timeout_ms;
ztimer_t _timeout = { .callback = _unset_arg, .arg = &_timeout };
if (timeout_ms != UINT32_MAX) {
ztimer_set(ZTIMER_MSEC, &_timeout, timeout_ms);
}

while (!has_global) {
/* stop if timeout reached */
if (ztimer_now(ZTIMER_MSEC) > t_stop) {
if (!_timeout.arg) {
DEBUG_PUTS("gnrc_netif: timeout reached");
break;
}

/* waiting for any message */
if (ztimer_msg_receive_timeout(ZTIMER_MSEC, &m, timeout_ms) < 0) {
if (timeout_ms == UINT32_MAX) {
msg_receive(&m);
} else if (ztimer_msg_receive_timeout(ZTIMER_MSEC, &m, timeout_ms) < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} else if (ztimer_msg_receive_timeout(ZTIMER_MSEC, &m, timeout_ms) < 0) {
}
else if (ztimer_msg_receive_timeout(ZTIMER_MSEC, &m, timeout_ms) < 0) {

according to RIOT coding style

Copy link
Contributor

Choose a reason for hiding this comment

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

since both styles are already in this file, this can be ignored

DEBUG_PUTS("gnrc_netif: timeout waiting for prefix");
break;
}
Expand All @@ -1439,6 +1456,8 @@
}
}

ztimer_remove(ZTIMER_MSEC, &_timeout);

/* called with a given interface */
if (netif != NULL) {
_netif_bus_detach(netif, &subs[0]);
Expand Down Expand Up @@ -2156,4 +2175,4 @@
}
}
}
/** @} */

Check warning on line 2178 in sys/net/gnrc/netif/gnrc_netif.c

View workflow job for this annotation

GitHub Actions / static-tests

source file is too long
Loading