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

pkg/ns: verify netns when initialized with GetNS #222

Merged
merged 3 commits into from
May 25, 2016
Merged

pkg/ns: verify netns when initialized with GetNS #222

merged 3 commits into from
May 25, 2016

Conversation

steveej
Copy link
Member

@steveej steveej commented May 24, 2016

Fixes #221.


return &netNS{
file: fd,
mounted: stat.Type == NSFS_MAGIC,
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't set mounted:true for plain GetNS() calls. The reason is because only the creator of the netns should be disposing of it via ns.Close(), and things that call GetNS() are the creator. I think all you want to do here is return an error if the mountpoint is not an NSFS mount point.

@dcbw
Copy link
Member

dcbw commented May 24, 2016

My take on this would be https://github.com/dcbw/cni/commits/namespace-validate ...

}

isNSFS, err := IsNSFS(nspath)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Still need to close the FD here on error return.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@dcbw
Copy link
Member

dcbw commented May 24, 2016

LGTM now, but how about some tests like:

        It("fails when the path is not a namespace", func() {
            tempFile, err := ioutil.TempFile("", "nstest")
            Expect(err).NotTo(HaveOccurred())
            defer tempFile.Close()
            defer os.Remove(tempFile.Name())

            _, err = ns.GetNS(tempFile.Name())
            Expect(err).To(MatchError(fmt.Sprintf("no network namespace mounted on file %q", tempFile.Name())))
        })

@steveej
Copy link
Member Author

steveej commented May 24, 2016

LGTM now, but how about some tests like:

Right, always good to have more tests! I fleshed your draft out and added a test case.

@dcbw
Copy link
Member

dcbw commented May 24, 2016

Right, always good to have more tests! I fleshed your draft out and added a test case.

Thanks, test LGTM.

@steveej steveej merged commit 6fb30a6 into containernetworking:master May 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants