-
Notifications
You must be signed in to change notification settings - Fork 881
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
Remove dynamic mac entry from fdb on endpoint deletion #1792
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,18 @@ package overlay | |
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
"syscall" | ||
|
||
"github.com/Sirupsen/logrus" | ||
"github.com/docker/docker/pkg/reexec" | ||
"github.com/docker/libnetwork/datastore" | ||
"github.com/docker/libnetwork/driverapi" | ||
"github.com/docker/libnetwork/netlabel" | ||
|
@@ -67,6 +70,54 @@ type network struct { | |
sync.Mutex | ||
} | ||
|
||
func init() { | ||
reexec.Register("set-default-vlan", setDefaultVlan) | ||
} | ||
|
||
func setDefaultVlan() { | ||
if len(os.Args) < 3 { | ||
logrus.Error("insufficient number of arguments") | ||
os.Exit(1) | ||
} | ||
nsPath := os.Args[1] | ||
ns, err := netns.GetFromPath(nsPath) | ||
if err != nil { | ||
logrus.Errorf("overlay namespace get failed, %v", err) | ||
os.Exit(1) | ||
} | ||
if err = netns.Set(ns); err != nil { | ||
logrus.Errorf("setting into overlay namespace failed, %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// make sure the sysfs mount doesn't propagate back | ||
if err = syscall.Unshare(syscall.CLONE_NEWNS); err != nil { | ||
logrus.Errorf("unshare failed, %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
flag := syscall.MS_PRIVATE | syscall.MS_REC | ||
if err = syscall.Mount("", "/", "", uintptr(flag), ""); err != nil { | ||
logrus.Errorf("root mount failed, %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
if err = syscall.Mount("sysfs", "/sys", "sysfs", 0, ""); err != nil { | ||
logrus.Errorf("mounting sysfs failed, %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
brName := os.Args[2] | ||
path := filepath.Join("/sys/class/net", brName, "bridge/default_pvid") | ||
data := []byte{'0', '\n'} | ||
|
||
if err = ioutil.WriteFile(path, data, 0644); err != nil { | ||
logrus.Errorf("endbling default vlan on bridge %s failed %v", brName, err) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} | ||
|
||
func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) { | ||
return nil, types.NotImplementedErrorf("not implemented") | ||
} | ||
|
@@ -505,6 +556,25 @@ func (n *network) setupSubnetSandbox(s *subnet, brName, vxlanName string) error | |
return fmt.Errorf("vxlan interface creation failed for subnet %q: %v", s.subnetIP.String(), err) | ||
} | ||
|
||
if !hostMode { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this specific to non-hostMode ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reexec is to avoid calling the potential blocking sysfs mount operations causing the namespace corruption. Its not needed in the hostmode since there is no per overlay network namespace. But in the hostmode also we might have to set the default-vlan, directly from the daemon without a reexec. I will do that in a separate PR after trying out in the hostmode. |
||
var name string | ||
for _, i := range sbox.Info().Interfaces() { | ||
if i.Bridge() { | ||
name = i.DstName() | ||
} | ||
} | ||
cmd := &exec.Cmd{ | ||
Path: reexec.Self(), | ||
Args: []string{"set-default-vlan", sbox.Key(), name}, | ||
Stdout: os.Stdout, | ||
Stderr: os.Stderr, | ||
} | ||
if err := cmd.Run(); err != nil { | ||
// not a fatal error | ||
logrus.Errorf("reexec to set bridge default vlan failed %v", err) | ||
} | ||
} | ||
|
||
if hostMode { | ||
if err := addFilters(n.id[:12], brName); err != nil { | ||
return err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope this works equally well across multiple Distros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested Ubuntu 15.10 running 4.2 kernel and 3.19 kernel. And Centos running 3.10.0-327.10.1.el7.x86_64.