[PATCH v4 0/7] pcapng: fixes and improvements

Stephen Hemminger
2026-01-13T00:52:02Z

This series addresses several issues in the pcapng library
and improves test coverage. Several of these patches were
submitted previously in other series but have been more throughly
tested and passed AI review.

Bug Fixes:

Patches 1-3 fix potential issues with string handling in the pcapng
administrative APIs. The pcapng file format uses 16-bit length fields
for option data, but the library did not validate input string
lengths, and used fixed-size stack buffers that could be overrun by
large comments or metadata strings.

Patch 1 adds length validation against the format's 16-bit limit
Patch 2 replaces fixed stack buffers with dynamic allocation
Patch 3 handles the case where comment options
exceed available mbuf tailroom by chaining an additional mbuf segment

Test Improvements:

Patches 4-6 improve the pcapng unit test coverage:

Patch 4 exercises the comment option code path with varied test strings
Patch 5 varies packet sizes to exercise more of the copy logic
Patch 6 ensures the test runs long enough to verify 32-bit TSC wraparound handling

Performance:

Patch 7 optimizes timestamp conversion by replacing division
operations with shift-multiply arithmetic, following the approach used
by the Linux kernel vDSO. This eliminates expensive divides from the
packet capture hot path.

v4 - add one longer comment, and handle case where clang
wants parenthesis for multi-line string constants.

Stephen Hemminger (7):
pcapng: add length checks to string arguments
pcapng: use malloc instead of fixed buffer size
pcapng: add additional mbuf if space required on copy
test: add more tests for comments in pcapng
test: vary size of packets in pcapng test
test: increase gap in pcapng test
pcapng: improve performance of timestamping

app/test/test_pcapng.c | 142 ++++++++++++++++++++++++++++----------
lib/pcapng/rte_pcapng.c | 147 +++++++++++++++++++++++++++++-----------
lib/pcapng/rte_pcapng.h | 8 ++-
3 files changed, 219 insertions(+), 78 deletions(-)

--
2.51.0