Let the kernel takes care of assigning the port ID of the netlink socket on Linux#1169
Open
Let the kernel takes care of assigning the port ID of the netlink socket on Linux#1169
Conversation
Let the kernel takes care of assigning the port ID of the netlink socket
hamishcoleman
pushed a commit
to hamishcoleman/n3n
that referenced
this pull request
Mar 27, 2024
Let the kernel takes care of assigning the port ID of the netlink socket.
The netlink socket id uses the same namespace in all docker containers,
so if the userspace code assigns the nl_pid then there is a possiblity
of a collision, resulting in errors like:
"Could not bind NETLINK socket: Address already in use [98]"
Cherry-picked from 0df939ed5b0a7013a73f2df78f6a805b5ec555b3 in ntop/n2n#1169
Thanks @sbrodeur
Contributor
|
Just in case github didnt send you the update, I have merged your fix into the recently released fork n3n - Thanks! |
pull bot
pushed a commit
to langyo/n2n
that referenced
this pull request
May 2, 2025
Let the kernel takes care of assigning the port ID of the netlink socket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Let the kernel takes care of assigning the port ID of the netlink socket on Linux.
I had a problem where I couldn't start an n2n edge node under Docker, because it happened that the netlink socket created by n2n with port ID set to the internal process ID would conflict another process on the host. I would get an error like "Could not bind NETLINK socket: Address already in use [98]". This is because the container's process has two process IDs, one that for inside the container and the another in the host. By calling getpid() from inside the container, n2n seems to get the internal process ID rather than an unique process ID on the host. The error did not occurred when running the n2n edge node on the host (i.e. without Docker), because then the process ID obtained would be unique, and so the port ID of the netlink socket.
As per the documentation from https://man7.org/linux/man-pages/man7/netlink.7.html :
If the application sets nl_pid before calling bind(2), then it is up to
the application to make sure that nl_pid is unique. If the
application sets it to 0, the kernel takes care of assigning it.
The kernel assigns the process ID to the first netlink socket the
process opens and assigns a unique nl_pid to every netlink socket
that the process subsequently creates.
It seems it would be best for the application to set the port ID to 0 and let the kernel handle this.
Please sign (check) the below before submitting the Pull Request:
Link to the related issue:
Describe changes: