fix: update extclient ingress endpoint/port with host changes

This commit is contained in:
the_aceix 2025-06-17 15:09:31 +00:00
parent 8fc489b5a6
commit 91c5fe0cf3
3 changed files with 18 additions and 0 deletions

View file

@ -308,6 +308,7 @@ func updateHost(w http.ResponseWriter, r *http.Request) {
}
}
}()
logic.LogEvent(&models.Event{
Action: models.Update,
Source: models.Subject{

View file

@ -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(),

View file

@ -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)
}
}