Skip to content

fix(api,redfish): format ipv6 bmc addresses at protocol boundaries#3749

Merged
chet merged 1 commit into
NVIDIA:mainfrom
chet:gh-issue-2240
Jul 21, 2026
Merged

fix(api,redfish): format ipv6 bmc addresses at protocol boundaries#3749
chet merged 1 commit into
NVIDIA:mainfrom
chet:gh-issue-2240

Conversation

@chet

@chet chet commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

A BMC IP needs three representations as it crosses NICo: a bare value for storage and resolution, a bracketed URI authority, and a quoted RFC 7239 Forwarded host parameter.

stored / resolved address:  2001:db8::1
URI authority:             [2001:db8::1]:443
Forwarded host parameter:  host="[2001:db8::1]"

Several paths carried the bare address one boundary too far. Endpoint exploration treated IPv6 colons like an explicit port and skipped the default :443; the admin browser, Redfish actions, and libredfish could build ambiguous host:port authorities; and proxy paths serialized invalid RFC 7239 values.

This change keeps the address bare for storage and metadata lookup, then formats it at the protocol boundary that needs a URI authority or header value. resolve_bmc_address handles hostnames, IPv4, bare or bracketed IPv6, and explicit or default ports through one path, while shared helpers cover URI host parsing and Forwarded serialization for the API, browser, libredfish, and health proxy.

IPv4 and hostname behavior remains unchanged, including resolver error mapping. The mock proxy also accepts quoted IPv6 values and case-insensitive host parameter names so its routing matches the real proxy's RFC 7239 handling.

Related issues

This supports #2240

Related work:

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

Focused coverage includes bare and bracketed IPv6, explicit and default ports, browser and libredfish URI construction, RFC 7239 header formatting, case-insensitive mock routing, and the existing IPv4 and hostname paths.

Local verification passes cargo make format-nightly, cargo make clippy, cargo make carbide-lints, cargo make check-workspace-deps, and the affected Rust tests.

Additional Notes

BmcAccessInfo.host intentionally remains bare because brackets belong to a URI authority, not the stored IP value.

crates/redfish/src/nv_redfish/mod.rs remains in #3008, the bmc-proxy upstream authority remains in #3010, and HostPortPair remains in #3012. This PR supports #2240 without closing it while those pieces remain open.

Closes #2240

@chet
chet requested a review from a team as a code owner July 20, 2026 23:51
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d4739fb7-bc35-42e4-8f36-8372c64fde3b

📥 Commits

Reviewing files that changed from the base of the PR and between 693fc78 and ec4611c.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • crates/api-core/src/handlers/bmc_endpoint_explorer.rs
  • crates/api-core/src/handlers/redfish.rs
  • crates/api-core/src/handlers/site_explorer.rs
  • crates/api-core/src/handlers/utils.rs
  • crates/api-web/src/redfish_browser.rs
  • crates/bmc-mock/src/combined_service.rs
  • crates/health/src/bmc.rs
  • crates/redfish/Cargo.toml
  • crates/redfish/src/libredfish/implementation.rs
  • crates/utils/src/redfish.rs
🚧 Files skipped from review as they are similar to previous changes (10)
  • crates/bmc-mock/src/combined_service.rs
  • crates/api-core/src/handlers/bmc_endpoint_explorer.rs
  • crates/api-web/src/redfish_browser.rs
  • crates/health/src/bmc.rs
  • crates/api-core/src/handlers/site_explorer.rs
  • crates/api-core/src/handlers/utils.rs
  • crates/redfish/Cargo.toml
  • crates/utils/src/redfish.rs
  • crates/api-core/src/handlers/redfish.rs
  • crates/redfish/src/libredfish/implementation.rs

Summary by CodeRabbit

  • Bug Fixes

    • Improved BMC address resolution for IP addresses, hostnames, ports, and IPv6 formats.
    • Fixed Redfish and proxy URL handling for IPv4 and IPv6 addresses.
    • Improved Forwarded header formatting and parsing, including quoted and bracketed IPv6 values.
    • Added clearer validation errors for missing or invalid BMC hosts.
  • Tests

    • Added coverage for address resolution, URL construction, IPv6 formatting, and forwarded-host parsing.

Walkthrough

BMC address resolution is centralized, while Redfish URI, endpoint, browser, and Forwarded header handling is updated for IPv4 and IPv6 literals. Shared parsing and formatting helpers receive focused tests across API, health, mock, browser, and libredfish components.

Changes

BMC and Redfish networking

Layer / File(s) Summary
Shared Redfish host formatting
crates/utils/src/redfish.rs
Adds shared IP parsing and Forwarded host formatting for IPv4, hostnames, and bare or bracketed IPv6 literals.
BMC address resolution
crates/api-core/src/handlers/utils.rs, crates/api-core/src/handlers/bmc_endpoint_explorer.rs, crates/api-core/src/handlers/site_explorer.rs
Centralizes numeric and hostname BMC address resolution with default HTTPS port handling, validation, and async resolution tests.
Redfish URI and client flow
crates/api-core/src/handlers/redfish.rs, crates/api-web/src/redfish_browser.rs, crates/redfish/src/libredfish/implementation.rs, crates/redfish/Cargo.toml
Normalizes metadata hosts, authorities, action URIs, browser base URLs, libredfish endpoint hosts, and proxied headers for IPv4 and IPv6 forms.
Forwarded header consumers
crates/health/src/bmc.rs, crates/bmc-mock/src/combined_service.rs
Uses standardized forwarded-host formatting and expands mock routing tests for quoted, bracketed, and combined header values.

Estimated code review effort: 4 (Complex) | ~45 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: formatting IPv6 BMC addresses at API and Redfish protocol boundaries.
Description check ✅ Passed The description matches the changeset and explains the IPv6 BMC formatting fixes, helpers, and test coverage.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/api-core/src/handlers/utils.rs (1)

186-197: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use check_cases_async for this async Result table.
This matches the repository’s table-test pattern and keeps scenario naming and failure reporting consistent.

🤖 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 `@crates/api-core/src/handlers/utils.rs` around lines 186 - 197, Update
resolves_hostname_forms_with_the_expected_port to use the repository’s
check_cases_async helper for the async Result table, preserving both hostname
scenarios, expected ports, loopback validation, and scenario labels through the
helper’s standard failure reporting.

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 `@crates/bmc-mock/src/combined_service.rs`:
- Around line 86-95: Update the Forwarded-parameter parsing in the shown
combined-service logic and its corresponding occurrence to recognize the `host`
parameter case-insensitively, while preserving trimming, quote removal,
bracketed IPv6 handling, and existing fallback behavior.

---

Nitpick comments:
In `@crates/api-core/src/handlers/utils.rs`:
- Around line 186-197: Update resolves_hostname_forms_with_the_expected_port to
use the repository’s check_cases_async helper for the async Result table,
preserving both hostname scenarios, expected ports, loopback validation, and
scenario labels through the helper’s standard failure reporting.
🪄 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: Enterprise

Run ID: a063f4da-c4d5-4b33-ad73-c5169f29f4d3

📥 Commits

Reviewing files that changed from the base of the PR and between dcdd5da and ed71ee1.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • crates/api-core/src/handlers/bmc_endpoint_explorer.rs
  • crates/api-core/src/handlers/redfish.rs
  • crates/api-core/src/handlers/site_explorer.rs
  • crates/api-core/src/handlers/utils.rs
  • crates/api-web/src/redfish_browser.rs
  • crates/bmc-mock/src/combined_service.rs
  • crates/health/src/bmc.rs
  • crates/redfish/Cargo.toml
  • crates/redfish/src/libredfish/implementation.rs
  • crates/utils/src/redfish.rs

Comment thread crates/bmc-mock/src/combined_service.rs
@chet chet changed the title fix(api,redfish): stop mangling ipv6 bmc addresses fix(api,redfish): format ipv6 bmc addresses at protocol boundaries Jul 21, 2026
A BMC address stays bare while NICo stores or resolves it, but URI
authorities and RFC 7239 `Forwarded` values need IPv6-specific brackets
and quoting. Several paths were carrying the bare form across those
serialization boundaries.

Centralize resolution and boundary formatting for endpoint discovery,
the admin browser, Redfish actions, `libredfish`, and the health proxy.
IPv4, hostname, and resolver-error behavior stay unchanged; the mock
proxy covers quoted IPv6 and case-insensitive `host` parameters.

`nv_redfish` URL construction remains in NVIDIA#3008 and `HostPortPair`
parsing remains in NVIDIA#3012.

This supports NVIDIA#2240

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
@chet
chet enabled auto-merge (squash) July 21, 2026 17:48
@chet
chet merged commit fd3d6e3 into NVIDIA:main Jul 21, 2026
61 checks passed
@chet
chet deleted the gh-issue-2240 branch July 21, 2026 17:52
CTOmari360 added a commit to CTOmari360/infra-controller that referenced this pull request Jul 21, 2026
… header

NvRedfishClientPool::create_bmc built the BMC base URL and the Forwarded
`host` parameter from a bare IpAddr, leaving IPv6 literals unbracketed: the
URL (https://2001:db8::1:8443) fails Url::parse, and the header
(host=2001:db8::1) violates RFC 7239.

Build the URL with the url crate (which brackets IPv6) via a build_bmc_url
helper returning Result<Url, _>, propagated as BmcError::InvalidRequest --
no expect on the production path -- mirroring health::BmcAddr::to_url().
IPv6-vs-hostname classification for proxy overrides lives on
HostPortPair::url_host(). For the Forwarded header, use the shared
carbide_utils::redfish::format_forwarded_host_parameter helper (NVIDIA#3749).

Adds unit coverage for URL building (IPv4/IPv6, proxy/no-proxy) and the
Forwarded host parameter. Part of NVIDIA#2237; addresses the Redfish-bracket item
of NVIDIA#2406.

Signed-off-by: Omar Refai <omar@refai.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[IPv6] BMC endpoint URLs aren't bracketed for IPv6 (redfish / lookup_host)

3 participants