Skip to content

bpf/tests: add support for scapy packets of 1036-1518 bytes#44314

Merged
joestringer merged 4 commits intocilium:mainfrom
msune:bpf_scapy_support_1518_pkts
Feb 17, 2026
Merged

bpf/tests: add support for scapy packets of 1036-1518 bytes#44314
joestringer merged 4 commits intocilium:mainfrom
msune:bpf_scapy_support_1518_pkts

Conversation

@msune
Copy link
Copy Markdown
Member

@msune msune commented Feb 12, 2026

This patchset:

  • Fixes CTX len trace on pkt len mismatch error
  • Throws build_bug() if scapy packets exceed 1518 bytes (current __SCAPY_MAX_BUF)
  • Cleans up __ASSERT_TRACE_FAIL_BUF()
  • Add support for scapy packets of 1036-1518 (see last commit message for details)
bpf/tests: support pkt sizes 1036-1518 bytes

Fix error trace showing the incorrect CTX len when packet and buffer
length mismatched.

Signed-off-by: Marc Suñé <marc.sune@isovalent.com>
Throw build bug if packets exceed the __SCAPY_MAX_BUF (1518bytes) on
BUF_DECL().

Signed-off-by: Marc Suñé <marc.sune@isovalent.com>
Remove unnecessary args to __ASSERT_TRACE_FAIL_BUF().

Signed-off-by: Marc Suñé <marc.sune@isovalent.com>
@msune msune requested a review from a team as a code owner February 12, 2026 10:38
@msune msune requested a review from ysksuzuki February 12, 2026 10:38
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Feb 12, 2026
Commit e80be9e work-arounded the 128 byte limitation of the
cilium builtins implementation by reimplementing (hack, innefficiently
as noted in the commit msg) a simple version of memcpy/memcmp to be
used by scapy assert checks (only).

Unfortunately, when buffers exceed ~1036 bytes, the clang/LLVM optimizer
removes memcpy code and (attempts to) use built-in instead (even at O1).
Since the builtin has a hard limit of 128 8-byte words [1] (thanks
Daniel Borkmann for the pointer), this leads to:

In file included from _scapy_selftest.c:12:
./scapy.h:64:23: error: A call to built-in function 'memcpy' is not supported.
   64 |                 *(__u64 *)(dst + i) = *(__u64 *)(src + i);
      |                                     ^
./scapy.h:64:23: error: A call to built-in function 'memcpy' is not supported.
./scapy.h:64:23: error: A call to built-in function 'memcpy' is not supported.
./scapy.h:64:23: error: A call to built-in function 'memcpy' is not supported.

or if directly using `__bpf_memcpy_builtin()` (which calls
`__builtin_memcpy()`):

In file included from _scapy_selftest.c:7:
In file included from ./pktgen.h:7:
/home/msuneclo/dev/cilium/bpf/include/bpf/builtins.h:165:2: error: A call to built-in function 'memcpy' is not supported.
  165 |         __builtin_memcpy(d, s, len);

This commit works-around this issue too by wrapping the original
_scapy_memcpy() to perform chunked memcpys. Current packet size is limited to
1518 bytes (__SCAPY_MAX_BUF), but could be extended to 2K.

[1] https://github.com/llvm/llvm-project/blob/a6929f7937696bb07788be6428fdcf1bf36775b5/llvm/lib/Target/BPF/BPFSelectionDAGInfo.h#L34

Signed-off-by: Marc Suñé <marc.sune@isovalent.com>
Reported-by: Simone Magnani <simone.magnani@isovalent.com>
@msune msune force-pushed the bpf_scapy_support_1518_pkts branch from a9ac8a9 to 0f1147d Compare February 12, 2026 10:42
@msune
Copy link
Copy Markdown
Member Author

msune commented Feb 12, 2026

cc @smagnani96

Copy link
Copy Markdown
Contributor

@smagnani96 smagnani96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯

@msune
Copy link
Copy Markdown
Member Author

msune commented Feb 12, 2026

/test

@ysksuzuki ysksuzuki added area/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. release-note/ci This PR makes changes to the CI. labels Feb 17, 2026
@maintainer-s-little-helper maintainer-s-little-helper bot added ready-to-merge This PR has passed all tests and received consensus from code owners to merge. and removed dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels Feb 17, 2026
@joestringer joestringer added this pull request to the merge queue Feb 17, 2026
Merged via the queue into cilium:main with commit 52269b9 Feb 17, 2026
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/ci This PR makes changes to the CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants