github.com/cloudfoundry-attic/garden-linux@v0.333.2-candidate/network/devices/veth.go (about) 1 package devices 2 3 import ( 4 "fmt" 5 "net" 6 7 "github.com/docker/libcontainer/netlink" 8 ) 9 10 type VethCreator struct{} 11 12 func (VethCreator) Create(hostIfcName, containerIfcName string) (host, container *net.Interface, err error) { 13 netlinkMu.Lock() 14 defer netlinkMu.Unlock() 15 16 if err := netlink.NetworkCreateVethPair(hostIfcName, containerIfcName, 1); err != nil { 17 return nil, nil, fmt.Errorf("devices: create veth pair: %v", err) 18 } 19 20 if host, err = net.InterfaceByName(hostIfcName); err != nil { 21 return nil, nil, fmt.Errorf("devices: look up created host interface: %v", err) 22 } 23 24 if container, err = net.InterfaceByName(containerIfcName); err != nil { 25 return nil, nil, fmt.Errorf("devices: look up created container interface: %v", err) 26 } 27 28 return host, container, nil 29 }