components/esp_netif/lwip/esp_netif_lwip.c
/**
 * @brief tcpip thread version of esp_netif_update_default_netif
 *
 * @note This function and all functions called from this must be called from lwip task context
 */
@brief tcpip thread version of esp_netif_update_default_netif
@note This function and all functions called from this must be called from lwip task context
@brief tcpip thread version of esp_netif_update_default_netif @note This function and all functions called from this must be called from lwip task context
static esp_err_t esp_netif_update_default_netif_lwip(esp_netif_api_msg_t *msg)
{
    esp_netif_t *esp_netif = msg->esp_netif;
    esp_netif_action_t action = (esp_netif_action_t)msg->data;
    ESP_LOGD(TAG, "%s %p", __func__, esp_netif);
    switch (action) {
        case ESP_NETIF_STARTED:
        {
            s_last_default_esp_netif = esp_netif_is_active(s_last_default_esp_netif);
            if (s_last_default_esp_netif && esp_netif_is_netif_up(s_last_default_esp_netif)
                && (s_last_default_esp_netif->route_prio > esp_netif->route_prio)) {
                esp_netif_set_default_netif(s_last_default_esp_netif);
            } else if (esp_netif_is_netif_up(esp_netif)) {
                s_last_default_esp_netif = esp_netif;
                esp_netif_set_default_netif(s_last_default_esp_netif);
            }
        }
        break;
        default:
        case ESP_NETIF_STOPPED:
        {
            s_last_default_esp_netif = NULL;
            esp_netif_list_lock();
            esp_netif_t *netif = esp_netif_next_unsafe(NULL);
            while (netif) {
                if (esp_netif_is_netif_up(netif)) {
                    if (s_last_default_esp_netif && esp_netif_is_netif_up(s_last_default_esp_netif)) {
                        if (netif->route_prio > s_last_default_esp_netif->route_prio) {
                            s_last_default_esp_netif = netif;
                        } 
                    } else {
                        s_last_default_esp_netif = netif;
                    }
                }
                netif = esp_netif_next_unsafe(netif);
            }
            esp_netif_list_unlock();
            if (s_last_default_esp_netif && esp_netif_is_netif_up(s_last_default_esp_netif)) {
                esp_netif_set_default_netif(s_last_default_esp_netif);
            }
        }
        break;
    }
    return ESP_OK;
}
static esp_err_t esp_netif_update_default_netif_lwip ( esp_netif_api_msg_t * msg ) { esp_netif_t * esp_netif = msg -> esp_netif ; esp_netif_action_t action = ( esp_netif_action_t ) msg -> data ; ESP_LOGD ( TAG , " " , __func__ , esp_netif ) ; switch ( action ) { case ESP_NETIF_STARTED : { s_last_default_esp_netif = esp_netif_is_active ( s_last_default_esp_netif ) ; if ( s_last_default_esp_netif && esp_netif_is_netif_up ( s_last_default_esp_netif ) && ( s_last_default_esp_netif -> route_prio > esp_netif -> route_prio ) ) { esp_netif_set_default_netif ( s_last_default_esp_netif ) ; } else if ( esp_netif_is_netif_up ( esp_netif ) ) { s_last_default_esp_netif = esp_netif ; esp_netif_set_default_netif ( s_last_default_esp_netif ) ; } } break ; default : case ESP_NETIF_STOPPED : { s_last_default_esp_netif = NULL ; esp_netif_list_lock ( ) ; esp_netif_t * netif = esp_netif_next_unsafe ( NULL ) ; while ( netif ) { if ( esp_netif_is_netif_up ( netif ) ) { if ( s_last_default_esp_netif && esp_netif_is_netif_up ( s_last_default_esp_netif ) ) { if ( netif -> route_prio > s_last_default_esp_netif -> route_prio ) { s_last_default_esp_netif = netif ; } } else { s_last_default_esp_netif = netif ; } } netif = esp_netif_next_unsafe ( netif ) ; } esp_netif_list_unlock ( ) ; if ( s_last_default_esp_netif && esp_netif_is_netif_up ( s_last_default_esp_netif ) ) { esp_netif_set_default_netif ( s_last_default_esp_netif ) ; } } break ; } return ESP_OK ; }
@brief tcpip thread version of esp_netif_update_default_netif
 @note This function and all functions called from this must be called from lwip task context
@brief tcpip thread version of esp_netif_update_default_netif @note This function and all functions called from this must be called from lwip task context
// check if previously default interface hasn't been destroyed in the meantime // else not needed, as the s_last_default_esp_netif is correct // s_last_default is either not set or down, current netif is up