pkg/lwip: Set link state properly when supported
Set link state correctly in lwIP for interfaces that support the NETOPT_LINK option. Interfaces that do not support it (like tap for native arch) remain up all the time. Netdevs that support NETOPT_LINK but do not send NETDEV_EVENT_LINK_UP/DOWN events will end up with a mismatched link state - but DHCP would already not start for them either. Use netifapi to signal lwIP to do the work in its own thread.
This commit is contained in:
parent
d6c4cd0a26
commit
60d5d1aa74
@ -23,6 +23,7 @@
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/ethip6.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/netifapi.h"
|
||||
#include "lwip/netif/netdev.h"
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/pbuf.h"
|
||||
@ -81,6 +82,7 @@ err_t lwip_netdev_init(struct netif *netif)
|
||||
LWIP_ASSERT("netif != NULL", (netif != NULL));
|
||||
LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));
|
||||
netdev_t *netdev;
|
||||
netopt_enable_t enabled = 0;
|
||||
uint16_t dev_type;
|
||||
err_t res = ERR_OK;
|
||||
|
||||
@ -186,7 +188,11 @@ err_t lwip_netdev_init(struct netif *netif)
|
||||
return ERR_IF; /* device type not supported yet */
|
||||
}
|
||||
netif->flags |= NETIF_FLAG_UP;
|
||||
netif->flags |= NETIF_FLAG_LINK_UP;
|
||||
/* Set link state up if link state is unsupported, or if it is up */
|
||||
if (netdev->driver->get(netdev, NETOPT_LINK, &enabled, sizeof(enabled)) <= 0 ||
|
||||
enabled) {
|
||||
netif->flags |= NETIF_FLAG_LINK_UP;
|
||||
}
|
||||
netif->flags |= NETIF_FLAG_IGMP;
|
||||
netif->flags |= NETIF_FLAG_MLD6;
|
||||
netdev->context = netif;
|
||||
@ -290,12 +296,17 @@ static void _event_cb(netdev_t *dev, netdev_event_t event)
|
||||
}
|
||||
break;
|
||||
}
|
||||
#ifdef MODULE_LWIP_DHCP_AUTO
|
||||
case NETDEV_EVENT_LINK_UP: {
|
||||
dhcp_start(netif);
|
||||
netifapi_netif_set_link_up(netif);
|
||||
#ifdef MODULE_LWIP_DHCP_AUTO
|
||||
netifapi_dhcp_start(netif);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case NETDEV_EVENT_LINK_DOWN: {
|
||||
netifapi_netif_set_link_down(netif);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@ -56,6 +56,12 @@ extern "C" {
|
||||
#define LWIP_ETHERNET 0
|
||||
#endif /* MODULE_LWIP_ETHERNET */
|
||||
|
||||
#ifdef MODULE_LWIP_NETIF
|
||||
#define LWIP_NETIF_API 1
|
||||
#else /* MODULE_LWIP_NETIF */
|
||||
#define LWIP_NETIF_API 0
|
||||
#endif /* MODULE_LWIP_NETIF */
|
||||
|
||||
#ifdef MODULE_LWIP_IGMP
|
||||
#define LWIP_IGMP 1
|
||||
#else /* MODULE_LWIP_IGMP */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user