mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-04-07 12:32:04 +02:00
fix: bracket IPv6 addresses in VPN DNS upstream config
upstreamConfigFor() used strings.Contains(":") to detect whether to
append ":53", but IPv6 addresses contain colons, so IPv6 servers were
passed as bare addresses (e.g. "2a0d:6fc0:9b0:3600::1") to net.Dial
which rejects them with "too many colons in address".
Use net.JoinHostPort() which handles both IPv4 and IPv6 correctly,
producing "[2a0d:6fc0:9b0:3600::1]:53" for IPv6.
This commit is contained in:
committed by
Cuong Manh Le
parent
5c0585b2e8
commit
95dd871e2d
@@ -2,6 +2,7 @@ package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -241,10 +242,12 @@ func (m *vpnDNSManager) Routes() map[string][]string {
|
||||
|
||||
// upstreamConfigFor creates a legacy upstream configuration for the given VPN DNS server.
|
||||
func (m *vpnDNSManager) upstreamConfigFor(server string) *ctrld.UpstreamConfig {
|
||||
endpoint := server
|
||||
if !strings.Contains(server, ":") {
|
||||
endpoint = server + ":53"
|
||||
}
|
||||
// Use net.JoinHostPort to correctly handle both IPv4 and IPv6 addresses.
|
||||
// Previously, the strings.Contains(":") check would skip appending ":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{
|
||||
Name: "VPN DNS",
|
||||
|
||||
Reference in New Issue
Block a user