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

Named namespaces #26

Closed
planetA opened this issue Jul 1, 2018 · 5 comments
Closed

Named namespaces #26

planetA opened this issue Jul 1, 2018 · 5 comments

Comments

@planetA
Copy link

planetA commented Jul 1, 2018

Hello,

is there a way to create a named network namespace? I mean the one that I can see in ip netns.

@ghost
Copy link

ghost commented Aug 5, 2018

We do this manually right now, here's the code:

        if err := syscall.Unshare(syscall.CLONE_NEWNET); err != nil {
                return err
        }
        p := path.Join("/var/run/netns/", netname)
        f, err := os.OpenFile(p, os.O_CREATE | os.O_EXCL, 0444)
        if err != nil {
                return err
        }
        f.Close()
        if err := syscall.Mount("/proc/self/ns/net", p, "bind", syscall.MS_BIND, ""); err != nil {
                return err
        }

Should probably clean this up and submit a PR; maintainers, would you be interested in this?

@planetA
Copy link
Author

planetA commented Aug 5, 2018 via email

@planetA
Copy link
Author

planetA commented Aug 7, 2018

I create a named one like this:

newNsPath := "/var/run/netns"
nsPath := fmt.Sprintf("/proc/%d/task/%d/ns/net", os.Getpid(), syscall.Gettid())
err = syscall.Mount(nsPath, newNsPath, "", syscall.MS_BIND|syscall.MS_REC, "")

@ghost
Copy link

ghost commented Aug 14, 2018

Ah, that's good to know, we spawned a new process to avoid this (also because it "burns" an OS thread available to the runtime)

@jeffwidman
Copy link
Collaborator

jeffwidman commented Aug 27, 2022

I think this can be closed as fixed?

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

No branches or pull requests

2 participants