plugins/ptp: allow host veth to be UP

This commit is contained in:
Stefan Junker 2015-09-23 11:03:22 +02:00
parent 6737bc8207
commit 231d2d5a27
2 changed files with 7 additions and 7 deletions

View File

@ -77,8 +77,9 @@ func RandomVethName() (string, error) {
return fmt.Sprintf("veth%x", entropy), nil return fmt.Sprintf("veth%x", entropy), nil
} }
// SetupVeth sets up a virtual ethernet link. // SetupVeth creates the virtual ethernet pair and sets up the container's end in the container netns.
// Should be in container netns. // Setting up the host end up has to be done in the host netns outside of this function.
// This is because moving the host veth end will cause it to be brought down automatically when it is moved to the host netns.
func SetupVeth(contVethName string, mtu int, hostNS *os.File) (hostVeth, contVeth netlink.Link, err error) { func SetupVeth(contVethName string, mtu int, hostNS *os.File) (hostVeth, contVeth netlink.Link, err error) {
var hostVethName string var hostVethName string
hostVethName, contVeth, err = makeVeth(contVethName, mtu) hostVethName, contVeth, err = makeVeth(contVethName, mtu)
@ -97,11 +98,6 @@ func SetupVeth(contVethName string, mtu int, hostNS *os.File) (hostVeth, contVet
return return
} }
if err = netlink.LinkSetUp(hostVeth); err != nil {
err = fmt.Errorf("failed to set %q up: %v", contVethName, err)
return
}
if err = netlink.LinkSetNsFd(hostVeth, int(hostNS.Fd())); err != nil { if err = netlink.LinkSetNsFd(hostVeth, int(hostNS.Fd())); err != nil {
err = fmt.Errorf("failed to move veth to host netns: %v", err) err = fmt.Errorf("failed to move veth to host netns: %v", err)
return return

View File

@ -128,6 +128,10 @@ func setupHostVeth(vethName string, ipConf *types.IPConfig) error {
return fmt.Errorf("failed to lookup %q: %v", vethName, err) return fmt.Errorf("failed to lookup %q: %v", vethName, err)
} }
if err = netlink.LinkSetUp(veth); err != nil {
return fmt.Errorf("failed to set %q up: %v", vethName, err)
}
// TODO(eyakubovich): IPv6 // TODO(eyakubovich): IPv6
ipn := &net.IPNet{ ipn := &net.IPNet{
IP: ipConf.Gateway, IP: ipConf.Gateway,