From 18cd2d83be52679e75e2a2e3f28fd136d95e7e67 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Mon, 20 Jan 2025 10:50:54 +0200 Subject: [PATCH] net: pkt: Alloc headroom also for variable size data buffers The headroom was not taken into account for variable size data buffers when CONFIG_NET_L2_ETHERNET_RESERVE_HEADER was enabled. Add a test case for it to make sure the reserve allocation works properly. Fixes #84053 Signed-off-by: Jukka Rissanen --- subsys/net/ip/net_pkt.c | 5 ++--- tests/net/vlan/testcase.yaml | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/subsys/net/ip/net_pkt.c b/subsys/net/ip/net_pkt.c index 30eb092e1c5..18afed972fe 100644 --- a/subsys/net/ip/net_pkt.c +++ b/subsys/net/ip/net_pkt.c @@ -1033,13 +1033,12 @@ static struct net_buf *pkt_alloc_buffer(struct net_pkt *pkt, #if defined(CONFIG_NET_PKT_ALLOC_STATS) uint32_t start_time = k_cycle_get_32(); - size_t total_size = size; + size_t total_size = size + headroom; #else ARG_UNUSED(pkt); #endif - ARG_UNUSED(headroom); - buf = net_buf_alloc_len(pool, size, timeout); + buf = net_buf_alloc_len(pool, size + headroom, timeout); #if CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG NET_FRAG_CHECK_IF_NOT_IN_USE(buf, buf->ref + 1); diff --git a/tests/net/vlan/testcase.yaml b/tests/net/vlan/testcase.yaml index c036e767a40..97f637bd3f1 100644 --- a/tests/net/vlan/testcase.yaml +++ b/tests/net/vlan/testcase.yaml @@ -11,3 +11,7 @@ tests: net.vlan.header_reserved: extra_configs: - CONFIG_NET_L2_ETHERNET_RESERVE_HEADER=y + net.vlan.header_reserved.variable_size: + extra_configs: + - CONFIG_NET_L2_ETHERNET_RESERVE_HEADER=y + - CONFIG_NET_BUF_VARIABLE_DATA_SIZE=y