mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-06 20:10:11 +02:00
fix(wireguard): support IPv6 address formatting from config files (#3273)
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user