Skip to content

Conversation

cosmo0920
Copy link
Contributor

@cosmo0920 cosmo0920 commented Oct 17, 2025

FIxes: #10910.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
[INPUT]
    Name    syslog
    Mode    tcp
    Listen  0.0.0.0
    Port    5140
    Frame   octet_counting
    Parser  syslog-rfc5424
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • New Features

    • Added a "format" option to the syslog input to select TCP framing: newline (default) or octet_counting (RFC 6587). Octet-counting supports messages with explicit length prefixes and optional trailing LF.
  • Tests

    • Added tests for octet-counting framing, covering LF/no-LF, fragmented frames, and multiple back-to-back frames.

Copy link

coderabbitai bot commented Oct 17, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds configurable TCP framing to the syslog input via a new "format" option (string). Introduces framing constants, plugin fields (format_str, frame_type), per-connection framing state, dual parsing modes (newline or RFC 6587 octet-counting), and tests covering octet-counting scenarios.

Changes

Cohort / File(s) Summary
Public config & enums
plugins/in_syslog/syslog.h
Added FLB_SYSLOG_FRAME_NEWLINE, FLB_SYSLOG_FRAME_OCTET_COUNTING, and added format_str (flb_sds_t) and frame_type (int) to struct flb_syslog.
Config option & init
plugins/in_syslog/syslog.c, plugins/in_syslog/syslog_conf.c
Added "format" config mapping to format_str (FLB_CONFIG_MAP_STR); initialized frame_type to NEWLINE by default and parse "octet_counting"/"octet" to set OCTET_COUNTING (warn on unknown values).
Connection framing state
plugins/in_syslog/syslog_conn.h, plugins/in_syslog/syslog_conn.c
Added frame_expected_len (size_t) and frame_have_len (int) to struct syslog_conn; initialized both to 0 when creating a connection.
Protocol parsing
plugins/in_syslog/syslog_prot.h, plugins/in_syslog/syslog_prot.c
Added <stdint.h> include; implemented dual framing in syslog_prot_process: keep newline framing path; add RFC 6587 octet-counting parsing (parse leading length, set expected len/state, validate availability, advance/reset state, optionally consume trailing LF).
Tests
tests/runtime/in_syslog.c
Added helpers (rstrip_nl_copy, build_octet_frame, build_two_frames) and four tests for octet-counting over TCP: simple, with LF, fragmented, and multi-frame sequences; added to TEST_LIST.

Sequence Diagram(s)

sequenceDiagram
    participant TCP as TCP Stream
    participant Parser as syslog_prot_process
    participant NL as Newline Path
    participant OC as Octet-Counting Path
    participant Output as Message Emitter

    TCP->>Parser: Deliver data buffer
    Parser->>Parser: Check flb_syslog.frame_type

    alt frame_type == NEWLINE
        Parser->>NL: Scan buffer for '\n' or '\0'
        NL->>Output: Emit message (line)
        NL->>Parser: Advance buffer by len + 1
    else frame_type == OCTET_COUNTING
        Parser->>OC: Parse leading digits until space -> len
        OC->>OC: Set frame_expected_len & frame_have_len
        OC->>OC: Ensure len bytes available
        OC->>Output: Emit message (len bytes)
        OC->>OC: Reset frame_expected_len & frame_have_len
        OC->>OC: Optionally consume trailing '\n'
        OC->>Parser: Advance buffer accordingly
    end

    Parser->>TCP: Await next data
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I counted bytes and hopped with cheer,

A number then space — the log is near.
Newlines still sing, octets now chime,
Messages line up, one at a time.
Hopping through packets, I keep perfect time.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "in_syslog: Add support for RFC 6587 octet-counting" directly and accurately describes the main change being implemented. The title is concise, specific about both the component (in_syslog plugin) and the feature being added (RFC 6587 octet-counting support), and clearly conveys the primary objective of this changeset without extraneous details. The changes in the pull request align perfectly with this title description.
Linked Issues Check ✅ Passed The pull request successfully implements all primary coding requirements from linked issue #10910. It adds RFC 6587 octet-counting framing support through dual-mode framing logic in syslog_prot.c (keeping newline as default while adding octet-counting), provides an optional "format" configuration parameter in syslog.c, introduces frame-type tracking constants and state fields in syslog.h/syslog_conn.h, implements frame parsing and state management logic in syslog_conf.c and syslog_prot.c, and includes comprehensive test coverage for octet-counting scenarios including fragmentation and multiple frames.
Out of Scope Changes Check ✅ Passed All code changes in this pull request are directly related to implementing RFC 6587 octet-counting framing support as specified in issue #10910. The modifications span configuration handling, data structure definitions, framing logic implementation, state management, and comprehensive test coverage, all targeted at adding octet-counting support to the syslog input plugin. No unrelated refactoring, bug fixes for different issues, or incidental feature additions were detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cosmo0920-handle-octet_counting

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cccd679 and d096aaa.

📒 Files selected for processing (1)
  • plugins/in_syslog/syslog_prot.h (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (30)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: PR - fuzzing test
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-without-cxx (3.31.6)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-centos-7

The term of frame is a bit of low level concept for users.

Signed-off-by: Hiroshi Hatake <[email protected]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/runtime/in_syslog.c (1)

323-354: Consider simplifying the truncation logic.

The defensive truncation code (lines 338-345) has a logic issue: if truncation occurs, mlen isn't reduced and the header's length field isn't recalculated, which could lead to writing mlen bytes even when the buffer can only hold less. Since the comment acknowledges buffers should be adequate in tests, consider either removing the truncation entirely or adding an assertion instead.

Example simplification:

-    if (need + 1 > outsz) {
-        /* truncate conservatively if buffer too small (shouldn't happen in tests) */
-        need = outsz - 1;
-        add_lf = 0;
-        if ((size_t)hlen > need) {
-            hlen = (int)need;
-        }
-    }
+    /* Buffers in tests should always be adequate */
+    if (need + 1 > outsz) {
+        return 0;  /* or assert */
+    }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 005d02d and 144bbd1.

📒 Files selected for processing (4)
  • plugins/in_syslog/syslog.c (1 hunks)
  • plugins/in_syslog/syslog.h (2 hunks)
  • plugins/in_syslog/syslog_conf.c (1 hunks)
  • tests/runtime/in_syslog.c (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/in_syslog/syslog.c
🧰 Additional context used
🧬 Code graph analysis (1)
tests/runtime/in_syslog.c (1)
src/flb_lib.c (2)
  • flb_input_set (300-330)
  • flb_start (914-925)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (27)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: pr-compile-without-cxx (3.31.6)
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: PR - fuzzing test
🔇 Additional comments (10)
plugins/in_syslog/syslog_conf.c (1)

110-121: LGTM! Frame type initialization is well-structured.

The framing initialization correctly defaults to newline, handles both "octet_counting" and "octet" variants, and provides helpful feedback for invalid values.

plugins/in_syslog/syslog.h (2)

36-39: LGTM! Framing constants are well-defined.

The constants use clear naming and the zero-value for NEWLINE provides a safe default.


74-76: LGTM! Struct fields are properly typed and positioned.

tests/runtime/in_syslog.c (7)

308-321: LGTM! String helper is safe and correct.

The function properly handles buffer bounds, null-termination, and edge cases.


356-365: LGTM! Frame concatenation is clean and correct.


1064-1124: LGTM! Basic octet counting test is properly structured.

The test correctly configures the plugin with format=octet_counting and validates the core framing functionality.


1127-1187: LGTM! Trailing LF test covers RFC 6587 optional trailer.

This correctly validates that the implementation handles the optional line feed trailer permitted by RFC 6587 section 3.4.1.


1190-1266: LGTM! Fragmentation test validates crucial TCP stream handling.

This test ensures the implementation correctly buffers partial frames and reassembles them, which is essential for reliable TCP-based syslog ingestion.


1269-1332: LGTM! Multi-frame test validates boundary detection.

This test ensures back-to-back frames are correctly parsed and separated, which is critical for high-throughput scenarios.


1352-1355: LGTM! TEST_LIST properly updated.

All four new tests are correctly registered and follow existing naming conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for RFC 6587 octet-counting in Fluent-Bit syslog input plugin

2 participants