From 6b89f4f34b9561672d256824e9be95d114de28ba Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Wed, 24 Mar 2021 22:59:26 +0100 Subject: [PATCH] pkg/lwip: Start DHCP early for all Ethernet netifs Netifs without link status support will keep sending discover messages with increasing time between. Netifs that support link status will wait for the link to be up, and then start sending. Netifs that support link status but send no link status events will continue to not work (unless link status is up from the first check when setting it up). --- pkg/lwip/contrib/lwip.c | 21 ++++++++++++--------- pkg/lwip/contrib/netdev/lwip_netdev.c | 7 +------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/pkg/lwip/contrib/lwip.c b/pkg/lwip/contrib/lwip.c index f8e11e06d9..867186ca87 100644 --- a/pkg/lwip/contrib/lwip.c +++ b/pkg/lwip/contrib/lwip.c @@ -15,12 +15,10 @@ #include "kernel_defines.h" -#if IS_USED(MODULE_LWIP_DHCP_AUTO) -#include "lwip/dhcp.h" -#endif #include "lwip/tcpip.h" #include "lwip/netif/netdev.h" #include "lwip/netif.h" +#include "lwip/netifapi.h" #include "netif/lowpan6.h" #ifdef MODULE_NETDEV_TAP @@ -279,12 +277,17 @@ void lwip_bootstrap(void) #endif /* also allow for external interface definition */ tcpip_init(NULL, NULL); -#if IS_USED(MODULE_LWIP_DHCP_AUTO) && IS_USED(MODULE_NETDEV_TAP) - /* XXX: Hack to get DHCP with IPv4 with `netdev_tap`, as it does - * not emit a `NETDEV_EVENT_LINK_UP` event. Remove, once it does - * at an appropriate point. - * (see https://github.com/RIOT-OS/RIOT/pull/14150) */ - dhcp_start(netif); +#if IS_USED(MODULE_LWIP_DHCP_AUTO) + { + /* Start DHCP on all supported netifs. Interfaces that support + * link status events will reset DHCP retries when link comes up. */ + struct netif *n = NULL; + NETIF_FOREACH(n) { + if (netif_is_flag_set(n, NETIF_FLAG_ETHERNET)) { + netifapi_dhcp_start(netif); + } + } + } #endif } diff --git a/pkg/lwip/contrib/netdev/lwip_netdev.c b/pkg/lwip/contrib/netdev/lwip_netdev.c index dedc2a9319..04daea7596 100644 --- a/pkg/lwip/contrib/netdev/lwip_netdev.c +++ b/pkg/lwip/contrib/netdev/lwip_netdev.c @@ -17,9 +17,6 @@ #include #include -#if MODULE_LWIP_DHCP_AUTO -#include "lwip/dhcp.h" -#endif #include "lwip/err.h" #include "lwip/ethip6.h" #include "lwip/netif.h" @@ -297,10 +294,8 @@ static void _event_cb(netdev_t *dev, netdev_event_t event) break; } case NETDEV_EVENT_LINK_UP: { + /* Will wake up DHCP state machine */ netifapi_netif_set_link_up(netif); -#ifdef MODULE_LWIP_DHCP_AUTO - netifapi_dhcp_start(netif); -#endif break; } case NETDEV_EVENT_LINK_DOWN: {