Skip to content

Commit ced80b1

Browse files
henrikbrixandersenmmahadevan108
authored andcommitted
lib: net_buf: move the network buffer implementation to lib
Move the net_buf implementation from the networking subsystem to a library as they have no dependency on the networking subsystem. Network buffers are used in subsystems outside of networking (e.g. Bluetooth, USB). Fixes: #36374 Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent cfc010f commit ced80b1

File tree

18 files changed

+83
-74
lines changed

18 files changed

+83
-74
lines changed

MAINTAINERS.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,7 +2803,6 @@ Networking:
28032803
- samples/net/lwm2m_client/
28042804
- samples/net/wifi/
28052805
- samples/net/dhcpv4_client/
2806-
- subsys/net/buf*.c
28072806
- subsys/net/l2/ethernet/gptp/
28082807
- subsys/net/l2/ieee802154/
28092808
- subsys/net/l2/wifi/
@@ -2846,7 +2845,7 @@ Networking:
28462845
- jukkar
28472846
files:
28482847
- include/zephyr/net/buf.h
2849-
- subsys/net/buf*.c
2848+
- lib/net_buf/
28502849
- tests/net/buf/
28512850
labels:
28522851
- "area: Networking Buffers"

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_subdirectory_ifdef(CONFIG_CPP cpp)
1414
add_subdirectory(hash)
1515
add_subdirectory(heap)
1616
add_subdirectory(mem_blocks)
17+
add_subdirectory_ifdef(CONFIG_NET_BUF net_buf)
1718
add_subdirectory(os)
1819
add_subdirectory(utils)
1920
add_subdirectory_ifdef(CONFIG_SMF smf)

lib/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ source "lib/heap/Kconfig"
1515

1616
source "lib/mem_blocks/Kconfig"
1717

18+
source "lib/net_buf/Kconfig"
19+
1820
source "lib/os/Kconfig"
1921

2022
source "lib/posix/Kconfig"

lib/net_buf/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
zephyr_library()
4+
zephyr_library_sources_ifdef(
5+
CONFIG_NET_BUF
6+
buf.c
7+
buf_simple.c
8+
)

lib/net_buf/Kconfig

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Network buffer configuration options
2+
3+
# Copyright (c) 2015 Intel Corporation
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
menuconfig NET_BUF
7+
bool "Network buffer support"
8+
help
9+
This option enables support for generic network protocol
10+
buffers.
11+
12+
if NET_BUF
13+
14+
config NET_BUF_LOG
15+
bool "Network buffer logging"
16+
select LOG
17+
help
18+
Enable logs and checks for the generic network buffers.
19+
20+
module = NET_BUF
21+
module-str = net_buf
22+
source "subsys/logging/Kconfig.template.log_config"
23+
24+
if NET_BUF_LOG
25+
26+
config NET_BUF_WARN_ALLOC_INTERVAL
27+
int "Interval of Network buffer allocation warnings"
28+
default 1
29+
range 0 60
30+
help
31+
Interval in seconds of Network buffer allocation warnings which are
32+
generated when a buffer cannot immediately be allocated with K_FOREVER
33+
which may lead to deadlocks. Setting it to 0 makes warnings to be
34+
printed only once per allocation.
35+
36+
config NET_BUF_SIMPLE_LOG
37+
bool "Network buffer memory debugging"
38+
select LOG
39+
help
40+
Enable extra debug logs and checks for the generic network buffers.
41+
42+
endif # NET_BUF_LOG
43+
44+
config NET_BUF_POOL_USAGE
45+
bool "Network buffer pool usage tracking"
46+
help
47+
Enable network buffer pool tracking. This means that:
48+
* amount of free buffers in the pool is remembered
49+
* total size of the pool is calculated
50+
* pool name is stored and can be shown in debugging prints
51+
52+
config NET_BUF_ALIGNMENT
53+
int "Network buffer alignment restriction"
54+
default 0
55+
help
56+
Alignment restriction for network buffers. This is useful for
57+
some hardware IP with DMA that requires the buffers to be aligned
58+
to a certain byte boundary, or dealing with cache line restrictions.
59+
Default value of 0 means the alignment will be the size of a void pointer,
60+
any other value will force the alignment of a net buffer in bytes.
61+
62+
endif # NET_BUF
File renamed without changes.
File renamed without changes.

subsys/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ add_subdirectory_ifdef(CONFIG_INPUT input)
4747
add_subdirectory_ifdef(CONFIG_JWT jwt)
4848
add_subdirectory_ifdef(CONFIG_LLEXT llext)
4949
add_subdirectory_ifdef(CONFIG_MODEM_MODULES modem)
50-
add_subdirectory_ifdef(CONFIG_NET_BUF net)
50+
add_subdirectory_ifdef(CONFIG_NETWORKING net)
5151
add_subdirectory_ifdef(CONFIG_PROFILING profiling)
5252
add_subdirectory_ifdef(CONFIG_RETENTION retention)
5353
add_subdirectory_ifdef(CONFIG_SENSING sensing)

subsys/net/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
zephyr_library()
4-
zephyr_library_sources_ifdef(
5-
CONFIG_NET_BUF
6-
buf.c
7-
buf_simple.c
8-
)
94
zephyr_library_sources_ifdef(CONFIG_NET_HOSTNAME_ENABLE hostname.c)
105

116
if(CONFIG_NETWORKING)

subsys/net/Kconfig

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,6 @@
55

66
menu "Networking"
77

8-
config NET_BUF
9-
bool "Network buffer support"
10-
help
11-
This option enables support for generic network protocol
12-
buffers.
13-
14-
if NET_BUF
15-
16-
config NET_BUF_LOG
17-
bool "Network buffer logging"
18-
select LOG
19-
help
20-
Enable logs and checks for the generic network buffers.
21-
22-
module = NET_BUF
23-
module-str = net_buf
24-
source "subsys/logging/Kconfig.template.log_config"
25-
26-
if NET_BUF_LOG
27-
28-
config NET_BUF_WARN_ALLOC_INTERVAL
29-
int "Interval of Network buffer allocation warnings"
30-
default 1
31-
range 0 60
32-
help
33-
Interval in seconds of Network buffer allocation warnings which are
34-
generated when a buffer cannot immediately be allocated with K_FOREVER
35-
which may lead to deadlocks. Setting it to 0 makes warnings to be
36-
printed only once per allocation.
37-
38-
config NET_BUF_SIMPLE_LOG
39-
bool "Network buffer memory debugging"
40-
select LOG
41-
help
42-
Enable extra debug logs and checks for the generic network buffers.
43-
44-
endif # NET_BUF_LOG
45-
46-
config NET_BUF_POOL_USAGE
47-
bool "Network buffer pool usage tracking"
48-
help
49-
Enable network buffer pool tracking. This means that:
50-
* amount of free buffers in the pool is remembered
51-
* total size of the pool is calculated
52-
* pool name is stored and can be shown in debugging prints
53-
54-
config NET_BUF_ALIGNMENT
55-
int "Network buffer alignment restriction"
56-
default 0
57-
help
58-
Alignment restriction for network buffers. This is useful for
59-
some hardware IP with DMA that requires the buffers to be aligned
60-
to a certain byte boundary, or dealing with cache line restrictions.
61-
Default value of 0 means the alignment will be the size of a void pointer,
62-
any other value will force the alignment of a net buffer in bytes.
63-
64-
endif # NET_BUF
65-
668
config NETWORKING
679
bool "Link layer and networking (including IP)"
6810
select NET_BUF

0 commit comments

Comments
 (0)