Skip to content

Af xdp fixes 8780 v5 - #16743

Open
Aboussejra wants to merge 5 commits into
OISF:mainfrom
Aboussejra:af-xdp-fixes-8780-v5
Open

Aboussejra wants to merge 5 commits into
OISF:mainfrom
Aboussejra:af-xdp-fixes-8780-v5

Conversation

@Aboussejra

Copy link
Copy Markdown

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

Describe changes:

Series of fixes for AF_XDP capture mode, tested on suricata 8.0.6 base:

  • WriteLinuxTunables fails when interface altname is used. Tunables were written using the name from suricata.yaml verbatim; when an altname is configured, the sysfs path does not exist. Added a commit to resolve the real netdev name before writing tunables.
  • XSK creation broken with 2 capture interfaces. Socket setup logic failed when two interfaces were configured for capture; fixed XSK creation path so multi-interface capture works.
  • Added XSK visibility about drops in stats.log. For diagnosing capture issues.
  • UMEM size not configurable. UMEM was hardcoded; added sizing option to the af-xdp section of suricata.yaml.

Provide values to any of the below to override the defaults.

  • To use a Suricata-Verify or Suricata-Update pull request,
    link to the pull request in the respective _BRANCH variable.
  • Leave unused overrides blank or remove.

SV_REPO=
SV_BRANCH=
SU_REPO=
SU_BRANCH=

…ltname used in suricata config

WriteLinuxTunables built the sysfs path from the configured interface
name. When an altname is used in the config, sysfs only exposes the
real netdev name and writing gro_flush_timeout/napi_defer_hard_irqs
failed. Resolve the real name via if_indextoname before building the
path.

Ticket: OISF#8780
The XSK queue id counter was global, so with two capture interfaces
the second interface's threads got queue ids continuing after the
first interface's, and xsk_socket__create failed for queues that do
not exist on that device. Make the counter per interface config and
assign ids with a single atomic fetch-and-add at thread init.

Ticket: OISF#8780
UMEM size was hardcoded to XSK ring default descriptors * 2 with
default frame size. Add umem-frames and frame-size options to the
af-xdp section so buffer memory can be tuned per interface.

Ticket: OISF#8780
Expose xsk_socket stats in stats.log: capture.afxdp.rx_dropped,
rx_invalid_descs, rx_ring_full and fill_ring_empty. Helps diagnose
whether kernel drops come from.

Ticket: OISF#8780
AF_XDP capture is receive only

Ticket: OISF#8780
@Aboussejra
Aboussejra requested review from a team and victorjulien as code owners November 26, 2026 09:12
@github-actions

Copy link
Copy Markdown

NOTE: This PR may contain new authors.

@lukashino

Copy link
Copy Markdown
Contributor

Hi @Aboussejra thank you for the next revision!

Can you please try the rebase once again and review the feedback from my review bot below?

Section " Missing or wrong in the PR":
Points 1 - 5 seem easy and very relevant. Points 6-7 seem like low-severity so that's not a blocker from my side. Additionally, proposing a live Suricata-verify test can greatly help (and will also prevent "push races" because you pin your PR to one version of SV testsuite PR ;) )

Section "Nits" would be best to address all of it.

I will leave "Design questions" to your consideration.

So the next version could have points 1-5 + nits addressed.

CI failures: not caused by this PR

  - Stale base: all 19 failed jobs in the main run fail on the same three SV tests: smtp-frames-offset-01, smtp-frames-offset-02 and tls-dual-match-sni-cert. The PR is based on 1f762c1a3 (Nov 24), and SV master already has tests for three main commits from Nov 26
    (be18217ab, 144ee6d83, 82b1eff4c). A rebase on current main should clear them.
  - Infra: "Prepare dependencies" failed with curl: (22) 403, and the "Analyze (rust)" log shows GitHub API rate-limit errors (I did not dig further into that one). A re-run should do.
  - Build side is fine: Commit Check and Formatting Check pass. I also built each of the five commits locally with AF_XDP enabled; all build.

  Confirmed working

  Tested on veth pairs, kernel 6.12, libxdp 1.6.2, copy mode only. Baseline is the local main build 9451642a2, whose af-xdp sources are identical to the PR's base.

  - Two interfaces: baseline fails on the second one with Failed to create socket: Invalid argument; the PR starts both.
  - Altname: baseline logs Could not open file: /sys/class/net/mon0/gro_flush_timeout and the busy-poll warning; the PR is clean.
  - Defaults unchanged: 4096 frames of 4096 bytes, rx ring 2048, 16 MiB per thread.
  - No TX ring: capture still works (1000 of 1000 packets).
  - New counters: they separate the drop causes correctly (rx_ring_full with a small UMEM, rx_dropped for oversized frames).
  - Your v2 review points (atomic init, power-of-two check, TX ring removal) are all addressed.

  Missing or wrong in the PR

  1. Docs not updated. doc/userguide/capture-hardware/af-xdp.rst has no umem-frames or frame-size, and the new counters are undocumented. Its "Memory assigned per socket/thread is 16MB" text and hugepage example are wrong once the size is configurable.
  2. Schema not updated. The four counters appear in EVE as stats.capture.afxdp.*, but etc/schema.json has additionalProperties: false on capture and no afxdp object at all. The existing afxdp counters are already missing there.
  3. frame-size is only checked for power of two. 1024 and 8192 pass parsing and then die with a bare failed to create umem: Invalid argument. The yaml comment itself says only 2048 or 4096 are valid, so the parser should reject the rest and name the option.
  4. No check of frame-size against MTU. With frame-size: 2048 on an MTU 3000 link, Suricata starts silently and drops 1000 of 1000 2500-byte frames as rx_dropped. This supports your v2 suggestion; a startup warning would be enough.
  5. umem-frames has no bounds:
     - -5 and 0 silently fall back to the default.
     - 4294971392 silently becomes 4096 (uint32 truncation).
     - 4294967296 reports "(0) must be a power of two".
     - 1 is accepted, logs rx-ring-size 0, and captured 20 of 1000 packets.
  6. mem-unaligned: yes with a UMEM that is not a hugepage multiple. With umem-frames: 256, munmap(1 MiB) at deinit fails with EINVAL and the return is unchecked. This leaks only at shutdown, so low severity; rounding the size up or rejecting it would fix it.
  7. Counters go backwards after a socket reopen. After an interface down/up I saw kernel_drops and rx_dropped go 500 → 0 → 300. kernel_drops already behaves this way on main; the PR copies the pattern to four more counters.

  Nits

  - QueueAssignment.assigned is now write-only. The AFXDPQueueProtectionInit comment and the queue_protect name are stale, since the mutex now only serialises xsk_socket__create.
  - isPowerOfTwo should follow Suricata naming (IsPowerOfTwo), and the geeksforgeeks URL comment can go.
  - Commit 1's subject is 99 characters. Commit 4's message ends mid-sentence ("Helps diagnose whether kernel drops come from.").
  - mmap: failed to acquire memory should print the size and errno, and hint at hugepages, now that the size is user-controlled.

  Design questions

  - Ring coupling: the rx ring is fixed at umem-frames / 2 and the fill ring at the whole UMEM. This is undocumented; should it be documented or separately configurable?
  - Counter overlap: in copy mode fill_ring_empty counts the same events as rx_dropped (both were 980 in one run), so they are not additive. From reading the kernel, in zero-copy mode those drops happen in the NIC and never reach capture.kernel_drops; I could not test
    zero-copy.
  - Long altnames: names of 16 or more characters still fail earlier in the ioctl helpers (unable to set device flags: No such device), so the fix covers short altnames only.
  - Tests: there is no af-xdp test in SV live, so nothing guards the two-interface fix.

Thank you.

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.

2 participants