← Back to Pull requests

lib: log: support packet 5-tuple logging #578

Closed
unknown closed this pull request without merging on Sep 08, 2026 12:50 UTC
View on GitHub
unknown unknown commented on Aug 11, 2026 20:44 UTC
Author

<!--
Thanks for contributing to bpfilter.

Before opening this PR: you should understand and stand behind every line in it,
and you should have built and tested it with the real workflow, not a one-off
compile. If you used AI for any of it, that's fine, just say so below. See
https://bpfilter.io/developers/contributing.html for the details.

Fill in the sections below and remove the irrelevant ones.
-->

Summary

Add log 5-tuple as an exclusive packet logging mode.

The implementation introduces a dedicated ELF stub that emits compact records
containing source and destination addresses, source and destination ports, and
the transport protocol. It supports complete IPv4/IPv6 TCP/UDP tuples while
preserving the existing fixed-size struct bf_log reservation and ring-buffer
capacity.

Unsupported packets do not emit a tuple record or fall back to raw-header
logging. Their counters, marks, verdicts, and normal rule execution remain
unchanged.

<!-- What does this change do, and why? Keep it to the point. -->

Related issue

<!-- e.g. "Fixes #123". If there is no issue, explain why the change is needed. -->

Fixes #568

Testing

Added coverage for:

  • valid log 5-tuple syntax, with and without every

  • rejection of combinations with packet-layer options

  • rejection on cgroup_sock_addr

  • option conversion and rule serialization

  • IPv4 and IPv6 with TCP and UDP

  • tuple addresses, ports, protocols, rule ID, and verdict

  • no tuple record for ICMP and non-IP packets

  • counters and verdicts when tuple logging is skipped

  • unsupported packets not consuming the rate-limit interval

  • unchanged raw-header logging behaviour
  • Debug build with sanitizers and coverage enabled:

    100% tests passed, 0 tests failed out of 122
    
    Label Time Summary:
    check          = 16.28 sec*proc (2 tests)
    e2e            = 99.33 sec*proc (94 tests)
    integration    =  0.14 sec*proc (2 tests)
    unit           =  0.65 sec*proc (23 tests)
    

    Release build:

    100% tests passed, 0 tests failed out of 122
    
    Label Time Summary:
    check          = 15.02 sec*proc (2 tests)
    e2e            = 57.04 sec*proc (94 tests)
    integration    =  0.14 sec*proc (2 tests)
    unit           =  0.22 sec*proc (23 tests)
    

    Additional passed verification:

  • make -C build-issue568 fixstyle

  • make -C build-issue568 test_bin test

  • make -C build-issue568 doc

  • debug ASan/UBSan execution

  • coverage generation — 84.4% lines and 95.5% functions

  • final lint, IWYU, checkstyle, and diff whitespace checks
  • <!--
    How did you verify this? Describe the build and tests you actually ran, not what
    you expect CI to do. Configure and build with CMake as the developer docs
    describe, run make -C $BUILD test_bin test, and make -C $BUILD doc if you
    changed the documentation.

    If this is one of your first PRs here, paste the relevant test output below. The
    summary line and pass counts are enough.
    -->

    Notes for the reviewer

    5-tuple is mutually exclusive with link, internet, and transport.
    Tuple records are emitted only for IPv4/IPv6 packets using TCP or UDP, following
    the eligibility behaviour discussed in #568. The eligibility check happens
    before rate-limit bookkeeping, so an unsupported packet does not consume the
    rule's every interval.
    cgroup_sock_addr is intentionally unsupported for this mode. Existing raw
    packet logging and socket-address logging remain unchanged.
    The new log type and ELF-stub identifiers are appended so existing identifier
    values remain stable.

    <!--
    Optional. Anything I should know: open questions, deliberate scope limits,
    tradeoffs you made, or areas you want feedback on. Flagging these here saves a
    round trip.
    -->

    AI disclosure


    I used AI for codebase exploration, understanding the existing logging and BPF
    code-generation paths, design iteration, parts of the implementation and tests,
    verification, review, and wording of this PR.
    I reviewed the resulting design and test evidence and remain responsible for
    the submitted changes.
    <!--
    First, read https://bpfilter.io/developers/contributing.html.

    Did you use AI for any part of this (code, tests, this description)? Say so and
    roughly for what. "None" is a fine answer. Undisclosed AI is grounds for closing
    the PR.
    -->

    Checklist

  • I understand every line in this PR and can explain why it is correct

  • I built the project and ran the tests covering this change

  • make -C $BUILD test_bin test passes and the code follows the style guide

  • Commits are formatted as component: subcomponent: short description

  • I have disclosed any AI usage above
  • Diff: 589 lines (+441 / -148) across 7 files Reviewer: blackdragoon26 Review duration: 39845m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 589 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.382
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #578"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.0% (MEDIUM) · Higher = larger blast radius
    50.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.7% · Safe to merge
    19.7%
    Repository