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

lwip: add ip6 input hook

The MR adds Kconfig options and a default weak implementation for the
lwIP ip6 input hook.
Jiacheng Guo 4 лет назад
Родитель
Сommit
d6c4e2cb34

+ 20 - 0
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

+ 15 - 13
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

+ 12 - 13
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

+ 0 - 2
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