From 61065def17a5e0fe051750ff2e9933d92eeee8d1 Mon Sep 17 00:00:00 2001 From: Owen Date: Wed, 10 Dec 2025 10:34:21 -0500 Subject: [PATCH] Fix ipv6 connectivity --- olm/olm.go | 7 +++++++ olm/util.go | 43 ---------------------------------------- peers/monitor/monitor.go | 5 ++++- 3 files changed, 11 insertions(+), 44 deletions(-) diff --git a/olm/olm.go b/olm/olm.go index 1f02d8e..becd514 100644 --- a/olm/olm.go +++ b/olm/olm.go @@ -502,6 +502,13 @@ func StartTunnel(config TunnelConfig) { return } + // If the endpoint changed, trigger holepunch to refresh NAT mappings + if updateData.Endpoint != "" && updateData.Endpoint != existingPeer.Endpoint { + logger.Info("Endpoint changed for site %d, triggering holepunch to refresh NAT mappings", updateData.SiteId) + holePunchManager.TriggerHolePunch() + holePunchManager.ResetInterval() + } + // Update successful logger.Info("Successfully updated peer for site %d", updateData.SiteId) }) diff --git a/olm/util.go b/olm/util.go index 9da1f00..6bfd171 100644 --- a/olm/util.go +++ b/olm/util.go @@ -1,9 +1,6 @@ package olm import ( - "fmt" - "net" - "strings" "time" "github.com/fosrl/newt/logger" @@ -11,33 +8,6 @@ import ( "github.com/fosrl/olm/websocket" ) -// Helper function to format endpoints correctly -func formatEndpoint(endpoint string) string { - if endpoint == "" { - return "" - } - // Check if it's already a valid host:port that SplitHostPort can parse (e.g., [::1]:8080 or 1.2.3.4:8080) - _, _, err := net.SplitHostPort(endpoint) - if err == nil { - return endpoint // Already valid, no change needed - } - - // If it failed, it might be our malformed "ipv6:port" string. Let's check and fix it. - lastColon := strings.LastIndex(endpoint, ":") - if lastColon > 0 { // Ensure there is a colon and it's not the first character - hostPart := endpoint[:lastColon] - // Check if the host part is a literal IPv6 address - if ip := net.ParseIP(hostPart); ip != nil && ip.To4() == nil { - // It is! Reformat it with brackets. - portPart := endpoint[lastColon+1:] - return fmt.Sprintf("[%s]:%s", hostPart, portPart) - } - } - - // If it's not the specific malformed case, return it as is. - return endpoint -} - func sendPing(olm *websocket.Client) error { err := olm.SendMessage("olm/ping", map[string]interface{}{ "timestamp": time.Now().Unix(), @@ -83,16 +53,3 @@ func GetNetworkSettingsJSON() (string, error) { func GetNetworkSettingsIncrementor() int { return network.GetIncrementor() } - -// stringSlicesEqual compares two string slices for equality -func stringSlicesEqual(a, b []string) bool { - if len(a) != len(b) { - return false - } - for i := range a { - if a[i] != b[i] { - return false - } - } - return true -} diff --git a/peers/monitor/monitor.go b/peers/monitor/monitor.go index ac91cb3..5821ff9 100644 --- a/peers/monitor/monitor.go +++ b/peers/monitor/monitor.go @@ -192,10 +192,13 @@ func (pm *PeerMonitor) AddPeer(siteID int, endpoint string, holepunchEndpoint st // update holepunch endpoint for a peer func (pm *PeerMonitor) UpdateHolepunchEndpoint(siteID int, endpoint string) { go func() { - time.Sleep(3 * time.Second) + // Short delay to allow WireGuard peer reconfiguration to complete + // The NAT mapping refresh is handled separately by TriggerHolePunch in olm.go + time.Sleep(500 * time.Millisecond) pm.mutex.Lock() defer pm.mutex.Unlock() pm.holepunchEndpoints[siteID] = endpoint + logger.Debug("Updated holepunch endpoint for site %d to %s", siteID, endpoint) }() }