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

netns: add documentation on how to go back on default netns #590

Merged
merged 1 commit into from Mar 1, 2019

Conversation

ffourcot
Copy link
Collaborator

@ffourcot ffourcot commented Mar 1, 2019

Hello,

I didn't find any reference in the documentation for this annoying thing. There is perhaps a better way, but in all cases I think that it's a good idea to add documentation on it.

@@ -222,6 +222,11 @@ def setns(netns, flags=os.O_CREAT, libc=None):
- O_CREAT -- create netns, if doesn't exist
- O_CREAT | O_EXCL -- create only if doesn't exist

Note that "main" netns as no name. But you can access it with::
Copy link
Owner

Choose a reason for hiding this comment

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

… has no name

@svinota
Copy link
Owner

svinota commented Mar 1, 2019

Another way is to open /proc/self/ns/net, save the fd, and switch back with setns(). This allows to revert to own namespace even if it was not the main one.

@svinota
Copy link
Owner

svinota commented Mar 1, 2019

Probably I have to dump it also to the docstring.

svinota added a commit that referenced this pull request Mar 1, 2019
- pushns() -- save the current netns
- popns() -- restore the last saved
- dropns() -- discard the last saved

Bug-Url: #590
@svinota
Copy link
Owner

svinota commented Mar 1, 2019

As an idea, looks at the commit — e7810d9

@svinota svinota merged commit c88a54b into svinota:master Mar 1, 2019
svinota added a commit that referenced this pull request Mar 1, 2019
@ffourcot
Copy link
Collaborator Author

ffourcot commented Mar 4, 2019

Thank you!

@svinota
Copy link
Owner

svinota commented Mar 4, 2019

Thank you for the issue. I had to implement it a long time ago, but didn't.

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.

None yet

2 participants