1616#include " freertos/semphr.h"
1717#include " freertos/queue.h"
1818
19- #include " esp_netif .h"
20- #include " esp_netif_types .h"
19+ #include " esp_netif_net_stack .h"
20+ #include " lwip/netif .h"
2121
2222static TaskHandle_t s_cli_task = NULL ;
2323static TaskHandle_t s_console_cli_task = NULL ;
@@ -27,6 +27,9 @@ static xQueueHandle tx_queue = NULL;
2727static esp_openthread_platform_config_t ot_native_config;
2828static TaskHandle_t s_ot_task = NULL ;
2929static esp_netif_t *openthread_netif = NULL ;
30+ #if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM
31+ static struct netif *ot_lwip_netif = NULL ;
32+ #endif
3033
3134#define OT_CLI_MAX_LINE_LENGTH 512
3235
@@ -38,6 +41,20 @@ typedef struct {
3841} ot_cli_console_t ;
3942static ot_cli_console_t otConsole = {NULL , false , (const char *)NULL , NULL };
4043
44+ #if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM
45+ extern " C" int lwip_hook_ip6_input (struct pbuf *p, struct netif *inp) {
46+ if (ot_lwip_netif && ot_lwip_netif == inp) {
47+ return 0 ;
48+ }
49+ if (ip6_addr_isany_val (inp->ip6_addr [0 ].u_addr .ip6 )) {
50+ // We don't have an LL address -> eat this packet here, so it won't get accepted on input netif
51+ pbuf_free (p);
52+ return 1 ;
53+ }
54+ return 0 ;
55+ }
56+ #endif
57+
4158// process the CLI commands sent to the OpenThread stack
4259static void ot_cli_loop (void *context) {
4360 String sTxString (" " );
@@ -258,6 +275,15 @@ static void ot_task_worker(void *aContext) {
258275 // Initialize the esp_netif bindings
259276 esp_netif_config_t cfg = ESP_NETIF_DEFAULT_OPENTHREAD ();
260277 openthread_netif = esp_netif_new (&cfg);
278+ #if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM
279+ // Get LwIP Netif
280+ if (openthread_netif != NULL ) {
281+ ot_lwip_netif = (struct netif *)esp_netif_get_netif_impl (openthread_netif);
282+ if (ot_lwip_netif == NULL ) {
283+ log_e (" Failed to get OpenThread LwIP netif" );
284+ }
285+ }
286+ #endif
261287 }
262288 if (!err && openthread_netif == NULL ) {
263289 log_e (" Failed to create OpenThread esp_netif" );
@@ -335,6 +361,9 @@ void OpenThreadCLI::end() {
335361 // Clean up
336362 esp_openthread_deinit ();
337363 esp_openthread_netif_glue_deinit ();
364+ #if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM
365+ ot_lwip_netif = NULL ;
366+ #endif
338367 esp_netif_destroy (openthread_netif);
339368 esp_vfs_eventfd_unregister ();
340369 }
0 commit comments