Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2p/nat: handle responses with alternative port in NAT-PMP #26321

Merged
merged 5 commits into from
Dec 7, 2022

Conversation

dbadoy
Copy link
Contributor

@dbadoy dbadoy commented Dec 7, 2022

For NAT-PMP, returns success with an available port if the requested port is already preempted. If this situation occurs, the current implementation considers it a success and performs the remaining tasks, but in practice, communication with external network nodes is impossible, and it is difficult to track down this issue.
This PR adds check logic for preempted ports and define this situation as an error.

ref: rfc6886 p.12, p.29

Copy link
Contributor

@fjl fjl left a comment

Choose a reason for hiding this comment

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

Good catch! I've changed the wording from 'preempted' to 'already mapped'.

@fjl fjl changed the title p2p/nat: handle preempted port number in natpmp p2p/nat: handle preempted port number in NAT-PMP Dec 7, 2022
@fjl fjl changed the title p2p/nat: handle preempted port number in NAT-PMP p2p/nat: handle responses with alternative port in NAT-PMP Dec 7, 2022
@dbadoy
Copy link
Contributor Author

dbadoy commented Dec 7, 2022

Thanks, that's more neat.
However, this error occurred because the request's external port was already mapped. How about including the external port in the error instead of the internal port?

@fjl
Copy link
Contributor

fjl commented Dec 7, 2022

You're right, it's better to mention the external port. I got confused.

@fjl
Copy link
Contributor

fjl commented Dec 7, 2022

Another thing, while this is a good fix, it'd be so much nicer to actually handle the alternative port returned by the router and use it, instead of abandoning the mapping. Same for UPnP.

At the time when p2p/nat was introduced we had no way of doing that, but things have changed. Nowadays the announced endpoint is managed by enode.LocalNode, and we could absolutely set the external port to a different one on that. Let me know if you are interested in implementing this functionality.

@dbadoy
Copy link
Contributor Author

dbadoy commented Dec 7, 2022

Nice. I would like to implement that. Shall I close this PR and make a new one?

@fjl
Copy link
Contributor

fjl commented Dec 7, 2022

Nice that you want to look into it. Let's just merge this fix now, and then see how it goes with the other idea.

@fjl fjl merged commit 4221280 into ethereum:master Dec 7, 2022
@fjl fjl added this to the 1.11.0 milestone Dec 7, 2022
shekhirin pushed a commit to shekhirin/go-ethereum that referenced this pull request Jun 6, 2023
nibty pushed a commit to FairCrypto/go-ethereum that referenced this pull request Apr 10, 2024
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.

2 participants