Skip to content

lwIP on ethernet: examples #8395

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

Merged
merged 19 commits into from
Jun 2, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
factorize
  • Loading branch information
d-a-v committed May 31, 2022
commit 86ab737495a48902b2a2c7440e1e311894e883e9
34 changes: 23 additions & 11 deletions cores/esp8266/LwipIntfDev.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,26 @@ class LwipIntfDev: public LwipIntf, public RawDev
// the first one is picked. On esp8266/Arduno: WiFi interfaces are
// checked first.
// 3. Or, use `::setDefault()` to force routing through this interface.
void setDefault(bool default = true);
void setDefault(bool deflt = true);

// true if interface has a valid IPv4 address
bool connected()
{
return !!ip4_addr_get_u32(ip_2_ip4(&_netif.ip_addr));
}

bool routable()
{
return !ip_addr_isany(&_netif.gw);
}

// ESP8266WiFi API compatibility

wl_status_t status();

protected:
err_t netif_init();
void check_route();
void netif_status_callback();

static err_t netif_init_s(netif* netif);
Expand Down Expand Up @@ -315,17 +321,26 @@ err_t LwipIntfDev<RawDev>::netif_init()

template<class RawDev>
void LwipIntfDev<RawDev>::netif_status_callback()
{
check_route();
if (connected())
{
sntp_stop();
sntp_init();
}
}

template<class RawDev>
void LwipIntfDev<RawDev>::check_route()
{
if (connected())
{
if (_default || (netif_default == nullptr && !ip_addr_isany(&_netif.gw)))
if (_default || (netif_default == nullptr && routable()))
{
// on user request,
// or if there is no current default interface, but a gateway is valid
// or if there is no current default interface, but our gateway is valid
netif_set_default(&_netif);
}
sntp_stop();
sntp_init();
}
else if (netif_default == &_netif)
{
Expand Down Expand Up @@ -401,13 +416,10 @@ err_t LwipIntfDev<RawDev>::handlePackets()
}

template<class RawDev>
void LwipIntfDev<RawDev>::setDefault(bool default)
void LwipIntfDev<RawDev>::setDefault(bool deflt)
{
_default = default;
if (default && connected())
{
netif_set_default(&_netif);
}
_default = deflt;
check_route();
}

#endif // _LWIPINTFDEV_H