From d6c4e2cb34889b715f5b4215651f202e43e2e25a Mon Sep 17 00:00:00 2001 From: Jiacheng Guo Date: Tue, 4 Jan 2022 19:06:38 +0800 Subject: [PATCH] lwip: add ip6 input hook The MR adds Kconfig options and a default weak implementation for the lwIP ip6 input hook. --- components/lwip/Kconfig | 20 +++++++++++++ .../port/esp32/hooks/lwip_default_hooks.c | 28 ++++++++++--------- .../port/esp32/include/lwip_default_hooks.h | 25 ++++++++--------- tools/ci/check_copyright_ignore.txt | 2 -- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index e229f2212a..e8466df288 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -1008,6 +1008,26 @@ menu "LWIP" endchoice + choice LWIP_HOOK_IP6_INPUT + prompt "IPv6 packet input" + depends on LWIP_IPV6 + default LWIP_HOOK_IP6_INPUT_NONE + help + Enables custom IPv6 packet input. + Setting this to "default" provides weak implementation + stub that could be overwritten in application code. + Setting this to "custom" provides hook's declaration + only and expects the application to implement it. + + config LWIP_HOOK_IP6_INPUT_NONE + bool "No hook declared" + config LWIP_HOOK_IP6_INPUT_DEFAULT + bool "Default (weak) implementation" + config LWIP_HOOK_IP6_INPUT_CUSTOM + bool "Custom implementation" + + endchoice + endmenu # Hooks menuconfig LWIP_DEBUG diff --git a/components/lwip/port/esp32/hooks/lwip_default_hooks.c b/components/lwip/port/esp32/hooks/lwip_default_hooks.c index 87f684a4f1..f053c16f15 100644 --- a/components/lwip/port/esp32/hooks/lwip_default_hooks.c +++ b/components/lwip/port/esp32/hooks/lwip_default_hooks.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 "lwip_default_hooks.h" @@ -48,3 +40,13 @@ const ip6_addr_t *__weak lwip_hook_nd6_get_gw(struct netif *netif, const ip6_add return 0; } #endif + +#ifdef CONFIG_LWIP_HOOK_IP6_INPUT_DEFAULT +int __weak lwip_hook_ip6_input(struct pbuf *p, struct netif *inp) +{ + LWIP_UNUSED_ARG(p); + LWIP_UNUSED_ARG(inp); + + return 0; +} +#endif diff --git a/components/lwip/port/esp32/include/lwip_default_hooks.h b/components/lwip/port/esp32/include/lwip_default_hooks.h index 3f3ec0b2ec..2388d4f3a0 100644 --- a/components/lwip/port/esp32/include/lwip_default_hooks.h +++ b/components/lwip/port/esp32/include/lwip_default_hooks.h @@ -1,22 +1,15 @@ -// 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 + */ #ifndef _LWIP_DEFAULT_HOOKS_H_ #define _LWIP_DEFAULT_HOOKS_H_ #include "lwip/ip_addr.h" #include "lwip/arch.h" #include "lwip/err.h" +#include "lwip/pbuf.h" #ifdef ESP_IDF_LWIP_HOOK_FILENAME #include ESP_IDF_LWIP_HOOK_FILENAME @@ -54,6 +47,12 @@ int lwip_hook_netconn_external_resolve(const char *name, ip_addr_t *addr, u8_t a #define LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE lwip_hook_netconn_external_resolve #endif /* CONFIG_LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE... */ +#if defined(CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM) || defined(CONFIG_LWIP_HOOK_IP6_INPUT_DEFAULT) +int lwip_hook_ip6_input(struct pbuf *p, struct netif *inp); + +#define LWIP_HOOK_IP6_INPUT lwip_hook_ip6_input +#endif /* CONFIG_LWIP_HOOK_IP6_INPUT_CUSTIOM... */ + #ifdef __cplusplus } #endif diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 52b79dc616..6bbe9dd8c8 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1209,7 +1209,6 @@ components/lwip/include/apps/ping/ping_sock.h components/lwip/include/apps/sntp/sntp.h components/lwip/port/esp32/debug/lwip_debug.c components/lwip/port/esp32/freertos/sys_arch.c -components/lwip/port/esp32/hooks/lwip_default_hooks.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 @@ -1217,7 +1216,6 @@ 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/lwip_default_hooks.h components/lwip/port/esp32/include/netdb.h components/lwip/port/esp32/include/netif/dhcp_state.h components/lwip/port/esp32/include/netif/ethernetif.h