From a9265db5f14a9370af410fdff9e3d5a2d9834d25 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 4 Oct 2023 17:35:57 +0200 Subject: [PATCH 1/4] feat(lwip): Add support for PPP server Added support PPP_SERVER option in LWIP Added support for configuring preferred addresses of PPP endpoints. --- components/esp_netif/include/esp_netif_ppp.h | 4 +++ .../esp_netif/lwip/esp_netif_lwip_ppp.c | 31 ++++++++++++++++++- components/lwip/Kconfig | 7 +++++ components/lwip/port/include/lwipopts.h | 5 +++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/components/esp_netif/include/esp_netif_ppp.h b/components/esp_netif/include/esp_netif_ppp.h index c9856c6206..d3d576c463 100644 --- a/components/esp_netif/include/esp_netif_ppp.h +++ b/components/esp_netif/include/esp_netif_ppp.h @@ -28,6 +28,10 @@ typedef struct esp_netif_ppp_config { * The current session must be closed, settings will be applied upon connecting. * */ #endif // CONFIG_LWIP_ENABLE_LCP_ECHO +#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT + uint32_t ppp_our_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */ + uint32_t ppp_their_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */ +#endif // CONFIG_LWIP_PPP_SERVER_SUPPORT } esp_netif_ppp_config_t; /** @brief event id offset for PHASE related events diff --git a/components/esp_netif/lwip/esp_netif_lwip_ppp.c b/components/esp_netif/lwip/esp_netif_lwip_ppp.c index ee4e6224d3..faac9d09e2 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_ppp.c +++ b/components/esp_netif/lwip/esp_netif_lwip_ppp.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -33,6 +33,10 @@ typedef struct lwip_peer2peer_ctx { bool ppp_error_event_enabled; #ifdef CONFIG_LWIP_ENABLE_LCP_ECHO bool ppp_lcp_echo_disabled; +#endif +#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT + uint32_t ppp_our_ip4_addr; // our desired IP (0 if no preference) + uint32_t ppp_their_ip4_addr; // their desired IP (0 if no preference) #endif ppp_pcb *ppp; } lwip_peer2peer_ctx_t; @@ -247,13 +251,29 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif) ppp_ctx->ppp->settings.lcp_echo_fails = LCP_MAXECHOFAILS; } #endif +#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT + if (ppp_ctx->ppp_our_ip4_addr != 0) { + // Set our preferred address, and accept the remote + ppp_ctx->ppp->ipcp_wantoptions.ouraddr = ppp_ctx->ppp_our_ip4_addr; + ppp_ctx->ppp->ipcp_wantoptions.accept_remote = 1; + } + if (ppp_ctx->ppp_their_ip4_addr != 0) { + // Set their preferred address, and accept the local + ppp_ctx->ppp->ipcp_wantoptions.hisaddr = ppp_ctx->ppp_their_ip4_addr; + ppp_ctx->ppp->ipcp_wantoptions.accept_local = 1; + } +#endif // CONFIG_LWIP_PPP_SERVER_SUPPORT #if ESP_IPV6_AUTOCONFIG ppp_ctx->ppp->netif->ip6_autoconfig_enabled = 1; #endif ESP_LOGD(TAG, "%s: Starting PPP connection: %p", __func__, ppp_ctx->ppp); +#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT + esp_err_t err = ppp_listen(ppp_ctx->ppp); +#else err_t err = ppp_connect(ppp_ctx->ppp, 0); +#endif if (err != ESP_OK) { ESP_LOGE(TAG, "%s: PPP connection cannot be started", __func__); if (ppp_ctx->ppp_error_event_enabled) { @@ -308,6 +328,10 @@ esp_err_t esp_netif_ppp_set_params(esp_netif_t *netif, const esp_netif_ppp_confi obj->ppp_error_event_enabled = config->ppp_error_event_enabled; #ifdef CONFIG_LWIP_ENABLE_LCP_ECHO obj->ppp_lcp_echo_disabled = config->ppp_lcp_echo_disabled; +#endif +#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT + obj->ppp_our_ip4_addr = config->ppp_our_ip4_addr; + obj->ppp_their_ip4_addr = config->ppp_their_ip4_addr; #endif return ESP_OK; } @@ -324,5 +348,10 @@ esp_err_t esp_netif_ppp_get_params(esp_netif_t *netif, esp_netif_ppp_config_t *c #ifdef CONFIG_LWIP_ENABLE_LCP_ECHO config->ppp_lcp_echo_disabled = obj->ppp_lcp_echo_disabled; #endif +#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT + config->ppp_our_ip4_addr = obj->ppp_our_ip4_addr; + config->ppp_their_ip4_addr = obj->ppp_their_ip4_addr; +#endif + return ESP_OK; } diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 8a6b661cdf..0431b74cd8 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -952,6 +952,13 @@ menu "LWIP" help Enable Microsoft Point-to-Point Encryption (MPPE) support + config LWIP_PPP_SERVER_SUPPORT + bool "Enable PPP server support" + depends on LWIP_PPP_SUPPORT + default n + help + Enable to use PPP server + config LWIP_ENABLE_LCP_ECHO bool "Enable LCP ECHO" depends on LWIP_PPP_SUPPORT diff --git a/components/lwip/port/include/lwipopts.h b/components/lwip/port/include/lwipopts.h index 90319d8898..c633c1a5bc 100644 --- a/components/lwip/port/include/lwipopts.h +++ b/components/lwip/port/include/lwipopts.h @@ -1105,6 +1105,11 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min) */ #define MPPE_SUPPORT CONFIG_LWIP_PPP_MPPE_SUPPORT +/** + * PPP_SERVER==1: Enable PPP server support (waiting for incoming PPP session). + */ +#define PPP_SERVER CONFIG_LWIP_PPP_SERVER_SUPPORT + /** * PPP_MAXIDLEFLAG: Max Xmit idle time (in ms) before resend flag char. * TODO: If PPP_MAXIDLEFLAG > 0 and next package is send during PPP_MAXIDLEFLAG time, From 501a25f0c724ad3179f35ed97efe75ca4152828d Mon Sep 17 00:00:00 2001 From: David Cermak Date: Mon, 8 Jan 2024 09:42:29 +0100 Subject: [PATCH 2/4] feat(lwip): Added PPP config option to control VJ header compression --- components/lwip/Kconfig | 10 ++++++++++ components/lwip/port/include/lwipopts.h | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 0431b74cd8..59843d1646 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -959,6 +959,16 @@ menu "LWIP" help Enable to use PPP server + config LWIP_PPP_VJ_HEADER_COMPRESSION + bool "Enable VJ IP Header compression" + depends on LWIP_PPP_SUPPORT + default y + help + Enable support for VJ header compression. + Please disable this if you're using NAPT on PPP interface, + since the compressed IP header might not be correctly interpreted + in NAT causing the compressed packet to be dropped. + config LWIP_ENABLE_LCP_ECHO bool "Enable LCP ECHO" depends on LWIP_PPP_SUPPORT diff --git a/components/lwip/port/include/lwipopts.h b/components/lwip/port/include/lwipopts.h index c633c1a5bc..811c2707f0 100644 --- a/components/lwip/port/include/lwipopts.h +++ b/components/lwip/port/include/lwipopts.h @@ -1110,6 +1110,11 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min) */ #define PPP_SERVER CONFIG_LWIP_PPP_SERVER_SUPPORT +/** + * VJ_SUPPORT==1: Support VJ header compression. + */ +#define VJ_SUPPORT CONFIG_LWIP_PPP_VJ_HEADER_COMPRESSION + /** * PPP_MAXIDLEFLAG: Max Xmit idle time (in ms) before resend flag char. * TODO: If PPP_MAXIDLEFLAG > 0 and next package is send during PPP_MAXIDLEFLAG time, From aa49e53d5b8061fc0ece3e3c21918577bffd68cb Mon Sep 17 00:00:00 2001 From: David Cermak Date: Mon, 8 Jan 2024 09:47:49 +0100 Subject: [PATCH 3/4] fix(lwip): esp_netif supports esp_netif_get_netif_impl() for PPP --- components/esp_netif/include/esp_netif_net_stack.h | 7 ++----- components/esp_netif/lwip/esp_netif_lwip.c | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/components/esp_netif/include/esp_netif_net_stack.h b/components/esp_netif/include/esp_netif_net_stack.h index 42ab134935..82d3981362 100644 --- a/components/esp_netif/include/esp_netif_net_stack.h +++ b/components/esp_netif/include/esp_netif_net_stack.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -29,10 +29,7 @@ extern "C" { esp_netif_t* esp_netif_get_handle_from_netif_impl(void *dev); /** - * @brief Returns network stack specific implementation handle (if supported) - * - * Note that it is not supported to acquire PPP netif impl pointer and - * this function will return NULL for esp_netif instances configured to PPP mode + * @brief Returns network stack specific implementation handle * * @param[in] esp_netif Handle to esp-netif instance * diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index 6361410e0e..c4b4253f45 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -493,8 +493,7 @@ esp_netif_t* esp_netif_get_handle_from_netif_impl(void *dev) void* esp_netif_get_netif_impl(esp_netif_t *esp_netif) { - // get impl ptr only for vanilla lwip impl (ppp_pcb not supported) - if (esp_netif && !ESP_NETIF_IS_POINT2POINT_TYPE(esp_netif, PPP_LWIP_NETIF)) { + if (esp_netif) { return esp_netif->lwip_netif; } return NULL; From aba6b8d8f7f5e5e44b300527fb32afe2b6aefc62 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 19 Jan 2024 17:47:55 +0100 Subject: [PATCH 4/4] fix(lwip): Used dedicated IP4 address type --- components/esp_netif/include/esp_netif_ppp.h | 4 ++-- components/esp_netif/lwip/esp_netif_lwip_ppp.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/esp_netif/include/esp_netif_ppp.h b/components/esp_netif/include/esp_netif_ppp.h index d3d576c463..ffdf4c6743 100644 --- a/components/esp_netif/include/esp_netif_ppp.h +++ b/components/esp_netif/include/esp_netif_ppp.h @@ -29,8 +29,8 @@ typedef struct esp_netif_ppp_config { * */ #endif // CONFIG_LWIP_ENABLE_LCP_ECHO #ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT - uint32_t ppp_our_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */ - uint32_t ppp_their_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */ + esp_ip4_addr_t ppp_our_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */ + esp_ip4_addr_t ppp_their_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */ #endif // CONFIG_LWIP_PPP_SERVER_SUPPORT } esp_netif_ppp_config_t; diff --git a/components/esp_netif/lwip/esp_netif_lwip_ppp.c b/components/esp_netif/lwip/esp_netif_lwip_ppp.c index faac9d09e2..03a11bafe3 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_ppp.c +++ b/components/esp_netif/lwip/esp_netif_lwip_ppp.c @@ -35,8 +35,8 @@ typedef struct lwip_peer2peer_ctx { bool ppp_lcp_echo_disabled; #endif #ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT - uint32_t ppp_our_ip4_addr; // our desired IP (0 if no preference) - uint32_t ppp_their_ip4_addr; // their desired IP (0 if no preference) + esp_ip4_addr_t ppp_our_ip4_addr; // our desired IP (IPADDR_ANY if no preference) + esp_ip4_addr_t ppp_their_ip4_addr; // their desired IP (IPADDR_ANY if no preference) #endif ppp_pcb *ppp; } lwip_peer2peer_ctx_t; @@ -252,14 +252,14 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif) } #endif #ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT - if (ppp_ctx->ppp_our_ip4_addr != 0) { + if (ppp_ctx->ppp_our_ip4_addr.addr != IPADDR_ANY) { // Set our preferred address, and accept the remote - ppp_ctx->ppp->ipcp_wantoptions.ouraddr = ppp_ctx->ppp_our_ip4_addr; + ppp_ctx->ppp->ipcp_wantoptions.ouraddr = ppp_ctx->ppp_our_ip4_addr.addr; ppp_ctx->ppp->ipcp_wantoptions.accept_remote = 1; } - if (ppp_ctx->ppp_their_ip4_addr != 0) { + if (ppp_ctx->ppp_their_ip4_addr.addr != IPADDR_ANY) { // Set their preferred address, and accept the local - ppp_ctx->ppp->ipcp_wantoptions.hisaddr = ppp_ctx->ppp_their_ip4_addr; + ppp_ctx->ppp->ipcp_wantoptions.hisaddr = ppp_ctx->ppp_their_ip4_addr.addr; ppp_ctx->ppp->ipcp_wantoptions.accept_local = 1; } #endif // CONFIG_LWIP_PPP_SERVER_SUPPORT