fix(wireguard): support IPv6 address formatting from config files (#3273)

This commit is contained in:
Drew Wells
2026-04-08 10:04:35 -05:00
committed by GitHub
parent 3b9c9b24bd
commit 2006fae0e3
2 changed files with 15 additions and 6 deletions
@@ -3,6 +3,7 @@ package files
import ( import (
"errors" "errors"
"fmt" "fmt"
"net"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
@@ -82,12 +83,15 @@ func parseWireguardPeerSection(peerSection *ini.Section) (
publicKey = getINIKeyFromSection(peerSection, "PublicKey") publicKey = getINIKeyFromSection(peerSection, "PublicKey")
endpoint := getINIKeyFromSection(peerSection, "Endpoint") endpoint := getINIKeyFromSection(peerSection, "Endpoint")
if endpoint != nil { if endpoint != nil {
parts := strings.Split(*endpoint, ":") host, port, err := net.SplitHostPort(*endpoint)
endpointIP = &parts[0] if err == nil {
const partsWithPort = 2 endpointIP = &host
if len(parts) >= partsWithPort { // IPv6 hosts contain colons; port is managed by the provider for those
endpointPort = new(string) if !strings.Contains(host, ":") {
*endpointPort = strings.Join(parts[1:], ":") endpointPort = &port
}
} else {
endpointIP = endpoint
} }
} }
@@ -179,6 +179,11 @@ Endpoint = 1.2.3.4:51820`,
endpointIP: ptrTo("1.2.3.4"), endpointIP: ptrTo("1.2.3.4"),
endpointPort: ptrTo("51820"), endpointPort: ptrTo("51820"),
}, },
"ipv6_endpoint": {
iniData: `[Peer]
Endpoint = [2a02:bbbb:aaaa:8075::10]:51820`,
endpointIP: ptrTo("2a02:bbbb:aaaa:8075::10"),
},
} }
for testName, testCase := range testCases { for testName, testCase := range testCases {