Skip to content

[r3.5] p2p: re-resolve STUN external IP at runtime#22188

Merged
AskAlexSharov merged 2 commits into
release/3.5from
cp/22105-to-3.5
Jul 3, 2026
Merged

[r3.5] p2p: re-resolve STUN external IP at runtime#22188
AskAlexSharov merged 2 commits into
release/3.5from
cp/22105-to-3.5

Conversation

@lystopad

@lystopad lystopad commented Jul 3, 2026

Copy link
Copy Markdown
Member

Cherry-pick of #22105 to release/3.5.

nat=stun resolved the public IP only once at startup, so a node whose public IP changed while running (dynamic ISP IP behind a NAT router, or a directly-connected PPPoE/DHCP host) kept advertising a stale enode. This re-resolves every 10 minutes and applies the address only when it changes to a usable (global-unicast, non-private) value, committed via SetStaticIP so the spoofable discovery endpoint predictor cannot override it. Other NAT modes (none, extip, upnp, pmp) are untouched.

Includes the follow-up global-unicast validation tightening from the same PR.

Clean cherry-pick (rebased onto current release/3.5; the two touched files do not overlap the intervening changes).

Not included

The OS network-change event trigger (#22112, netlink/route-socket/IP-Helper) is still in review on main and will be backported separately once merged. This backport is the poll-based fix only, which is complete and correct on its own.

Verification

  • go test ./p2p/ -race — pass
  • make lint (p2p) — 0 issues
  • builds on the release/3.5 base

lystopad added 2 commits July 3, 2026 08:52
nat=stun resolved the public IP only once at startup, so a node whose
public IP changed while running (dynamic ISP IP behind a NAT router, or a
directly-connected PPPoE/DHCP host) kept advertising a stale enode.

Add a tracker scoped to the nat.STUN case that re-resolves every 10
minutes and applies the address only when it changes. The value is set
via SetStaticIP (authoritative), so the spoofable discovery endpoint
predictor cannot override it, and the resolved IP is validated before it
reaches the local record. Other NAT modes (none, extip, upnp, pmp) are
left untouched.

Follow-up (separate PR): trigger an immediate, rate-limited re-resolve
from OS network-change events (netlink/route socket/IP Helper) to cut
detection latency on directly-connected dynamic-IP hosts.
Reject the IPv4 broadcast address and other non-unicast specials by
requiring IsGlobalUnicast (which excludes broadcast/multicast/loopback/
unspecified/link-local) while still excluding private ranges.
@AskAlexSharov AskAlexSharov merged commit 6dedc17 into release/3.5 Jul 3, 2026
90 checks passed
@AskAlexSharov AskAlexSharov deleted the cp/22105-to-3.5 branch July 3, 2026 08:35
@lystopad lystopad self-assigned this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants