Skip to content

NM-363: prevent restart loop on repeated IPv6 endpoint detection#1335

Draft
abhishek9686 wants to merge 1 commit into
release-v1.6.0from
NM-363
Draft

NM-363: prevent restart loop on repeated IPv6 endpoint detection#1335
abhishek9686 wants to merge 1 commit into
release-v1.6.0from
NM-363

Conversation

@abhishek9686

Copy link
Copy Markdown
Member

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

  • My changes affect only 10 files or less.
  • I have performed a self-review of my code and tested it.
  • If it is a new feature, I have added thorough tests, my code is <= 1450 lines.
  • If it is a bugfix, my code is <= 200 lines.
  • My functions are <= 80 lines.
  • I have had my code reviewed by a peer.
  • My unit tests pass locally.
  • Netclient & Netmaker are awesome.

@tenki-reviewer

tenki-reviewer Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Complete

Files Reviewed: 3
Findings: 1

By Severity:

  • 🟢 Low: 1

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)
functions/daemon.go
functions/mqpublish.go
ncutils/netclientutils.go

@tenki-reviewer tenki-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: Seeds config.HostPublicIP/HostPublicIP6 from stored endpoints before hole punching, and uses the new IPsEqual utility in the checkin ticker to avoid unnecessary daemon restarts.
  • functions/mqpublish.go: Seeds config.HostPublicIP/HostPublicIP6 during checkin and uses IPsEqual to compare addresses.
  • ncutils/netclientutils.go: Adds IPsEqual() utility that normalizes IP addresses via To16() 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.

Comment thread functions/daemon.go
Comment on lines +215 to +220
if netclientCfg.EndpointIP != nil {
config.HostPublicIP = netclientCfg.EndpointIP
}
if netclientCfg.EndpointIPv6 != nil {
config.HostPublicIP6 = netclientCfg.EndpointIPv6
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@abhishek9686 abhishek9686 marked this pull request as draft June 24, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant