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

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

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5836
Author: @lixmal
Created: 4/9/2026
Status: Merged
Merged: 4/9/2026
Merged by: @lixmal

Base: proto-ipv6-overlayHead: client-ipv6-hostport-fixes


📝 Commits (1)

  • 12752b3 Use net.JoinHostPort and net.SplitHostPort for IPv6-safe host:port handling

📊 Changes

21 files changed (+193 additions, -36 deletions)

View changed files

📝 client/anonymize/anonymize.go (+2 -2)
📝 client/anonymize/anonymize_test.go (+10 -0)
📝 client/cmd/ssh.go (+1 -1)
📝 client/firewall/uspfilter/conntrack/common_test.go (+48 -0)
📝 client/firewall/uspfilter/conntrack/icmp.go (+3 -2)
📝 client/firewall/uspfilter/conntrack/icmp_test.go (+36 -0)
📝 client/firewall/uspfilter/tracer.go (+3 -1)
📝 client/internal/profilemanager/config.go (+2 -2)
📝 client/internal/relay/relay.go (+2 -1)
📝 client/internal/rosenpass/manager.go (+5 -2)
client/internal/rosenpass/manager_test.go (+14 -0)
📝 client/ssh/proxy/proxy.go (+1 -1)
📝 client/ssh/server/port_forwarding.go (+15 -14)
📝 client/ssh/server/server.go (+6 -4)
📝 combined/cmd/config.go (+1 -1)
📝 management/internals/modules/reverseproxy/service/manager/manager.go (+2 -1)
📝 management/server/http/handlers/dns/nameservers_handler.go (+4 -1)
📝 management/server/http/handlers/dns/nameservers_handler_test.go (+34 -0)
📝 relay/test/benchmark_test.go (+1 -1)
📝 relay/testec2/turn_allocator.go (+1 -1)

...and 1 more files

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/5836 **Author:** [@lixmal](https://github.com/lixmal) **Created:** 4/9/2026 **Status:** ✅ Merged **Merged:** 4/9/2026 **Merged by:** [@lixmal](https://github.com/lixmal) **Base:** `proto-ipv6-overlay` ← **Head:** `client-ipv6-hostport-fixes` --- ### 📝 Commits (1) - [`12752b3`](https://github.com/netbirdio/netbird/commit/12752b3273bf54a58e2c5968a6dd0ee536cf2257) Use net.JoinHostPort and net.SplitHostPort for IPv6-safe host:port handling ### 📊 Changes **21 files changed** (+193 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `client/anonymize/anonymize.go` (+2 -2) 📝 `client/anonymize/anonymize_test.go` (+10 -0) 📝 `client/cmd/ssh.go` (+1 -1) 📝 `client/firewall/uspfilter/conntrack/common_test.go` (+48 -0) 📝 `client/firewall/uspfilter/conntrack/icmp.go` (+3 -2) 📝 `client/firewall/uspfilter/conntrack/icmp_test.go` (+36 -0) 📝 `client/firewall/uspfilter/tracer.go` (+3 -1) 📝 `client/internal/profilemanager/config.go` (+2 -2) 📝 `client/internal/relay/relay.go` (+2 -1) 📝 `client/internal/rosenpass/manager.go` (+5 -2) ➕ `client/internal/rosenpass/manager_test.go` (+14 -0) 📝 `client/ssh/proxy/proxy.go` (+1 -1) 📝 `client/ssh/server/port_forwarding.go` (+15 -14) 📝 `client/ssh/server/server.go` (+6 -4) 📝 `combined/cmd/config.go` (+1 -1) 📝 `management/internals/modules/reverseproxy/service/manager/manager.go` (+2 -1) 📝 `management/server/http/handlers/dns/nameservers_handler.go` (+4 -1) 📝 `management/server/http/handlers/dns/nameservers_handler_test.go` (+34 -0) 📝 `relay/test/benchmark_test.go` (+1 -1) 📝 `relay/testec2/turn_allocator.go` (+1 -1) _...and 1 more files_ </details> ### 📄 Description ## 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 --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 06:08:14 -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#24084