Skip to content

Generate config: Properly handle ipv6 endpoints #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,29 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G

desiredHost := setting.EndpointAddress
desiredPort := server.Interface.ListenPort
if strings.Contains(desiredHost, ":") {
split := strings.Split(desiredHost, ":")
desiredHost = split[0]
if n, err := strconv.Atoi(split[1]); err == nil {
desiredPort = n
is_ipv4 := strings.Contains(desiredHost, ".")
if is_ipv4 {
if strings.Contains(desiredHost, ":") {
split := strings.Split(desiredHost, ":")
desiredHost = split[0]
if n, err := strconv.Atoi(split[1]); err == nil {
desiredPort = n
} else {
log.Error("Endpoint appears to be incorrectly formatted: ", err)
}
}
} else {
if strings.Contains(desiredHost, "]") {
// IPv6 with port
split := strings.Split(desiredHost, "]")
desiredHost = split[0] + "]"
if n, err := strconv.Atoi(split[1][1:]); err == nil {
desiredPort = n
} else {
log.Error("Endpoint appears to be incorrectly formatted: ", err)
}
} else {
log.Error("Endpoint appears to be incorrectly formatted: ", err)
desiredHost = "[" + desiredHost + "]"
}
}
peerEndpoint := fmt.Sprintf("Endpoint = %s:%d\n", desiredHost, desiredPort)
Expand Down