From cfe91b8df1211f407d8b4885a9b9438e57adc449 Mon Sep 17 00:00:00 2001 From: Maochen Wang Date: Sun, 29 Dec 2024 04:08:06 +0800 Subject: [PATCH] net: ip: net_pkt: only reserve L2 header for TX case Only reserve L2 header for TX case when allocating net buffer, as for RX case, all the received headers are already in linear buffer when the driver receives the data, and reserve extra L2 header for RX case may exceed the default buffer size. Signed-off-by: Maochen Wang --- subsys/net/ip/net_pkt.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/subsys/net/ip/net_pkt.c b/subsys/net/ip/net_pkt.c index 2c1a4d3089d..30eb092e1c5 100644 --- a/subsys/net/ip/net_pkt.c +++ b/subsys/net/ip/net_pkt.c @@ -1337,6 +1337,16 @@ int net_pkt_alloc_buffer_with_reserve(struct net_pkt *pkt, return 0; } +static bool is_pkt_tx(struct net_pkt *pkt) +{ +#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL) + if ((pkt->context != NULL) && (get_tx_slab(pkt->context) != NULL)) { + return pkt->slab == get_tx_slab(pkt->context); + } +#endif + return pkt->slab == &tx_pkts; +} + #if NET_LOG_LEVEL >= LOG_LEVEL_DBG int net_pkt_alloc_buffer_debug(struct net_pkt *pkt, size_t size, @@ -1364,7 +1374,7 @@ int net_pkt_alloc_buffer(struct net_pkt *pkt, iface = net_pkt_iface(pkt); - if (iface != NULL && net_if_l2(iface)->alloc != NULL) { + if (iface != NULL && is_pkt_tx(pkt) && net_if_l2(iface)->alloc != NULL) { ret = net_if_l2(iface)->alloc(iface, pkt, size, proto, timeout); if (ret != -ENOTSUP) { return ret;