Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Add a safer version of WithNetNS* #2475

Merged
merged 5 commits into from
Oct 26, 2016
Merged

Add a safer version of WithNetNS* #2475

merged 5 commits into from
Oct 26, 2016

Conversation

brb
Copy link
Contributor

@brb brb commented Aug 10, 2016

This PR introduces a safe version of WithNetNS*. The new function executes work() by shelling out weaveutil which before executing it enters a given network namespace via nsenter.

Also, the PR replaces the usage of WithNetNS*Unsafe with the newly introduced function where needed.

Fixes #2419

@brb brb added this to the 1.7.0 milestone Aug 23, 2016
@brb brb assigned awh Aug 23, 2016
@brb
Copy link
Contributor Author

brb commented Aug 23, 2016

PTAL.

@brb brb force-pushed the issues/2419-withnetns branch from 6b3a67f to 4b44bce Compare September 14, 2016 14:09
@awh awh modified the milestones: 1.7.0, 1.8.0 Sep 23, 2016
@awh awh assigned brb and unassigned awh Sep 28, 2016
Copy link
Member

@rade rade left a comment

Choose a reason for hiding this comment

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

^

return err == nil
}

func AttachContainer(ns netns.NsHandle, id, ifName, bridgeName string, mtu int, withMulticastRoute bool, cidrs []*net.IPNet, keepTXOn bool) error {
func AttachContainer(ns netns.NsHandle, nsPath, id, ifName, bridgeName string, mtu int, withMulticastRoute bool, cidrs []*net.IPNet, keepTXOn bool) error {

This comment was marked as abuse.

This comment was marked as abuse.

@bboreham
Copy link
Contributor

bboreham commented Oct 6, 2016

I squashed the commits in this PR, in branch issues/2419-withnetns
If #2541 lands I will rebase on top of that

@bboreham bboreham removed their assignment Oct 6, 2016
@awh awh assigned brb and unassigned brb Oct 12, 2016
@brb brb force-pushed the issues/2419-withnetns branch from 4b44bce to 1755ec7 Compare October 19, 2016 15:06
brb added 2 commits October 19, 2016 16:07
The subcommands are going to be used with WithNetNS wrapper.
- Make them safe by using the safe version of WithNetNS.
- Improve naming.
@brb brb force-pushed the issues/2419-withnetns branch from 1755ec7 to 3492cd9 Compare October 19, 2016 15:15
@brb
Copy link
Contributor Author

brb commented Oct 19, 2016

PTAL. A few things:

  • I'm in favor of getting rid of all occurrences ofWithNetNS*Unsafe as unaware users might trip over it.
  • ParseNetDev is ugly. Open to suggestions.
  • If moving NetDev pieces from common/ to net/ clogs reviewing, I will remove the corresponding commit from this PR.

@brb brb removed their assignment Oct 19, 2016
@brb brb force-pushed the issues/2419-withnetns branch from cebd490 to e611f04 Compare October 19, 2016 16:02
@brb brb assigned awh Oct 19, 2016
Copy link
Contributor

@awh awh left a comment

Choose a reason for hiding this comment

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

I'm in favor of getting rid of all occurrences of WithNetNS*Unsafe as unaware users might trip over it.

Are you talking about the three remaining usages of WithNetNSLinkUnsafe in cni.go and netns.go? File a separate issue.

ParseNetDev is ugly. Open to suggestions.

As mentioned in the comments, list-netdev should print out JSON encoded Dev structs (actually, I think there is a general principle here that all the utility executables should communicate by receiving and emitting JSON encoded structs the definitions of which are shared with the caller, but that's a separate conversation)


// listNetDevs outputs network ifaces identified by the given indexes
// in the format of weavenet.Dev.
func listNetDevs(args []string) error {

This comment was marked as abuse.

This comment was marked as abuse.

return fmt.Sprintf("%s %s %s", d.Name, d.MAC, d.CIDRs)
}

func ParseNetDev(netdev string) (Dev, error) {

This comment was marked as abuse.

if err != nil {
return nil, fmt.Errorf("list-netdevs failed: %s", err)
}
for _, netdevStr := range strings.Split(netdevsStr, "\n") {

This comment was marked as abuse.

@awh awh removed their assignment Oct 20, 2016
@awh awh assigned brb Oct 20, 2016
@bboreham
Copy link
Contributor

We don't really need to change addrs.go or proc-addrs.go; they concentrate all their namespace-changing in one region. And if you don't do that then a lot of the rest of the complexity goes away.

@brb
Copy link
Contributor Author

brb commented Oct 20, 2016

As mentioned above, I'm in favor of getting rid of WithNetNS*Unsafe for safety reasons. Therefore I made the changes to addrs.go and proc-addrs.go.

@brb brb mentioned this pull request Oct 20, 2016
@brb brb force-pushed the issues/2419-withnetns branch from 9751455 to 9754da1 Compare October 20, 2016 17:18
@brb
Copy link
Contributor Author

brb commented Oct 20, 2016

PTAL. I've create #2556 to track removal of WithNetNS*Unsafe.

@brb brb removed their assignment Oct 20, 2016
@brb brb assigned awh Oct 20, 2016
@awh awh merged commit a5ff7ab into master Oct 26, 2016
@awh awh deleted the issues/2419-withnetns branch October 26, 2016 12:50
brb added a commit that referenced this pull request Nov 3, 2016
This reverts commit a5ff7ab, reversing
changes made to 04a6e6d.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants