Sfoglia il codice sorgente

lwip: Support for linux target

Implement linux port layer and reuse the original FreeRTOS layer
that's compiled and used on linux target as well, by means of FreeRTOS
simulator.
David Cermak 3 anni fa
parent
commit
fa97004faf
60 ha cambiato i file con 408 aggiunte e 440 eliminazioni
  1. 18 0
      .gitlab/ci/host-test.yml
  2. 6 6
      components/esp_netif/CMakeLists.txt
  3. 8 0
      components/esp_netif/linux/stubs/include/machine/endian.h
  4. 1 0
      components/esp_netif/lwip/esp_netif_lwip.c
  5. 3 0
      components/esp_netif/lwip/esp_netif_lwip_defaults.c
  6. 33 14
      components/lwip/CMakeLists.txt
  7. 1 1
      components/lwip/apps/dhcpserver/dhcpserver.c
  8. 1 0
      components/lwip/apps/ping/ping.c
  9. 2 1
      components/lwip/apps/ping/ping_sock.c
  10. 1 0
      components/lwip/apps/sntp/sntp.c
  11. 5 13
      components/lwip/port/debug/lwip_debug.c
  12. 3 29
      components/lwip/port/esp32/include/arch/cc.h
  13. 2 30
      components/lwip/port/esp32/include/arch/perf.h
  14. 5 13
      components/lwip/port/esp32/include/arch/vfs_lwip.h
  15. 0 20
      components/lwip/port/esp32/include/arpa/inet.h
  16. 0 33
      components/lwip/port/esp32/include/debug/lwip_debug.h
  17. 0 48
      components/lwip/port/esp32/include/netdb.h
  18. 0 22
      components/lwip/port/esp32/include/netinet/in.h
  19. 0 21
      components/lwip/port/esp32/include/netinet/tcp.h
  20. 7 23
      components/lwip/port/esp32/include/sys/socket.h
  21. 5 13
      components/lwip/port/esp32/no_vfs_syscalls.c
  22. 3 32
      components/lwip/port/freertos/include/arch/sys_arch.h
  23. 7 31
      components/lwip/port/freertos/sys_arch.c
  24. 0 0
      components/lwip/port/hooks/lwip_default_hooks.c
  25. 5 1
      components/lwip/port/hooks/tcp_isn_default.c
  26. 12 0
      components/lwip/port/include/arpa/inet.h
  27. 25 0
      components/lwip/port/include/debug/lwip_debug.h
  28. 0 0
      components/lwip/port/include/lwip_default_hooks.h
  29. 0 4
      components/lwip/port/include/lwipopts.h
  30. 29 0
      components/lwip/port/include/netdb.h
  31. 0 0
      components/lwip/port/include/netif/dhcp_state.h
  32. 14 0
      components/lwip/port/include/netinet/in.h
  33. 13 0
      components/lwip/port/include/netinet/tcp.h
  34. 5 13
      components/lwip/port/include/sntp/sntp_get_set_time.h
  35. 1 1
      components/lwip/port/include/sockets_ext.h
  36. 61 0
      components/lwip/port/linux/include/arch/cc.h
  37. 8 0
      components/lwip/port/linux/include/arch/vfs_lwip.h
  38. 6 0
      components/lwip/port/linux/include/net/if.h
  39. 12 0
      components/lwip/port/linux/include/sys/fcntl.h
  40. 13 0
      components/lwip/port/linux/include/sys/socket.h
  41. 1 1
      components/lwip/port/sockets_ext.c
  42. 5 0
      components/lwip/test_afl_host/.build-test-rules.yml
  43. 1 0
      components/lwip/test_afl_host/CMakeLists.txt
  44. 13 3
      components/lwip/test_afl_host/Makefile
  45. 2 2
      components/lwip/test_afl_host/README.md
  46. 1 2
      components/lwip/test_afl_host/esp32_mock.c
  47. 0 35
      components/lwip/test_afl_host/esp32_mock.h
  48. 0 8
      components/lwip/test_afl_host/esp_attr.h
  49. 0 0
      components/lwip/test_afl_host/esp_task.h
  50. 2 0
      components/lwip/test_afl_host/sdkconfig.defaults
  51. 10 0
      components/pthread/CMakeLists.txt
  52. 1 1
      docs/en/api-reference/storage/vfs.rst
  53. 1 1
      docs/zh_CN/api-reference/storage/vfs.rst
  54. 15 0
      examples/common_components/env_caps/linux/Kconfig.env_caps
  55. 1 1
      examples/protocols/sockets/tcp_client/CMakeLists.txt
  56. 1 0
      tools/ci/check_copyright_config.yaml
  57. 0 17
      tools/ci/check_copyright_ignore.txt
  58. 1 0
      tools/ci/executable-list.txt
  59. 3 0
      tools/mocks/startup/CMakeLists.txt
  60. 35 0
      tools/mocks/startup/startup_mock.c

+ 18 - 0
.gitlab/ci/host-test.yml

@@ -336,6 +336,24 @@ test_mqtt_on_host:
     - idf.py build
     - LSAN_OPTIONS=verbosity=1:log_threads=1 build/host_mqtt_client_test.elf
 
+test_sockets_on_host:
+  extends: .host_test_template
+  script:
+    # test the tcp-client example with system sockets
+    - cd ${IDF_PATH}/examples/protocols/sockets/tcp_client
+    - echo 'CONFIG_EXAMPLE_IPV4_ADDR="127.0.0.1"' >> sdkconfig.defaults
+    - idf.py --preview set-target linux
+    - idf.py build
+    - timeout 5 ./build/tcp_client.elf >test.log || true
+    - grep "Socket unable to connect" test.log
+    # test the udp-client example with lwip sockets
+    - cd ${IDF_PATH}/examples/protocols/sockets/udp_client
+    - echo 'CONFIG_EXAMPLE_IPV4_ADDR="127.0.0.1"' >> sdkconfig.defaults
+    - idf.py --preview set-target linux
+    - idf.py build
+    - timeout 5 ./build/udp_client.elf >test.log || true
+    - grep "Message sent" test.log
+
 test_eh_frame_parser:
   extends: .host_test_template
   script:

+ 6 - 6
components/esp_netif/CMakeLists.txt

@@ -1,11 +1,5 @@
 idf_build_get_property(target IDF_TARGET)
 
-if(${target} STREQUAL "linux")
-    # Header only library for linux
-    idf_component_register(INCLUDE_DIRS include)
-    return()
-endif()
-
 set(srcs_lwip
         "lwip/esp_netif_lwip.c"
         "lwip/esp_netif_sntp.c"
@@ -23,6 +17,12 @@ set(srcs
 set(include_dirs "include")
 set(priv_include_dirs "private_include")
 
+idf_build_get_property(target IDF_TARGET)
+if(${target} STREQUAL "linux")
+    list(APPEND include_dirs
+            "linux/stubs/include")
+endif()
+
 if(CONFIG_PPP_SUPPORT)
     list(APPEND srcs_lwip lwip/esp_netif_lwip_ppp.c)
 endif()

+ 8 - 0
components/esp_netif/linux/stubs/include/machine/endian.h

@@ -0,0 +1,8 @@
+/*
+ * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#pragma once
+
+#include_next <endian.h>

+ 1 - 0
components/esp_netif/lwip/esp_netif_lwip.c

@@ -16,6 +16,7 @@
 #include "esp_netif.h"
 #include "esp_netif_private.h"
 #include "esp_random.h"
+#include "esp_system.h"
 
 #include "lwip/tcpip.h"
 #include "lwip/dhcp.h"

+ 3 - 0
components/esp_netif/lwip/esp_netif_lwip_defaults.c

@@ -10,6 +10,7 @@
 #if defined(CONFIG_PPP_SUPPORT)
 #include "esp_netif_lwip_ppp.h"
 #endif
+#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
 
 #if CONFIG_ESP_NETIF_BRIDGE_EN
 #include "netif/bridgeif.h"
@@ -64,3 +65,5 @@ const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_ppp      = &s_n
 const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_eth      = &s_eth_netif_config;
 const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_sta = &s_wifi_netif_config_sta;
 const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_ap  = &s_wifi_netif_config_ap;
+
+#endif /*CONFIG_ESP_NETIF_TCPIP_LWIP*/

+ 33 - 14
components/lwip/CMakeLists.txt

@@ -1,10 +1,18 @@
+idf_build_get_property(target IDF_TARGET)
+if(NOT ${target} STREQUAL "linux")
+    # ESP platform targets share the same port folder
+    set(target esp32)
+endif()
+
 set(include_dirs
     include
     include/apps
     include/apps/sntp
     lwip/src/include
-    port/esp32/include
-    port/esp32/include/arch
+    port/include
+    port/freertos/include/
+    port/${target}/include
+    port/${target}/include/arch
     )
 
 set(srcs
@@ -85,11 +93,11 @@ set(srcs
     "lwip/src/netif/ppp/upap.c"
     "lwip/src/netif/ppp/utils.c"
     "lwip/src/netif/ppp/vj.c"
-    "port/esp32/hooks/tcp_isn_default.c"
-    "port/esp32/hooks/lwip_default_hooks.c"
-    "port/esp32/debug/lwip_debug.c"
-    "port/esp32/freertos/sys_arch.c"
-    "port/esp32/sockets_ext.c")
+    "port/hooks/tcp_isn_default.c"
+    "port/hooks/lwip_default_hooks.c"
+    "port/debug/lwip_debug.c"
+    "port/sockets_ext.c"
+    "port/freertos/sys_arch.c")
 
 if(CONFIG_LWIP_PPP_SUPPORT)
     list(APPEND srcs
@@ -125,10 +133,15 @@ if(CONFIG_LWIP_PPP_SUPPORT)
         "lwip/src/netif/ppp/polarssl/sha1.c")
 endif()
 
-if(CONFIG_VFS_SUPPORT_IO)
-    list(APPEND srcs "port/esp32/vfs_lwip.c")
-else()
-    list(APPEND srcs "port/esp32/no_vfs_syscalls.c")
+if(NOT ${target} STREQUAL "linux")
+    # Support for vfs and linker fragments only for target builds
+    set(priv_requires vfs)
+    set(linker_fragments linker.lf)
+    if(CONFIG_VFS_SUPPORT_IO)
+        list(APPEND srcs "port/${target}/vfs_lwip.c")
+    else()
+        list(APPEND srcs "port/${target}/no_vfs_syscalls.c")
+    endif()
 endif()
 
 if(CONFIG_LWIP_ICMP)
@@ -147,9 +160,9 @@ if(CONFIG_LWIP_DHCP_RESTORE_LAST_IP)
 endif()
 
 idf_component_register(SRCS "${srcs}"
-                    INCLUDE_DIRS "${include_dirs}"
-                    LDFRAGMENTS linker.lf
-                    PRIV_REQUIRES vfs)
+                    INCLUDE_DIRS  ${include_dirs}
+                    LDFRAGMENTS   ${linker_fragments}
+                    PRIV_REQUIRES ${priv_requires})
 
 # lots of LWIP source files evaluate macros that check address of stack variables
 target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-address)
@@ -188,3 +201,9 @@ if(CONFIG_LWIP_DHCP_RESTORE_LAST_IP)
 endif()
 
 target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
+
+if(${target} STREQUAL "linux")
+    set(THREADS_PREFER_PTHREAD_FLAG ON)
+    find_package(Threads REQUIRED)
+    target_link_libraries(${COMPONENT_LIB} PRIVATE Threads::Threads)
+endif()

+ 1 - 1
components/lwip/apps/dhcpserver/dhcpserver.c

@@ -3,9 +3,9 @@
  *
  * SPDX-License-Identifier: Apache-2.0
  */
-//#include "esp_common.h"
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 #include "lwip/dhcp.h"
 #include "lwip/err.h"
 #include "lwip/pbuf.h"

+ 1 - 0
components/lwip/apps/ping/ping.c

@@ -55,6 +55,7 @@
 #if PING_USE_SOCKETS
 #include "lwip/sockets.h"
 #include "lwip/inet.h"
+#include "esp_task.h"
 #include "ping/ping_sock.h"
 #endif /* PING_USE_SOCKETS */
 

+ 2 - 1
components/lwip/apps/ping/ping_sock.c

@@ -6,6 +6,7 @@
 
 #include <stdlib.h>
 #include <stdbool.h>
+#include <sys/time.h>
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "lwip/opt.h"
@@ -231,7 +232,7 @@ esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_c
     /* set ICMP type and code field */
     ep->packet_hdr->code = 0;
     /* ping id should be unique, treat task handle as ping ID */
-    ep->packet_hdr->id = ((uint32_t)ep->ping_task_hdl) & 0xFFFF;
+    ep->packet_hdr->id = ((intptr_t)ep->ping_task_hdl) & 0xFFFF;
     /* fill the additional data buffer with some data */
     char *d = (char *)(ep->packet_hdr) + sizeof(struct icmp_echo_hdr);
     for (uint32_t i = 0; i < config->data_size; i++) {

+ 1 - 0
components/lwip/apps/sntp/sntp.c

@@ -15,6 +15,7 @@
 #undef SNTP_OPMODE_POLL
 #include "lwip/apps/sntp.h"
 #include "lwip/tcpip.h"
+#include "esp_macros.h"
 
 static const char *TAG = "sntp";
 

+ 5 - 13
components/lwip/port/esp32/debug/lwip_debug.c → components/lwip/port/debug/lwip_debug.c

@@ -1,16 +1,8 @@
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+/*
+ * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
 #include "debug/lwip_debug.h"
 #include "lwip/api.h"

+ 3 - 29
components/lwip/port/esp32/include/arch/cc.h

@@ -1,35 +1,9 @@
 /*
- * Copyright (c) 2001, Swedish Institute of Computer Science.
- * All rights reserved.
+ * SPDX-FileCopyrightText: 2001 Swedish Institute of Computer Science
  *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the lwIP TCP/IP stack.
- *
- * Author: Adam Dunkels <adam@sics.se>
+ * SPDX-License-Identifier: BSD-3-Clause
  *
+ * SPDX-FileContributor: 2018-2022 Espressif Systems (Shanghai) CO LTD
  */
 #ifndef __ARCH_CC_H__
 #define __ARCH_CC_H__

+ 2 - 30
components/lwip/port/esp32/include/arch/perf.h

@@ -1,35 +1,7 @@
 /*
- * Copyright (c) 2001, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the lwIP TCP/IP stack.
- *
- * Author: Adam Dunkels <adam@sics.se>
+ * SPDX-FileCopyrightText: 2001 Swedish Institute of Computer Science
  *
+ * SPDX-License-Identifier: BSD-3-Clause
  */
 #ifndef __PERF_H__
 #define __PERF_H__

+ 5 - 13
components/lwip/port/esp32/include/arch/vfs_lwip.h

@@ -1,16 +1,8 @@
-// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+/*
+ * SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
 #ifdef __cplusplus
 extern "C" {

+ 0 - 20
components/lwip/port/esp32/include/arpa/inet.h

@@ -1,20 +0,0 @@
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef INET_H_
-#define INET_H_
-
-#include "lwip/inet.h"
-
-#endif /* INET_H_ */

+ 0 - 33
components/lwip/port/esp32/include/debug/lwip_debug.h

@@ -1,33 +0,0 @@
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-
-#ifndef _LWIP_DEBUG_H
-#define _LWIP_DEBUG_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void dbg_lwip_tcp_pcb_show(void);
-void dbg_lwip_udp_pcb_show(void);
-void dbg_lwip_tcp_rxtx_show(void);
-void dbg_lwip_udp_rxtx_show(void);
-void dbg_lwip_mem_cnt_show(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // _LWIP_DEBUG_H

+ 0 - 48
components/lwip/port/esp32/include/netdb.h

@@ -1,48 +0,0 @@
-/**
- * @file
- * This file is a posix wrapper for lwip/netdb.h.
- */
-
-/*
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * This file is part of the lwIP TCP/IP stack.
- *
- */
-
-#include "lwip/netdb.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef ESP_PLATFORM
-int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
-                char *host, socklen_t hostlen,
-                char *serv, socklen_t servlen, int flags);
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 22
components/lwip/port/esp32/include/netinet/in.h

@@ -1,22 +0,0 @@
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef IN_H_
-#define IN_H_
-
-#include "lwip/inet.h"
-
-#define IN6_IS_ADDR_MULTICAST(a)    IN_MULTICAST(a)
-
-#endif /* IN_H_ */

+ 0 - 21
components/lwip/port/esp32/include/netinet/tcp.h

@@ -1,21 +0,0 @@
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-// Copyright 2020 Francesco Giancane <francesco.giancane@accenture.com>
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef _NETINET_TCP_H
-#define _NETINET_TCP_H
-
-#include "lwip/tcp.h"
-
-#endif /* _NETINET_TCP_H  */

+ 7 - 23
components/lwip/port/esp32/include/sys/socket.h

@@ -2,33 +2,15 @@
  * @file
  * This file is a posix wrapper for lwip/sockets.h.
  */
-
 /*
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
+ * SPDX-FileCopyrightText: 2001-2004 Swedish Institute of Computer Science
  *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * This file is part of the lwIP TCP/IP stack.
+ * SPDX-License-Identifier: BSD-3-Clause
  *
+ * SPDX-FileContributor: 2018-2022 Espressif Systems (Shanghai) CO LTD
  */
+#ifndef LWIP_HDR_SYS_SOCKETS_H
+#define LWIP_HDR_SYS_SOCKETS_H
 
 #include "lwip/sockets.h"
 /*
@@ -36,3 +18,5 @@
 	while for ESP32 port is defined in net/if.h
 */
 #include <net/if.h>
+
+#endif /* LWIP_HDR_SYS_SOCKETS_H */

+ 5 - 13
components/lwip/port/esp32/no_vfs_syscalls.c

@@ -1,16 +1,8 @@
-// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+/*
+ * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
 #include <string.h>
 #include <stdbool.h>

+ 3 - 32
components/lwip/port/esp32/include/arch/sys_arch.h → components/lwip/port/freertos/include/arch/sys_arch.h

@@ -1,46 +1,17 @@
 /*
- * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
- * All rights reserved.
+ * SPDX-FileCopyrightText: 2001-2003 Swedish Institute of Computer Science
  *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * This file is part of the lwIP TCP/IP stack.
- *
- * Author: Adam Dunkels <adam@sics.se>
+ * SPDX-License-Identifier: BSD-3-Clause
  *
+ * SPDX-FileContributor: 2018-2022 Espressif Systems (Shanghai) CO LTD
  */
-
 #ifndef __SYS_ARCH_H__
 #define __SYS_ARCH_H__
 
-#ifdef __linux__
-#include "esp32_mock.h"
-#else
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "freertos/queue.h"
 #include "freertos/semphr.h"
-#endif // __linux__
 
 #ifdef __cplusplus
 extern "C" {

+ 7 - 31
components/lwip/port/esp32/freertos/sys_arch.c → components/lwip/port/freertos/sys_arch.c

@@ -1,38 +1,18 @@
 /*
- * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
- * All rights reserved.
+ * SPDX-FileCopyrightText: 2001-2003 Swedish Institute of Computer Science
  *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * This file is part of the lwIP TCP/IP stack.
- *
- * Author: Adam Dunkels <adam@sics.se>
+ * SPDX-License-Identifier: BSD-3-Clause
  *
+ * SPDX-FileContributor: 2018-2022 Espressif Systems (Shanghai) CO LTD
  */
 
 /* lwIP includes. */
 
 #include <pthread.h>
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "freertos/semphr.h"
+#include "freertos/queue.h"
 #include "lwip/debug.h"
 #include "lwip/def.h"
 #include "lwip/sys.h"
@@ -40,12 +20,8 @@
 #include "lwip/stats.h"
 #include "arch/sys_arch.h"
 #include "arch/vfs_lwip.h"
-#ifdef __linux__
-#include "esp32_mock.h"
-#else // __linux__
 #include "esp_log.h"
 #include "esp_compiler.h"
-#endif // __linux__
 
 static const char* TAG = "lwip_arch";
 

+ 0 - 0
components/lwip/port/esp32/hooks/lwip_default_hooks.c → components/lwip/port/hooks/lwip_default_hooks.c


+ 5 - 1
components/lwip/port/esp32/hooks/tcp_isn_default.c → components/lwip/port/hooks/tcp_isn_default.c

@@ -1,3 +1,8 @@
+/*
+ * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 /**
  * @file
  *
@@ -75,7 +80,6 @@
 #include "lwip/sys.h"
 #include <string.h>
 #include "esp_rom_md5.h"
-#include "esp_memory_utils.h"
 
 #ifdef CONFIG_LWIP_HOOK_TCP_ISN_DEFAULT
 

+ 12 - 0
components/lwip/port/include/arpa/inet.h

@@ -0,0 +1,12 @@
+/*
+ * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef INET_H_
+#define INET_H_
+
+#include "lwip/inet.h"
+
+#endif /* INET_H_ */

+ 25 - 0
components/lwip/port/include/debug/lwip_debug.h

@@ -0,0 +1,25 @@
+/*
+ * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+
+#ifndef _LWIP_DEBUG_H
+#define _LWIP_DEBUG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void dbg_lwip_tcp_pcb_show(void);
+void dbg_lwip_udp_pcb_show(void);
+void dbg_lwip_tcp_rxtx_show(void);
+void dbg_lwip_udp_rxtx_show(void);
+void dbg_lwip_mem_cnt_show(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _LWIP_DEBUG_H

+ 0 - 0
components/lwip/port/esp32/include/lwip_default_hooks.h → components/lwip/port/include/lwip_default_hooks.h


+ 0 - 4
components/lwip/port/esp32/include/lwipopts.h → components/lwip/port/include/lwipopts.h

@@ -17,12 +17,8 @@
 #include <sys/types.h>
 #include <sys/select.h>
 #include <sys/poll.h>
-#ifdef __linux__
-#include "esp32_mock.h"
-#else
 #include "esp_task.h"
 #include "esp_random.h"
-#endif // __linux__
 #include "sdkconfig.h"
 #include "sntp/sntp_get_set_time.h"
 #include "sockets_ext.h"

+ 29 - 0
components/lwip/port/include/netdb.h

@@ -0,0 +1,29 @@
+/**
+ * @file
+ * This file is a posix wrapper for lwip/netdb.h.
+ */
+
+/*
+ * SPDX-FileCopyrightText: 2001-2004 Swedish Institute of Computer Science
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * SPDX-FileContributor: 2018-2022 Espressif Systems (Shanghai) CO LTD
+ */
+
+#include "lwip/netdb.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef ESP_PLATFORM
+int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
+                char *host, socklen_t hostlen,
+                char *serv, socklen_t servlen, int flags);
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif

+ 0 - 0
components/lwip/port/esp32/include/netif/dhcp_state.h → components/lwip/port/include/netif/dhcp_state.h


+ 14 - 0
components/lwip/port/include/netinet/in.h

@@ -0,0 +1,14 @@
+/*
+ * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef IN_H_
+#define IN_H_
+
+#include "lwip/inet.h"
+
+#define IN6_IS_ADDR_MULTICAST(a)    IN_MULTICAST(a)
+
+#endif /* IN_H_ */

+ 13 - 0
components/lwip/port/include/netinet/tcp.h

@@ -0,0 +1,13 @@
+/*
+ * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) CO LTD
+ * SPDX-FileCopyrightText: 2020 Francesco Giancane <francesco.giancane@accenture.com>
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef _NETINET_TCP_H
+#define _NETINET_TCP_H
+
+#include "lwip/tcp.h"
+
+#endif /* _NETINET_TCP_H  */

+ 5 - 13
components/lwip/port/esp32/include/sntp/sntp_get_set_time.h → components/lwip/port/include/sntp/sntp_get_set_time.h

@@ -1,16 +1,8 @@
-// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+/*
+ * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
 #ifndef __SNTP_GET_SET_TIME_H__
 #define __SNTP_GET_SET_TIME_H__

+ 1 - 1
components/lwip/port/esp32/include/sockets_ext.h → components/lwip/port/include/sockets_ext.h

@@ -1,5 +1,5 @@
 /*
- * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
+ * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  *
  * SPDX-License-Identifier: Apache-2.0
  */

+ 61 - 0
components/lwip/port/linux/include/arch/cc.h

@@ -0,0 +1,61 @@
+/*
+ * SPDX-FileCopyrightText: 2001-2003 Swedish Institute of Computer Science
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * SPDX-FileContributor: 2022-2023 Espressif Systems (Shanghai) CO LTD
+ */
+#ifndef LWIP_ARCH_CC_H
+#define LWIP_ARCH_CC_H
+
+/* see https://sourceforge.net/p/predef/wiki/OperatingSystems/ */
+#if defined __ANDROID__
+#define LWIP_UNIX_ANDROID
+#elif defined __linux__
+#define LWIP_UNIX_LINUX
+#elif defined __APPLE__
+#define LWIP_UNIX_MACH
+#elif defined __OpenBSD__
+#define LWIP_UNIX_OPENBSD
+#elif defined __CYGWIN__
+#define LWIP_UNIX_CYGWIN
+#elif defined __GNU__
+#define LWIP_UNIX_HURD
+#endif
+
+#define LWIP_TIMEVAL_PRIVATE 0
+#include <sys/time.h>
+#include "esp_linux_helper.h"
+
+#define LWIP_ERRNO_INCLUDE <errno.h>
+
+#if defined(LWIP_UNIX_LINUX) || defined(LWIP_UNIX_HURD)
+#define LWIP_ERRNO_STDINCLUDE	1
+#endif
+
+/* different handling for unit test, normally not needed */
+#ifdef LWIP_NOASSERT_ON_ERROR
+#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
+  handler;}} while(0)
+#endif
+
+#if defined(LWIP_UNIX_ANDROID) && defined(FD_SET)
+typedef __kernel_fd_set fd_set;
+#endif
+
+#if defined(LWIP_UNIX_MACH)
+/* sys/types.h and signal.h bring in Darwin byte order macros. pull the
+   header here and disable LwIP's version so that apps still can get
+   the macros via LwIP headers and use system headers */
+#include <sys/types.h>
+#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
+#endif
+
+struct sio_status_s;
+typedef struct sio_status_s sio_status_t;
+#define sio_fd_t sio_status_t*
+#define __sio_fd_t_defined
+
+typedef unsigned int sys_prot_t;
+
+#endif /* LWIP_ARCH_CC_H */

+ 8 - 0
components/lwip/port/linux/include/arch/vfs_lwip.h

@@ -0,0 +1,8 @@
+/*
+ * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#pragma once
+
+static inline void esp_vfs_lwip_sockets_register(void) {}

+ 6 - 0
components/lwip/port/linux/include/net/if.h

@@ -0,0 +1,6 @@
+/*
+ * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#pragma once

+ 12 - 0
components/lwip/port/linux/include/sys/fcntl.h

@@ -0,0 +1,12 @@
+/*
+ * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#pragma once
+#ifdef LWIP_HDR_ESP_LWIPOPTS_H
+// ignore when included from lwipopts.h since lwip provides all necessary definitions
+#else
+// otherwise include system fcntl
+#include_next <sys/fcntl.h>
+#endif

+ 13 - 0
components/lwip/port/linux/include/sys/socket.h

@@ -0,0 +1,13 @@
+/*
+ * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef LWIP_HDR_LINUX_SYS_SOCKETS_H
+#define LWIP_HDR_LINUX_SYS_SOCKETS_H
+/* Include lwip sockets by default */
+#include "lwip/sockets.h"
+#else
+/* Otherwise use system sockets if LWIP_HDR_LINUX_SYS_SOCKETS_H already defined */
+#include_next <sys/socket.h>
+#endif /* LWIP_HDR_LINUX_SYS_SOCKETS_H */

+ 1 - 1
components/lwip/port/esp32/sockets_ext.c → components/lwip/port/sockets_ext.c

@@ -1,5 +1,5 @@
 /*
- * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
+ * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  *
  * SPDX-License-Identifier: Apache-2.0
  */

+ 5 - 0
components/lwip/test_afl_host/.build-test-rules.yml

@@ -0,0 +1,5 @@
+# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
+
+components/lwip/test_afl_host:
+  enable:
+    - if: IDF_TARGET == "linux"

+ 1 - 0
components/lwip/test_afl_host/CMakeLists.txt

@@ -2,6 +2,7 @@
 # in this exact order for cmake to work correctly
 cmake_minimum_required(VERSION 3.16)
 
+set(COMPONENTS lwip)
 include($ENV{IDF_PATH}/tools/cmake/project.cmake)
 
 project(fuzz_test_lwip)

+ 13 - 3
components/lwip/test_afl_host/Makefile

@@ -1,4 +1,7 @@
 LWIP_COMPONENT_DIR=../
+FREERTOS_COMPONENT_DIR=$(LWIP_COMPONENT_DIR)/../freertos
+COMPONENT_DIR=$(LWIP_COMPONENT_DIR)/../
+MOCKS_DIR=$(LWIP_COMPONENT_DIR)/../../tools/mocks
 
 CFLAGS=-D IDF_VER=\"v3.1\" \
 		-DESP_PLATFORM \
@@ -37,8 +40,14 @@ INC_DIRS=-I . \
 		-I $(LWIP_COMPONENT_DIR)/lwip/src/include \
 		-I $(LWIP_COMPONENT_DIR)/lwip/src/include/netif \
 		-I $(LWIP_COMPONENT_DIR)/lwip/src/include/posix \
-		-I $(LWIP_COMPONENT_DIR)/lwip/src/include/posix \
-		-I $(LWIP_COMPONENT_DIR)/port/esp32/include
+		-I $(LWIP_COMPONENT_DIR)/port/include \
+		-I $(LWIP_COMPONENT_DIR)/port/linux/include \
+		-I $(LWIP_COMPONENT_DIR)/port/freertos/include \
+		-I $(FREERTOS_COMPONENT_DIR)/FreeRTOS-Kernel/include \
+		-I $(FREERTOS_COMPONENT_DIR)/esp_additions/include/freertos \
+		-I $(FREERTOS_COMPONENT_DIR)/FreeRTOS-Kernel/portable/linux/include \
+		-I $(COMPONENT_DIR)/esp_hw_support/include \
+		-I $(COMPONENT_DIR)/linux/include
 
 TEST_NAME=test
 FUZZ=afl-fuzz
@@ -95,7 +104,8 @@ dhcpserver.o: ../apps/dhcpserver/dhcpserver.c $(GEN_CFG)
 
 .PHONY: $(GEN_CFG)
 $(GEN_CFG):
-	$(IDF_PATH)/tools/idf.py reconfigure
+# Run reconfiguration without potential AFL in PATHs
+	PATH=$(subst $(AFL_PATH):,/:,$(PATH)) idf.py reconfigure
 
 $(TEST_NAME): $(OBJECTS)
 	@echo "[LD] $@"

+ 2 - 2
components/lwip/test_afl_host/README.md

@@ -1,5 +1,5 @@
-| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
-| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- |
+| Supported Targets | Linux |
+| ----------------- | ----- |
 
 ## Introduction
 This test uses [american fuzzy lop](http://lcamtuf.coredump.cx/afl/) to mangle real dns, dhcp client, dhcp server packets and look for exceptions caused by the parser.

+ 1 - 2
components/lwip/test_afl_host/esp32_mock.c

@@ -1,5 +1,5 @@
 /*
- * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
+ * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  *
  * SPDX-License-Identifier: Apache-2.0
  */
@@ -17,7 +17,6 @@
 #include "lwip/timeouts.h"
 #include "lwip/udp.h"
 #include "lwip/timeouts.h"
-#include "esp32_mock.h"
 #include "no_warn_host.h"
 
 #define ESP_OK          0

+ 0 - 35
components/lwip/test_afl_host/esp32_mock.h

@@ -1,35 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-
-#ifndef _ESP32_MOCK_H_
-#define _ESP32_MOCK_H_
-
-#include <stdint.h>
-#include <unistd.h>
-
-/* ------------------------------------------------- ESP32 Port Mock ---------------------------------------------------
- *
- * ------------------------------------------------------------------------------------------------------------------ */
-
-// --------------------- lwipopts.h ------------------------
-
-#define ESP_TASK_TCPIP_STACK
-#define ESP_TASK_TCPIP_PRIO
-
-uint32_t esp_random(void);
-
-// --------------------- sys_arch.h ------------------------
-
-// Required to get linux assert.h to work ???
-#define __ASSERT_FUNC __ASSERT_FUNCTION
-
-typedef void * SemaphoreHandle_t;
-typedef void * TaskHandle_t;
-typedef void * QueueHandle_t;
-
-#define vTaskDelay(ms)      usleep((m)*0)
-
-#endif // _ESP32_MOCK_H_

+ 0 - 8
components/lwip/test_afl_host/esp_attr.h

@@ -1,10 +1,2 @@
 #pragma once
-#define _ESP_NETIF_SUPPRESS_LEGACY_WARNING_
-#define __ARCH_CC_H__
-#define __XTENSA_API_H__
 #define IRAM_ATTR
-#define FLAG_ATTR(TYPE)
-#define SSIZE_MAX INT_MAX
-#undef assert
-#define assert(x)
-#define sys_prot_t int

+ 0 - 0
components/lwip/test_afl_host/esp_task.h


+ 2 - 0
components/lwip/test_afl_host/sdkconfig.defaults

@@ -2,3 +2,5 @@ CONFIG_LWIP_TCPIP_CORE_LOCKING=n
 CONFIG_LWIP_CHECK_THREAD_SAFETY=n
 CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=n
 CONFIG_FREERTOS_SMP=n
+CONFIG_IDF_TARGET="linux"
+CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n

+ 10 - 0
components/pthread/CMakeLists.txt

@@ -1,3 +1,13 @@
+idf_build_get_property(target IDF_TARGET)
+if(${target} STREQUAL "linux")
+    # Make pthread component an empty interface lib referencing host pthread for Linux target
+    idf_component_register()
+    set(THREADS_PREFER_PTHREAD_FLAG ON)
+    find_package(Threads REQUIRED)
+    target_link_libraries(${COMPONENT_LIB} INTERFACE Threads::Threads)
+    return()
+endif()
+
 set(sources "pthread.c"
             "pthread_cond_var.c"
             "pthread_local_storage.c"

+ 1 - 1
docs/en/api-reference/storage/vfs.rst

@@ -137,7 +137,7 @@ A socket VFS driver needs to be registered with the following functions defined:
 
 :cpp:func:`stop_socket_select_isr` has the same functionality as :cpp:func:`stop_socket_select` but it can be used from ISR.
 
-Please see :component_file:`lwip/port/esp32/vfs_lwip.c` for a reference socket driver implementation using LWIP.
+Please see :component_file:`lwip/port/esp32xx/vfs_lwip.c` for a reference socket driver implementation using LWIP.
 
 .. note::
     If you use :cpp:func:`select` for socket file descriptors only then you can disable the :ref:`CONFIG_VFS_SUPPORT_SELECT` option to reduce the code size and improve performance.

+ 1 - 1
docs/zh_CN/api-reference/storage/vfs.rst

@@ -137,7 +137,7 @@ VFS 组件支持通过 :cpp:func:`select` 进行同步输入/输出多路复用
 
 :cpp:func:`stop_socket_select_isr` 与 :cpp:func:`stop_socket_select` 的作用相似,但是前者可在 ISR 中使用。
 
-请参考 :component_file:`lwip/port/esp32/vfs_lwip.c` 以了解使用 LWIP 的套接字驱动参考实现。
+请参考 :component_file:`lwip/port/esp32xx/vfs_lwip.c` 以了解使用 LWIP 的套接字驱动参考实现。
 
 .. note::
     如果 :cpp:func:`select` 用于套接字文件描述符,您可以禁用 :ref:`CONFIG_VFS_SUPPORT_SELECT` 选项来减少代码量,提高性能。

+ 15 - 0
examples/common_components/env_caps/linux/Kconfig.env_caps

@@ -0,0 +1,15 @@
+config ENV_GPIO_RANGE_MIN
+    int
+    default 0
+
+config ENV_GPIO_RANGE_MAX
+    int
+    default 0
+
+config ENV_GPIO_IN_RANGE_MAX
+    int
+    default ENV_GPIO_RANGE_MAX
+
+config ENV_GPIO_OUT_RANGE_MAX
+    int
+    default ENV_GPIO_RANGE_MAX

+ 1 - 1
examples/protocols/sockets/tcp_client/CMakeLists.txt

@@ -2,7 +2,7 @@
 # CMakeLists in this exact order for cmake to work correctly
 cmake_minimum_required(VERSION 3.16)
 
-if(${IDF_TARGET} STREQUAL "linux")
+if("${IDF_TARGET}" STREQUAL "linux")
     set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/"
                     "$ENV{IDF_PATH}/examples/protocols/linux_stubs/esp_stubs")
     set(COMPONENTS main)

+ 1 - 0
tools/ci/check_copyright_config.yaml

@@ -64,6 +64,7 @@ lwip_component:
   include:
     - 'components/lwip/**'
     - 'components/esp_netif/lwip/**'
+    - 'examples/common_components/protocol_examples_tapif_io/lwip'
   allowed_licenses:
     - Apache-2.0
     - BSD-3-Clause

+ 0 - 17
tools/ci/check_copyright_ignore.txt

@@ -711,23 +711,6 @@ components/lwip/apps/ping/ping.c
 components/lwip/include/apps/dhcpserver/dhcpserver_options.h
 components/lwip/include/apps/esp_ping.h
 components/lwip/include/apps/ping/ping.h
-components/lwip/port/esp32/debug/lwip_debug.c
-components/lwip/port/esp32/freertos/sys_arch.c
-components/lwip/port/esp32/hooks/tcp_isn_default.c
-components/lwip/port/esp32/include/arch/cc.h
-components/lwip/port/esp32/include/arch/perf.h
-components/lwip/port/esp32/include/arch/sys_arch.h
-components/lwip/port/esp32/include/arch/vfs_lwip.h
-components/lwip/port/esp32/include/arpa/inet.h
-components/lwip/port/esp32/include/debug/lwip_debug.h
-components/lwip/port/esp32/include/netdb.h
-components/lwip/port/esp32/include/netif/ethernetif.h
-components/lwip/port/esp32/include/netif/openthreadif.h
-components/lwip/port/esp32/include/netinet/in.h
-components/lwip/port/esp32/include/netinet/tcp.h
-components/lwip/port/esp32/include/sntp/sntp_get_set_time.h
-components/lwip/port/esp32/include/sys/socket.h
-components/lwip/port/esp32/no_vfs_syscalls.c
 components/lwip/test_afl_host/dhcp_di.h
 components/lwip/test_afl_host/dhcpserver_di.h
 components/lwip/test_afl_host/dns_di.h

+ 1 - 0
tools/ci/executable-list.txt

@@ -41,6 +41,7 @@ examples/build_system/cmake/idf_as_lib/run-esp32h4.sh
 examples/build_system/cmake/idf_as_lib/run-esp32s2.sh
 examples/build_system/cmake/idf_as_lib/run-esp32s3.sh
 examples/build_system/cmake/idf_as_lib/run.sh
+examples/common_components/protocol_examples_tapif_io/make_tap_netif
 examples/storage/parttool/parttool_example.py
 examples/storage/parttool/parttool_example.sh
 examples/system/ota/otatool/get_running_partition.py

+ 3 - 0
tools/mocks/startup/CMakeLists.txt

@@ -0,0 +1,3 @@
+# This is a manual mock that supplies `main()` if FreeRTOS is mocked
+idf_component_register(SRCS "startup_mock.c"
+                       REQUIRES main esp_event)

+ 35 - 0
tools/mocks/startup/startup_mock.c

@@ -0,0 +1,35 @@
+/*
+ * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <stdbool.h>
+#include "esp_err.h"
+#include "Mockqueue.h"
+#include "Mocktask.h"
+#include "Mockesp_event.h"
+#include <stdio.h>
+
+extern void app_main(void);
+
+int main(int argc, char **argv)
+{
+    int queue;
+    setbuf(stdout, NULL);
+
+    // Mocks are used only as workarounds to build this application
+    // without FreeRTOS simulator.
+    // The code below presets the mocks to ignore and return
+    xQueueSemaphoreTake_IgnoreAndReturn(true);
+    xQueueGenericSend_IgnoreAndReturn(true);
+    vQueueDelete_Ignore();
+    xQueueCreateMutex_IgnoreAndReturn((QueueHandle_t)&queue);
+    xTaskGetTickCount_IgnoreAndReturn(0);
+    xQueueGenericCreate_IgnoreAndReturn((QueueHandle_t)&queue);
+    xTaskCreatePinnedToCore_IgnoreAndReturn((BaseType_t) &queue);
+    esp_event_loop_create_default_IgnoreAndReturn(ESP_OK);
+    xQueueGiveMutexRecursive_IgnoreAndReturn(true);
+    app_main();
+    return 0;
+}