[PR #5836] [client, management, relay, misc] Use net.JoinHostPort for IPv6-safe host:port handling #28620

Open
opened 2026-08-05 08:06:39 -04:00 by saavagebueno · 0 comments
Owner

Original Pull Request: https://github.com/netbirdio/netbird/pull/5836

State: closed
Merged: Yes


Describe your changes

Replace fmt.Sprintf("%s:%d", host, port) and strings.Split(addr, ":") with net.JoinHostPort/net.SplitHostPort across the codebase. Without this, IPv6 addresses produce malformed strings like 2001:db8::1:3478 instead of [2001:db8::1]:3478.

  • Replace host:port construction with net.JoinHostPort in SSH port forwarding, relay TURN probing, DNS nameserver URL parsing, STUN URI construction, management URL construction, reverse proxy service URLs, and packet tracer display
  • Replace strings.Split on : with net.SplitHostPort in rosenpass UDP port parsing
  • Fix anonymizer URI reconstruction to use net.JoinHostPort so bracketed IPv6 addresses are preserved through AnonymizeString
  • Add tests for ConnKey.String(), ICMPConnKey.String(), findRandomAvailableUDPPort, toServerNSList with IPv6, and AnonymizeString with IPv6 STUN/HTTPS URIs

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Summary by CodeRabbit

  • Bug Fixes

    • Improved IPv6 address handling and formatting consistency across the application.
    • Enhanced proper host:port combination formatting for network addresses, particularly benefiting IPv6 support.
  • Tests

    • Added comprehensive test coverage for IPv6 address anonymization and formatting in various contexts.
    • Extended test suite for port parsing and address string output validation.
**Original Pull Request:** https://github.com/netbirdio/netbird/pull/5836 **State:** closed **Merged:** Yes --- ## Describe your changes Replace `fmt.Sprintf("%s:%d", host, port)` and `strings.Split(addr, ":")` with `net.JoinHostPort`/`net.SplitHostPort` across the codebase. Without this, IPv6 addresses produce malformed strings like `2001:db8::1:3478` instead of `[2001:db8::1]:3478`. - Replace host:port construction with `net.JoinHostPort` in SSH port forwarding, relay TURN probing, DNS nameserver URL parsing, STUN URI construction, management URL construction, reverse proxy service URLs, and packet tracer display - Replace `strings.Split` on `:` with `net.SplitHostPort` in rosenpass UDP port parsing - Fix anonymizer URI reconstruction to use `net.JoinHostPort` so bracketed IPv6 addresses are preserved through `AnonymizeString` - Add tests for `ConnKey.String()`, `ICMPConnKey.String()`, `findRandomAvailableUDPPort`, `toServerNSList` with IPv6, and `AnonymizeString` with IPv6 STUN/HTTPS URIs ## Issue ticket number and link ## Stack <!-- branch-stack --> ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (if possible) > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved IPv6 address handling and formatting consistency across the application. * Enhanced proper host:port combination formatting for network addresses, particularly benefiting IPv6 support. * **Tests** * Added comprehensive test coverage for IPv6 address anonymization and formatting in various contexts. * Extended test suite for port parsing and address string output validation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
saavagebueno added the pull-request label 2026-08-05 08:06:39 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#28620