Let the kernel takes care of assigning the port ID of the netlink socket on Linux #1169
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: