Skip to content

af-packet: respect vlan.use-for-tracking in eBPF bypass#15458

Closed
ssam18 wants to merge 4 commits into
OISF:mainfrom
ssam18:fix/issue-8242-vlan-mask-ebpf-bypass-v2
Closed

af-packet: respect vlan.use-for-tracking in eBPF bypass#15458
ssam18 wants to merge 4 commits into
OISF:mainfrom
ssam18:fix/issue-8242-vlan-mask-ebpf-bypass-v2

Conversation

@ssam18

@ssam18 ssam18 commented May 25, 2026

Copy link
Copy Markdown
Contributor

Make sure these boxes are checked accordingly before submitting your Pull Request. Thank you.

Contribution style:

Our Contribution agreements:

Changes (if applicable):

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

Supersedes #15430.

AFPBypassCallback and AFPXDPBypassCallback in src/source-af-packet.c now AND p->vlan_id[N] with g_vlan_mask before writing it into the eBPF flow_table_v4 / flow_table_v6 map keys, so the userspace key matches the kernel side when vlan.use-for-tracking is false (kernel side writes zero, so userspace must too).

Affects all 8 insert sites across the two callbacks (IPv4 and IPv6, forward and reverse half-flows), matching the masking pattern already used 30+ times in src/flow-hash.c.

Original patch by John Graat on Redmine #8242, rebased onto current main. The patch in the ticket targeted a vlan2 field that has since been removed from the flowvN_keys struct in src/util-ebpf.h, so only vlan0 and vlan1 are masked here.

The features: add EBPF as a feature commit is cherry-picked from #15446 so the companion suricata-verify test in OISF/suricata-verify#3113 (which uses requires: features: EBPF) can run against this build independently of #15446 merging first.

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=OISF/suricata-verify#3113
SU_REPO=
SU_BRANCH=

ssam18 and others added 2 commits May 20, 2026 11:43
AFPBypassCallback and AFPXDPBypassCallback populate the flow_table_v4 and flow_table_v6 eBPF maps using p->vlan_id[N] directly. When the matching xdp_filter.c program is built with VLAN_TRACKING=0 (i.e. vlan.use-for-tracking is false in suricata.yaml), the kernel side writes vlan0 and vlan1 as 0 on every map lookup, so userspace inserts that carry the real VLAN id never match and per-flow bypass counters stay at zero.

Apply g_vlan_mask to each vlan_id assignment, matching the masking
pattern already used by flow-hash.c. When vlan.use-for-tracking is
true, g_vlan_mask is 0xffff and behaviour is unchanged.

Original patch by John Graat on Redmine ticket 8242. Rebased to
current main and dropped the now-removed vlan2 field.
Ticket: 8242
for SV to run tests based on the presence of this feature
@github-actions

Copy link
Copy Markdown

NOTE: This PR may contain new authors.

@catenacyber

Copy link
Copy Markdown
Contributor

To run the SV part in CI, I think we also need here ea71db4 and 7e996bb

What do you think ?

@catenacyber catenacyber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we need CI to run the test

so as to run ebpf live tests
Ticket: 7674

Allows a compile-time option AFPACKET_TEST_REPLAY, that allows
to set a configuration max-packets per afpacket interface,
after which the PktAcqLoop stops.

This allows suricata-verify tests to run with tcpreplay,
and know when to stop
@ssam18 ssam18 requested a review from jasonish as a code owner May 28, 2026 13:23
@catenacyber

Copy link
Copy Markdown
Contributor

Please open a new PR instead of force-pushing

@SamareshSingh

Copy link
Copy Markdown

Sure. Will do from next time

@catenacyber

Copy link
Copy Markdown
Contributor

Please do it this time

@ssam18

ssam18 commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of #15469 as per @catenacyber's request. Same 4 commits (the vlan-mask fix + EBPF feature + the two SV/CI plumbing picks from #15415), opened as a fresh PR rather than additions on top of this branch.

@ssam18 ssam18 closed this May 28, 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.

3 participants