Просмотр исходного кода

esp-netif: set default interface for ppp netif must be called from lwip context

On update of any interface (set up/down) a routing preference is updated calling esp_netif_update_default_netif() that is called from
lwip context. But if the related netif was ppp type, the set_default api used user-mode, thus causing a dead lock.

Closes https://github.com/espressif/esp-idf/issues/4746
David Cermak 6 лет назад
Родитель
Сommit
e8ff22b5fb

+ 23 - 6
components/esp_netif/lwip/esp_netif_lwip.c

@@ -140,6 +140,8 @@ static esp_netif_t* esp_netif_is_active(esp_netif_t *arg)
  * @brief This function sets default netif no matter which implementation used
  * @brief This function sets default netif no matter which implementation used
  *
  *
  * @param esp_netif handle to network interface
  * @param esp_netif handle to network interface
+ *
+ * @note: This function must be called from lwip thread
  */
  */
 static void esp_netif_set_default_netif(esp_netif_t *esp_netif)
 static void esp_netif_set_default_netif(esp_netif_t *esp_netif)
 {
 {
@@ -151,14 +153,17 @@ static void esp_netif_set_default_netif(esp_netif_t *esp_netif)
 }
 }
 
 
 /**
 /**
- * @brief This function sets default routing netif based on priorities of all interfaces which are up
- * @param esp_netif current interface which just updated state
- * @param action updating action (on-off)
- *
- * @note: This function must be called from lwip thread
+ * @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 void esp_netif_update_default_netif(esp_netif_t *esp_netif, esp_netif_action_t action) {
+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) {
     switch (action) {
         case ESP_NETIF_STARTED:
         case ESP_NETIF_STARTED:
         {
         {
@@ -200,6 +205,18 @@ static void esp_netif_update_default_netif(esp_netif_t *esp_netif, esp_netif_act
         }
         }
         break;
         break;
     }
     }
+    return ESP_OK;
+}
+
+/**
+ * @brief This function sets default routing netif based on priorities of all interfaces which are up
+ *
+ * @param esp_netif current interface which just updated state
+ * @param action updating action (on-off)
+ */
+static esp_err_t esp_netif_update_default_netif(esp_netif_t *esp_netif, esp_netif_action_t action)
+{
+    return esp_netif_lwip_ipc_call(esp_netif_update_default_netif_lwip, esp_netif, (void*)action);
 }
 }
 
 
 void esp_netif_set_ip4_addr(esp_ip4_addr_t *addr, uint8_t a, uint8_t b, uint8_t c, uint8_t d)
 void esp_netif_set_ip4_addr(esp_ip4_addr_t *addr, uint8_t a, uint8_t b, uint8_t c, uint8_t d)

+ 1 - 1
components/esp_netif/lwip/esp_netif_lwip_ppp.c

@@ -248,7 +248,7 @@ esp_err_t esp_netif_ppp_set_auth(esp_netif_t *netif, esp_netif_auth_type_t autht
 
 
 void esp_netif_ppp_set_default_netif(lwip_ppp_ctx_t* ppp_ctx)
 void esp_netif_ppp_set_default_netif(lwip_ppp_ctx_t* ppp_ctx)
 {
 {
-    pppapi_set_default(ppp_ctx->ppp);
+    ppp_set_default(ppp_ctx->ppp);
 }
 }
 
 
 lwip_ppp_ctx_t* esp_netif_new_ppp(esp_netif_t *esp_netif, const esp_netif_netstack_config_t *esp_netif_stack_config)
 lwip_ppp_ctx_t* esp_netif_new_ppp(esp_netif_t *esp_netif, const esp_netif_netstack_config_t *esp_netif_stack_config)

+ 2 - 0
components/esp_netif/lwip/esp_netif_lwip_ppp.h

@@ -70,6 +70,8 @@ esp_err_t esp_netif_stop_ppp(lwip_ppp_ctx_t *ppp);
 /**
 /**
  * @brief  Sets default netif for routing priority config
  * @brief  Sets default netif for routing priority config
  *
  *
+ * @note: This function must be called from lwip thread
+ *
  */
  */
 void esp_netif_ppp_set_default_netif(lwip_ppp_ctx_t* ppp_ctx);
 void esp_netif_ppp_set_default_netif(lwip_ppp_ctx_t* ppp_ctx);