Skip to content

NETOBSERV-2273: support multiple DNS tracking ports via comma-separated list#994

Open
OlivierCazade wants to merge 1 commit into
netobserv:mainfrom
OlivierCazade:dns-ports
Open

NETOBSERV-2273: support multiple DNS tracking ports via comma-separated list#994
OlivierCazade wants to merge 1 commit into
netobserv:mainfrom
OlivierCazade:dns-ports

Conversation

@OlivierCazade

@OlivierCazade OlivierCazade commented Jun 19, 2026

Copy link
Copy Markdown
Member

Description

Update DNS_TRACKING_PORT to accept comma-separated port values while maintaining backward compatibility with single port configuration.

Changes:

  • Add support for up to 8 DNS ports (MAX_DNS_PORTS)
  • Replace single dns_port with dns_ports array in eBPF config
  • Remove hardcoded port 53 check in track_dns_packet()
  • Add is_dns_port() helper with bounded loop for eBPF verifier
  • Update config to parse DNS_TRACKING_PORT as comma-separated string
  • Update documentation with multi-port usage examples

Examples:

  • DNS_TRACKING_PORT=53 (single port, backward compatible)
  • DNS_TRACKING_PORT=53,5353,8053 (multiple ports)

Dependencies

n/a

Checklist

  • Does the changes in PR need specific configuration or environment set up for testing?
    • if so please describe it in PR description.
  • I have added thorough unit tests for the change.
  • QE requirements (check 1 from the list):
    • Standard QE validation, with pre-merge tests unless stated otherwise.
    • Regression tests only (e.g. refactoring with no user-facing change).
    • No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team).

To run a perfscale test, comment with: /test ebpf-node-density-heavy-25nodes

Summary by CodeRabbit

  • New Features
    • DNS tracking now supports monitoring multiple DNS ports simultaneously (up to 8) via DNS_TRACKING_PORT as a comma-separated list (default: 53, e.g., 53,5053).
  • Bug Fixes
    • DNS packet filtering now matches traffic when either the source or destination port is in the configured port list (instead of a single port).
  • Documentation
    • Updated DNS_TRACKING_PORT docs with multi-port format and max supported count.
  • Tests
    • Added tests covering parsing behavior, whitespace trimming, truncation to 8 ports, invalid/empty entries, edge ports, and config disabled behavior.

@openshift-ci-robot

openshift-ci-robot commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

@OlivierCazade: This pull request references NETOBSERV-2273 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Description

Update DNS_TRACKING_PORT to accept comma-separated port values while maintaining backward compatibility with single port configuration.

Changes:

  • Add support for up to 8 DNS ports (MAX_DNS_PORTS)
  • Replace single dns_port with dns_ports array in eBPF config
  • Remove hardcoded port 53 check in track_dns_packet()
  • Add is_dns_port() helper with bounded loop for eBPF verifier
  • Update config to parse DNS_TRACKING_PORT as comma-separated string
  • Update documentation with multi-port usage examples

Examples:

  • DNS_TRACKING_PORT=53 (single port, backward compatible)
  • DNS_TRACKING_PORT=53,5353,8053 (multiple ports)

Dependencies

n/a

Checklist

  • Does the changes in PR need specific configuration or environment set up for testing?
    • if so please describe it in PR description.
  • I have added thorough unit tests for the change.
  • QE requirements (check 1 from the list):
  • Standard QE validation, with pre-merge tests unless stated otherwise.
  • Regression tests only (e.g. refactoring with no user-facing change).
  • No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team).

To run a perfscale test, comment with: /test ebpf-node-density-heavy-25nodes

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci

openshift-ci Bot commented Jun 19, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign stleerh for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

DNS tracking now accepts up to 8 configured ports instead of one. The BPF contract stores a port array plus count, the tracer parses comma-separated config into those values, and tests plus docs cover the new format.

Changes

DNS Multi-Port Configuration

Layer / File(s) Summary
BPF DNS port array contract
bpf/configs.h
Adds MAX_DNS_PORTS (8) and replaces the single dns_port volatile with dns_ports[MAX_DNS_PORTS] and dns_ports_count.
BPF port-matching logic
bpf/dns_tracker.h
Removes DNS_DEFAULT_PORT, adds is_dns_port(), and updates track_dns_packet() to match against the configured port list.
Go config parsing and eBPF wiring
pkg/config/config.go, pkg/tracer/tracer.go
Changes DNSTrackingPort to DNSTrackingPorts, adds parsing/truncation for comma-separated ports, and wires the resulting array and count into eBPF variables.
Tests and documentation
pkg/tracer/dns_ports_test.go, docs/config.md
Adds parsing coverage, checks maxDNSPorts == 8, and documents the multi-port DNS_TRACKING_PORT format and limit.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% 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
Title check ✅ Passed Title directly and specifically describes the main change: enabling comma-separated DNS tracking ports.
Description check ✅ Passed Description covers the main changes, includes examples, and completes the required checklist with unit tests added and QE validation requested.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Linked repositories: Your configuration references 2 linked repositories, but your current plan allows 0. Analyzed ``, skipped netobserv/netobserv-operator, `netobserv/flowlogs-pipeline`.


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
bpf/configs.h (1)

1-5: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add the required GPLv2 header for BPF code.

This changed bpf/ header is missing the required GPL v2 license header.
As per coding guidelines, "eBPF code in bpf/ directory must use GPL v2 license headers".

Suggested patch
+// SPDX-License-Identifier: GPL-2.0
+
 `#ifndef` __CONFIGS_H__
 `#define` __CONFIGS_H__
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bpf/configs.h` around lines 1 - 5, The bpf/configs.h file is missing the
required GPL v2 license header that must appear at the top of all eBPF code
files. Add the GPL v2 license header comment block at the very beginning of the
file, before the `#ifndef __CONFIGS_H__` preprocessor guard. This header should
include the standard GPL v2 license text and copyright information to comply
with the coding guidelines for BPF code.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/tracer/tracer.go`:
- Around line 2147-2151: The condition checking `i >= maxDNSPorts` uses the raw
loop index which counts all ports including invalid or empty entries, causing
the loop to stop before accepting the maximum of 8 valid ports. Instead of
checking the loop index, introduce a separate counter variable to track only the
number of accepted/valid ports and increment it only when a port is successfully
processed and added. Replace the condition in the loop with a check against this
accepted port counter instead of the loop index `i`.
- Around line 2141-2166: Create unit tests for the DNS multi-port parsing logic
in the configureFlowSpecVariables function to verify correct behavior when
handling valid ports, invalid ports, empty entries, and the maxDNSPorts
truncation limit. Write the tests using Go's standard testing package with test
functions accepting *testing.T parameter to ensure complete coverage of the port
parsing and validation code paths that split and parse the DNS tracking ports
configuration.

---

Outside diff comments:
In `@bpf/configs.h`:
- Around line 1-5: The bpf/configs.h file is missing the required GPL v2 license
header that must appear at the top of all eBPF code files. Add the GPL v2
license header comment block at the very beginning of the file, before the
`#ifndef __CONFIGS_H__` preprocessor guard. This header should include the
standard GPL v2 license text and copyright information to comply with the coding
guidelines for BPF code.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2abf4a0c-a76e-4782-a9f7-ffb923b1c42f

📥 Commits

Reviewing files that changed from the base of the PR and between e65338a and c63b4a5.

📒 Files selected for processing (5)
  • bpf/configs.h
  • bpf/dns_tracker.h
  • docs/config.md
  • pkg/config/config.go
  • pkg/tracer/tracer.go

Comment thread pkg/tracer/tracer.go Outdated
Comment thread pkg/tracer/tracer.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
bpf/configs.h (1)

1-3: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add the required GPL v2 license header to this eBPF header.

This file is under bpf/ and currently has no GPL v2 header, which violates repo policy for bpf/*.{c,h} files.

As per coding guidelines, "eBPF code in bpf/ directory must use GPL v2 license headers".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bpf/configs.h` around lines 1 - 3, Add a GPL v2 license header comment block
at the very beginning of the configs.h file, before the existing header guards
(__CONFIGS_H__). The license header should be formatted as a multi-line C
comment containing the GPL v2 license text that complies with the repository's
eBPF coding guidelines for files in the bpf/ directory.

Source: Coding guidelines

🧹 Nitpick comments (1)
pkg/tracer/dns_ports_test.go (1)

155-175: 🏗️ Heavy lift

Avoid mirroring production parsing logic inside the test body.

The test reimplements configureFlowSpecVariables parsing path, so future logic regressions can be duplicated in test and still pass. Prefer testing the production path directly (or extracting a shared parser helper used by both prod and tests).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/tracer/dns_ports_test.go` around lines 155 - 175, The test is
reimplementing the DNS port parsing logic using splitAndTrimPorts, parsePort,
and manual array population instead of calling the actual production function
configureFlowSpecVariables. This duplication means regressions in the production
parsing logic won't be caught by the test. Replace the inline parsing logic with
a direct call to the production function configureFlowSpecVariables, or extract
the shared parsing logic into a helper function that both the production code
and test can reuse.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/tracer/dns_ports_test.go`:
- Line 1: The file dns_ports_test.go is missing the mandatory Apache v2 license
header at the top. Add the Apache v2 license header comments before the package
tracer declaration to comply with the coding guidelines that require all Go
files to include this license preamble. The license header should appear as
comments at the very beginning of the file, before any other content including
the package declaration.
- Around line 17-22: The parsePort function is returning raw errors without
context, which loses information about which input failed and violates Go
error-wrapping guidelines. Modify the error return statement on line 20 to wrap
the error returned from strconv.ParseUint with contextual information about the
input that failed, using Go's error wrapping pattern with fmt.Errorf and the %w
verb to include both a descriptive message and the original error.

---

Outside diff comments:
In `@bpf/configs.h`:
- Around line 1-3: Add a GPL v2 license header comment block at the very
beginning of the configs.h file, before the existing header guards
(__CONFIGS_H__). The license header should be formatted as a multi-line C
comment containing the GPL v2 license text that complies with the repository's
eBPF coding guidelines for files in the bpf/ directory.

---

Nitpick comments:
In `@pkg/tracer/dns_ports_test.go`:
- Around line 155-175: The test is reimplementing the DNS port parsing logic
using splitAndTrimPorts, parsePort, and manual array population instead of
calling the actual production function configureFlowSpecVariables. This
duplication means regressions in the production parsing logic won't be caught by
the test. Replace the inline parsing logic with a direct call to the production
function configureFlowSpecVariables, or extract the shared parsing logic into a
helper function that both the production code and test can reuse.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 27b06ca6-e301-4d14-bc0b-a847e23e53f7

📥 Commits

Reviewing files that changed from the base of the PR and between c63b4a5 and 480bbb4.

📒 Files selected for processing (6)
  • bpf/configs.h
  • bpf/dns_tracker.h
  • docs/config.md
  • pkg/config/config.go
  • pkg/tracer/dns_ports_test.go
  • pkg/tracer/tracer.go
✅ Files skipped from review due to trivial changes (1)
  • docs/config.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/config/config.go
  • bpf/dns_tracker.h
  • pkg/tracer/tracer.go

Comment thread pkg/tracer/dns_ports_test.go
Comment thread pkg/tracer/dns_ports_test.go Outdated
Comment thread bpf/dns_tracker.h Outdated

static __always_inline bool is_dns_port(u16 port) {
// Bounded loop for eBPF verifier
#pragma unroll

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.

no need to use those pragma the compliers take care of that we no longer need to use them

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done, thanks

Comment thread bpf/dns_tracker.h
if (i >= dns_ports_count) {
break;
}
if (port == dns_ports[i]) {

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.

have u checked out using global array map table to pass in this configuration instead of using global variables array ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To be honest I am not sure to fully understand the differences between both. Could you elaborate ?

As far as I can tell, the project is using global variables when needed.

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.

we use global as config knobs but I think for passing an array which operator can change runtime its better to store the list as an array map from user space and let the kernel read it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This config comes from env, the operator can not change it without recreating the pod.

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.

how many ports this can be ? as global u will always burn that space regardless if DNS is enabled or not, but if its few ports then that might not be a concern ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For now, there is a hard limit of 8 different ports.

@OlivierCazade OlivierCazade force-pushed the dns-ports branch 2 times, most recently from fbccda9 to ebbd76c Compare June 22, 2026 16:26

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (1)
pkg/tracer/dns_ports_test.go (1)

116-121: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

“DNS tracking disabled” case is testing the test branch, not production behavior.

Line 143 conditionally skips parsing inside the test itself, so the case at Line 116 only validates zero-value locals. It does not verify the real disabled-path wiring in configureFlowSpecVariables (pkg/tracer/tracer.go Lines 2168-2181). Consider moving this assertion to a test that exercises that function directly (or drop this case from the parser table).

Also applies to: 143-145

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/tracer/dns_ports_test.go` around lines 116 - 121, The test case "DNS
tracking disabled - no parsing" at line 116-121 does not actually validate
production behavior because the parsing is conditionally skipped inside the test
at line 143-145, meaning it only checks zero-value defaults rather than the real
disabled-path wiring in the configureFlowSpecVariables function in
pkg/tracer/tracer.go. Either move this test assertion to directly test the
configureFlowSpecVariables function's disabled-path implementation at lines
2168-2181, or remove this test case from the parser table since it does not
exercise actual production code paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@bpf/configs.h`:
- Around line 1-5: The file bpf/configs.h is missing the required GPL v2 license
header. Add the GPL v2 license header (including SPDX identifier and license
text) at the very top of the file, before the include guard that starts with
`#ifndef __CONFIGS_H__`. This ensures compliance with eBPF coding guidelines
that mandate GPL v2 license headers for all files in the bpf/ directory.

---

Nitpick comments:
In `@pkg/tracer/dns_ports_test.go`:
- Around line 116-121: The test case "DNS tracking disabled - no parsing" at
line 116-121 does not actually validate production behavior because the parsing
is conditionally skipped inside the test at line 143-145, meaning it only checks
zero-value defaults rather than the real disabled-path wiring in the
configureFlowSpecVariables function in pkg/tracer/tracer.go. Either move this
test assertion to directly test the configureFlowSpecVariables function's
disabled-path implementation at lines 2168-2181, or remove this test case from
the parser table since it does not exercise actual production code paths.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ca635ed2-f3cd-4e0a-9289-4a9cab071d94

📥 Commits

Reviewing files that changed from the base of the PR and between fbccda9 and ebbd76c.

📒 Files selected for processing (6)
  • bpf/configs.h
  • bpf/dns_tracker.h
  • docs/config.md
  • pkg/config/config.go
  • pkg/tracer/dns_ports_test.go
  • pkg/tracer/tracer.go
✅ Files skipped from review due to trivial changes (1)
  • docs/config.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • bpf/dns_tracker.h
  • pkg/config/config.go
  • pkg/tracer/tracer.go

Comment thread bpf/configs.h
Comment thread pkg/config/config.go Outdated
DNSTrackingPort uint16 `env:"DNS_TRACKING_PORT" envDefault:"53"`
// DNSTrackingPorts used to define which ports the DNS service is mapped to at the pod level,
// so we can track DNS at the pod level. Comma-separated list of ports (e.g., "53,5353,8053")
DNSTrackingPorts string `env:"DNS_TRACKING_PORT" envDefault:"53"`

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.

wouldn't it be cleaner if we define it as

DNSTrackingPorts []uint16

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed, thanks!

Update DNS_TRACKING_PORT to accept comma-separated port values while
maintaining backward compatibility with single port configuration.

Changes:
- Add support for up to 8 DNS ports (MAX_DNS_PORTS)
- Replace single dns_port with dns_ports array in eBPF config
- Remove hardcoded port 53 check in track_dns_packet()
- Add is_dns_port() helper with bounded loop for eBPF verifier
- Update config to parse DNS_TRACKING_PORT as comma-separated string
- Update documentation with multi-port usage examples

Examples:
- DNS_TRACKING_PORT=53 (single port, backward compatible)
- DNS_TRACKING_PORT=53,5353,8053 (multiple ports)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@openshift-ci

openshift-ci Bot commented Jun 25, 2026

Copy link
Copy Markdown

@OlivierCazade: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/qe-e2e-tests 84b9134 link false /test qe-e2e-tests

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@msherif1234

Copy link
Copy Markdown
Contributor

/LGTM

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.

3 participants