From b091076bae457743fa4358ff0e149b25c3f3c43a Mon Sep 17 00:00:00 2001 From: lunafe <45958598+lunafe@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:03:29 +0800 Subject: [PATCH] fix #2970 parsing IPv6 address in wireguard peers configure --- proxy/wireguard/client.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/proxy/wireguard/client.go b/proxy/wireguard/client.go index 2560c538..4136525e 100644 --- a/proxy/wireguard/client.go +++ b/proxy/wireguard/client.go @@ -254,7 +254,6 @@ func (h *Handler) makeVirtualTun(bind *netBindClient) (Tunnel, error) { return t, nil } - // serialize the config into an IPC request func (h *Handler) createIPCRequest(bind *netBindClient, conf *DeviceConfig) string { var request strings.Builder @@ -275,8 +274,11 @@ func (h *Handler) createIPCRequest(bind *netBindClient, conf *DeviceConfig) stri request.WriteString(fmt.Sprintf("preshared_key=%s\n", peer.PreSharedKey)) } - split := strings.Split(peer.Endpoint, ":") - addr := net.ParseAddress(split[0]) + address, port, err := net.SplitHostPort(peer.Endpoint) + if err != nil { + newError("failed to split endpoint ", peer.Endpoint, " into address and port").AtError().WriteToLog() + } + addr := net.ParseAddress(address) if addr.Family().IsDomain() { dialerIp := bind.dialer.DestIpAddress() if dialerIp != nil { @@ -306,7 +308,7 @@ func (h *Handler) createIPCRequest(bind *netBindClient, conf *DeviceConfig) stri } if peer.Endpoint != "" { - request.WriteString(fmt.Sprintf("endpoint=%s:%s\n", addr, split[1])) + request.WriteString(fmt.Sprintf("endpoint=%s:%s\n", addr, port)) } for _, ip := range peer.AllowedIps {