NM-363: prevent restart loop on repeated IPv6 endpoint detection#1335
NM-363: prevent restart loop on repeated IPv6 endpoint detection#1335abhishek9686 wants to merge 1 commit into
Conversation
|
Review Complete Files Reviewed: 3 By Severity:
PR adds IP seeding from stored endpoints and an IPsEqual utility for address normalization across daemon.go, mqpublish.go, and netclientutils.go. One minor finding: dead code seeding of HostPublicIP/HostPublicIP6 in daemon.go that gets immediately overwritten. Files Reviewed (3 files) |
There was a problem hiding this comment.
Risk: 🟢 Low (18/100) — 1 low finding · 61 LOC across 3 files
Overview
This PR modifies 3 files to improve network address consistency:
functions/daemon.go: Seedsconfig.HostPublicIP/HostPublicIP6from stored endpoints before hole punching, and uses the newIPsEqualutility in the checkin ticker to avoid unnecessary daemon restarts.functions/mqpublish.go: Seedsconfig.HostPublicIP/HostPublicIP6during checkin and usesIPsEqualto compare addresses.ncutils/netclientutils.go: AddsIPsEqual()utility that normalizes IP addresses viaTo16()before comparison, correctly handling IPv4-mapped IPv6.
Findings
finding-001 (low): Dead code seeding in daemon.go:215-220
The seeded HostPublicIP/HostPublicIP6 values are unconditionally overwritten by holePunchWgPort() calls at lines 222 and 239 before any downstream code can read them. The existing fallback logic in the else branches already restores from stored endpoints on failure, making the new seed lines dead code. Remove lines 215-220.
Borderline (confidence 78, not included)
The IPsEqual normalization used in the checkin ticker is not used in the hostServerUpdate publish path, which still uses raw net.IP.Equal(). This could cause a spurious MQTT publish if an IPv4-mapped representation leaks into HostPublicIP. Self-correcting but wasteful.
| if netclientCfg.EndpointIP != nil { | ||
| config.HostPublicIP = netclientCfg.EndpointIP | ||
| } | ||
| if netclientCfg.EndpointIPv6 != nil { | ||
| config.HostPublicIP6 = netclientCfg.EndpointIPv6 | ||
| } |
There was a problem hiding this comment.
🟢 Dead EndpointIP→HostPublicIP/HostPublicIP6 seeding code in daemon.go startGoRoutines (bug)
The PR adds seeding of config.HostPublicIP and config.HostPublicIP6 from stored netclientCfg.EndpointIP/EndpointIPv6 in daemon.go:startGoRoutines (lines 215-220). These assignments are immediately overwritten by synchronous holePunchWgPort() calls at line 222 (IPv4) and lines 239-254 (IPv6), before any goroutine or downstream code can read the seeded values. The existing fallback logic in the else branches (lines 229-232 for IPv4, lines 250-253 for IPv6) already restores HostPublicIP/HostPublicIP6 from the stored endpoints when hole punching fails, making the new lines 215-220 entirely dead code. In contrast, the same seeding pattern in mqpublish.go:Checkin (lines 69-76) is effective because it precedes hostServerUpdate without an immediate synchronous overwrite.
💡 Suggestion: Remove the dead seeding block at daemon.go:215-220. The fallback logic at lines 229-232 (IPv4) and 250-253 (IPv6) already handles seeding HostPublicIP/HostPublicIP6 from stored endpoints when hole punching fails.
📋 Prompt for AI Agents
In functions/daemon.go, remove lines 215-220 (the if blocks that seed config.HostPublicIP and config.HostPublicIP6 from netclientCfg.EndpointIP and netclientCfg.EndpointIPv6). These assignments are dead code: line 222 unconditionally overwrites config.HostPublicIP with the holePunchWgPort result, and the existing else branches at lines 229-232 and 250-253 already restore these values from stored endpoints on hole-punch failure.
Describe your changes
Provide Issue ticket number if applicable/not in title
Provide link to Netmaker PR if required
Provide testing steps
Checklist before requesting a review