Skip to content

fix(redfish): bracket IPv6 BMC hosts in nv-redfish URLs#3008

Open
CTOmari360 wants to merge 1 commit into
NVIDIA:mainfrom
CTOmari360:fix/redfish-bracket-ipv6-bmc-url
Open

fix(redfish): bracket IPv6 BMC hosts in nv-redfish URLs#3008
CTOmari360 wants to merge 1 commit into
NVIDIA:mainfrom
CTOmari360:fix/redfish-bracket-ipv6-bmc-url

Conversation

@CTOmari360

Copy link
Copy Markdown
Contributor

NvRedfishClientPool::create_bmc builds the BMC base URL with bare format!s and then .expect()s Url::parse. IPv6 hosts were left unbracketed, so an IPv6 BMC produced an invalid authority such as https://2001:db8::1:8443 — which Url::parse rejects, panicking the caller.

The codebase already brackets IPv6 on the sibling path (crates/health/src/endpoint/model.rs::BmcAddr::to_url); the nv_redfish pool was missing the same handling.

This extracts a small, testable build_bmc_url helper that brackets IPv6 literals in every arm:

  • port-only proxy — brackets the BMC's own IpAddr (the panicking case),
  • host / host+port proxy — brackets a config-supplied IPv6 literal proxy host,
  • no override — unchanged; SocketAddr's Display already brackets.

Hostnames, IPv4 literals, and already-bracketed hosts are passed through untouched.

Related issues

Part of the #2237 IPv6 bug bucket; addresses the Redfish-bracket item of #2406. (Scoped to just this fix, so it does not close the multi-item #2406.)

Type of Change

  • Fix - Bug fixes

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated

cargo test -p carbide-redfish --features test-support nv_redfish::tests — 5 passing, covering each arm. The new port_only_proxy_brackets_ipv6_bmc test fails before this change (produces https://2001:db8::1:8443, asserted against the bracketed https://[2001:db8::1]:8443). cargo clippy -- -D warnings and cargo fmt --check both clean.

Additional Notes

The libredfish proxy path (crates/redfish/src/libredfish/implementation.rs) constructs its endpoint inside the external libredfish crate and is out of scope here.

NvRedfishClientPool::create_bmc built the BMC base URL with bare
format!s and then .expect()ed Url::parse. IPv6 hosts were left
unbracketed, so an IPv6 BMC produced an invalid authority such as
https://2001:db8::1:8443 -- which Url::parse rejects, panicking the
caller. This mirrors the bracketing the health crate's
BmcAddr::to_url already applies on its own path.

Extract a testable build_bmc_url helper that brackets IPv6 literals in
every arm: the port-only proxy path uses the BMC's own IpAddr, and the
host / host+port proxy paths bracket config-supplied IPv6 literals. The
no-override arm is unchanged -- SocketAddr's Display already brackets.

Add unit tests covering each arm; the port-only IPv6 case fails before
this change.

Part of the NVIDIA#2237 IPv6 bug bucket; addresses the Redfish-bracket item of NVIDIA#2406.

Signed-off-by: Omar Refai <omar@refai.org>
@CTOmari360 CTOmari360 requested a review from a team as a code owner June 30, 2026 03:50
@copy-pr-bot

copy-pr-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Comment on lines +205 to +211
fn url_host(host: &str) -> Cow<'_, str> {
if host.parse::<Ipv6Addr>().is_ok() {
Cow::Owned(format!("[{host}]"))
} else {
Cow::Borrowed(host)
}
}

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.

This code doesn't look right. Probably HostPortPair should be able to destinguish IPv6 address from Hostname or return url_host(). This code here looks like patch on wrong / missing behavior of other object.

Could you please move this function there to make incoherent design of HostAndPort more local?

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.

Probably it can be combined with your #3010 PR

@ajf

ajf commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Same question as on the golang code, can we use the url library to do this IPv6 bracketing for us? If we're dealing with URLs we should probably use the url crate.

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.

3 participants