-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: net: Add control callback before connection creation to Dialer and ListenConfig #54314
Comments
Can you explain exactly which system calls must be made with the new namespace, and which can be made with the original namespace? For example, are you saying that If that is the distinction, can't we use the existing Thanks. |
Yes. AFAIK of linux, a socket is bound to the thread's namespace at creation time. Once created, it's OK for
|
Just to be sure I'm clear, it sounds like the problem is that you want to set the namespace before calling If I understand correctly, then the code you show above won't work, because |
Yes, exactly.
Yes. The |
Background
Sometimes we need to dial inside another net namespace and switch back. On linux, namespace is thread-level, so a thread lock is needed.
With
"github.com/vishvananda/netns"
for example:However, this blocks the current thread until
Dial()
returns. A workaround may be moving the unlocking stuff intodialer.Control
:This doesn't work well because
dialParallel()
dials in new goroutines which are out of control.Proposal
Add callback before and after the connection (socket) is created in
net.Dialer
:The call of
PreControl - PostControl
pair should be in the same goroutine and surround the socket syscall.PostControl
should be called regardless of whether the conn is successfully created.Similar thing can be done with
net.ListenConfig
.The text was updated successfully, but these errors were encountered: