diff --git a/components/asio/port/include/esp_asio_config.h b/components/asio/port/include/esp_asio_config.h index 53215ca16e..d80717ed9a 100644 --- a/components/asio/port/include/esp_asio_config.h +++ b/components/asio/port/include/esp_asio_config.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -21,8 +21,7 @@ // // LWIP compatibility inet and address macros/functions // -# define LWIP_COMPAT_SOCKET_INET 1 -# define LWIP_COMPAT_SOCKET_ADDR 1 +# include "esp_cpp_sockets.h" // // Specific ASIO feature flags diff --git a/components/esp_eth/src/esp_eth_netif_glue.c b/components/esp_eth/src/esp_eth_netif_glue.c index 58026bea8c..cfb0adf72d 100644 --- a/components/esp_eth/src/esp_eth_netif_glue.c +++ b/components/esp_eth/src/esp_eth_netif_glue.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -40,6 +40,11 @@ static esp_err_t eth_input_to_netif(esp_eth_handle_t eth_handle, uint8_t *buffer return esp_netif_receive((esp_netif_t *)priv, buffer, length, NULL); } +static void eth_l2_free(void *h, void* buffer) +{ + free(buffer); +} + static esp_err_t esp_eth_post_attach(esp_netif_t *esp_netif, void *args) { uint8_t eth_mac[6]; @@ -52,7 +57,7 @@ static esp_err_t esp_eth_post_attach(esp_netif_t *esp_netif, void *args) esp_netif_driver_ifconfig_t driver_ifconfig = { .handle = netif_glue->eth_driver, .transmit = esp_eth_transmit, - .driver_free_rx_buffer = NULL + .driver_free_rx_buffer = eth_l2_free }; ESP_ERROR_CHECK(esp_netif_set_driver_config(esp_netif, &driver_ifconfig)); diff --git a/components/esp_netif/CMakeLists.txt b/components/esp_netif/CMakeLists.txt index 44c9ef8e0d..accc6e01a0 100644 --- a/components/esp_netif/CMakeLists.txt +++ b/components/esp_netif/CMakeLists.txt @@ -13,6 +13,7 @@ set(srcs "vfs_l2tap/esp_vfs_l2tap.c" "lwip/esp_netif_lwip.c" "lwip/esp_netif_lwip_defaults.c" + "lwip/esp_netif_lwip_orig.c" "lwip/esp_netif_sta_list.c") set(include_dirs "include") diff --git a/components/esp_netif/Kconfig b/components/esp_netif/Kconfig index 090b590145..bfa3d54bca 100644 --- a/components/esp_netif/Kconfig +++ b/components/esp_netif/Kconfig @@ -28,6 +28,14 @@ menu "ESP NETIF Adapter" help Dummy implementation of esp-netif functionality which connects driver transmit to receive function. This option is for testing purpose only + + config ESP_NETIF_TCPIP_LWIP_ORIG + bool "LwIP-orig" + depends on !LWIP_PPP_SUPPORT && !LWIP_IPV4_NAPT + help + This choice sets the original, vanilla-lwIP as the TCP/IP stack. + Warning: Current implementation does not support PPP and NAPT features + endchoice config ESP_NETIF_L2_TAP diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index 390b9708f8..7fe1d2d67a 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -10,12 +10,13 @@ #include "esp_check.h" #include "esp_netif_lwip_internal.h" +#include "esp_netif_lwip_orig.h" #include "esp_netif.h" #include "esp_netif_private.h" #include "esp_random.h" -#if CONFIG_ESP_NETIF_TCPIP_LWIP +#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG) #include "lwip/tcpip.h" #include "lwip/dhcp.h" @@ -99,6 +100,7 @@ static bool tcpip_initialized = false; static esp_netif_t *s_last_default_esp_netif = NULL; static bool s_is_last_default_esp_netif_overridden = false; + #if !LWIP_TCPIP_CORE_LOCKING static sys_sem_t api_sync_sem = NULL; static sys_sem_t api_lock_sem = NULL; @@ -490,7 +492,7 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config) // Create parent esp-netif object esp_netif_t *esp_netif = calloc(1, sizeof(struct esp_netif_obj)); if (!esp_netif) { - ESP_LOGE(TAG, "Failed to allocate %d bytes (fee heap size %d)", sizeof(struct esp_netif_obj), + ESP_LOGE(TAG, "Failed to allocate %d bytes (free heap size %d)", sizeof(struct esp_netif_obj), esp_get_free_heap_size()); return NULL; } @@ -498,7 +500,7 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config) // Create ip info esp_netif_ip_info_t *ip_info = calloc(1, sizeof(esp_netif_ip_info_t)); if (!ip_info) { - ESP_LOGE(TAG, "Failed to allocate %d bytes (fee heap size %d)", sizeof(esp_netif_ip_info_t), + ESP_LOGE(TAG, "Failed to allocate %d bytes (free heap size %d)", sizeof(esp_netif_ip_info_t), esp_get_free_heap_size()); free(esp_netif); return NULL; @@ -508,7 +510,7 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config) // creating another ip info (to store old ip) ip_info = calloc(1, sizeof(esp_netif_ip_info_t)); if (!ip_info) { - ESP_LOGE(TAG, "Failed to allocate %d bytes (fee heap size %d)", sizeof(esp_netif_ip_info_t), + ESP_LOGE(TAG, "Failed to allocate %d bytes (free heap size %d)", sizeof(esp_netif_ip_info_t), esp_get_free_heap_size()); free(esp_netif->ip_info); free(esp_netif); @@ -519,7 +521,7 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config) // Create underlying lwip netif struct netif * lwip_netif = calloc(1, sizeof(struct netif)); if (!lwip_netif) { - ESP_LOGE(TAG, "Failed to allocate %d bytes (fee heap size %d)", sizeof(struct netif), + ESP_LOGE(TAG, "Failed to allocate %d bytes (free heap size %d)", sizeof(struct netif), esp_get_free_heap_size()); free(esp_netif->ip_info_old); free(esp_netif->ip_info); @@ -552,6 +554,8 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config) return NULL; } + set_lwip_netif_callback(); + return esp_netif; } @@ -562,6 +566,15 @@ static void esp_netif_lwip_remove(esp_netif_t *esp_netif) netif_set_down(esp_netif->lwip_netif); } netif_remove(esp_netif->lwip_netif); +#if ESP_GRATUITOUS_ARP + if (esp_netif->flags&ESP_NETIF_FLAG_GARP) { + netif_unset_garp_flag(esp_netif->lwip_netif); + } +#endif + if (esp_netif->flags & ESP_NETIF_DHCP_CLIENT) { + dhcp_cleanup(esp_netif->lwip_netif); + } + } } @@ -611,6 +624,9 @@ void esp_netif_destroy(esp_netif_t *esp_netif) { if (esp_netif) { esp_netif_remove_from_list(esp_netif); + if (esp_netif_get_nr_of_ifs() == 0) { + remove_lwip_netif_callback(); + } free(esp_netif->ip_info); free(esp_netif->ip_info_old); free(esp_netif->if_key); @@ -923,12 +939,12 @@ esp_err_t esp_netif_receive(esp_netif_t *esp_netif, void *buffer, size_t len, vo return ESP_OK; } +static esp_err_t esp_netif_start_ip_lost_timer(esp_netif_t *esp_netif); + // // DHCP: // -static esp_err_t esp_netif_start_ip_lost_timer(esp_netif_t *esp_netif); - -static void esp_netif_dhcpc_cb(struct netif *netif) +void esp_netif_internal_dhcpc_cb(struct netif *netif) { if (!netif) { ESP_LOGD(TAG, "null netif=%p", netif); @@ -941,7 +957,6 @@ static void esp_netif_dhcpc_cb(struct netif *netif) esp_netif_ip_info_t *ip_info = esp_netif->ip_info; esp_netif_ip_info_t *ip_info_old = esp_netif->ip_info_old; - if ( !ip4_addr_cmp(ip_2_ip4(&netif->ip_addr), IP4_ADDR_ANY4) ) { //check whether IP is changed @@ -1122,7 +1137,7 @@ static esp_err_t esp_netif_dhcpc_start_api(esp_netif_api_msg_t *msg) return ESP_ERR_ESP_NETIF_DHCPC_START_FAILED; } - dhcp_set_cb(p_netif, esp_netif_dhcpc_cb); + dhcp_set_cb(p_netif, esp_netif_internal_dhcpc_cb); esp_netif->dhcpc_status = ESP_NETIF_DHCP_STARTED; return ESP_OK; @@ -1624,11 +1639,11 @@ esp_ip6_addr_type_t esp_netif_ip6_get_addr_type(esp_ip6_addr_t* ip6_addr) } -static void esp_netif_nd6_cb(struct netif *p_netif, uint8_t ip_index) +void esp_netif_internal_nd6_cb(struct netif *p_netif, uint8_t ip_index) { ESP_LOGD(TAG, "%s lwip-netif:%p", __func__, p_netif); if (!p_netif) { - ESP_LOGD(TAG, "esp_netif_nd6_cb called with null p_netif"); + ESP_LOGD(TAG, "esp_netif_internal_nd6_cb called with null p_netif"); return; } @@ -1661,7 +1676,7 @@ static esp_err_t esp_netif_create_ip6_linklocal_api(esp_netif_api_msg_t *msg) struct netif *p_netif = esp_netif->lwip_netif; if (p_netif != NULL && netif_is_up(p_netif)) { netif_create_ip6_linklocal_address(p_netif, 1); - nd6_set_cb(p_netif, esp_netif_nd6_cb); + nd6_set_cb(p_netif, esp_netif_internal_nd6_cb); return ESP_OK; } else { return ESP_FAIL; @@ -2058,4 +2073,4 @@ esp_err_t esp_netif_remove_ip6_address(esp_netif_t *esp_netif, const esp_ip6_add #endif // CONFIG_LWIP_IPV6 -#endif /* CONFIG_ESP_NETIF_TCPIP_LWIP */ +#endif /* CONFIG_ESP_NETIF_TCPIP_LWIP || CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG */ diff --git a/components/esp_netif/lwip/esp_netif_lwip_defaults.c b/components/esp_netif/lwip/esp_netif_lwip_defaults.c index dc71d61e18..c57445da56 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_defaults.c +++ b/components/esp_netif/lwip/esp_netif_lwip_defaults.c @@ -8,7 +8,7 @@ #include "esp_netif_lwip_internal.h" #include "esp_netif_lwip_ppp.h" -#ifdef CONFIG_ESP_NETIF_TCPIP_LWIP +#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG) #include "netif/wlanif.h" #include "netif/ethernetif.h" diff --git a/components/esp_netif/lwip/esp_netif_lwip_internal.h b/components/esp_netif/lwip/esp_netif_lwip_internal.h index 66607fe495..e19163c75a 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_internal.h +++ b/components/esp_netif/lwip/esp_netif_lwip_internal.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,7 +12,7 @@ #include "lwip/netif.h" #include "dhcpserver/dhcpserver.h" -#ifdef CONFIG_ESP_NETIF_TCPIP_LWIP +#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG) struct esp_netif_netstack_lwip_vanilla_config { err_t (*init_fn)(struct netif*); diff --git a/components/esp_netif/lwip/esp_netif_lwip_orig.c b/components/esp_netif/lwip/esp_netif_lwip_orig.c new file mode 100644 index 0000000000..0465aee7b8 --- /dev/null +++ b/components/esp_netif/lwip/esp_netif_lwip_orig.c @@ -0,0 +1,82 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#include "esp_check.h" +#include "esp_netif_lwip_internal.h" +#include "esp_netif_lwip_orig.h" + +#include "esp_netif.h" +#include "esp_netif_private.h" + +#define DHCP_CB_CHANGE (LWIP_NSC_IPV4_SETTINGS_CHANGED | LWIP_NSC_IPV4_ADDRESS_CHANGED | LWIP_NSC_IPV4_GATEWAY_CHANGED | LWIP_NSC_IPV4_NETMASK_CHANGED) + +static void netif_callback_fn(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args) +{ + if (reason & DHCP_CB_CHANGE) { + esp_netif_internal_dhcpc_cb(netif); + } +#if LWIP_IPV6 + if (reason & LWIP_NSC_IPV6_ADDR_STATE_CHANGED) { + s8_t addr_idx = args->ipv6_addr_state_changed.addr_index; + if (netif_ip6_addr_state(netif, addr_idx) & IP6_ADDR_VALID) { + /* address is valid -> call the callback function */ + esp_netif_internal_nd6_cb(netif, addr_idx); + } + } +#endif /* #if LWIP_IPV6 */ +} + +static netif_ext_callback_t netif_callback = { .callback_fn = NULL, .next = NULL }; + +void set_lwip_netif_callback(void) +{ + if (netif_callback.callback_fn == NULL ) { + netif_add_ext_callback(&netif_callback, netif_callback_fn); + } +} + +void remove_lwip_netif_callback(void) +{ + netif_remove_ext_callback(&netif_callback); + memset(&netif_callback, 0, sizeof(netif_callback)); +} + +void dns_clear_servers(bool keep_fallback) +{ + u8_t numdns = 0; + + for (numdns = 0; numdns < DNS_MAX_SERVERS; numdns ++) { + if (keep_fallback && numdns == DNS_FALLBACK_SERVER_INDEX) { + continue; + } + + dns_setserver(numdns, NULL); + } +} + +#ifdef CONFIG_LWIP_GARP_TMR_INTERVAL +void netif_send_garp(void *arg) +{ + struct netif *netif = arg; + etharp_gratuitous(netif); + sys_timeout(CONFIG_LWIP_GARP_TMR_INTERVAL*1000, netif_send_garp, netif); +} + +void netif_set_garp_flag(struct netif *netif) +{ + sys_timeout(CONFIG_LWIP_GARP_TMR_INTERVAL*1000, netif_send_garp, netif); +} + +void netif_unset_garp_flag(struct netif *netif) +{ + sys_untimeout(netif_send_garp, netif); +} +#endif // CONFIG_LWIP_GARP_TMR_INTERVAL diff --git a/components/esp_netif/lwip/esp_netif_lwip_orig.h b/components/esp_netif/lwip/esp_netif_lwip_orig.h new file mode 100644 index 0000000000..f3dd2d743d --- /dev/null +++ b/components/esp_netif/lwip/esp_netif_lwip_orig.h @@ -0,0 +1,47 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include "esp_netif_lwip_internal.h" + + +#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP) + +/** + * @brief Sets one extended lwip netif callbacks for all esp-netif + */ +void set_lwip_netif_callback(void); + +void remove_lwip_netif_callback(void); + +void esp_netif_internal_dhcpc_cb(struct netif *netif); + +void esp_netif_internal_nd6_cb(struct netif *netif, uint8_t index); + +static inline void dhcp_set_cb(struct netif *netif, void (*cb)(struct netif*)) { } + +static inline void nd6_set_cb(struct netif *netif, void (*cb)(struct netif *netif, u8_t ip_index)) { } + +void dns_clear_servers(bool keep_fallback); + +#if ESP_GRATUITOUS_ARP + +void netif_set_garp_flag(struct netif *netif); + +void netif_unset_garp_flag(struct netif *netif); + +#endif // ESP_GRATUITOUS_ARP + +#else // !CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG and !CONFIG_ESP_NETIF_TCPIP_LWIP + +static inline void set_lwip_netif_callback(void) { } + +static inline void remove_lwip_netif_callback(void) { } + +static inline void netif_unset_garp_flag(struct netif *netif) {} + +#endif // CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG or CONFIG_ESP_NETIF_TCPIP_LWIP diff --git a/components/esp_netif/lwip/esp_netif_lwip_ppp.h b/components/esp_netif/lwip/esp_netif_lwip_ppp.h index b579eb80a8..a9abba6649 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_ppp.h +++ b/components/esp_netif/lwip/esp_netif_lwip_ppp.h @@ -1,22 +1,12 @@ -// Copyright 2019 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: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef _ESP_NETIF_LWIP_PPP_H_ #define _ESP_NETIF_LWIP_PPP_H_ -#if CONFIG_ESP_NETIF_TCPIP_LWIP - /** * @brief Creates new PPP related structure * @@ -77,7 +67,5 @@ esp_err_t esp_netif_stop_ppp(netif_related_data_t *netif_related); */ void esp_netif_ppp_set_default_netif(netif_related_data_t *netif_related); -#endif /* CONFIG_ESP_NETIF_TCPIP_LWIP */ - #endif // _ESP_NETIF_LWIP_PPP_H_ diff --git a/components/lwip/CMakeLists.txt b/components/lwip/CMakeLists.txt index 75dac0f804..5496efd74c 100644 --- a/components/lwip/CMakeLists.txt +++ b/components/lwip/CMakeLists.txt @@ -85,6 +85,7 @@ set(srcs "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/esp32/netif/wlanif.c") if(CONFIG_LWIP_PPP_SUPPORT) @@ -159,15 +160,10 @@ idf_component_register(SRCS "${srcs}" # lots of LWIP source files evaluate macros that check address of stack variables target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-address) -set_source_files_properties( - lwip/src/netif/ppp/ppp.c - PROPERTIES COMPILE_FLAGS - -Wno-uninitialized - ) set_source_files_properties( lwip/src/netif/ppp/pppos.c PROPERTIES COMPILE_FLAGS - -Wno-implicit-fallthrough + -Wno-type-limits ) # "comparison is always false due to limited range of data type" warning # when setting CONFIG_LWIP_TCP_WND_DEFAULT to 65535 diff --git a/components/lwip/linker.lf b/components/lwip/linker.lf index 28c6a14c67..bfb051a28f 100644 --- a/components/lwip/linker.lf +++ b/components/lwip/linker.lf @@ -46,7 +46,6 @@ entries: etharp:etharp_output_to_arp_index (noflash_text) etharp:etharp_output (noflash_text) ip4_addr:ip4_addr_isbroadcast_u32 (noflash_text) - ip4:ip4_route_src_hook (noflash_text) ip4:ip4_route_src (noflash_text) ip4:ip4_route (noflash_text) ip4:ip4_input (noflash_text) diff --git a/components/lwip/lwip b/components/lwip/lwip index 76303df238..6ca936f6b5 160000 --- a/components/lwip/lwip +++ b/components/lwip/lwip @@ -1 +1 @@ -Subproject commit 76303df2386902e0d7873be4217f1d9d1b50f982 +Subproject commit 6ca936f6b588cee702c638eee75c2436e6cf75de diff --git a/components/lwip/port/esp32/include/esp_cpp_sockets.h b/components/lwip/port/esp32/include/esp_cpp_sockets.h new file mode 100644 index 0000000000..e71dd36ab1 --- /dev/null +++ b/components/lwip/port/esp32/include/esp_cpp_sockets.h @@ -0,0 +1,98 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#pragma once + +#include "sys/poll.h" +#include "lwip/sockets.h" +#include "netdb.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP) + +// lwIP's socket API is mostly implemented as macros, +// but ASIO uses the same symbols in different namespaces, where macros wouldn't work. +// Here we have to undefined the symbols for ASIO build and declare as standard functions +#undef getaddrinfo +#undef gethostbyname_r +#undef gethostbyname +#undef freeaddrinfo +#undef accept +#undef bind +#undef shutdown +#undef getpeername +#undef getsockname +#undef setsockopt +#undef setsockopt +#undef getsockopt +#undef closesocket +#undef connect +#undef listen +#undef recvmsg +#undef recv +#undef recvfrom +#undef sendmsg +#undef send +#undef sendto +#undef socket +#undef inet_ntop +#undef inet_pton +#undef poll +#undef select + +static inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) +{ return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop); } +static inline struct hostent *gethostbyname(const char *name) +{ return lwip_gethostbyname(name); } +static inline void freeaddrinfo(struct addrinfo *ai) +{ lwip_freeaddrinfo(ai); } +static inline int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res) +{ return lwip_getaddrinfo(nodename, servname, hints, res); } +static inline int accept(int s,struct sockaddr *addr,socklen_t *addrlen) +{ return lwip_accept(s,addr,addrlen); } +static inline int bind(int s,const struct sockaddr *name, socklen_t namelen) +{ return lwip_bind(s,name,namelen); } +static inline int shutdown(int s,int how) +{ return lwip_shutdown(s,how); } +static inline int getpeername(int s,struct sockaddr *name,socklen_t *namelen) +{ return lwip_getpeername(s,name,namelen); } +static inline int getsockname(int s,struct sockaddr *name,socklen_t *namelen) +{ return lwip_getsockname(s,name,namelen); } +static inline int setsockopt(int s,int level,int optname,const void *opval,socklen_t optlen) +{ return lwip_setsockopt(s,level,optname,opval,optlen); } +static inline int getsockopt(int s,int level,int optname,void *opval,socklen_t *optlen) +{ return lwip_getsockopt(s,level,optname,opval,optlen); } +static inline int closesocket(int s) +{ return lwip_close(s); } +static inline int connect(int s,const struct sockaddr *name,socklen_t namelen) +{ return lwip_connect(s,name,namelen); } +static inline int listen(int s,int backlog) +{ return lwip_listen(s,backlog); } +static inline ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags) +{ return lwip_recvmsg(sockfd, msg, flags); } +static inline ssize_t recv(int s,void *mem,size_t len,int flags) +{ return lwip_recv(s,mem,len,flags); } +static inline ssize_t recvfrom(int s,void *mem,size_t len,int flags,struct sockaddr *from,socklen_t *fromlen) +{ return lwip_recvfrom(s,mem,len,flags,from,fromlen); } +static inline ssize_t send(int s,const void *dataptr,size_t size,int flags) +{ return lwip_send(s,dataptr,size,flags); } +static inline ssize_t sendmsg(int s,const struct msghdr *message,int flags) +{ return lwip_sendmsg(s,message,flags); } +static inline ssize_t sendto(int s,const void *dataptr,size_t size,int flags,const struct sockaddr *to,socklen_t tolen) +{ return lwip_sendto(s,dataptr,size,flags,to,tolen); } +static inline int socket(int domain,int type,int protocol) +{ return lwip_socket(domain,type,protocol); } +static inline const char *inet_ntop(int af, const void *src, char *dst, socklen_t size) +{ return lwip_inet_ntop(af, src, dst, size); } +static inline int inet_pton(int af, const char *src, void *dst) +{ return lwip_inet_pton(af, src, dst); } +#endif // CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG || CONFIG_ESP_NETIF_TCPIP_LWIP + +#ifdef __cplusplus +} +#endif diff --git a/components/lwip/port/esp32/include/lwipopts.h b/components/lwip/port/esp32/include/lwipopts.h index af45cffecb..6fab157aa9 100644 --- a/components/lwip/port/esp32/include/lwipopts.h +++ b/components/lwip/port/esp32/include/lwipopts.h @@ -16,15 +16,17 @@ #include #include #include -#include "netif/dhcp_state.h" -#include "sntp/sntp_get_set_time.h" +#include #ifdef __linux__ #include "esp32_mock.h" #else #include "esp_task.h" #include "esp_random.h" #endif // __linux__ - +#include "sdkconfig.h" +#include "netif/dhcp_state.h" +#include "sntp/sntp_get_set_time.h" +#include "sockets_ext.h" /* ----------------------------------------------- @@ -589,6 +591,18 @@ #define LWIP_NETIF_STATUS_CALLBACK 0 #endif +#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP) +/** + * LWIP_NETIF_EXT_STATUS_CALLBACK==1: Support an extended callback function + * for several netif related event that supports multiple subscribers. + * + * This ext-callback is used by ESP-NETIF with lwip-orig (upstream version) + * to provide netif related events on IP4/IP6 address/status changes + */ +#define LWIP_NETIF_EXT_STATUS_CALLBACK 1 +#endif + + /** * LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP *tries* to put all data * to be sent into one single pbuf. This is for compatibility with DMA-enabled @@ -1111,6 +1125,11 @@ #endif #define LWIP_HOOK_FILENAME "lwip_default_hooks.h" #define LWIP_HOOK_IP4_ROUTE_SRC ip4_route_src_hook +#define LWIP_HOOK_SOCKETS_GETSOCKOPT(s, sock, level, optname, optval, optlen, err) \ + lwip_getsockopt_impl_ext(sock, level, optname, optval, optlen, err)?(done_socket(sock), true): false + +#define LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, err) \ + lwip_setsockopt_impl_ext(sock, level, optname, optval, optlen, err)?(done_socket(sock), true): false /* --------------------------------------- diff --git a/components/lwip/port/esp32/include/sys/socket.h b/components/lwip/port/esp32/include/sys/socket.h index 5ea4db4ab8..eaaa1e0fec 100644 --- a/components/lwip/port/esp32/include/sys/socket.h +++ b/components/lwip/port/esp32/include/sys/socket.h @@ -30,6 +30,7 @@ * */ +#include "esp_cpp_sockets.h" #include "lwip/sockets.h" /* SOMAXCONN is expected to be found in this header too, diff --git a/components/lwip/port/esp32/vfs_lwip.c b/components/lwip/port/esp32/vfs_lwip.c index 517838e30e..f4c779686d 100644 --- a/components/lwip/port/esp32/vfs_lwip.c +++ b/components/lwip/port/esp32/vfs_lwip.c @@ -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 + */ #include #include diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index bea739ef1a..761712431f 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -475,7 +475,7 @@ components/esp_local_ctrl/src/esp_local_ctrl_transport_ble.c components/esp_netif/include/esp_netif_ppp.h components/esp_netif/include/esp_netif_slip.h components/esp_netif/loopback/esp_netif_loopback.c -components/esp_netif/lwip/esp_netif_lwip_ppp.h +components/esp_netif/lwip/esp_netif_lwip_ppp.c components/esp_netif/lwip/esp_netif_lwip_slip.c components/esp_netif/lwip/esp_netif_lwip_slip.h components/esp_netif/private_include/esp_netif_private.h @@ -984,7 +984,6 @@ components/lwip/port/esp32/netif/dhcp_state.c components/lwip/port/esp32/netif/ethernetif.c components/lwip/port/esp32/netif/wlanif.c components/lwip/port/esp32/no_vfs_syscalls.c -components/lwip/port/esp32/vfs_lwip.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