mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-29 01:18:48 +02:00
fix: bracket IPv6 addresses in VPN DNS upstream config
upstreamConfigFor() used strings.Contains(":") to decide whether to
append ":53", which always evaluates true for IPv6 addresses. This left
bare addresses like "2a0d:6fc0:9b0:3600::1" without brackets or port,
causing net.Dial to reject with "too many colons in address".
Use net.JoinHostPort() which handles IPv6 bracketing automatically,
producing "[2a0d:6fc0:9b0:3600::1]:53".
This commit is contained in:
+7
-4
@@ -2,6 +2,7 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -222,10 +223,12 @@ func (m *vpnDNSManager) Routes() map[string][]string {
|
|||||||
|
|
||||||
// upstreamConfigFor creates a legacy upstream configuration for the given VPN DNS server.
|
// upstreamConfigFor creates a legacy upstream configuration for the given VPN DNS server.
|
||||||
func (m *vpnDNSManager) upstreamConfigFor(server string) *ctrld.UpstreamConfig {
|
func (m *vpnDNSManager) upstreamConfigFor(server string) *ctrld.UpstreamConfig {
|
||||||
endpoint := server
|
// Use net.JoinHostPort to correctly handle both IPv4 and IPv6 addresses.
|
||||||
if !strings.Contains(server, ":") {
|
// Previously, the strings.Contains(":") check would skip appending ":53"
|
||||||
endpoint = server + ":53"
|
// for IPv6 addresses (they contain colons), leaving a bare address like
|
||||||
}
|
// "2a0d:6fc0:9b0:3600::1" which net.Dial rejects with "too many colons".
|
||||||
|
// net.JoinHostPort produces "[2a0d:6fc0:9b0:3600::1]:53" as required.
|
||||||
|
endpoint := net.JoinHostPort(server, "53")
|
||||||
|
|
||||||
return &ctrld.UpstreamConfig{
|
return &ctrld.UpstreamConfig{
|
||||||
Name: "VPN DNS",
|
Name: "VPN DNS",
|
||||||
|
|||||||
Reference in New Issue
Block a user