Esempio n. 1
0
func (v *veth) create(n *network, nspid int) (err error) {
	tmpName, err := v.generateTempPeerName()
	if err != nil {
		return err
	}
	n.TempVethPeerName = tmpName
	defer func() {
		if err != nil {
			netlink.NetworkLinkDel(n.HostInterfaceName)
			netlink.NetworkLinkDel(n.TempVethPeerName)
		}
	}()
	if n.Bridge == "" {
		return fmt.Errorf("bridge is not specified")
	}
	if err := netlink.NetworkCreateVethPair(n.HostInterfaceName, n.TempVethPeerName, n.TxQueueLen); err != nil {
		return err
	}
	if err := v.attach(&n.Network); err != nil {
		return err
	}
	child, err := net.InterfaceByName(n.TempVethPeerName)
	if err != nil {
		return err
	}
	return netlink.NetworkSetNsPid(child, nspid)
}
Esempio n. 2
0
// DeleteLink deletes link interface on Linux host.
// It is equivalent of running: ip link delete dev ${interface name}
func (l *Link) DeleteLink() error {
	return netlink.NetworkLinkDel(l.NetInterface().Name)
}
Esempio n. 3
0
// DeleteLink deletes netowrk link from Linux Host
// It is equivalent of running: ip link delete dev ${name}
func DeleteLink(name string) error {
	return netlink.NetworkLinkDel(name)
}
Esempio n. 4
0
// DeletePeerLink deletes peer link. It also deletes the other peer interface in VethPair
func (veth *VethPair) DeletePeerLink() error {
	return netlink.NetworkLinkDel(veth.peerIfc.Name)
}