mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
feat(esp_netif): PPP: Use RAM allocated pbufs instead of POOL (fixed size)
PPP netif: Used allocated packet buffers of exact size for input to TCP/IP stack to consume less memory in download mode (compared to the previously used fixed sized packet buffers)
This commit is contained in:
parent
966b8620c2
commit
10a5fcf99e
@ -24,7 +24,7 @@ if(${target} STREQUAL "linux")
|
||||
endif()
|
||||
|
||||
if(CONFIG_PPP_SUPPORT)
|
||||
list(APPEND srcs_lwip lwip/esp_netif_lwip_ppp.c)
|
||||
list(APPEND srcs_lwip lwip/esp_netif_lwip_ppp.c lwip/netif/ppp.c)
|
||||
endif()
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "esp_netif_lwip_internal.h"
|
||||
#include <string.h>
|
||||
#include "lwip/ip6_addr.h"
|
||||
#include "netif/pppif.h"
|
||||
|
||||
ESP_EVENT_DEFINE_BASE(NETIF_PPP_STATUS);
|
||||
|
||||
@ -285,7 +286,7 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif)
|
||||
esp_netif_recv_ret_t esp_netif_lwip_ppp_input(void *ppp_ctx, void *buffer, size_t len, void *eb)
|
||||
{
|
||||
struct lwip_peer2peer_ctx * obj = ppp_ctx;
|
||||
err_t ret = pppos_input_tcpip(obj->ppp, buffer, len);
|
||||
err_t ret = pppos_input_tcpip_as_ram_pbuf(obj->ppp, buffer, len);
|
||||
if (ret != ERR_OK) {
|
||||
ESP_LOGE(TAG, "pppos_input_tcpip failed with %d", ret);
|
||||
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_FAIL);
|
||||
|
28
components/esp_netif/lwip/netif/ppp.c
Normal file
28
components/esp_netif/lwip/netif/ppp.c
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2001-2004 Swedish Institute of Computer Science
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* SPDX-FileContributor: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*/
|
||||
#include "pppif.h"
|
||||
#include "lwip/tcpip.h"
|
||||
|
||||
/*
|
||||
* Similar to pppos_input_tcpip() from lwip's ppp netif, but instead
|
||||
* of PBUF_POOL, we use PBUF_RAM type of the pbuf we pass to the stack
|
||||
*/
|
||||
err_t pppos_input_tcpip_as_ram_pbuf(ppp_pcb *ppp, u8_t *s, int l)
|
||||
{
|
||||
struct pbuf *p = pbuf_alloc(PBUF_RAW, l, PBUF_RAM);
|
||||
if (!p) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
pbuf_take(p, s, l);
|
||||
|
||||
err_t err = tcpip_inpkt(p, ppp_netif(ppp), pppos_input_sys);
|
||||
if (err != ERR_OK) {
|
||||
pbuf_free(p);
|
||||
}
|
||||
return err;
|
||||
}
|
22
components/esp_netif/lwip/netif/pppif.h
Normal file
22
components/esp_netif/lwip/netif/pppif.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2001-2004 Swedish Institute of Computer Science
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* SPDX-FileContributor: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*/
|
||||
#include "lwip/pbuf.h"
|
||||
#include "netif/ppp/pppos.h"
|
||||
|
||||
/** Pass received raw characters to PPPoS to be decoded through lwIP TCPIP thread.
|
||||
*
|
||||
* This function uses allocated packet buffers of exact size for input to TCP/IP stack
|
||||
* to consume less memory in download mode, compared to the pppos_input_tcpip() from lwIP.
|
||||
* (original implementation uses `PBUF_POOL`, which on ESP port uses standard malloc
|
||||
* to allocate a fixed size pbuf)
|
||||
*
|
||||
* @param ppp PPP descriptor index, returned by pppos_create()
|
||||
* @param s received data
|
||||
* @param l length of received data
|
||||
*/
|
||||
err_t pppos_input_tcpip_as_ram_pbuf(ppp_pcb *ppp, u8_t *s, int l);
|
Loading…
x
Reference in New Issue
Block a user