Skip to content

Commit 5eaeb3e

Browse files
committed
Add max_entries constraints for RingBuffer
1 parent cd52d0d commit 5eaeb3e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pythonbpf/maps/maps_pass.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ def process_ringbuf_map(map_name, rval, module):
8686
map_params = _parse_map_params(rval, expected_args=["max_entries"])
8787
map_params["type"] = BPFMapType.RINGBUF
8888

89+
# NOTE: constraints borrowed from https://docs.ebpf.io/linux/map-type/BPF_MAP_TYPE_RINGBUF/
90+
max_entries = map_params.get("max_entries")
91+
if (
92+
not isinstance(max_entries, int)
93+
or max_entries < 4096
94+
or (max_entries & (max_entries - 1)) != 0
95+
):
96+
raise ValueError(
97+
"Ringbuf max_entries must be a power of two greater than or equal to the page size (4096)"
98+
)
99+
89100
logger.info(f"Ringbuf map parameters: {map_params}")
90101

91102
map_global = create_bpf_map(module, map_name, map_params)

0 commit comments

Comments
 (0)