From 91c5fe0cf300e498995cd6b99f7b03c43c598181 Mon Sep 17 00:00:00 2001 From: the_aceix Date: Tue, 17 Jun 2025 15:09:31 +0000 Subject: [PATCH] fix: update extclient ingress endpoint/port with host changes --- controllers/hosts.go | 1 + pro/controllers/users.go | 6 ++++++ utils/utils.go | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/controllers/hosts.go b/controllers/hosts.go index 0d5cd4f8..e2d820d1 100644 --- a/controllers/hosts.go +++ b/controllers/hosts.go @@ -308,6 +308,7 @@ func updateHost(w http.ResponseWriter, r *http.Request) { } } }() + logic.LogEvent(&models.Event{ Action: models.Update, Source: models.Subject{ diff --git a/pro/controllers/users.go b/pro/controllers/users.go index d8722d8b..c18396cf 100644 --- a/pro/controllers/users.go +++ b/pro/controllers/users.go @@ -1304,6 +1304,12 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) { if extClient.DNS == "" { extClient.DNS = node.IngressDNS } + + extClient.IngressGatewayEndpoint = utils.GetExtClientEndpoint( + host.EndpointIP, + host.EndpointIPv6, + logic.GetPeerListenPort(host), + ) extClient.AllowedIPs = logic.GetExtclientAllowedIPs(extClient) gws = append(gws, models.UserRemoteGws{ GwID: node.ID.String(), diff --git a/utils/utils.go b/utils/utils.go index bd793a7e..c093f44e 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -1,7 +1,9 @@ package utils import ( + "fmt" "log/slog" + "net" "runtime" "strings" "time" @@ -75,3 +77,12 @@ func NoEmptyStringToCsv(strs ...string) string { } return sb.String() } + +// GetExtClientEndpoint returns the external client endpoint in the format "host:port" or "[host]:port" for IPv6 +func GetExtClientEndpoint(hostIpv4Endpoint, hostIpv6Endpoint net.IP, hostListenPort int) string { + if hostIpv4Endpoint.To4() == nil { + return fmt.Sprintf("[%s]:%d", hostIpv6Endpoint.String(), hostListenPort) + } else { + return fmt.Sprintf("%s:%d", hostIpv4Endpoint.String(), hostListenPort) + } +}