Skip to content

dpdk: add support for segmented mbufs v12 - #16750

Open
lukashino wants to merge 6 commits into
OISF:mainfrom
lukashino:dpdk-segmented-mbufs-v12
Open

lukashino wants to merge 6 commits into
OISF:mainfrom
lukashino:dpdk-segmented-mbufs-v12

Conversation

@lukashino

Copy link
Copy Markdown
Contributor

Follow-up of #16476

Suricata may receive segmented (chained) mbufs (big packets, larger than MTU, chunked into multiple mbufs).
Previously, these packets would trigger a warning and potentially be processed
incorrectly since only the first segment was accessible.

Now Suricata handles segmented mbufs by:

  1. Attempting to linearize in-place with rte_pktmbuf_linearize()
  2. If linearization fails (insufficient tailroom), copying all segments into the packet's internal buffer

Link to ticket: https://redmine.openinfosecfoundation.org/issues/6012

Describe changes:
v12:

  • enable scatter mode when MTU cannot be set
  • dropped "replace" keyword support in DPDK (as the feature was not actually requested)
  • brought back a counter that signals the amount of dropped mbufs because the packet was modified by the engine and the mbuf was shared.

v10:

  • Doc-only commit: the replace checksum sentence is now its own commit, first in the series, with no ticket: 6938e47 doc: state which checksums replace recalculates. Commit 3 now only adds the
    "supported with NFQ, IPFW and DPDK" line.
  • Upgrade notes: both entries are gone, and the series no longer touches upgrade.rst.
  • Drop path (folded into ed47bf5 dpdk: handle segmented mbufs in copy modes):
    • The receive loop now creates the Packet first, then runs the checks (validation, linearize, copy-mode checks, copy).
    • Every rejection calls PacketDrop(p, ACTION_DROP, PKT_DROP_REASON_CAPTURE_ERROR), frees the mbuf, sets it to NULL and releases through TmqhOutputPacketpool().
    • capture.dpdk.segmented_drops and segmented_too_large still give the DPDK-specific detail.
  • New drop reason: ips.drop_reason.capture_error, added before PKT_DROP_REASON_INNER_PACKET, so PKT_DROP_REASON_NON_FW_MAX stays correct. It's in both string tables in decode.c, in etc/schema.json
    and in dpdk.rst. The commit message explains why.

v9:

  • implemented changes to account for copy-modes and potential payload rewrite (replace/stream modification)
  • replace keyword available in DPDK (can be withdrawn, no strong feelings)
  • so far keeping the commit from the original author but since the IPS implementation required substantial overlapping changes, I consider squashing it together

SV_BRANCH=OISF/suricata-verify#3585

Lukas Sismis and others added 6 commits November 26, 2026 23:15
Define the DPDK packet and error counters emitted by the capture module
so that EVE statistics validate against the schema.

Ticket: 6012
The paragraph claimed that, apart from the checksum validation offload,
no other offloads can be enabled. Suricata also enables VLAN stripping
with vlan-strip-offload, MBUF_FAST_FREE and, with DPDK older than 21.11,
the jumbo frame offload needed to apply an MTU above 1518.

List the offloads Suricata enables.
Suricata sized its mbufs for the MTU, the Ethernet header, the CRC and
one VLAN tag. NIC drivers account for two VLAN tags (QinQ): i40e and ice
add them to their maximum frame size, while ixgbe keeps its maximum
frame at the MTU plus 18 bytes and adds the two tags only when it
decides whether a frame fits into one mbuf.

Size the mbufs for two VLAN tags to be in line with these drivers.

Ticket: 6012
A packet larger than one mbuf arrives as a chain of segmented mbufs,
e.g. when Suricata runs as a secondary DPDK process and the primary
application uses small mbufs, or when a PMD does not enforce the MTU.
Suricata only warned about such packets and decoded them as if the first
segment held the whole packet, reading past its data.

Process a chain as one contiguous packet:
1. Merge it into its first mbuf with rte_pktmbuf_linearize().
2. If that is not possible (not enough tailroom, or the first segment is
   not a direct mbuf with a single reference), copy all segments into
   the packet's own buffer.

Each worker thread logs a warning for the first chain it receives, which
advises to increase the mbuf size (secondary process) or the MTU
(primary process) to avoid the extra work.

In the copy modes (IPS/TAP), the mbuf chain is what gets forwarded.
Forwarding chains requires the multi-segment TX offload, which replaces
MBUF_FAST_FREE and selects a slower TX path on some NICs. As mbufs sized
from the MTU rarely lead to chains on physical NICs, forwarding them is
opt-in through the new tx-segmented-mbufs interface setting (default
false), which both copy interfaces must share. When a copy interface
does not advertise multi-segment TX, a warning is logged at startup and
chains are transmitted anyway, as many virtual PMDs transmit them
correctly without advertising the offload.

Chains that cannot be inspected in full or forwarded are dropped when
received:
- malformed chains, whose segments do not add up to the packet length,
- chains that cannot be merged and exceed the maximum packet size,
- chains that cannot be merged and whose copy fails, as the buffer for a
  packet above the default packet size cannot be allocated,
- in the copy modes, chains that cannot be merged while
  tx-segmented-mbufs is disabled, that have more segments than the copy
  interface can transmit, or that have an empty segment.

DPDK treats a chain with an empty segment as valid, rte_pktmbuf_adj()
and rte_pktmbuf_trim() produce such chains, and merging or copying them
works. Some drivers cannot transmit them though: ice, for example,
rejects them in rte_eth_tx_prepare(), which Suricata does not call. So
only the chains that would be transmitted as received are dropped.

The copy interface is asked for its segment limit when the worker
threads start to receive packets. All interfaces are configured by
then, while e.g. a bond port does not know the limits of its members
before its first configuration.

The drops are counted in capture.dpdk.segmented_drops, the oversized
chains in capture.dpdk.segmented_too_large. In IPS mode, they are also
counted in ips.blocked with the new capture_error drop reason, so that
the drop reasons explain the blocked packets. In each worker thread, the
first drop for each reason logs a warning.

When inline stream normalization modifies a packet that was copied from
a chain, the data is written back to the chain before it is transmitted.
The packet is written back only if no segment of the chain is shared (an
indirect mbuf, or an mbuf or external buffer with more than one
reference, as handed over by a primary application that clones or keeps
references to its mbufs). Otherwise, the modified packet is freed
instead of transmitted, counted in capture.dpdk.shared_mbuf_drops, and a
warning is logged once per worker thread. The verdict accounting
precedes the release, so such a packet has no drop event and is still
counted as forwarded: in ips.replaced in IPS mode and in ips.accepted in
firewall mode.

Ticket: 6012

Co-authored-by: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
A packet received in a contiguous mbuf points directly to the mbuf data,
so inline stream normalization rewrites the mbuf in place. When the mbuf
is shared (an indirect mbuf, or an mbuf or external buffer with more
than one reference, as handed over by a primary application that clones
or keeps references to its mbufs), this also changes the data for its
other holders. This behavior predates the segmented mbuf support.

When inline stream normalization is enabled, copy the data of a shared
contiguous mbuf into the packet's buffer, so that the modifications land
in the copy. On release, such a packet is handled like a copied chain:
an unmodified packet is forwarded as received, a modified one is written
back only if no segment is shared anymore, and is otherwise freed and
counted in capture.dpdk.shared_mbuf_drops.

Mbufs that are not shared still point to the mbuf data. Without inline
stream normalization nothing rewrites packet data, so shared contiguous
mbufs are not copied either, e.g. in an IDS secondary process that
receives clones of all packets.

The copy can only fail when the buffer for a packet above the default
packet size cannot be allocated. Such a packet is dropped before
inspection, counted in capture.dpdk.shared_mbuf_drops and, in IPS mode,
in ips.blocked with the capture_error drop reason.

Ticket: 6012
Suricata sizes its mbufs from the configured MTU. A device that does not
support setting the MTU, e.g. net_pcap, is not limited by it and can
deliver frames larger than one mbuf. From DPDK 26.07, net_pcap delivers
such frames, as segmented mbufs, only with the RX scatter offload
enabled, and drops them otherwise.

Enable RX scatter on the devices for which rte_eth_dev_set_mtu() returns
-ENOTSUP and that offer the offload, and log it. Offloads are part of
the port configuration, while the MTU can only be set on a configured
port: on an unconfigured one the call fails with -EINVAL or, before
DPDK 21.11, reaches a driver that is not ready for it. So the port,
which is not started yet, is configured again with the offload.

Devices that accept the MTU keep RX scatter disabled. Frames within the
MTU fit into one mbuf there, and the offload alone selects slower RX
paths on several NICs, e.g. it disables the vector RX and TX paths of
bnxt. A bond port accepts the MTU when all of its members do. There is
no configuration option for the offload.

Ticket: 6012
Copilot AI balanced review requested due to automatic review settings November 26, 2026 22:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@suricata-review-bot suricata-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI-generated review.

Verdict: approve

No high- or medium-severity findings.

Automated at commit 819c4f70da28 using Claude Code with claude-opus-5-5/xhigh. Run: e76c8e7216c2f6d7.

@suricata-qa

Copy link
Copy Markdown

WARNING:

field baseline test %
SURI_TLPW2_single_stats_chk
.decoder.event.erspan.unsupported_encapsulation - 0 -
SURI_TLPW2_autofp_stats_chk
.decoder.event.erspan.unsupported_encapsulation - 0 -
SURI_TLPW1_stats_chk
.decoder.event.erspan.unsupported_encapsulation - 0 -
SURI_TLPR1_stats_chk
.decoder.event.erspan.unsupported_encapsulation - 0 -
IPS_AFP_stats_chk
.ips.drop_reason.capture_error - 0 -
.decoder.event.erspan.unsupported_encapsulation - 0 -
TREX_GENERIC_stats_chk
.decoder.event.erspan.unsupported_encapsulation - 0 -

Pipeline = 36152

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.85232% with 107 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.95%. Comparing base (2dd24e7) to head (819c4f7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16750      +/-   ##
==========================================
- Coverage   83.98%   83.95%   -0.03%     
==========================================
  Files        1008     1008              
  Lines      286748   286967     +219     
==========================================
+ Hits       240832   240937     +105     
- Misses      45916    46030     +114     
Flag Coverage Δ
fuzzcorpus 61.59% <0.00%> (-0.01%) ⬇️
livemode 26.40% <54.85%> (+0.47%) ⬆️
netns 26.29% <50.00%> (-0.03%) ⬇️
pcap 46.20% <0.00%> (-0.03%) ⬇️
suricata-verify 69.08% <50.00%> (-0.05%) ⬇️
unittests 59.24% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@victorjulien victorjulien added this to the 9.0 milestone Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants