mirror of
https://github.com/gravitl/netmaker.git
synced 2026-04-22 16:07:11 +08:00
fix(go): check for overlapping ports on endpoint change;
This commit is contained in:
@@ -426,7 +426,10 @@ func handleHostRegister(w http.ResponseWriter, r *http.Request) {
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
logic.UpdateHostFromClient(&newHost, currHost)
|
||||
endpointChanged, _ := logic.UpdateHostFromClient(&newHost, currHost)
|
||||
if endpointChanged {
|
||||
logic.CheckHostPorts(currHost)
|
||||
}
|
||||
if err = logic.UpsertHost(currHost); err != nil {
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
||||
return
|
||||
|
||||
@@ -521,7 +521,11 @@ func hostUpdateFallback(w http.ResponseWriter, r *http.Request) {
|
||||
//remove old peer entry
|
||||
replacePeers = true
|
||||
}
|
||||
sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
|
||||
var endpointChanged bool
|
||||
endpointChanged, sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
|
||||
if endpointChanged {
|
||||
logic.CheckHostPorts(currentHost)
|
||||
}
|
||||
err := logic.UpsertHost(currentHost)
|
||||
if err != nil {
|
||||
slog.Error("failed to update host", "id", currentHost.ID, "error", err)
|
||||
|
||||
+1
-2
@@ -175,7 +175,7 @@ func UpdateHost(newHost, currentHost *schema.Host) {
|
||||
}
|
||||
|
||||
// UpdateHostFromClient - used for updating host on server with update recieved from client
|
||||
func UpdateHostFromClient(newHost, currHost *schema.Host) (sendPeerUpdate bool) {
|
||||
func UpdateHostFromClient(newHost, currHost *schema.Host) (isEndpointChanged, sendPeerUpdate bool) {
|
||||
if newHost.PublicKey != currHost.PublicKey {
|
||||
currHost.PublicKey = newHost.PublicKey
|
||||
sendPeerUpdate = true
|
||||
@@ -189,7 +189,6 @@ func UpdateHostFromClient(newHost, currHost *schema.Host) (sendPeerUpdate bool)
|
||||
currHost.WgPublicListenPort = newHost.WgPublicListenPort
|
||||
sendPeerUpdate = true
|
||||
}
|
||||
isEndpointChanged := false
|
||||
if !currHost.EndpointIP.Equal(newHost.EndpointIP) {
|
||||
currHost.EndpointIP = newHost.EndpointIP
|
||||
sendPeerUpdate = true
|
||||
|
||||
+5
-1
@@ -140,7 +140,11 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) {
|
||||
//remove old peer entry
|
||||
replacePeers = true
|
||||
}
|
||||
sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
|
||||
var endpointChanged bool
|
||||
endpointChanged, sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
|
||||
if endpointChanged {
|
||||
logic.CheckHostPorts(currentHost)
|
||||
}
|
||||
err := logic.UpsertHost(currentHost)
|
||||
if err != nil {
|
||||
slog.Error("failed to update host", "id", currentHost.ID, "error", err)
|
||||
|
||||
Reference in New Issue
Block a user