Skip to content

p2p/nat: use default route for nat-pmp gateway#35069

Open
jackg22 wants to merge 1 commit into
ethereum:masterfrom
jackg22:codex/natpmp-default-gateway
Open

p2p/nat: use default route for nat-pmp gateway#35069
jackg22 wants to merge 1 commit into
ethereum:masterfrom
jackg22:codex/natpmp-default-gateway

Conversation

@jackg22

@jackg22 jackg22 commented May 28, 2026

Copy link
Copy Markdown

Summary

  • prefer discovered default gateways for NAT-PMP on Linux by parsing /proc/net/route
  • keep the existing X.X.X.1 heuristic as a fallback and de-duplicate guessed gateways
  • add Linux unit tests for the route-table parsing helpers

Why

potentialGateways currently assumes that a router lives at .1 within each private IPv4 subnet. That works on many home networks, but it misses common setups where the default gateway uses another address such as .254. NAT-PMP discovery then probes the wrong host and fails even though a working gateway exists.

This change makes Linux use the actual default route first, while preserving the current fallback behavior on other platforms and when route discovery is unavailable.

Validation

  • gofmt -w p2p/nat/natpmp.go p2p/nat/natpmp_gateway_linux.go p2p/nat/natpmp_gateway_linux_test.go p2p/nat/natpmp_gateway_other.go
  • go test ./p2p/nat
  • GOOS=linux GOARCH=amd64 go test -c ./p2p/nat

@jackg22 jackg22 marked this pull request as ready for review May 30, 2026 17:24
@jackg22 jackg22 requested review from fjl and zsfelfoldi as code owners May 30, 2026 17:24
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