Skip to content

network: Handle baraketed ipv6 addresses#11676

Open
cosmo0920 wants to merge 2 commits intomasterfrom
cosmo0920-handle-baraketed-ipv6-addresses
Open

network: Handle baraketed ipv6 addresses#11676
cosmo0920 wants to merge 2 commits intomasterfrom
cosmo0920-handle-baraketed-ipv6-addresses

Conversation

@cosmo0920
Copy link
Copy Markdown
Contributor

@cosmo0920 cosmo0920 commented Apr 6, 2026

Closes #11668.


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
service:
    flush:           1
    daemon:          off
    log_level:       debug
    hot_reload:      on
    http_server:     on
    http_listen:     "[::]"

pipeline:
    inputs:
        - name: random
          tag:  test

    filters:
        - name: lua
          match: "*"
          call: append_tag
          code: |
            function append_tag(tag, timestamp, record)
              new_record = record
              new_record["tag"] = tag
              return 1, timestamp, new_record
            end
    outputs:
        - name: stdout
          match: "*"
  • Debug log output from testing the change
Fluent Bit v5.0.2
* Copyright (C) 2015-2026 The Fluent Bit Authors
* Fluent Bit is a CNCF graduated project under the Fluent organization
* https://fluentbit.io

______ _                  _    ______ _ _           _____  _____ 
|  ___| |                | |   | ___ (_) |         |  ___||  _  |
| |_  | |_   _  ___ _ __ | |_  | |_/ /_| |_  __   _|___ \ | |/' |
|  _| | | | | |/ _ \ '_ \| __| | ___ \ | __| \ \ / /   \ \|  /| |
| |   | | |_| |  __/ | | | |_  | |_/ / | |_   \ V //\__/ /\ |_/ /
\_|   |_|\__,_|\___|_| |_|\__| \____/|_|\__|   \_/ \____(_)\___/


[2026/04/06 16:17:55.706] [ info] Configuration:
[2026/04/06 16:17:55.706] [ info]  flush time     | 1.000000 seconds
[2026/04/06 16:17:55.706] [ info]  grace          | 5 seconds
[2026/04/06 16:17:55.706] [ info]  daemon         | 0
[2026/04/06 16:17:55.706] [ info] ___________
[2026/04/06 16:17:55.706] [ info]  inputs:
[2026/04/06 16:17:55.706] [ info]      random
[2026/04/06 16:17:55.706] [ info] ___________
[2026/04/06 16:17:55.706] [ info]  filters:
[2026/04/06 16:17:55.706] [ info]      lua.0
[2026/04/06 16:17:55.706] [ info] ___________
[2026/04/06 16:17:55.706] [ info]  outputs:
[2026/04/06 16:17:55.706] [ info]      stdout.0
[2026/04/06 16:17:55.706] [ info] ___________
[2026/04/06 16:17:55.706] [ info]  collectors:
[2026/04/06 16:17:55.706] [ info] [fluent bit] version=5.0.2, commit=24a62bc6f2, pid=1514
[2026/04/06 16:17:55.706] [debug] [engine] coroutine stack size: 36864 bytes (36.0K)
[2026/04/06 16:17:55.706] [ info] [storage] ver=1.4.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2026/04/06 16:17:55.706] [ info] [simd    ] NEON
[2026/04/06 16:17:55.706] [ info] [cmetrics] version=2.1.1
[2026/04/06 16:17:55.706] [ info] [ctraces ] version=0.7.1
[2026/04/06 16:17:55.706] [ info] [input:random:random.0] initializing
[2026/04/06 16:17:55.706] [ info] [input:random:random.0] storage_strategy='memory' (memory only)
[2026/04/06 16:17:55.706] [debug] [random:random.0] created event channels: read=21 write=22
[2026/04/06 16:17:55.706] [debug] [input:random:random.0] interval_sec=1 interval_nsec=0
[2026/04/06 16:17:55.707] [debug] [stdout:stdout.0] created event channels: read=23 write=24
[2026/04/06 16:17:55.707] [ info] [output:stdout:stdout.0] worker #0 started
[2026/04/06 16:17:55.707] [debug] [downstream] listening on [::]:2020
[2026/04/06 16:17:55.707] [ info] [http_server] listen iface=[::] tcp_port=2020
[2026/04/06 16:17:55.707] [ info] [sp] stream processor started
[2026/04/06 16:17:55.707] [ info] [engine] Shutdown Grace Period=5, Shutdown Input Grace Period=2
^C[2026/04/06 16:17:57] [engine] caught signal (SIGINT)
[2026/04/06 16:17:57.706] [ info] [input] pausing random.0
[2026/04/06 16:17:57.706] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2026/04/06 16:17:57.706] [ info] [output:stdout:stdout.0] thread worker #0 stopped
  • Attached Valgrind output that shows no leaks or memory corruption was found

leaks command's result on macOS:

Process 1802 is not debuggable. Due to security restrictions, leaks can only show or save contents of readonly memory of restricted processes.

Process:         fluent-bit [1802]
Path:            /Users/USER/*/fluent-bit
Load Address:    0x10274c000
Identifier:      fluent-bit
Version:         0
Code Type:       ARM64
Platform:        macOS
Parent Process:  leaks [1801]
Target Type:     live task

Date/Time:       2026-04-06 16:19:02.607 +0900
Launch Time:     2026-04-06 16:18:55.330 +0900
OS Version:      macOS 26.3.1 (25D2128)
Report Version:  7
Analysis Tool:   /Applications/Xcode.app/Contents/Developer/usr/bin/leaks
Analysis Tool Version:  Xcode 26.4 (17E192)

Physical footprint:         7681K
Physical footprint (peak):  7793K
Idle exit:                  untracked
----

leaks Report Version: 4.0, multi-line stacks
Process 1802: 1257 nodes malloced for 197 KB
Process 1802: 0 leaks for 0 total leaked bytes.

[2026/04/06 16:19:03] [engine] caught signal (SIGCONT)
[2026/04/06 16:19:03] [engine] caught signal (SIGHUP)

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

  • Bug Fixes

    • Proper handling of IPv6 addresses in bracket notation (e.g., [::1]) when configuring servers, improving reliability across environments.
  • Tests

    • Added targeted test coverage for listening on bracketed IPv6 addresses to prevent regressions.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3ff002ad-3bbe-4014-b640-2fcce4204db1

📥 Commits

Reviewing files that changed from the base of the PR and between 6ca2baa and 88795b1.

📒 Files selected for processing (2)
  • src/flb_network.c
  • tests/internal/network.c
✅ Files skipped from review due to trivial changes (1)
  • src/flb_network.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/internal/network.c

📝 Walkthrough

Walkthrough

Normalize bracketed IPv6 listen addresses (e.g., [::1]) by stripping surrounding brackets before calling getaddrinfo in server/UDP server setup; add a test verifying bracketed IPv6 listen behavior.

Changes

Cohort / File(s) Summary
IPv6 Bracket Normalization
src/flb_network.c
Detect bracketed IPv6 literals, allocate listen_addr_copy with the unbracketed address, use normalized_listen_addr for getaddrinfo, and ensure listen_addr_copy is freed on all paths; add newline at EOF.
IPv6 Bracketed Address Test
tests/internal/network.c
Add TEST_HOSTv6_BRACKETED and test_ipv6_bracketed_listen() which calls flb_net_server with "[::1]", tolerates EAFNOSUPPORT as skip, asserts successful fd otherwise, and register the test in TEST_LIST.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • edsiper

Poem

🐰 Brackets trimmed with gentle care,
IPv6 hops out into the air.
Bind succeeds, no more despair,
I nibble bugs and leave it fair.
🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title contains a typo ('baraketed' instead of 'bracketed'), but clearly describes the main change: handling bracketed IPv6 addresses in network setup.
Linked Issues check ✅ Passed Changes directly address issue #11668 by normalizing bracketed IPv6 addresses (stripping brackets before getaddrinfo), implementing tests, and resolving the startup crash on IPv6-only deployments.
Out of Scope Changes check ✅ Passed All changes are directly related to handling bracketed IPv6 addresses: implementation in flb_network.c, corresponding tests in network.c, and one EOF newline addition unrelated to core functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cosmo0920-handle-baraketed-ipv6-addresses

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
Copy Markdown

@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.

Reviewed commit: 51b44da9e3

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

FLB_NETWORK_DEFAULT_BACKLOG_SIZE,
FLB_FALSE);

if (errno == EAFNOSUPPORT) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate EAFNOSUPPORT skip on server creation failure

The new test checks errno == EAFNOSUPPORT unconditionally, but errno is not reset on success, so a stale value from an earlier syscall can cause this test to return early even when flb_net_server(...) succeeded. In that case the assertion is skipped and the opened socket is leaked, which can hide regressions and make the internal network suite flaky. Check errno only when fd_server == -1.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@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

🧹 Nitpick comments (2)
tests/internal/network.c (1)

163-181: Add a UDP bracketed IPv6 regression test as well.

This PR changes both flb_net_server() and flb_net_server_udp() in src/flb_network.c, but only TCP has bracketed-address coverage. Add a focused flb_net_server_udp(TEST_PORT, "[::1]", ...) test and register it in TEST_LIST.

As per coding guidelines: tests/**/*.{c,h,py}: Add or update tests for behavior changes, especially protocol parsing and encoder/decoder paths.

Also applies to: 186-186

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/internal/network.c` around lines 163 - 181, Add a UDP counterpart to
the existing TCP bracketed IPv6 test by creating a new test function (e.g.,
test_ipv6_bracketed_udp_listen) that calls flb_net_server_udp(TEST_PORT,
TEST_HOSTv6_BRACKETED or "[::1]", FLB_NETWORK_DEFAULT_BACKLOG_SIZE, FLB_FALSE),
handles EAFNOSUPPORT the same way, checks the returned fd != -1, and closes it
if opened; then register this new test name in the TEST_LIST array so the UDP
bracketed-address parsing change is covered. Ensure the new test mirrors the
structure and error handling of test_ipv6_bracketed_listen and uses the same
TEST_PORT/TEST_HOSTv6_BRACKETED symbols.
src/flb_network.c (1)

1651-1669: Consider extracting duplicated IPv6 normalization into a small helper.

Both flb_net_server() and flb_net_server_udp() now carry the same normalization block; a shared helper would reduce drift risk and keep behavior aligned.

♻️ Suggested refactor sketch
+static const char *flb_net_normalize_listen_addr(const char *listen_addr,
+                                                  char **allocated_copy)
+{
+    size_t listen_addr_len;
+
+    *allocated_copy = NULL;
+    if (listen_addr != NULL && listen_addr[0] == '[') {
+        listen_addr_len = strlen(listen_addr);
+        if (listen_addr_len >= 3 && listen_addr[listen_addr_len - 1] == ']') {
+            *allocated_copy = flb_strndup(listen_addr + 1, listen_addr_len - 2);
+            if (*allocated_copy != NULL) {
+                return *allocated_copy;
+            }
+        }
+    }
+    return listen_addr;
+}

Also applies to: 1725-1743

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/flb_network.c` around lines 1651 - 1669, Extract the IPv6
bracket-stripping logic into a small helper (e.g.,
flb_net_normalize_listen_addr) that takes const char *listen_addr and returns a
newly allocated char* containing the unbracketed address or NULL if no
allocation was needed/fails; update both flb_net_server and flb_net_server_udp
to call this helper, use the returned pointer as the normalized address when
non-NULL, and free it after use to avoid leaks; ensure the helper encapsulates
the length checks (>=3 and trailing ']') and uses flb_strndup like the original
code so behavior remains identical.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/internal/network.c`:
- Around line 171-174: The code checks errno == EAFNOSUPPORT without first
verifying the syscall failed; only check errno when the call returned -1. Locate
the conditional that compares errno to EAFNOSUPPORT (the block returning early
with TEST_MSG "This protocol is not supported in this platform") and change it
to guard on the syscall's return value (e.g., if (ret == -1 && errno ==
EAFNOSUPPORT) or if (fd < 0 && errno == EAFNOSUPPORT)) so stale errno won't
cause an incorrect early return; apply the same pattern to the other similar
check mentioned earlier.

---

Nitpick comments:
In `@src/flb_network.c`:
- Around line 1651-1669: Extract the IPv6 bracket-stripping logic into a small
helper (e.g., flb_net_normalize_listen_addr) that takes const char *listen_addr
and returns a newly allocated char* containing the unbracketed address or NULL
if no allocation was needed/fails; update both flb_net_server and
flb_net_server_udp to call this helper, use the returned pointer as the
normalized address when non-NULL, and free it after use to avoid leaks; ensure
the helper encapsulates the length checks (>=3 and trailing ']') and uses
flb_strndup like the original code so behavior remains identical.

In `@tests/internal/network.c`:
- Around line 163-181: Add a UDP counterpart to the existing TCP bracketed IPv6
test by creating a new test function (e.g., test_ipv6_bracketed_udp_listen) that
calls flb_net_server_udp(TEST_PORT, TEST_HOSTv6_BRACKETED or "[::1]",
FLB_NETWORK_DEFAULT_BACKLOG_SIZE, FLB_FALSE), handles EAFNOSUPPORT the same way,
checks the returned fd != -1, and closes it if opened; then register this new
test name in the TEST_LIST array so the UDP bracketed-address parsing change is
covered. Ensure the new test mirrors the structure and error handling of
test_ipv6_bracketed_listen and uses the same TEST_PORT/TEST_HOSTv6_BRACKETED
symbols.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 83001558-9e9b-4438-a97c-918cd1b9fe84

📥 Commits

Reviewing files that changed from the base of the PR and between 3e414ac and 6ca2baa.

📒 Files selected for processing (2)
  • src/flb_network.c
  • tests/internal/network.c

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
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.

Startup crash due to failure to bind IPv6 address in IPv6 EKS cluster in Fluentbit 5.x.x

1 participant