Merge branch 'feat/lwip_ppp_more_opts_v5.2' into 'release/v5.2'

lwip: PPP configs to enable/disable: Server side, IP header compression (v5.2)

See merge request espressif/esp-idf!33192
This commit is contained in:
Jiang Jiang Jian 2024-08-30 10:45:29 +08:00
commit 3835e1d89a
6 changed files with 64 additions and 8 deletions

View File

@ -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
*

View File

@ -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
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;
/** @brief event id offset for PHASE related events

View File

@ -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;

View File

@ -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
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;
@ -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.addr != IPADDR_ANY) {
// Set our preferred address, and accept the remote
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.addr != IPADDR_ANY) {
// Set their preferred address, and accept the local
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
#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;
}

View File

@ -952,6 +952,23 @@ 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_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

View File

@ -1105,6 +1105,16 @@ 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
/**
* 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,